]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-snippet - Fix size limits for quoted snippets
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 25 Feb 2020 12:31:43 +0000 (14:31 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 26 Feb 2020 08:14:23 +0000 (10:14 +0200)
If the input only had quoted text, the snippet size wasn't limited to
max_snippet_chars as long as there was any whitespace in the quoted text.

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

index a3cc319d33427dea591c564238c69116be98e0ce..e108b5821b331ad8543c81f9327e0a410b020edf 100644 (file)
@@ -60,15 +60,16 @@ static void snippet_add_content(struct snippet_context *ctx,
                        ctx->state = SNIPPET_STATE_NEWLINE;
                return;
        }
+       if (target->chars_left == 0)
+               return;
+       target->chars_left--;
        if (ctx->add_whitespace) {
                str_append_c(target->snippet, ' ');
                ctx->add_whitespace = FALSE;
-               if (target->chars_left-- == 0)
+               if (target->chars_left == 0)
                        return;
+               target->chars_left--;
        }
-       if (target->chars_left == 0)
-               return;
-       target->chars_left--;
        *count_r = uni_utf8_char_bytes(data[0]);
        i_assert(*count_r <= size);
        str_append_data(target->snippet, data, *count_r);
index 735acbde476eaaaa1c8c5f880dcecbf28e5ee69d..387a10734111c4ea112f39ef0a12215c16387c41 100644 (file)
@@ -81,6 +81,11 @@ static const struct {
          "top\nposter\n>quote1\n>quote2\n",
          100,
          "top poster" },
+       { "Content-Type: text/plain\n"
+         "\n"
+         ">quoted long text",
+         6,
+         ">quoted" },
        { "Content-Type: text/plain; charset=utf-8\n"
          "\n"
          "Invalid utf8 \x80\xff\n",