]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mailbox_sync_init() - open mailbox immediately if it's not open yet
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 10 Jul 2017 11:19:47 +0000 (14:19 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 12 Jul 2017 21:21:49 +0000 (00:21 +0300)
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.

src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index 5a5884a0812d0ec6a9a626d091c5f33cfc38d724..12b7f4443b5b7c0b659ab30eb08736a069368e4b 100644 (file)
@@ -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 {
index 274b9f7b6e27eb90c56b0a8f51f55f582df7289e..fa12e77fa9d9af0aeb30764d06d1ffe1b208fb27 100644 (file)
@@ -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);