Blame SOURCES/dovecot-2.3.8-a668d767.patch

2c808a
diff --git a/src/lib-mail/message-parser.c b/src/lib-mail/message-parser.c
2c808a
index 011dea9050..8baf622e59 100644
2c808a
--- a/src/lib-mail/message-parser.c
2c808a
+++ b/src/lib-mail/message-parser.c
2c808a
@@ -138,6 +138,7 @@ message_part_append(struct message_parser_ctx *ctx)
2c808a
 	struct message_part *parent = ctx->part;
2c808a
 	struct message_part *part;
2c808a
 
2c808a
+	i_assert(!ctx->preparsed);
2c808a
 	i_assert(parent != NULL);
2c808a
 	i_assert((parent->flags & (MESSAGE_PART_FLAG_MULTIPART |
2c808a
 				   MESSAGE_PART_FLAG_MESSAGE_RFC822)) != 0);
2c808a
@@ -171,12 +172,14 @@ static void message_part_finish(struct message_parser_ctx *ctx)
2c808a
 {
2c808a
 	struct message_part **const *parent_next_partp;
2c808a
 
2c808a
-	i_assert(ctx->nested_parts_count > 0);
2c808a
-	ctx->nested_parts_count--;
2c808a
+	if (!ctx->preparsed) {
2c808a
+		i_assert(ctx->nested_parts_count > 0);
2c808a
+		ctx->nested_parts_count--;
2c808a
 
2c808a
-	parent_next_partp = array_back(&ctx->next_part_stack);
2c808a
-	array_pop_back(&ctx->next_part_stack);
2c808a
-	ctx->next_part = *parent_next_partp;
2c808a
+		parent_next_partp = array_back(&ctx->next_part_stack);
2c808a
+		array_pop_back(&ctx->next_part_stack);
2c808a
+		ctx->next_part = *parent_next_partp;
2c808a
+	}
2c808a
 
2c808a
 	message_size_add(&ctx->part->parent->body_size, &ctx->part->body_size);
2c808a
 	message_size_add(&ctx->part->parent->body_size, &ctx->part->header_size);
2c808a
diff --git a/src/lib-mail/test-message-parser.c b/src/lib-mail/test-message-parser.c
2c808a
index 13984f939e..a00f0d6200 100644
2c808a
--- a/src/lib-mail/test-message-parser.c
2c808a
+++ b/src/lib-mail/test-message-parser.c
2c808a
@@ -178,9 +178,10 @@ static void test_message_parser_small_blocks(void)
2c808a
 static void test_message_parser_stop_early(void)
2c808a
 {
2c808a
 	struct message_parser_ctx *parser;
2c808a
-	struct istream *input;
2c808a
+	struct istream *input, *input2;
2c808a
 	struct message_part *parts;
2c808a
 	struct message_block block;
2c808a
+	const char *error;
2c808a
 	unsigned int i;
2c808a
 	pool_t pool;
2c808a
 	int ret;
2c808a
@@ -198,6 +199,24 @@ static void test_message_parser_stop_early(void)
2c808a
 							      &block)) > 0) ;
2c808a
 		test_assert(ret == 0);
2c808a
 		message_parser_deinit(&parser, &parts;;
2c808a
+
2c808a
+		/* test preparsed - first re-parse everything with a stream
2c808a
+		   that sees EOF at this position */
2c808a
+		input2 = i_stream_create_from_data(test_msg, i);
2c808a
+		parser = message_parser_init(pool, input2, &set_empty);
2c808a
+		while ((ret = message_parser_parse_next_block(parser,
2c808a
+							      &block)) > 0) ;
2c808a
+		test_assert(ret == -1);
2c808a
+		message_parser_deinit(&parser, &parts;;
2c808a
+
2c808a
+		/* now parse from the parts */
2c808a
+		i_stream_seek(input2, 0);
2c808a
+		parser = message_parser_init_from_parts(parts, input2, &set_empty);
2c808a
+		while ((ret = message_parser_parse_next_block(parser,
2c808a
+							      &block)) > 0) ;
2c808a
+		test_assert(ret == -1);
2c808a
+		test_assert(message_parser_deinit_from_parts(&parser, &parts, &error) == 0);
2c808a
+		i_stream_unref(&input2);
2c808a
 	}
2c808a
 
2c808a
 	i_stream_unref(&input);