]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-snippet - Don't include trailing whitespace in snippet
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 25 Feb 2020 12:34:18 +0000 (14:34 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 26 Feb 2020 08:14:23 +0000 (10:14 +0200)
src/lib-mail/message-snippet.c
src/lib-mail/test-message-snippet.c

index 441d03d308f7b8a56bfd4e619cd7611b7bbf4a7d..a4ab7b11d68de6cab9bed86b9de992e2e723398f 100644 (file)
@@ -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]);
index 35289367dee87764bb54c465d3586e1b6f353977..b874280cbc921ae338974802c2c9decfcfe7fbec 100644 (file)
@@ -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",