Skip to content

Commit

Permalink
lib-lda: Refactor - Add struct mail_deliver_mailbox
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Feb 21, 2017
1 parent 1b41f47 commit 2d42ba7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/lib-lda/mail-deliver.c
Expand Up @@ -41,6 +41,10 @@ struct mail_deliver_cache {
uoff_t psize, vsize;
};

struct mail_deliver_mailbox {
union mailbox_module_context module_ctx;
};

static const char *lda_log_wanted_headers[] = {
"From", "Message-ID", "Subject",
NULL
Expand Down Expand Up @@ -508,11 +512,11 @@ deliver_mail_func_t *mail_deliver_hook_set(deliver_mail_func_t *new_hook)
static int mail_deliver_save_finish(struct mail_save_context *ctx)
{
struct mailbox *box = ctx->transaction->box;
union mailbox_module_context *mbox = MAIL_DELIVER_STORAGE_CONTEXT(box);
struct mail_deliver_mailbox *mbox = MAIL_DELIVER_STORAGE_CONTEXT(box);
struct mail_deliver_user *muser =
MAIL_DELIVER_USER_CONTEXT(box->storage->user);

if (mbox->super.save_finish(ctx) < 0)
if (mbox->module_ctx.super.save_finish(ctx) < 0)
return -1;

/* initialize most of the fields from dest_mail */
Expand All @@ -523,11 +527,11 @@ static int mail_deliver_save_finish(struct mail_save_context *ctx)
static int mail_deliver_copy(struct mail_save_context *ctx, struct mail *mail)
{
struct mailbox *box = ctx->transaction->box;
union mailbox_module_context *mbox = MAIL_DELIVER_STORAGE_CONTEXT(box);
struct mail_deliver_mailbox *mbox = MAIL_DELIVER_STORAGE_CONTEXT(box);
struct mail_deliver_user *muser =
MAIL_DELIVER_USER_CONTEXT(box->storage->user);

if (mbox->super.copy(ctx, mail) < 0)
if (mbox->module_ctx.super.copy(ctx, mail) < 0)
return -1;

/* initialize most of the fields from dest_mail */
Expand Down Expand Up @@ -598,7 +602,7 @@ static void mail_deliver_mail_user_created(struct mail_user *user)
static void mail_deliver_mailbox_allocated(struct mailbox *box)
{
struct mailbox_vfuncs *v = box->vlast;
union mailbox_module_context *mbox;
struct mail_deliver_mailbox *mbox;
struct mail_deliver_user *muser =
MAIL_DELIVER_USER_CONTEXT(box->storage->user);

Expand All @@ -607,14 +611,14 @@ static void mail_deliver_mailbox_allocated(struct mailbox *box)
if (muser->deliver_ctx == NULL)
return;

mbox = p_new(box->pool, union mailbox_module_context, 1);
mbox->super = *v;
box->vlast = &mbox->super;
mbox = p_new(box->pool, struct mail_deliver_mailbox, 1);
mbox->module_ctx.super = *v;
box->vlast = &mbox->module_ctx.super;
v->save_finish = mail_deliver_save_finish;
v->copy = mail_deliver_copy;
v->transaction_commit = mail_deliver_transaction_commit;

MODULE_CONTEXT_SET_SELF(box, mail_deliver_storage_module, mbox);
MODULE_CONTEXT_SET(box, mail_deliver_storage_module, mbox);
}

static struct mail_storage_hooks mail_deliver_hooks = {
Expand Down

0 comments on commit 2d42ba7

Please sign in to comment.