Address test: removed header MIME-decoding to prevent address parsing problems.
authorStephan Bosch <stephan@rename-it.nl>
Sat Jan 01 14:10:53 2011 +0100 (2011-01-01)
changeset 145499f8dc1e246a
parent 1453 67d2240966ec
child 1455 146a2a9d5cb0
Address test: removed header MIME-decoding to prevent address parsing problems.
src/lib-sieve/plugins/date/tst-date.c
src/lib-sieve/sieve-message.c
src/lib-sieve/sieve-message.h
src/lib-sieve/tst-address.c
src/lib-sieve/tst-header.c
tests/test-address.svtest
     1.1 --- a/src/lib-sieve/plugins/date/tst-date.c	Tue Dec 07 00:05:50 2010 +0100
     1.2 +++ b/src/lib-sieve/plugins/date/tst-date.c	Sat Jan 01 14:10:53 2011 +0100
     1.3 @@ -461,11 +461,11 @@
     1.4  	 */
     1.5  
     1.6  	if ( sieve_operation_is(op, date_operation) ) {
     1.7 -	
     1.8 +
     1.9  		sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "date test");
    1.10  
    1.11  		/* Create value stringlist */
    1.12 -		hdr_value_list = sieve_message_header_stringlist_create(renv, hdr_list);
    1.13 +		hdr_value_list = sieve_message_header_stringlist_create(renv, hdr_list, FALSE);
    1.14  		value_list = ext_date_stringlist_create
    1.15  			(renv, hdr_value_list, time_zone, str_c(date_part));
    1.16  
     2.1 --- a/src/lib-sieve/sieve-message.c	Tue Dec 07 00:05:50 2010 +0100
     2.2 +++ b/src/lib-sieve/sieve-message.c	Sat Jan 01 14:10:53 2011 +0100
     2.3 @@ -266,20 +266,24 @@
     2.4  
     2.5  	const char *const *headers;
     2.6  	int headers_index;
     2.7 +
     2.8 +	unsigned int mime_decode:1;
     2.9  };
    2.10  
    2.11  struct sieve_stringlist *sieve_message_header_stringlist_create
    2.12 -(const struct sieve_runtime_env *renv, struct sieve_stringlist *field_names)
    2.13 +(const struct sieve_runtime_env *renv, struct sieve_stringlist *field_names,
    2.14 +	bool mime_decode)
    2.15  {
    2.16  	struct sieve_message_header_stringlist *strlist;
    2.17 -	    
    2.18 +
    2.19  	strlist = t_new(struct sieve_message_header_stringlist, 1);
    2.20  	strlist->strlist.runenv = renv;
    2.21  	strlist->strlist.exec_status = SIEVE_EXEC_OK;
    2.22  	strlist->strlist.next_item = sieve_message_header_stringlist_next_item;
    2.23  	strlist->strlist.reset = sieve_message_header_stringlist_reset;
    2.24  	strlist->field_names = field_names;
    2.25 -  
    2.26 +	strlist->mime_decode = mime_decode;
    2.27 +
    2.28  	return &strlist->strlist;
    2.29  }
    2.30  
    2.31 @@ -334,11 +338,20 @@
    2.32  		}
    2.33  
    2.34  		/* Fetch all matching headers from the e-mail */
    2.35 -		if ( mail_get_headers_utf8(mail, str_c(hdr_item), &strlist->headers) < 0 ||
    2.36 -			( strlist->headers != NULL && strlist->headers[0] == NULL ) ) {
    2.37 -			/* Try next item when this fails somehow */
    2.38 -			strlist->headers = NULL;
    2.39 -			continue;
    2.40 +		if ( strlist->mime_decode ) {
    2.41 +			if ( mail_get_headers_utf8(mail, str_c(hdr_item), &strlist->headers) < 0 ||
    2.42 +				( strlist->headers != NULL && strlist->headers[0] == NULL ) ) {
    2.43 +				/* Try next item when this fails somehow */
    2.44 +				strlist->headers = NULL;
    2.45 +				continue;
    2.46 +			}
    2.47 +		} else {
    2.48 +			if ( mail_get_headers(mail, str_c(hdr_item), &strlist->headers) < 0 ||
    2.49 +				( strlist->headers != NULL && strlist->headers[0] == NULL ) ) {
    2.50 +				/* Try next item when this fails somehow */
    2.51 +				strlist->headers = NULL;
    2.52 +				continue;
    2.53 +			}
    2.54  		}
    2.55  	}
    2.56  
     3.1 --- a/src/lib-sieve/sieve-message.h	Tue Dec 07 00:05:50 2010 +0100
     3.2 +++ b/src/lib-sieve/sieve-message.h	Sat Jan 01 14:10:53 2011 +0100
     3.3 @@ -58,6 +58,7 @@
     3.4   */
     3.5  
     3.6  struct sieve_stringlist *sieve_message_header_stringlist_create
     3.7 -	(const struct sieve_runtime_env *renv, struct sieve_stringlist *field_names);
     3.8 -	
     3.9 +	(const struct sieve_runtime_env *renv, struct sieve_stringlist *field_names,
    3.10 +		bool mime_decode);
    3.11 +
    3.12  #endif /* __SIEVE_MESSAGE_H */
     4.1 --- a/src/lib-sieve/tst-address.c	Tue Dec 07 00:05:50 2010 +0100
     4.2 +++ b/src/lib-sieve/tst-address.c	Sat Jan 01 14:10:53 2011 +0100
     4.3 @@ -254,7 +254,7 @@
     4.4  	sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "address test");
     4.5  
     4.6  	/* Create value stringlist */
     4.7 -	hdr_value_list = sieve_message_header_stringlist_create(renv, hdr_list);
     4.8 +	hdr_value_list = sieve_message_header_stringlist_create(renv, hdr_list, FALSE);
     4.9  	addr_list = sieve_header_address_list_create(renv, hdr_value_list);
    4.10  	value_list = sieve_address_part_stringlist_create(renv, &addrp, addr_list);
    4.11  
     5.1 --- a/src/lib-sieve/tst-header.c	Tue Dec 07 00:05:50 2010 +0100
     5.2 +++ b/src/lib-sieve/tst-header.c	Sat Jan 01 14:10:53 2011 +0100
     5.3 @@ -186,7 +186,7 @@
     5.4  	sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "header test");
     5.5  
     5.6  	/* Create header stringlist */
     5.7 -	value_list = sieve_message_header_stringlist_create(renv, hdr_list);
     5.8 +	value_list = sieve_message_header_stringlist_create(renv, hdr_list, TRUE);
     5.9  
    5.10  	/* Perform match */
    5.11  	if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret)) < 0 )
     6.1 --- a/tests/test-address.svtest	Tue Dec 07 00:05:50 2010 +0100
     6.2 +++ b/tests/test-address.svtest	Sat Jan 01 14:10:53 2011 +0100
     6.3 @@ -370,3 +370,27 @@
     6.4  		test_fail "invalid default address part (2)";
     6.5  	}
     6.6  }
     6.7 +
     6.8 +/*
     6.9 + * TEST: Erroneous mime encoding
    6.10 + */
    6.11 +
    6.12 +test_set "message" text:
    6.13 +From: "William Wallace <william@scotsmen.ex>"
    6.14 +To: "=?UTF-8?B?IkR1bWIgTWFpbGVyIg==?="
    6.15 +	<horde@lists.scotsmen.ex>
    6.16 +Subject: Test
    6.17 +
    6.18 +Frop!
    6.19 +.
    6.20 +;
    6.21 +
    6.22 +
    6.23 +test "Erroneous mime encoding" {
    6.24 +        # Relevant sieve rule:
    6.25 +
    6.26 +        if not address :is ["To","CC"] ["horde@lists.scotsmen.ex","archers@lists.scotsmen.ex"] {
    6.27 +                test_fail "Failed to match improperly encoded address headers";
    6.28 +        }
    6.29 +}
    6.30 +