]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
LAYOUT=index: Rebuild list index if INBOX is missing on inbox=yes namespace
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 29 Nov 2017 12:51:02 +0000 (14:51 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 29 Nov 2017 13:41:07 +0000 (15:41 +0200)
This avoids having to manually rebuild the list index afterwards if it
becomes lost.

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

index c1fbb31e694921e6797e110f2294fd86c6d85654..1fc407a1778d8aeb841a0a7cb9a90ac32758be98 100644 (file)
@@ -398,6 +398,8 @@ static int mailbox_list_index_parse_records(struct mailbox_list_index *ilist,
                                parent->children = node;
                                continue;
                        }
+               } else if (strcasecmp(node->name, "INBOX") == 0) {
+                       ilist->rebuild_on_missing_inbox = FALSE;
                }
                if (hash_table_lookup(duplicate_hash, node) == NULL)
                        hash_table_insert(duplicate_hash, node, node);
@@ -592,6 +594,8 @@ int mailbox_list_index_handle_corruption(struct mailbox_list *list)
 
        if (ilist->call_corruption_callback)
                reason = MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_CORRUPTED;
+       else if (ilist->rebuild_on_missing_inbox)
+               reason = MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_NO_INBOX;
        else
                return 0;
 
@@ -624,6 +628,7 @@ int mailbox_list_index_set_uncorrupted(struct mailbox_list *list)
        struct mailbox_list_index_sync_context *sync_ctx;
 
        ilist->call_corruption_callback = FALSE;
+       ilist->rebuild_on_missing_inbox = FALSE;
 
        if (mailbox_list_index_sync_begin(list, &sync_ctx) < 0)
                return -1;
@@ -904,6 +909,8 @@ static void mailbox_list_index_init_finish(struct mailbox_list *list)
        ilist->path = dir == NULL ? "(in-memory mailbox list index)" :
                p_strdup_printf(list->pool, "%s/%s", dir, list->set.list_index_fname);
        ilist->index = mail_index_alloc(dir, list->set.list_index_fname);
+       ilist->rebuild_on_missing_inbox =
+               (list->ns->flags & NAMESPACE_FLAG_INBOX_ANY) != 0;
 
        ilist->ext_id = mail_index_ext_register(ilist->index, "list",
                                sizeof(struct mailbox_list_index_header),
index e0cb7386feeb78961e41ada4ea2e7ed21cc2ddb3..e6d5de18b2184a5608f0b242b602e7d3e1a95a30 100644 (file)
@@ -121,6 +121,7 @@ struct mailbox_list_index {
        unsigned int corrupted_names_or_parents:1;
        unsigned int handling_corruption:1;
        unsigned int call_corruption_callback:1;
+       unsigned int rebuild_on_missing_inbox:1;
 };
 
 struct mailbox_list_index_iterate_context {
index 63742cdf38118bce8c22738e539df60289a55e52..4a9b790bd1495e0093cb8f8194f73de391063c33 100644 (file)
 enum mail_storage_list_index_rebuild_reason {
        /* Mailbox list index was found to be corrupted. */
        MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_CORRUPTED,
+       /* Mailbox list index doesn't have INBOX in an inbox=yes namespace.
+          Rebuild is done to verify whether the user really is an empty new
+          user, or if an existing user's mailbox list index was lost. Because
+          this is called in non-error conditions, the callback shouldn't log
+          any errors or warnings if it didn't find any missing mailboxes. */
+       MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_NO_INBOX,
 };
 
 struct mail_storage_module_register {