Mercurial > dovecot > core-2.2
changeset 9119:b16ec327b266 HEAD
mail_deliver(): Support returning a destination mail.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 16 Apr 2009 18:10:30 -0400 |
parents | 03fe226e85d4 |
children | 749339f9d1df |
files | src/lib-lda/mail-deliver.c src/lib-lda/mail-deliver.h |
diffstat | 2 files changed, 30 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-lda/mail-deliver.c Thu Apr 16 18:10:05 2009 -0400 +++ b/src/lib-lda/mail-deliver.c Thu Apr 16 18:10:30 2009 -0400 @@ -135,11 +135,13 @@ { struct mail_namespace *ns; struct mailbox *box; + enum mailbox_transaction_flags trans_flags; struct mailbox_transaction_context *t; struct mail_save_context *save_ctx; struct mail_keywords *kw; enum mail_error error; const char *mailbox_name; + uint32_t uid_validity, uid1 = 0, uid2 = 0; bool default_save; int ret = 0; @@ -166,7 +168,10 @@ return -1; } - t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL); + trans_flags = MAILBOX_TRANSACTION_FLAG_EXTERNAL; + if (ctx->save_dest_mail) + trans_flags |= MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS; + t = mailbox_transaction_begin(box, trans_flags); kw = str_array_length(keywords) == 0 ? NULL : mailbox_keywords_create_valid(box, keywords); @@ -178,18 +183,33 @@ if (ret < 0) mailbox_transaction_rollback(&t); - else - ret = mailbox_transaction_commit(&t); + else { + ret = mailbox_transaction_commit_get_uids(&t, &uid_validity, + &uid1, &uid2); + } if (ret == 0) { ctx->saved_mail = TRUE; mail_deliver_log(ctx, "saved mail to %s", mailbox_name); + + if (ctx->save_dest_mail && mailbox_sync(box, 0, 0, NULL) == 0) { + i_assert(uid1 == uid2); + + t = mailbox_transaction_begin(box, 0); + ctx->dest_mail = mail_alloc(t, MAIL_FETCH_STREAM_BODY, + NULL); + if (mail_set_uid(ctx->dest_mail, uid1) < 0) { + mail_free(&ctx->dest_mail); + mailbox_transaction_rollback(&t); + } + } } else { mail_deliver_log(ctx, "save failed to %s: %s", mailbox_name, mail_storage_get_last_error(*storage_r, &error)); } - mailbox_close(&box); + if (ctx->dest_mail == NULL) + mailbox_close(&box); return ret; }
--- a/src/lib-lda/mail-deliver.h Thu Apr 16 18:10:05 2009 -0400 +++ b/src/lib-lda/mail-deliver.h Thu Apr 16 18:10:30 2009 -0400 @@ -21,8 +21,14 @@ something to it. */ const char *dest_mailbox_name; + /* Filled with destination mail, if save_dest_mail=TRUE. + The caller must free the mail, its transaction and close + the mailbox. */ + struct mail *dest_mail; + bool tried_default_save; bool saved_mail; + bool save_dest_mail; }; typedef int deliver_mail_func_t(struct mail_deliver_context *ctx,