From: Timo Sirainen Date: Tue, 25 Feb 2020 15:33:30 +0000 (+0200) Subject: lib-mail: message-snippet - Quoted text could have been wrongly added to the snippet X-Git-Tag: 2.3.10~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=463103a2cc9f922ac2a80dfc1312177dab5b188b;p=thirdparty%2Fdovecot%2Fcore.git 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. --- 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);