diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index c0abd5a564..bb140577ca 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -691,6 +691,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 1fd86a9bf6..6982587b06 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -1868,6 +1868,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; @@ -1877,6 +1886,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); } @@ -1892,7 +1903,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);