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