changeset 19527:207586dae1e1

lib-mail: message-parser wasn't returning hdr=NULL blocks after 078c2c8c
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 30 Dec 2015 08:21:46 -0500
parents e0bd9253121b
children a7fcd12d0d83
files src/lib-mail/message-parser.c src/lib-mail/test-message-parser.c
diffstat 2 files changed, 34 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-mail/message-parser.c	Wed Dec 30 08:21:24 2015 -0500
+++ b/src/lib-mail/message-parser.c	Wed Dec 30 08:21:46 2015 -0500
@@ -516,14 +516,16 @@
 	bool full;
 	int ret;
 
-	if ((ret = message_parser_read_more(ctx, block_r, &full)) <= 0)
+	if ((ret = message_parser_read_more(ctx, block_r, &full)) == 0)
 		return ret;
 
 	/* before parsing the header see if we can find a --boundary from here.
 	   we're guaranteed to be at the beginning of the line here. */
-	ret = ctx->boundaries == NULL ? -1 :
-		boundary_line_find(ctx, block_r->data,
-				   block_r->size, full, &boundary);
+	if (ret > 0) {
+		ret = ctx->boundaries == NULL ? -1 :
+			boundary_line_find(ctx, block_r->data,
+					   block_r->size, full, &boundary);
+	}
 	if (ret < 0) {
 		/* no boundary */
 		ret = message_parse_header_next(ctx->hdr_parser_ctx, &hdr);
--- a/src/lib-mail/test-message-parser.c	Wed Dec 30 08:21:24 2015 -0500
+++ b/src/lib-mail/test-message-parser.c	Wed Dec 30 08:21:46 2015 -0500
@@ -181,11 +181,39 @@
 	test_end();
 }
 
+static void test_message_parser_no_eoh(void)
+{
+	static const char input_msg[] = "a:b\n";
+	struct message_parser_ctx *parser;
+	struct istream *input;
+	struct message_part *parts;
+	struct message_block block;
+	pool_t pool;
+
+	test_begin("message parser no EOH");
+	pool = pool_alloconly_create("message parser", 10240);
+	input = test_istream_create(input_msg);
+
+	parser = message_parser_init(pool, input, 0, 0);
+	test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
+		    block.hdr != NULL && strcmp(block.hdr->name, "a") == 0 &&
+		    block.hdr->value_len == 1 && block.hdr->value[0] == 'b');
+	test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
+		    block.hdr == NULL && block.size == 0);
+	test_assert(message_parser_parse_next_block(parser, &block) < 0);
+	test_assert(message_parser_deinit(&parser, &parts) == 0);
+
+	i_stream_unref(&input);
+	pool_unref(&pool);
+	test_end();
+}
+
 int main(void)
 {
 	static void (*test_functions[])(void) = {
 		test_message_parser_small_blocks,
 		test_message_parser_truncated_mime_headers,
+		test_message_parser_no_eoh,
 		NULL
 	};
 	return test_run(test_functions);