]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: istream-header-filter: Fix HEADER_FILTER_ADD_MISSING_EOH with callback
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 18 Mar 2019 13:34:10 +0000 (15:34 +0200)
committerMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Wed, 25 Sep 2019 08:25:20 +0000 (11:25 +0300)
If mail already had EOH and callback returned matched=TRUE in the EOH
callback (e.g. adding more headers), the callback was called a second
time for the EOH.

Currently there doesn't seem to be any existing code that was affected by
this bug.

src/lib-mail/istream-header-filter.c
src/lib-mail/test-istream-header-filter.c

index 77f44f63968176b01908f91ca24723c765efcdcd..cc8eef8128d23bedde579534e5446328f2b16796 100644 (file)
@@ -211,7 +211,6 @@ static ssize_t read_header(struct header_filter_istream *mstream)
                        }
 
                        if (matched) {
-                               mstream->seen_eoh = FALSE;
                                mstream->eoh_not_matched = TRUE;
                                continue;
                        }
index 1c20e111421103139d9734bd946f36a9c6eaf5fa..3eb66d610876e6db2d3187a5c9096a55cdd4b42e 100644 (file)
@@ -527,19 +527,30 @@ static void test_istream_add_missing_eoh(void)
 
 static void test_istream_add_missing_eoh_and_edit(void)
 {
-       const char *input = "From: foo\nTo: bar\n";
-       const char *output = "From: foo\nTo: 123\nAdded: header\n\n";
+       static const struct {
+               const char *input;
+               const char *output;
+       } tests[] = {
+               { "From: foo\nTo: bar\n",
+                 "From: foo\nTo: 123\nAdded: header\n\n" },
+               { "From: foo\nTo: bar\n\n",
+                 "From: foo\nTo: 123\nAdded: header\n\n" },
+               { "From: foo\nTo: bar\n\nbody\n",
+                 "From: foo\nTo: 123\nAdded: header\n\nbody\n" },
+       };
        struct istream *istream;
+       unsigned int i;
 
        test_begin("i_stream_create_header_filter: add missing EOH and edit headers");
-       istream = test_istream_create(input);
-       test_istream_run(istream, strlen(input), output,
-                        HEADER_FILTER_EXCLUDE |
-                        HEADER_FILTER_ADD_MISSING_EOH |
-                        HEADER_FILTER_NO_CR,
-                        edit_callback);
-       i_stream_unref(&istream);
-
+       for (i = 0; i < N_ELEMENTS(tests); i++) {
+               istream = test_istream_create(tests[i].input);
+               test_istream_run(istream, strlen(tests[i].input), tests[i].output,
+                                HEADER_FILTER_EXCLUDE |
+                                HEADER_FILTER_ADD_MISSING_EOH |
+                                HEADER_FILTER_NO_CR,
+                                edit_callback);
+               i_stream_unref(&istream);
+       }
        test_end();
 }