From 3b53c87f68d4aa59c04227349a29991f651d264c Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Mon, 21 Jul 2008 23:19:39 +0200
Subject: [PATCH] Testsuite: tested handling of teststuite envelope environment
 and fixed bugs in the envelope test in the process.

---
 TODO                                 |  3 ++-
 src/lib-sieve/ext-envelope.c         |  6 ++---
 src/lib-sieve/sieve-address-parts.c  | 14 +++++-----
 src/testsuite/tests/testsuite.svtest | 40 ++++++++++++++++++++++++++--
 src/testsuite/testsuite-objects.c    |  1 +
 5 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/TODO b/TODO
index c91b11229..7a44932db 100644
--- a/TODO
+++ b/TODO
@@ -6,6 +6,7 @@ Next (in order of descending priority/precedence):
 * Test with dovecot --enable-debug for initial mempool allocation size
 * Full standards compliance review for the engine and all fully implemented 
   sieve extensions.
+    - Address test MUST restrict itself to headers that contain addresses.'
 * Code cleanup 
 * Make sure cmusieve can be replaced seamlessly with the new plugin.
 * Full security review. Enforce limits on number of created objects, script 
@@ -16,7 +17,7 @@ Next (in order of descending priority/precedence):
 
 * ## MAKE A FIRST RELEASE ##
 
-* Add normalize() method to comparators to normalize the string before mathing
+* Add normalize() method to comparators to normalize the string before matching
   (for efficiency).
 * Verify outgoing mail addresses at runtime when necessary (e.g. after variables 
   substitution)
diff --git a/src/lib-sieve/ext-envelope.c b/src/lib-sieve/ext-envelope.c
index 19d1a999d..1ccb0c759 100644
--- a/src/lib-sieve/ext-envelope.c
+++ b/src/lib-sieve/ext-envelope.c
@@ -207,11 +207,11 @@ static int ext_envelope_get_fields
 	
  	t_array_init(&envelope_values, 2);
  	
-	if ( strncmp(field, "from", 4) == 0 )
+	if ( strcasecmp(field, "from") == 0 )
 		value = msgdata->return_path;
-	else if ( strncmp(field, "to", 2) == 0 )
+	else if ( strcasecmp(field, "to") == 0 )
 		value = msgdata->to_address;	
-	else if ( strncmp(field, "auth", 2) == 0 ) /* Non-standard */
+	else if ( strcasecmp(field, "auth") == 0 ) /* Non-standard */ 
 		value = msgdata->auth_user;
 		
 	if ( value != NULL )
diff --git a/src/lib-sieve/sieve-address-parts.c b/src/lib-sieve/sieve-address-parts.c
index f13ac3dcd..9a5faec29 100644
--- a/src/lib-sieve/sieve-address-parts.c
+++ b/src/lib-sieve/sieve-address-parts.c
@@ -198,17 +198,15 @@ bool sieve_address_match
 				strlen(data), 256, FALSE);
 	
 		while (!matched && addr != NULL) {
-			if (addr->domain != NULL) {
-				/* mailbox@domain */
-				const char *part;
+			/* mailbox@domain */
+			const char *part;
 			
-				i_assert(addr->mailbox != NULL);
+			i_assert(addr->mailbox != NULL);
 
-				part = addrp->extract_from(addr);
+			part = addrp->extract_from(addr);
 			
-				if ( part != NULL && sieve_match_value(mctx, part, strlen(part)) )
-					matched = TRUE;				
-			} 
+			if ( part != NULL && sieve_match_value(mctx, part, strlen(part)) )
+				matched = TRUE;				
 
 			addr = addr->next;
 		}
diff --git a/src/testsuite/tests/testsuite.svtest b/src/testsuite/tests/testsuite.svtest
index 8b79dbd54..97bb5bcb7 100644
--- a/src/testsuite/tests/testsuite.svtest
+++ b/src/testsuite/tests/testsuite.svtest
@@ -1,4 +1,5 @@
 require "vnd.dovecot.testsuite";
+require "envelope";
 
 test "Message Environment" {
 	test_set "message" text:
@@ -9,7 +10,6 @@ Subject: Frop!
 Frop!
 .
 	;
-	test_set "envelope.from" "stephan@rename-it.nl";
 
 	if not header :contains "from" "rename-it.nl" {
 		test_fail "message data not set properly.";
@@ -23,7 +23,6 @@ Subject: Friep!
 Friep!
 .
 	;
-	test_set "envelope.from" "stephan@rename-it.nl";
 
 	if not header :is "from" "nico@vestingbar.nl" {
     	test_fail "message data not set properly.";
@@ -32,3 +31,40 @@ Friep!
 	keep;
 }
 
+test "Envelope Environment" {
+	test_set "envelope.from" "stephan@hutsefluts.nl";
+
+	if not envelope :is "from" "stephan@hutsefluts.nl" {
+        test_fail "envelope.from data not set properly.";
+    }
+
+	test_set "envelope.to" "news@rename-it.nl";
+
+	if not envelope :is "to" "news@rename-it.nl" {
+        test_fail "envelope.to data not set properly.";
+    }
+
+	test_set "envelope.auth" "sirius";
+
+    if not envelope :is "auth" "sirius@" {
+        test_fail "envelope.auth data not set properly.";
+    }
+
+	test_set "envelope.from" "stephan@rename-it.nl";
+
+	if not envelope :is "from" "stephan@rename-it.nl" {
+        test_fail "envelope.from data not reset properly.";
+    }
+
+	test_set "envelope.to" "past-news@rename-it.nl";
+
+	if not envelope :is "to" "past-news@rename-it.nl" {
+        test_fail "envelope.to data not reset properly.";
+    }
+
+	test_set "envelope.auth" "zilla";
+
+    if not envelope :is "auth" "zilla@" {
+        test_fail "envelope.auth data not reset properly.";
+    }
+}
diff --git a/src/testsuite/testsuite-objects.c b/src/testsuite/testsuite-objects.c
index 3f2420f15..14c2a32cb 100644
--- a/src/testsuite/testsuite-objects.c
+++ b/src/testsuite/testsuite-objects.c
@@ -325,6 +325,7 @@ static bool tsto_envelope_set_member(int id, string_t *value)
 		return TRUE;
 	case TESTSUITE_OBJECT_ENVELOPE_AUTH_USER: 
 		testsuite_envelope_set_auth_user(str_c(value));
+		printf("AUTH: %s\n", str_c(value));
 		return TRUE;
 	}
 	
-- 
GitLab