]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added struct mailbox.corrupted_mailbox_name
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 16 Nov 2016 01:10:10 +0000 (03:10 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 18 Nov 2016 11:46:37 +0000 (13:46 +0200)
This allows backends that are adding lost mailboxes to mailbox list index to
indicate that they don't actually know the name of the mailbox, and the
mailbox list index should try to figure it out and rename the mailbox to its
proper name.

src/lib-storage/list/mailbox-list-index-backend.c
src/lib-storage/mail-storage-private.h

index c9a11f869da48f697c2d2cf9984abcf088b2d3cc..4af6f0e96d6cedffe0588960b423a8abf7083c2d 100644 (file)
@@ -288,11 +288,19 @@ index_list_mailbox_create_selectable(struct mailbox *box,
                return -1;
 
        seq = mailbox_list_index_sync_name(sync_ctx, box->name, &node, &created);
+       if (box->corrupted_mailbox_name) {
+               /* an existing mailbox is being created with a "unknown" name.
+                  opening the mailbox will hopefully find its real name and
+                  rename it. */
+               node->flags |= MAILBOX_LIST_INDEX_FLAG_CORRUPTED_NAME;
+               mail_index_update_flags(sync_ctx->trans, seq, MODIFY_ADD,
+                       MAILBOX_LIST_INDEX_FLAG_CORRUPTED_NAME);
+       }
        if (!created &&
            (node->flags & (MAILBOX_LIST_INDEX_FLAG_NONEXISTENT |
                            MAILBOX_LIST_INDEX_FLAG_NOSELECT)) == 0) {
                /* already selectable */
-               (void)mailbox_list_index_sync_end(&sync_ctx, FALSE);
+               (void)mailbox_list_index_sync_end(&sync_ctx, TRUE);
                return 0;
        }
 
@@ -303,8 +311,10 @@ index_list_mailbox_create_selectable(struct mailbox *box,
        i_assert(guid_128_is_empty(rec.guid));
 
        /* make it selectable */
-       node->flags = 0;
-       mail_index_update_flags(sync_ctx->trans, seq, MODIFY_REPLACE, 0);
+       node->flags &= ~(MAILBOX_LIST_INDEX_FLAG_NONEXISTENT |
+                        MAILBOX_LIST_INDEX_FLAG_NOSELECT |
+                        MAILBOX_LIST_INDEX_FLAG_NOINFERIORS);
+       mail_index_update_flags(sync_ctx->trans, seq, MODIFY_REPLACE, node->flags);
 
        memcpy(rec.guid, mailbox_guid, sizeof(rec.guid));
        mail_index_update_ext(sync_ctx->trans, seq, ilist->ext_id, &rec, NULL);
@@ -460,6 +470,9 @@ static bool mailbox_has_corrupted_name(struct mailbox *box)
 {
        struct mailbox_list_index_node *node;
 
+       if (box->corrupted_mailbox_name)
+               return TRUE;
+
        node = mailbox_list_index_lookup(box->list, box->name);
        return node != NULL &&
                (node->flags & MAILBOX_LIST_INDEX_FLAG_CORRUPTED_NAME) != 0;
index 044fabf19676386eacab672b0fe12e94532934fe..ee6f49f7749f4fb7a2bd3e817234c07d163eb9d2 100644 (file)
@@ -413,6 +413,9 @@ struct mailbox {
        unsigned int skip_create_name_restrictions:1;
        /* v2.2.x API kludge: quick-parameter to list_index_has_changed() */
        unsigned int list_index_has_changed_quick:1;
+       /* Using LAYOUT=index and mailbox is being opened with a corrupted
+          mailbox name. Try to revert to the previously known good name. */
+       unsigned int corrupted_mailbox_name:1;
 };
 
 struct mail_vfuncs {