dovecot-2.2-pigeonhole: Applied sieve-body-fix.patch.

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Mon Feb 13 01:03:50 EET 2012


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/eed6fba433f4
changeset: 1602:eed6fba433f4
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon Feb 13 00:01:30 2012 +0100
description:
Applied sieve-body-fix.patch.
Fixes behavior of body test with multipart MIME body parts.
Testsuite needs to be extended accordingly.

diffstat:

 TODO                                         |   1 -
 src/lib-sieve/plugins/body/ext-body-common.c |  65 +++++++++++++++++++++++++++++---
 2 files changed, 58 insertions(+), 8 deletions(-)

diffs (123 lines):

diff -r 408cc4b15640 -r eed6fba433f4 TODO
--- a/TODO	Sun Feb 12 23:53:31 2012 +0100
+++ b/TODO	Mon Feb 13 00:01:30 2012 +0100
@@ -25,7 +25,6 @@
 	  (posix regexes actually do support utf8, but only when locale is set
 	  accordingly)
 * Finish body extension:
-	- Implement proper :content "multipart" behavior
 	- Build test cases for decoding MIME encodings to UTF-8
 * Cleanup the test suite
 	- Restructure test scripts
diff -r 408cc4b15640 -r eed6fba433f4 src/lib-sieve/plugins/body/ext-body-common.c
--- a/src/lib-sieve/plugins/body/ext-body-common.c	Sun Feb 12 23:53:31 2012 +0100
+++ b/src/lib-sieve/plugins/body/ext-body-common.c	Mon Feb 13 00:01:30 2012 +0100
@@ -83,6 +83,25 @@
 	return FALSE;
 }
 
+static bool _want_multipart_content_type
+(const char * const *wanted_types)
+{
+	for (; *wanted_types != NULL; wanted_types++) {
+		if (**wanted_types == '\0') {
+			/* empty string matches everything */
+			return TRUE;
+		}
+
+		/* match only main type */
+		if ( strncasecmp(*wanted_types, "multipart", 9) == 0 && 
+			( strlen(*wanted_types) == 9 || *(*wanted_types+9) == '/' ) )
+			return TRUE;
+	}
+
+	return FALSE;
+}
+
+
 static bool ext_body_get_return_parts
 (struct ext_body_message_context *ctx, const char * const *wanted_types,
 	bool decode_to_plain)
@@ -201,9 +220,10 @@
 	struct message_decoder_context *decoder;
 	struct message_block block, decoded;
 	struct message_part *parts, *prev_part = NULL;
+	ARRAY_DEFINE(part_index, struct message_part *);
 	struct istream *input;
 	unsigned int idx = 0;
-	bool save_body = FALSE, have_all;
+	bool save_body = FALSE, want_multipart, have_all;
 	int ret;
 
 	/* First check whether any are missing */
@@ -215,17 +235,23 @@
 	/* Get the message stream */
 	if ( mail_get_stream(mail, NULL, NULL, &input) < 0 )
 		return FALSE;
-	//if (mail_get_parts(mail, &parts) < 0)
-	//	return FALSE;
+
+	if (mail_get_parts(mail, &parts) < 0)
+		return FALSE;
+
+	if ( (want_multipart=_want_multipart_content_type(content_types)) ) {
+		t_array_init(&part_index, 8);
+	}
 
 	buffer_set_used_size(ctx->tmp_buffer, 0);
 	
 	/* Initialize body decoder */
 	decoder = decode_to_plain ? message_decoder_init(FALSE) : NULL;	
 
-	//parser = message_parser_init_from_parts(parts, input, 0, 0);
-	parser = message_parser_init(ctx->pool, input, 0, 0);
-
+	//parser = message_parser_init_from_parts(parts, input, 0,
+		//MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS);
+	parser = message_parser_init(ctx->pool, input, 0,
+		MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS);
 	while ( (ret = message_parser_parse_next_block(parser, &block)) > 0 ) {
 
 		if ( block.part != prev_part ) {
@@ -238,8 +264,9 @@
 					strcmp(body_part->content_type, "message/rfc822") == 0 ) {
 					message_rfc822 = TRUE;
 				} else {
-					if ( save_body ) 
+					if ( save_body ) { 
 						ext_body_part_save(ctx, body_part, decoder != NULL);
+					}
 				}
 			}
 
@@ -247,6 +274,30 @@
 			body_part = array_idx_modifiable(&ctx->cached_body_parts, idx);
 			body_part->content_type = "text/plain";
 
+			/* Check whether this is the epilogue block of a wanted multipart part */
+			if ( want_multipart ) {
+				array_idx_set(&part_index, idx, &block.part);
+
+				if ( prev_part != NULL && prev_part->next != block.part &&
+					block.part->parent != prev_part ) {
+					struct message_part *const *iparts;
+					unsigned int count, i;
+
+					iparts = array_get(&part_index, &count);
+					for ( i = 0; i < count; i++ ) {
+						if ( iparts[i] == block.part ) {
+							const struct ext_body_part_cached *parent =
+								array_idx(&ctx->cached_body_parts, i);
+							body_part->content_type = parent->content_type;
+							body_part->have_body = TRUE;
+							save_body = _is_wanted_content_type
+								(content_types, body_part->content_type);		
+							break;
+						}
+					}
+				}
+			}
+
 			/* If this is message/rfc822 content retain the enveloping part for
 			 * storing headers as content.
 			 */


More information about the dovecot-cvs mailing list