From: Timo Sirainen Date: Tue, 25 Feb 2020 12:34:18 +0000 (+0200) Subject: lib-mail: message-snippet - Don't include trailing whitespace in snippet X-Git-Tag: 2.3.11.2~580 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=734a2b5bf955770bef8118f717bba5d6350f6b72;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: message-snippet - Don't include trailing whitespace in snippet --- diff --git a/src/lib-mail/message-snippet.c b/src/lib-mail/message-snippet.c index 441d03d308..a4ab7b11d6 100644 --- a/src/lib-mail/message-snippet.c +++ b/src/lib-mail/message-snippet.c @@ -64,10 +64,12 @@ static void snippet_add_content(struct snippet_context *ctx, return; target->chars_left--; if (ctx->add_whitespace) { + if (target->chars_left == 0) { + /* don't add a trailing whitespace */ + return; + } str_append_c(target->snippet, ' '); ctx->add_whitespace = FALSE; - if (target->chars_left == 0) - return; target->chars_left--; } *count_r = uni_utf8_char_bytes(data[0]); diff --git a/src/lib-mail/test-message-snippet.c b/src/lib-mail/test-message-snippet.c index 35289367de..b874280cbc 100644 --- a/src/lib-mail/test-message-snippet.c +++ b/src/lib-mail/test-message-snippet.c @@ -86,6 +86,21 @@ static const struct { ">quoted long text", 7, ">quoted" }, + { "Content-Type: text/plain\n" + "\n" + ">quoted long text", + 8, + ">quoted" }, + { "Content-Type: text/plain\n" + "\n" + "whitespace and more", + 10, + "whitespace" }, + { "Content-Type: text/plain\n" + "\n" + "whitespace and more", + 11, + "whitespace" }, { "Content-Type: text/plain; charset=utf-8\n" "\n" "Invalid utf8 \x80\xff\n",