changeset 20556:86d9ea2f8fc8

lib-lda: Support %{storage_id} in deliver_log_format
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 02 Aug 2016 21:10:42 +0300
parents d5642dc6cccc
children 31d7157aa0b1
files src/lib-lda/mail-deliver.c
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-lda/mail-deliver.c	Tue Aug 02 21:09:34 2016 +0300
+++ b/src/lib-lda/mail-deliver.c	Tue Aug 02 21:10:42 2016 +0300
@@ -68,6 +68,7 @@
 		{ '\0', NULL, "delivery_time" },
 		{ '\0', NULL, "session_time" },
 		{ '\0', NULL, "to_envelope" },
+		{ '\0', NULL, "storage_id" },
 		{ '\0', NULL, NULL }
 	};
 	struct var_expand_table *tab;
@@ -99,6 +100,7 @@
 		tab[8].value = dec2str(ctx->session_time_msecs);
 		tab[9].value = ctx->dest_addr;
 	}
+	(void)mail_get_special(mail, MAIL_FETCH_STORAGE_ID, &tab[10].value);
 	return tab;
 }
 
@@ -393,7 +395,6 @@
 
 	if (ret == 0) {
 		ctx->saved_mail = TRUE;
-		mail_deliver_log(ctx, "saved mail to %s", mailbox_name);
 		if (ctx->save_dest_mail) {
 			/* copying needs the message body. with maildir we also
 			   need to get the GUID in case the message gets
@@ -404,7 +405,23 @@
 				mail_free(&ctx->dest_mail);
 				mailbox_transaction_rollback(&t);
 			}
+			/* might as well get the storage_id */
+			(void)mail_get_special(ctx->dest_mail, MAIL_FETCH_STORAGE_ID,
+					       &ctx->var_expand_table[10].value);
+		} else if (var_has_key(ctx->set->deliver_log_format, '\0', "storage_id")) {
+			/* storage ID is available only after commit. */
+			struct mail *mail = mail_deliver_open_mail(box, &changes,
+				MAIL_FETCH_STORAGE_ID, &t);
+			if (mail != NULL) {
+				const char *str;
+
+				(void)mail_get_special(mail, MAIL_FETCH_STORAGE_ID, &str);
+				ctx->var_expand_table[10].value = t_strdup(str);
+				mail_free(&mail);
+				(void)mailbox_transaction_commit(&t);
+			}
 		}
+		mail_deliver_log(ctx, "saved mail to %s", mailbox_name);
 		pool_unref(&changes.pool);
 	} else {
 		mail_deliver_log(ctx, "save failed to %s: %s", mailbox_name,