HIDDEN int mailbox_rename_nocopy(struct mailbox *oldmailbox,
                                 const char *newname, int silent)
{
    char quotaroot[MAX_MAILBOX_BUFFER];
    int hasquota = quota_findroot(quotaroot, sizeof(quotaroot), newname);

    /* Move any quota usage */
    int r = mailbox_changequotaroot(oldmailbox,
                                    hasquota ? quotaroot: NULL, silent);

    if (!r) {
        /* copy any mailbox annotations */
        mbentry_t newmbentry = MBENTRY_INITIALIZER;
        newmbentry.name = (char *) newname;
        struct mailbox newmailbox = { .mbentry = &newmbentry,
                                      .index_locktype = LOCK_EXCLUSIVE };
        r = annotate_rename_mailbox(oldmailbox, &newmailbox);
    }

    if (!r && mailbox_has_conversations(oldmailbox)) {
        struct conversations_state *oldcstate =
            mailbox_get_cstate(oldmailbox);

        assert(oldcstate);

        if (mboxname_isdeletedmailbox(newname, NULL)) {
            /* we never store data about deleted mailboxes */
            r = mailbox_delete_conversations(oldmailbox);
        }
        else if (oldcstate->folders_byname) {
            /* we can just rename within the same user */
            r = conversations_rename_folder(oldcstate, mailbox_name(oldmailbox), newname);
        }
        // otherwise, we don't need to rename because it's the same uniqueid
    }

    /* unless on a replica, bump the modseq */
    if (!silent) mailbox_modseq_dirty(oldmailbox);

    /* update the name in the header */
    xzfree(oldmailbox->h.name);
    oldmailbox->h.name = xstrdup(newname);
    oldmailbox->header_dirty = 1;

    return r;
}
HIDDEN int mailbox_rename_nocopy(struct mailbox *oldmailbox,
                                 const char *newname, int silent)
{
    char quotaroot[MAX_MAILBOX_BUFFER];
    int hasquota = quota_findroot(quotaroot, sizeof(quotaroot), newname);

     
    int r = mailbox_changequotaroot(oldmailbox,
                                    hasquota ? quotaroot: NULL, silent);

    if (!r) {
         
        mbentry_t newmbentry = MBENTRY_INITIALIZER;
        newmbentry.name = (char *) newname;
        struct mailbox newmailbox = { .mbentry = &newmbentry,
                                      .index_locktype = LOCK_EXCLUSIVE };
        r = annotate_rename_mailbox(oldmailbox, &newmailbox);
    }

    if (!r && mailbox_has_conversations(oldmailbox)) {
        struct conversations_state *oldcstate =
            mailbox_get_cstate(oldmailbox);

        assert(oldcstate);

        if (mboxname_isdeletedmailbox(newname, NULL)) {
             
            r = mailbox_delete_conversations(oldmailbox);
        }
        else if (oldcstate->folders_byname) {
             
            r = conversations_rename_folder(oldcstate, mailbox_name(oldmailbox), newname);
        }
         
    }

     
    if (!silent) mailbox_modseq_dirty(oldmailbox);

     
    xzfree(oldmailbox->h.name);
    oldmailbox->h.name = xstrdup(newname);
    oldmailbox->header_dirty = 1;

    return r;
}