dovecot-2.2-pigeonhole: lib-sieve: spamtest/virustest extensions...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sat Dec 28 10:41:36 EET 2013


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/f9fd5606b3e7
changeset: 1833:f9fd5606b3e7
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sat Dec 28 09:41:24 2013 +0100
description:
lib-sieve: spamtest/virustest extensions: Tests were erroneously performed against the original message.
When used together with extprograms filter to add the spam headers, the changes were not being used by the spamtest and virustest extensions.

diffstat:

 src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c |  11 ++-
 tests/plugins/extprograms/bin/spamc                            |   6 +
 tests/plugins/extprograms/filter/execute.svtest                |  35 +++++++++-
 3 files changed, 48 insertions(+), 4 deletions(-)

diffs (114 lines):

diff -r 3f67c4ded9b8 -r f9fd5606b3e7 src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c
--- a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c	Sat Dec 28 09:24:42 2013 +0100
+++ b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c	Sat Dec 28 09:41:24 2013 +0100
@@ -454,9 +454,9 @@
 	struct ext_spamvirustest_data *ext_data =
 		(struct ext_spamvirustest_data *) ext->context;
 	struct ext_spamvirustest_header_spec *status_header, *max_header;
-	const struct sieve_message_data *msgdata = renv->msgdata;
 	struct sieve_message_context *msgctx = renv->msgctx;
 	struct ext_spamvirustest_message_context *mctx;
+	struct mail *mail;
 	regmatch_t match_values[2];
 	const char *header_value, *error;
 	const char *status = NULL, *max = NULL;
@@ -481,10 +481,14 @@
 		sieve_message_context_extension_get(msgctx, ext);
 
 	if ( mctx == NULL ) {
+		/* Create new context */
 		mctx = p_new(pool, struct ext_spamvirustest_message_context, 1);
 		sieve_message_context_extension_set(msgctx, ext, (void *)mctx);
 	} else if ( mctx->reload == ext_data->reload ) {
+		/* Use cached result */
 		return ext_spamvirustest_get_score(ext, mctx->score_ratio, percent);
+	} else {
+		/* Extension was reloaded (probably in testsuite) */
 	}
 
 	mctx->reload = ext_data->reload;
@@ -493,6 +497,7 @@
 	 * Get max status value
 	 */
 
+	mail = sieve_message_get_mail(renv->msgctx);
 	status_header = &ext_data->status_header;
 	max_header = &ext_data->max_header;
 
@@ -500,7 +505,7 @@
 		if ( max_header->header_name != NULL ) {
 			/* Get header from message */
 			if ( mail_get_first_header_utf8
-				(msgdata->mail, max_header->header_name, &header_value) < 0 ||
+				(mail, max_header->header_name, &header_value) < 0 ||
 				header_value == NULL ) {
 				sieve_runtime_trace(renv,  SIEVE_TRLVL_TESTS,
 					"header '%s' not found in message",
@@ -553,7 +558,7 @@
 
 	/* Get header from message */
 	if ( mail_get_first_header_utf8
-		(msgdata->mail, status_header->header_name, &header_value) < 0 ||
+		(mail, status_header->header_name, &header_value) < 0 ||
 		header_value == NULL ) {
 		sieve_runtime_trace(renv,  SIEVE_TRLVL_TESTS,
 			"header '%s' not found in message",
diff -r 3f67c4ded9b8 -r f9fd5606b3e7 tests/plugins/extprograms/bin/spamc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/plugins/extprograms/bin/spamc	Sat Dec 28 09:41:24 2013 +0100
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+echo 'X-Spam-Status: Yes, score=66.5/5.0 tests=CONTAINS_LARGE_ROOSTER'
+cat
+
+exit 0
diff -r 3f67c4ded9b8 -r f9fd5606b3e7 tests/plugins/extprograms/filter/execute.svtest
--- a/tests/plugins/extprograms/filter/execute.svtest	Sat Dec 28 09:24:42 2013 +0100
+++ b/tests/plugins/extprograms/filter/execute.svtest	Sat Dec 28 09:41:24 2013 +0100
@@ -3,6 +3,7 @@
 require "vnd.dovecot.debug";
 require "variables";
 require "editheader";
+require "spamtest";
 require "body";
 require "fileinto";
 require "mailbox";
@@ -177,4 +178,36 @@
 	if not header "X-E" "5" {
 		test_fail "X-E header missing in final message";
 	}
-}	
+}
+
+test_config_set "sieve_spamtest_status_header"
+	"X-Spam-Status: [^,]*, score=(-?[[:digit:]]+\\.[[:digit:]]).*";
+test_config_set "sieve_spamtest_max_value" "10";
+test_config_set "sieve_spamtest_status_type" "score";
+test_config_reload :extension "spamtest";
+
+test_result_reset;
+test "Spamtest" {
+	if exists "x-spam-status" {
+		test_fail "message already modified";
+	}
+
+	if not header "subject" "Frop!" {
+		test_fail "message is wrong";
+	}
+
+	filter "spamc";
+
+	if not exists "x-spam-status" {
+		test_fail "x-spam-score header not added";
+	}
+
+	if spamtest :is "0" {
+		test_fail "spamtest not configured or test failed";
+	}
+
+	if not spamtest :is "10" {
+		test_fail "spamtest yields incorrect value";
+	}
+}
+


More information about the dovecot-cvs mailing list