dovecot-1.2-sieve: Vacation extension: from address of reply is ...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Tue Apr 20 00:36:16 EEST 2010


details:   http://hg.rename-it.nl/dovecot-1.2-sieve/rev/1a9b3c3a4fdf
changeset: 1248:1a9b3c3a4fdf
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon Apr 19 23:36:05 2010 +0200
description:
Vacation extension: from address of reply is now by default equal to whatever known recipient alias matched the headers of the message.

diffstat:

 src/lib-sieve/plugins/vacation/cmd-vacation.c |  20 ++++--
 tests/extensions/vacation/smtp.svtest         |  86 +++++++++++++++++++++++++---
 2 files changed, 88 insertions(+), 18 deletions(-)

diffs (191 lines):

diff -r bcfa819f257b -r 1a9b3c3a4fdf src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c	Mon Apr 19 22:50:01 2010 +0200
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c	Mon Apr 19 23:36:05 2010 +0200
@@ -867,7 +867,7 @@
 
 static bool act_vacation_send	
 (const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx,
-	const char *sender, const char *recipient)
+	const char *reply_to, const char *reply_from)
 {
 	const struct sieve_message_data *msgdata = aenv->msgdata;
 	const struct sieve_script_env *senv = aenv->scriptenv;
@@ -902,7 +902,7 @@
 
 	/* Open smtp session */
 
-	smtp_handle = senv->smtp_open(sender, NULL, &f);
+	smtp_handle = senv->smtp_open(reply_to, NULL, &f);
 	outmsgid = sieve_message_get_new_id(senv);
 
 	/* Produce a proper reply */
@@ -913,15 +913,15 @@
 
 	if ( ctx->from != NULL && *(ctx->from) != '\0' )
 		rfc2822_header_field_utf8_printf(f, "From", "%s", ctx->from);
-	else if ( recipient != NULL ) 
-		rfc2822_header_field_printf(f, "From", "<%s>", recipient);
+	else if ( reply_from != NULL ) 
+		rfc2822_header_field_printf(f, "From", "<%s>", reply_from);
 	else
 		rfc2822_header_field_printf(f, "From", "Postmaster <%s>", senv->postmaster_address);
 		
 	/* FIXME: If From header of message has same address, we should use that in 
 	 * stead properly include the phrase part.
 	 */
-	rfc2822_header_field_printf(f, "To", "<%s>", sender);
+	rfc2822_header_field_printf(f, "To", "<%s>", reply_to);
 
 	if ( _contains_8bit(subject) )
 		rfc2822_header_field_utf8_printf(f, "Subject", "%s", subject);
@@ -963,7 +963,7 @@
 		sieve_result_error(aenv, 
 			"failed to send vacation response to <%s> "
 			"(refer to server log for more information)", 
-			str_sanitize(sender, 128));	
+			str_sanitize(reply_to, 128));	
 		return TRUE;
 	}
 	
@@ -997,6 +997,7 @@
 	const char *const *headers;
 	const char *sender = sieve_message_get_sender(aenv->msgctx);
 	const char *recipient = sieve_message_get_recipient(aenv->msgctx);
+	const char *reply_from = NULL;
 
 	/* Is the recipient unset? 
 	 */
@@ -1096,8 +1097,10 @@
 		if ( mail_get_headers_utf8
 			(msgdata->mail, *hdsp, &headers) >= 0 && headers[0] != NULL ) {	
 			
-			if ( _contains_my_address(headers, recipient) ) 
+			if ( _contains_my_address(headers, recipient) ) {
+				reply_from = recipient;
 				break;
+			}
 			
 			if ( ctx->addresses != NULL ) {
 				bool found = FALSE;
@@ -1105,6 +1108,7 @@
 		
 				while ( !found && *my_address != NULL ) {
 					found = _contains_my_address(headers, *my_address);
+					reply_from = *my_address;
 					my_address++;
 				}
 				
@@ -1124,7 +1128,7 @@
 	
 	/* Send the message */
 	
-	if ( act_vacation_send(aenv, ctx, sender, recipient) ) {
+	if ( act_vacation_send(aenv, ctx, sender, reply_from) ) {
 		sieve_result_log(aenv, "sent vacation response to <%s>", 
 			str_sanitize(sender, 128));	
 
diff -r bcfa819f257b -r 1a9b3c3a4fdf tests/extensions/vacation/smtp.svtest
--- a/tests/extensions/vacation/smtp.svtest	Mon Apr 19 22:50:01 2010 +0200
+++ b/tests/extensions/vacation/smtp.svtest	Mon Apr 19 23:36:05 2010 +0200
@@ -15,21 +15,21 @@
 test_set "envelope.to" "timo at iki.fi";
 
 test "Basic" {
-	vacation :addresses "tss at iki.fi" :from "Timo Sirainen <tss at iki.fi>" "I am gone";
+	vacation :addresses "tss at iki.fi" :from "Timo Sirainen <sirainen at iki.fi>" "I am gone";
 
 	if not test_result_execute {
-        test_fail "failed to execute vacation";
-    }
+		test_fail "failed to execute vacation";
+	}
 
-    test_message :smtp 0;
+	test_message :smtp 0;
 
-    if not address :is "to" "sirius at rename-it.nl" {
-        test_fail "to address incorrect";
-    }
+	if not address :is "to" "sirius at rename-it.nl" {
+		test_fail "to address incorrect";
+	}
 
-    if not address :is "from" "tss at iki.fi" {
-        test_fail "from address incorrect";
-    }
+	if not address :is "from" "sirainen at iki.fi" {
+		test_fail "from address incorrect";
+	}
 
 	if not envelope :is "to" "sirius at rename-it.nl" {
 		test_fail "envelope recipient incorrect";
@@ -54,3 +54,69 @@
 		test_fail "reject sent message to NULL sender";
 	}
 }
+
+test_result_reset;
+
+test_set "message" text:
+From: stephan at rename-it.nl
+To: timo at iki.fi
+Cc: stephan at drunksnipers.com
+Subject: Frop!
+
+Frop!
+.
+;
+
+test_set "envelope.from" "sirius at rename-it.nl";
+test_set "envelope.to" "timo at iki.fi";
+
+test "Envelope.to == To" {
+	vacation "I am gone";
+
+	if not test_result_execute {
+		test_fail "failed to execute vacation";
+	}
+
+	test_message :smtp 0;
+
+	if not address :is "from" "timo at iki.fi" {
+		test_fail "from address incorrect";
+	}
+
+	if not envelope :is "from" "" {
+		test_fail "envelope sender not null";
+	}
+}
+
+test_result_reset;
+
+test_set "message" text:
+From: stephan at rename-it.nl
+To: tss at iki.fi
+Cc: stephan at drunksnipers.com
+Subject: Frop!
+
+Frop!
+.
+;
+
+test_set "envelope.from" "sirius at rename-it.nl";
+test_set "envelope.to" "timo at iki.fi";
+
+test "Envelope.to != To" {
+	vacation :addresses "tss at iki.fi" "I am gone";
+
+	if not test_result_execute {
+		test_fail "failed to execute vacation";
+	}
+
+	test_message :smtp 0;
+
+	if not address :is "from" "tss at iki.fi" {
+		test_fail "from address incorrect";
+	}
+
+	if not envelope :is "from" "" {
+		test_fail "envelope sender not null";
+	}
+}


More information about the dovecot-cvs mailing list