Skip to content

Commit

Permalink
lib-storage: Added struct mailbox.corrupted_mailbox_name
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen authored and GitLab committed Nov 16, 2016
1 parent 85cbe5d commit 540555c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib-storage/list/mailbox-list-index-backend.c
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/lib-storage/mail-storage-private.h
Expand Up @@ -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 {
Expand Down

0 comments on commit 540555c

Please sign in to comment.