Mercurial > dovecot > core-2.2
changeset 21429:64625a782e87
lib-storage: Copy cache decisions from inbox on create
Otherwise the decisions are definitely wrong, since
they are nonexistent. Copying from INBOX would make sense.
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Tue, 27 Dec 2016 09:45:58 +0200 |
parents | d64bd3f11bdf |
children | 1ce6c0be2213 |
files | src/lib-storage/mail-storage.c |
diffstat | 1 files changed, 32 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c Tue Dec 27 09:44:52 2016 +0200 +++ b/src/lib-storage/mail-storage.c Tue Dec 27 09:45:58 2016 +0200 @@ -26,6 +26,7 @@ #include "mail-search-register.h" #include "mailbox-search-result-private.h" #include "mailbox-guid-cache.h" +#include "mail-cache.h" #include <ctype.h> @@ -1315,6 +1316,33 @@ return box->inbox_any; } +static void mailbox_copy_cache_decisions_from_inbox(struct mailbox *box) +{ + struct mail_namespace *ns = + mail_namespace_find_inbox(box->storage->user->namespaces); + struct mailbox *inbox = + mailbox_alloc(ns->list, "INBOX", MAILBOX_FLAG_READONLY); + enum mailbox_existence existence; + + /* this should be NoSelect but since inbox can never be + NoSelect we use EXISTENCE_NONE to avoid creating inbox by accident */ + if (mailbox_exists(inbox, FALSE, &existence) == 0 && + existence != MAILBOX_EXISTENCE_NONE && + mailbox_open(inbox) == 0 && + mailbox_open(box) == 0) { + struct mail_index_transaction *dit = + mail_index_transaction_begin(box->view, + MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL); + + mail_cache_decisions_copy(dit, inbox->cache, box->cache); + + /* we can't do much about errors here */ + (void)mail_index_transaction_commit(&dit); + } + + mailbox_free(&inbox); +} + int mailbox_create(struct mailbox *box, const struct mailbox_update *update, bool directory) { @@ -1326,9 +1354,11 @@ box->creating = TRUE; ret = box->v.create_box(box, update, directory); box->creating = FALSE; - if (ret == 0) + if (ret == 0) { box->list->guid_cache_updated = TRUE; - else if (box->opened) { + if (!box->inbox_any) + mailbox_copy_cache_decisions_from_inbox(box); + } else if (box->opened) { /* Creation failed after (partially) opening the mailbox. It may not be in a valid state, so close it. */ mail_storage_last_error_push(box->storage);