From: Timo Sirainen Date: Mon, 10 Jul 2017 11:19:47 +0000 (+0300) Subject: lib-storage: mailbox_sync_init() - open mailbox immediately if it's not open yet X-Git-Tag: 2.2.32.rc1~119 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f88cdc29e01b9d86c2f21640b2b3ee4f75ef91b9;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: mailbox_sync_init() - open mailbox immediately if it's not open yet This simplifies the work for plugins that want to hook into mailbox.sync_init() so they no longer have to handle the "mailbox isn't opened" case. --- diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 5a5884a081..12b7f4443b 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -699,6 +699,7 @@ struct mail_save_context { struct mailbox_sync_context { struct mailbox *box; enum mailbox_sync_flags flags; + bool open_failed; }; struct mailbox_header_lookup_ctx { diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 274b9f7b6e..fa12e77fa9 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -1863,6 +1863,15 @@ mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) i_panic("Trying to sync mailbox %s with open transactions", box->name); } + if (!box->opened) { + if (mailbox_open(box) < 0) { + ctx = i_new(struct mailbox_sync_context, 1); + ctx->box = box; + ctx->flags = flags; + ctx->open_failed = TRUE; + return ctx; + } + } T_BEGIN { ctx = box->v.sync_init(box, flags); } T_END; @@ -1872,6 +1881,8 @@ mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) bool mailbox_sync_next(struct mailbox_sync_context *ctx, struct mailbox_sync_rec *sync_rec_r) { + if (ctx->open_failed) + return FALSE; return ctx->box->v.sync_next(ctx, sync_rec_r); } @@ -1887,7 +1898,13 @@ int mailbox_sync_deinit(struct mailbox_sync_context **_ctx, *_ctx = NULL; i_zero(status_r); - ret = box->v.sync_deinit(ctx, status_r); + + if (!ctx->open_failed) + ret = box->v.sync_deinit(ctx, status_r); + else { + i_free(ctx); + ret = -1; + } if (ret < 0 && box->inbox_user && !box->storage->user->inbox_open_error_logged) { errormsg = mailbox_get_last_internal_error(box, &error);