From 7b83caf114436545268781aef459504183fb2808 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 19 Oct 2008 11:58:33 +0200
Subject: [PATCH] Added explicit messages and tests for unsupported use of
 variables.

---
 TODO                                        |  3 +-
 src/lib-sieve/plugins/include/cmd-include.c | 14 ++++++++
 src/lib-sieve/plugins/regex/mcht-regex.c    |  7 ++--
 src/lib-sieve/sieve-comparators.c           | 13 +++++++
 tests/compile/errors.svtest                 | 14 ++++++++
 tests/compile/errors/unsupported.sieve      | 39 +++++++++++++++++++++
 6 files changed, 87 insertions(+), 3 deletions(-)
 create mode 100644 tests/compile/errors/unsupported.sieve

diff --git a/TODO b/TODO
index 6d8705265..756f20833 100644
--- a/TODO
+++ b/TODO
@@ -42,7 +42,8 @@ Next (in order of descending priority/precedence):
 * Make testsuite much more exhaustive and add support for testing the actual
   result.
 
-* Build a sieve tool to filter an entire existing mailbox through a sieve script.
+* Build a sieve tool to filter an entire existing mailbox through a sieve 
+  script.
 * Build a server with test mail accounts that processes lots and lots of mail 
   (e.g. spam, mailing lists etc.)
 
diff --git a/src/lib-sieve/plugins/include/cmd-include.c b/src/lib-sieve/plugins/include/cmd-include.c
index ca1a329e2..426fdc556 100644
--- a/src/lib-sieve/plugins/include/cmd-include.c
+++ b/src/lib-sieve/plugins/include/cmd-include.c
@@ -176,11 +176,25 @@ static bool cmd_include_validate(struct sieve_validator *validator,
 	struct sieve_script *script;
 	const char *script_dir, *script_name;
 	
+	/* Check argument */
 	if ( !sieve_validate_positional_argument
 		(validator, cmd, arg, "value", 1, SAAT_STRING) ) {
 		return FALSE;
 	}
 
+	if ( !sieve_validator_argument_activate(validator, cmd, arg, FALSE) )
+		return FALSE;
+
+	/* FIXME: We can currently only handle string literal argument, so
+	 * variables are not allowed.
+	 */
+	if ( !sieve_argument_is_string_literal(arg) ) {
+		sieve_argument_validate_error(validator, arg, 
+			"this Sieve implementation currently only supports "
+			"a literal string argument for the include command");
+		return FALSE;
+	}
+
 	/* Find the script */
 
 	script_name = sieve_ast_argument_strc(arg);
diff --git a/src/lib-sieve/plugins/regex/mcht-regex.c b/src/lib-sieve/plugins/regex/mcht-regex.c
index 77536621d..26be8f668 100644
--- a/src/lib-sieve/plugins/regex/mcht-regex.c
+++ b/src/lib-sieve/plugins/regex/mcht-regex.c
@@ -116,10 +116,13 @@ static int mcht_regex_validate_key_argument
 {
 	struct _regex_key_context *keyctx = (struct _regex_key_context *) context;
 
+	/* FIXME: We can currently only handle string literal argument, so
+	 * variables are not allowed.
+	 */
 	if ( !sieve_argument_is_string_literal(key) ) {
 		sieve_argument_validate_error(keyctx->valdtr, key,
-			"this sieve implementation currently does not accept variable strings "
-			"as regular expression");
+			"this Sieve implementation currently only accepts a literal string "
+			"for a regular expression");
 		return FALSE;
 	}
 
diff --git a/src/lib-sieve/sieve-comparators.c b/src/lib-sieve/sieve-comparators.c
index 038f85892..f6be3e550 100644
--- a/src/lib-sieve/sieve-comparators.c
+++ b/src/lib-sieve/sieve-comparators.c
@@ -157,6 +157,19 @@ static bool tag_comparator_validate
 			sieve_ast_argument_name(*arg) );
 		return FALSE;
 	}
+
+	if ( !sieve_validator_argument_activate(validator, cmd, *arg, FALSE) )
+		return FALSE;
+
+	/* FIXME: We can currently only handle string literal argument, so
+	 * variables are not allowed.
+	 */
+	if ( !sieve_argument_is_string_literal(*arg) ) {
+		sieve_argument_validate_error(validator, *arg, 
+			"this Sieve implementation currently only supports "
+			"a literal string argument for the :comparator tag");
+		return FALSE;
+	}
 	
 	/* Get comparator from registry */
 	cmp = sieve_comparator_find(validator, sieve_ast_argument_strc(*arg));
diff --git a/tests/compile/errors.svtest b/tests/compile/errors.svtest
index 024b41f20..98430a163 100644
--- a/tests/compile/errors.svtest
+++ b/tests/compile/errors.svtest
@@ -313,3 +313,17 @@ test "Tagged argument errors (FIXME: count only)" {
     }
 }
 
+/*
+ * Unsupported language features
+ */
+
+test "Unsupported language features (FIXME: count only)" {
+    if test_compile "errors/unsupported.sieve" {
+        test_fail "compile should have failed.";
+    }
+
+    if not test_error :count "eq" :comparator "i;ascii-numeric" "4" {
+        test_fail "wrong number of errors reported";
+    }
+}
+
diff --git a/tests/compile/errors/unsupported.sieve b/tests/compile/errors/unsupported.sieve
new file mode 100644
index 000000000..6ecf21d07
--- /dev/null
+++ b/tests/compile/errors/unsupported.sieve
@@ -0,0 +1,39 @@
+/* 
+ * Handling of unsupported language features.
+ *
+ *   Total errors: 3 (+1 = 4)
+ */
+
+require "variables";
+require "include";
+require "regex";
+
+/* 
+ * Unsupported use of variables
+ */
+
+/* Comparator argument */ 
+
+set "comp" "i;ascii-numeric";
+
+if address :comparator "${comp}" "from" "stephan@rename-it.nl" {
+	stop;
+}
+
+/* Included script */
+
+set "script" "blacklist";
+
+include "${blacklist}";
+
+/* Variable regexp */
+
+set "match" "(.*)rename-it(.*)";
+
+if address :regex "from" "${match}" {
+	stop;
+}
+ 
+
+
+
-- 
GitLab