From 540555c5b435203e1c26c8e7b924b2643ae07ae3 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 16 Nov 2016 03:10:10 +0200 Subject: [PATCH] lib-storage: Added struct mailbox.corrupted_mailbox_name 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. --- .../list/mailbox-list-index-backend.c | 19 ++++++++++++++++--- src/lib-storage/mail-storage-private.h | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib-storage/list/mailbox-list-index-backend.c b/src/lib-storage/list/mailbox-list-index-backend.c index 24b376a95d..530a208099 100644 --- a/src/lib-storage/list/mailbox-list-index-backend.c +++ b/src/lib-storage/list/mailbox-list-index-backend.c @@ -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; diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 8893709c7a..66951c18a0 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -414,6 +414,9 @@ struct mailbox { bool update_first_saved:1; /* mailbox_verify_create_name() only checks for mailbox_verify_name() */ bool skip_create_name_restrictions:1; + /* Using LAYOUT=index and mailbox is being opened with a corrupted + mailbox name. Try to revert to the previously known good name. */ + bool corrupted_mailbox_name:1; }; struct mail_vfuncs {