From 463103a2cc9f922ac2a80dfc1312177dab5b188b Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 25 Feb 2020 17:33:30 +0200 Subject: [PATCH] lib-mail: message-snippet - Quoted text could have been wrongly added to the snippet This happened when the mail was large enough that the parsing used multiple blocks. Parsing the following blocks were adding text in quoted state to the non-quoted snippet string. --- src/lib-mail/message-snippet.c | 7 ++++++- src/lib-mail/test-message-snippet.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib-mail/message-snippet.c b/src/lib-mail/message-snippet.c index a4ab7b11d6..2100b70554 100644 --- a/src/lib-mail/message-snippet.c +++ b/src/lib-mail/message-snippet.c @@ -81,7 +81,7 @@ static bool snippet_generate(struct snippet_context *ctx, const unsigned char *data, size_t size) { size_t i, count; - struct snippet_data *target = &ctx->snippet; + struct snippet_data *target; if (ctx->html2text != NULL) { buffer_set_used_size(ctx->plain_output, 0); @@ -91,6 +91,11 @@ static bool snippet_generate(struct snippet_context *ctx, size = ctx->plain_output->used; } + if (ctx->state == SNIPPET_STATE_QUOTED) + target = &ctx->quoted_snippet; + else + target = &ctx->snippet; + /* message-decoder should feed us only valid and complete UTF-8 input */ diff --git a/src/lib-mail/test-message-snippet.c b/src/lib-mail/test-message-snippet.c index b874280cbc..af96e13e57 100644 --- a/src/lib-mail/test-message-snippet.c +++ b/src/lib-mail/test-message-snippet.c @@ -133,7 +133,12 @@ static void test_message_snippet(void) test_begin("message snippet"); for (i = 0; i < N_ELEMENTS(tests); i++) { str_truncate(str, 0); - input = i_stream_create_from_data(tests[i].input, strlen(tests[i].input)); + input = test_istream_create(tests[i].input); + /* Limit the input max buffer size so the parsing uses multiple + blocks. 45 = large enough to be able to read the Content-* + headers. */ + test_istream_set_max_buffer_size(input, + I_MIN(45, strlen(tests[i].input))); test_assert_idx(message_snippet_generate(input, tests[i].max_snippet_chars, str) == 0, i); test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i); i_stream_destroy(&input); -- 2.47.3