]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-snippet: Fix expected number of leading non-whitespace chars
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Mon, 28 Dec 2020 10:26:07 +0000 (10:26 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 14 Jan 2021 10:33:07 +0000 (10:33 +0000)
If message body starts with a single char + space (e.g. "I am"), the
space is wrongly removed (i.e. snippet would be "Iam") because at least two
non-whitespace characters are expected. Fix the minimum to 1 to fix this.

src/lib-mail/message-snippet.c
src/lib-mail/test-message-snippet.c

index e6965fd707f47f53758adceed34c672c0939d185..f99e37a2df93d87f9bc806082b551791f76815aa 100644 (file)
@@ -54,7 +54,7 @@ static void snippet_add_content(struct snippet_context *ctx,
        }
        if (i_isspace(*data)) {
                /* skip any leading whitespace */
-               if (str_len(target->snippet) > 1)
+               if (str_len(target->snippet) > 0)
                        ctx->add_whitespace = TRUE;
                if (data[0] == '\n')
                        ctx->state = SNIPPET_STATE_NEWLINE;
index af96e13e573328d208007fa7b46b29de136019d8..3d09288f5729f90e0ea031ca5faf7d364a1cfa42 100644 (file)
@@ -122,6 +122,36 @@ static const struct {
           "</div><br =class=3D\"\"></body></html>=\n",
           100,
           ">quoted text is included" },
+       { "Content-Type: text/plain; charset=utf-8\n"
+         "\n"
+         "I think\n",
+         100,
+         "I think"
+       },
+       { "Content-Type: text/plain; charset=utf-8\n"
+         "\n"
+         "  Lorem Ipsum\n",
+         100,
+         "Lorem Ipsum"
+       },
+       { "Content-Type: text/plain; charset=utf-8\n"
+         "\n"
+         " I think\n",
+         100,
+         "I think"
+       },
+       { "Content-Type: text/plain; charset=utf-8\n"
+         "\n"
+         "   A cat\n",
+         100,
+         "A cat"
+       },
+       { "Content-Type: text/plain; charset=utf-8\n"
+         "\n"
+         " \n",
+         100,
+         ""
+       },
 };
 
 static void test_message_snippet(void)