]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_header_encode() needs to encode control characters as well.
authorTimo Sirainen <tss@iki.fi>
Mon, 5 May 2014 11:57:13 +0000 (14:57 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 5 May 2014 11:57:13 +0000 (14:57 +0300)
src/lib-mail/message-header-encode.c
src/lib-mail/test-message-header-encode.c

index dc746802e9d85cf38668445ee50fae3d6b5b14d8..fa387f0e57f30a77f1588ef2ef3d5c463849469d 100644 (file)
 
 static bool input_idx_need_encoding(const unsigned char *input, unsigned int i)
 {
+       /* 8bit chars */
        if ((input[i] & 0x80) != 0)
                return TRUE;
+       /* control chars */
+       if (input[i] < 32)
+               return TRUE;
 
+       /* <LWSP>=? */
        if (input[i] == '=' && input[i+1] == '?' &&
            (i == 0 || IS_LWSP(input[i-1])))
                return TRUE;
@@ -65,12 +70,12 @@ void message_header_encode_q(const unsigned char *input, unsigned int len,
                case '?':
                case '_':
                        line_len_left -= 2;
-                       str_printfa(output, "=%2X", input[i]);
+                       str_printfa(output, "=%02X", input[i]);
                        break;
                default:
                        if (input[i] < 32 || (input[i] & 0x80) != 0) {
                                line_len_left -= 2;
-                               str_printfa(output, "=%2X", input[i]);
+                               str_printfa(output, "=%02X", input[i]);
                        } else {
                                str_append_c(output, input[i]);
                        }
index 3989d7092357f6d233f6909f67e1ea45508636dc..a2da561dd97c4965d474c7549976182d8c12fbe8 100644 (file)
@@ -168,6 +168,8 @@ static void test_message_header_encode(void)
                "a ää ä b", "a =?utf-8?b?w6TDpCDDpA==?= b",
                "ä a ä", "=?utf-8?q?=C3=A4_a_=C3=A4?=",
                "ää a ä", "=?utf-8?b?w6TDpCBhIMOk?=",
+               "foo\001bar", "=?utf-8?q?foo=01bar?=",
+               "\x01\x02\x03\x04\x05\x06\x07\x08", "=?utf-8?b?AQIDBAUGBwg=?="
        };                          
        string_t *str = t_str_new(128);
        unsigned int i;