From 04d86b2f708bb066d3cb0963665a63f68045e130 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@dovecot.fi>
Date: Sat, 9 Apr 2016 23:16:06 +0200
Subject: [PATCH] lib-sieve: vnd.dovecot.report extension: Made the report
 action behave correctly when there is no envelope.

---
 .../plugins/vnd.dovecot/report/cmd-report.c   | 32 +++++++++++--------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/lib-sieve/plugins/vnd.dovecot/report/cmd-report.c b/src/lib-sieve/plugins/vnd.dovecot/report/cmd-report.c
index d7c20bcf5..5e57aee90 100644
--- a/src/lib-sieve/plugins/vnd.dovecot/report/cmd-report.c
+++ b/src/lib-sieve/plugins/vnd.dovecot/report/cmd-report.c
@@ -462,7 +462,6 @@ static int act_report_send
 	struct ostream *output;
 	string_t *msg;
 	const char *const *headers;
-	const char *sender, *orig_recipient;
 	const char *outmsgid, *boundary, *error, *subject;
 	int ret;
 
@@ -473,9 +472,6 @@ static int act_report_send
 		return SIEVE_EXEC_OK;
 	}
 
-	sender = sieve_message_get_sender(msgctx);
-	orig_recipient = sieve_message_get_orig_recipient(msgctx);
-
 	/* Make sure we have a subject for our report */
 	if ( mail_get_headers_utf8
 		(msgdata->mail, "subject", &headers) < 0 ) {
@@ -551,16 +547,24 @@ static int act_report_send
 	rfc2822_header_write(msg,	"User-Agent",
 		PACKAGE_NAME "/" PACKAGE_VERSION " "
 		PIGEONHOLE_NAME "/" PIGEONHOLE_VERSION);
-	if (sender == NULL) {
-		rfc2822_header_write(msg,
-			"Original-Mail-From", "<>");
-	} else {
-		rfc2822_header_printf(msg,
-			"Original-Mail-From", "<%s>", sender);
-	}
-	if (orig_recipient != NULL) {
-		rfc2822_header_printf(msg,
-			"Original-Rcpt-To", "<%s>", orig_recipient);
+
+	if ( (aenv->flags & SIEVE_EXECUTE_FLAG_NO_ENVELOPE) == 0 ) {
+		const char *sender, *orig_recipient;
+
+		sender = sieve_message_get_sender(msgctx);
+		orig_recipient = sieve_message_get_orig_recipient(msgctx);
+
+		if (sender == NULL) {
+			rfc2822_header_write(msg,
+				"Original-Mail-From", "<>");
+		} else {
+			rfc2822_header_printf(msg,
+				"Original-Mail-From", "<%s>", sender);
+		}
+		if (orig_recipient != NULL) {
+			rfc2822_header_printf(msg,
+				"Original-Rcpt-To", "<%s>", orig_recipient);
+		}
 	}
 	str_append(msg, "\r\n");
 
-- 
GitLab