dovecot-2.1-pigeonhole: lib-sieve: editheader: made deleteheader...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Tue Nov 29 00:32:28 EET 2011


details:   http://hg.rename-it.nl/dovecot-2.1-pigeonhole/rev/9a0b9ca3aca5
changeset: 1564:9a0b9ca3aca5
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon Nov 28 23:32:14 2011 +0100
description:
lib-sieve: editheader: made deleteheader match ignore leading and trailing whitespace.

diffstat:

 src/lib-sieve/edit-mail.c                       |  24 +++++++++++-
 tests/extensions/editheader/deleteheader.svtest |  33 ++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletions(-)

diffs (79 lines):

diff -r 8d0cfe6f66f0 -r 9a0b9ca3aca5 src/lib-sieve/edit-mail.c
--- a/src/lib-sieve/edit-mail.c	Mon Nov 28 22:13:18 2011 +0100
+++ b/src/lib-sieve/edit-mail.c	Mon Nov 28 23:32:14 2011 +0100
@@ -930,12 +930,34 @@
 	*edhiter = NULL;
 }
 
+static inline string_t *_header_right_trim(const char *raw) 
+{
+	string_t *result;
+	int i;
+	
+	for ( i = strlen(raw)-1; i >= 0; i-- ) {
+		if ( raw[i] != ' ' && raw[i] != '\t' ) break;
+	}
+	
+	result = t_str_new(i+1);
+	str_append_n(result, raw, i + 1);
+	return result;
+}
+
 void edit_mail_headers_iterate_get
 (struct edit_mail_header_iter *edhiter, const char **value_r)
 {
+	const char *raw;
+	int i;
+
 	i_assert( edhiter->current != NULL && edhiter->current->header != NULL);
 
-	*value_r = edhiter->current->field->utf8_value;
+	raw = edhiter->current->field->utf8_value;
+	for ( i = strlen(raw)-1; i >= 0; i-- ) {
+		if ( raw[i] != ' ' && raw[i] != '\t' ) break;
+	}
+
+	*value_r = t_strndup(raw, i+1);
 }
 
 bool edit_mail_headers_iterate_next
diff -r 8d0cfe6f66f0 -r 9a0b9ca3aca5 tests/extensions/editheader/deleteheader.svtest
--- a/tests/extensions/editheader/deleteheader.svtest	Mon Nov 28 22:13:18 2011 +0100
+++ b/tests/extensions/editheader/deleteheader.svtest	Mon Nov 28 23:32:14 2011 +0100
@@ -929,3 +929,36 @@
 		test_fail "body not retained in redirected mail";
 	}
 }
+
+/*
+ * TEST: Ignoring whitespace
+ */
+
+test_set "message" text:
+From: stephan at example.org
+To: nico at frop.example.com
+Subject:         Help        
+X-A:     Text
+X-B: Text            
+
+Text
+.
+;
+
+test "Ignoring whitespace" {
+	deleteheader :is "subject" "Help";
+	deleteheader :is "x-a" "Text";
+	deleteheader :is "x-b" "Text";
+
+	if exists "subject" {
+		test_fail "subject header not deleted";
+	}
+
+	if exists "x-a" {
+		test_fail "x-a header not deleted";
+	}
+
+	if exists "x-b" {
+		test_fail "x-b header not deleted";
+	}
+}


More information about the dovecot-cvs mailing list