From b73e922263e837b85273f0310f5e07a71ef775fa Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 28 Dec 2008 21:09:49 +0100
Subject: [PATCH] Testsuite: added basic result execution tests for various
 extensions.

---
 src/lib-sieve/plugins/vacation/cmd-vacation.c | 31 ++++++++++++-------
 src/lib-sieve/sieve-actions.c                 |  1 +
 src/lib-sieve/sieve-result.c                  |  4 +--
 src/testsuite/testsuite-result.c              |  2 --
 tests/execute/actions.svtest                  | 12 +++++--
 tests/extensions/imapflags/execute.svtest     |  4 +++
 tests/extensions/reject/execute.svtest        |  8 +++--
 tests/extensions/vacation/execute.svtest      | 10 +++++-
 8 files changed, 51 insertions(+), 21 deletions(-)

diff --git a/src/lib-sieve/plugins/vacation/cmd-vacation.c b/src/lib-sieve/plugins/vacation/cmd-vacation.c
index 4f096ce55..9e862fa0c 100644
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c
@@ -821,7 +821,7 @@ static bool act_vacation_send
 	FILE *f;
  	const char *outmsgid;
  	const char *const *headers;
-	int references;
+	int ret;
 
 	/* Check smpt functions just to be sure */
 
@@ -854,23 +854,26 @@ static bool act_vacation_send
 	rfc2822_header_field_printf(f, "Subject", "%s", 
 		str_sanitize(ctx->subject, 256));
 
-	references = mail_get_headers
+	/* Compose proper in-reply-to and references headers */
+	
+	ret = mail_get_headers
 		(aenv->msgdata->mail, "references", &headers);
 			
 	if ( msgdata->id != NULL ) {
 		rfc2822_header_field_write(f, "In-Reply-To", msgdata->id);
 	
-		if ( references >= 0 )
+		if ( ret >= 0 && headers[0] != NULL )
 			rfc2822_header_field_write
 				(f, "References", t_strconcat(headers[0], " ", msgdata->id, NULL));
 		else
 			rfc2822_header_field_write(f, "References", msgdata->id);
-	} else if ( references > 0 ) {
+	} else if ( ret >= 0 && headers[0] != NULL ) {
 		rfc2822_header_field_write(f, "References", headers[0]);
 	}
 			
 	rfc2822_header_field_write(f, "Auto-Submitted", "auto-replied (vacation)");
 	rfc2822_header_field_write(f, "Precedence", "bulk");
+	
 	rfc2822_header_field_write(f, "MIME-Version", "1.0");
     
 	if ( !ctx->mime ) {
@@ -936,12 +939,15 @@ static bool act_vacation_commit
 	}
 	
 	/* Did whe respond to this user before? */
-	act_vacation_hash(msgdata, ctx, dupl_hash);
-	if (senv->duplicate_check(dupl_hash, sizeof(dupl_hash), senv->username)) 
-	{
-		sieve_result_log(aenv, "discarded duplicate vacation response to <%s>",
-			str_sanitize(msgdata->return_path, 128));
-		return TRUE;
+	if ( senv->duplicate_check != NULL ) {
+		act_vacation_hash(msgdata, ctx, dupl_hash);
+	
+		if ( senv->duplicate_check(dupl_hash, sizeof(dupl_hash), senv->username) ) 
+		{
+			sieve_result_log(aenv, "discarded duplicate vacation response to <%s>",
+				str_sanitize(msgdata->return_path, 128));
+			return TRUE;
+		}
 	}
 	
 	/* Are we trying to respond to a mailing list ? */
@@ -1051,8 +1057,9 @@ static bool act_vacation_commit
 			str_sanitize(msgdata->return_path, 128));	
 
 		/* Mark as replied */
-		senv->duplicate_mark(dupl_hash, sizeof(dupl_hash), senv->username,
-			ioloop_time + ctx->days * (24 * 60 * 60));
+		if ( senv->duplicate_mark != NULL )
+			senv->duplicate_mark(dupl_hash, sizeof(dupl_hash), senv->username,
+				ioloop_time + ctx->days * (24 * 60 * 60));
 
 		return TRUE;
 	}
diff --git a/src/lib-sieve/sieve-actions.c b/src/lib-sieve/sieve-actions.c
index bd5e1d265..1cf734dfe 100644
--- a/src/lib-sieve/sieve-actions.c
+++ b/src/lib-sieve/sieve-actions.c
@@ -361,6 +361,7 @@ static bool act_store_commit
 	if ( trans->namespace == NULL ) {
 		if ( aenv->scriptenv->namespaces == NULL ) {
 			act_store_log_status(trans, aenv, FALSE, status);
+			*keep = FALSE;
 			return TRUE;
 		}
 
diff --git a/src/lib-sieve/sieve-result.c b/src/lib-sieve/sieve-result.c
index 5c2c945d4..e0c0ab725 100644
--- a/src/lib-sieve/sieve-result.c
+++ b/src/lib-sieve/sieve-result.c
@@ -704,8 +704,8 @@ int sieve_result_execute
 			bool keep = TRUE;
 		
 			if ( act->commit != NULL ) 
-				commit_ok = act->commit(act, &result->action_env, rac->tr_context, &keep) && 
-					commit_ok;
+				commit_ok = act->commit
+					(act, &result->action_env, rac->tr_context, &keep) && commit_ok;
 	
 			/* Execute post_commit event of side effects */
 			rsef = rac->seffects != NULL ? rac->seffects->first_effect : NULL;
diff --git a/src/testsuite/testsuite-result.c b/src/testsuite/testsuite-result.c
index 9bdfedee2..bfa95fbb2 100644
--- a/src/testsuite/testsuite-result.c
+++ b/src/testsuite/testsuite-result.c
@@ -10,13 +10,11 @@
 #include "testsuite-common.h"
 #include "testsuite-result.h"
 
-unsigned int _testsuite_result_index; /* Yuck */
 static struct sieve_result *_testsuite_result;
 
 void testsuite_result_init(void)
 {
 	_testsuite_result = NULL;
-	_testsuite_result_index = 0;
 }
 
 void testsuite_result_deinit(void)
diff --git a/tests/execute/actions.svtest b/tests/execute/actions.svtest
index c5dbee769..cf3b1a0ff 100644
--- a/tests/execute/actions.svtest
+++ b/tests/execute/actions.svtest
@@ -13,11 +13,11 @@ Test.
 
 test "Fileinto" {
 	if not test_script_compile "actions/fileinto.sieve" {
-		test_fail "compile failed";
+		test_fail "script compile failed";
 	}
 
 	if not test_script_run {
-		test_fail "execute failed";
+		test_fail "script run failed";
 	}
 
 	if not test_result :count "eq" :comparator "i;ascii-numeric" "3" {
@@ -35,6 +35,10 @@ test "Fileinto" {
 	if not test_result :index 3 "store" {
 		test_fail "third action is not 'store'";
 	} 
+
+	if not test_result_execute {
+		test_fail "result execute failed";
+	}
 }
 
 test "Redirect" {
@@ -65,5 +69,9 @@ test "Redirect" {
 	if not test_result :index 4 "redirect" {
 		test_fail "fourth action is not 'redirect'";
 	} 
+
+	if not test_result_execute {
+		test_fail "result execute failed";
+	}
 }
 
diff --git a/tests/extensions/imapflags/execute.svtest b/tests/extensions/imapflags/execute.svtest
index 35cc95924..dac5c763b 100644
--- a/tests/extensions/imapflags/execute.svtest
+++ b/tests/extensions/imapflags/execute.svtest
@@ -12,4 +12,8 @@ test "Flags Side Effect" {
 	if not test_script_run {
 		test_fail "script execute failed";
 	}
+
+	if not test_result_execute {
+		test_fail "result execute failed";	
+	}
 }
diff --git a/tests/extensions/reject/execute.svtest b/tests/extensions/reject/execute.svtest
index 911a978aa..bf3f629ad 100644
--- a/tests/extensions/reject/execute.svtest
+++ b/tests/extensions/reject/execute.svtest
@@ -13,11 +13,11 @@ Test.
 
 test "Execute" {
 	if not test_script_compile "execute/basic.sieve" {
-		test_fail "compile failed";
+		test_fail "script compile failed";
 	}
 
 	if not test_script_run {
-		test_fail "execute failed";
+		test_fail "script run failed";
 	}
 
 	if not test_result :count "eq" :comparator "i;ascii-numeric" "1" {
@@ -27,4 +27,8 @@ test "Execute" {
 	if not test_result :index 1 "reject" {
 		test_fail "reject action missing from result";
 	}
+
+	if not test_result_execute {
+		test_fail "result execute failed";
+	}
 }
diff --git a/tests/extensions/vacation/execute.svtest b/tests/extensions/vacation/execute.svtest
index 0b68b44f8..ed6dc53bb 100644
--- a/tests/extensions/vacation/execute.svtest
+++ b/tests/extensions/vacation/execute.svtest
@@ -8,7 +8,7 @@ test "Action" {
 	}
 
 	if not test_script_run {
-		test_fail "script execute failed";
+		test_fail "script run failed";
 	}
 
 	if not test_result :count "eq" :comparator "i;ascii-numeric" "2" {
@@ -22,6 +22,10 @@ test "Action" {
 	if not test_result :index 2 "store" {
 		test_fail "store action is missing in result";
 	}
+
+	if not test_result_execute {
+		test_fail "result execute failed";
+	}
 }
 
 test "No :handle specified" {
@@ -32,4 +36,8 @@ test "No :handle specified" {
 	if not test_script_run {
 		test_fail "script execute failed";
 	}
+
+	if not test_result_execute {
+		test_fail "result execute failed";
+	}
 }
-- 
GitLab