]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quoted-printable decoding: Don't add CR if it wasn't in input.
authorTimo Sirainen <tss@iki.fi>
Mon, 18 Mar 2013 13:46:16 +0000 (15:46 +0200)
committerTimo Sirainen <tss@iki.fi>
Mon, 18 Mar 2013 13:46:16 +0000 (15:46 +0200)
This guarantees that the decoded Q-P won't be larger than its input.

src/lib-mail/quoted-printable.c
src/lib-mail/test-quoted-printable.c

index 342ebce2ede87d8a997d584276630c1cc7879f44..8ecfa58d3d0d937ea171d138b0414fb9bfaf8798 100644 (file)
@@ -33,7 +33,7 @@ quoted_printable_decode_full(const unsigned char *src, size_t src_size,
 {
        char hexbuf[3];
        size_t src_pos, pos, next;
-       bool errors = FALSE;
+       bool have_cr, errors = FALSE;
        int ret;
 
        hexbuf[2] = '\0';
@@ -46,13 +46,19 @@ quoted_printable_decode_full(const unsigned char *src, size_t src_size,
                if (src[src_pos] == '\n') {
                        /* drop trailing whitespace */
                        pos = src_pos;
-                       if (pos > 0 && src[pos-1] == '\r')
+                       if (pos > 0 && src[pos-1] == '\r') {
                                pos--;
+                               have_cr = TRUE;
+                       } else {
+                               have_cr = FALSE;
+                       }
                        while (pos > 0 && QP_IS_TRAILING_SPACE(src[pos-1]))
                                pos--;
                        buffer_append(dest, src + next, pos - next);
                        next = src_pos+1;
-                       buffer_append(dest, "\r\n", 2);
+                       if (have_cr)
+                               buffer_append_c(dest, '\r');
+                       buffer_append_c(dest, '\n');
                        continue;
                }
 
index a6f78248691aa75f71eebe5271c66826af90e135..8adf1dcd416b81a07d15fad65919087862802d74 100644 (file)
@@ -21,7 +21,7 @@ static void test_quoted_printable_decode(void)
                { "foo = \n=01", "foo \001", 0, 0 },
                { "foo =\t\r\nbar", "foo bar", 0, 0 },
                { "foo =\r\n=01", "foo \001", 0, 0 },
-               { "foo  \nbar=", "foo\r\nbar", 1, 0 },
+               { "foo  \nbar=", "foo\nbar", 1, 0 },
                { "=0A=0D  ", "\n\r", 2, 0 },
                { "foo_bar", "foo_bar", 0, 0 },
                { "foo=", "foo", 1, 0 },