dovecot-1.3: mail_deliver(): Support returning a destination mail.

dovecot at dovecot.org dovecot at dovecot.org
Fri Apr 17 01:12:36 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.3/rev/b16ec327b266
changeset: 9119:b16ec327b266
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Apr 16 18:10:30 2009 -0400
description:
mail_deliver(): Support returning a destination mail.

diffstat:

2 files changed, 30 insertions(+), 4 deletions(-)
src/lib-lda/mail-deliver.c |   28 ++++++++++++++++++++++++----
src/lib-lda/mail-deliver.h |    6 ++++++

diffs (84 lines):

diff -r 03fe226e85d4 -r b16ec327b266 src/lib-lda/mail-deliver.c
--- 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 @@ int mail_deliver_save(struct mail_delive
 {
 	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 @@ int mail_deliver_save(struct mail_delive
 		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 @@ int mail_deliver_save(struct mail_delive
 
 	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;
 }
 
diff -r 03fe226e85d4 -r b16ec327b266 src/lib-lda/mail-deliver.h
--- 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 @@ struct mail_deliver_context {
 	   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,


More information about the dovecot-cvs mailing list