Skip to content

Commit

Permalink
lib-storage: mailbox_sync_init() - open mailbox immediately if it's n…
Browse files Browse the repository at this point in the history
…ot 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.
  • Loading branch information
sirainen authored and Timo Sirainen committed Jul 10, 2017
1 parent b596cac commit 4906f65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib-storage/mail-storage-private.h
Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion src/lib-storage/mail-storage.c
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down

0 comments on commit 4906f65

Please sign in to comment.