From: Timo Sirainen Date: Mon, 5 May 2014 11:57:13 +0000 (+0300) Subject: lib-mail: message_header_encode() needs to encode control characters as well. X-Git-Tag: 2.2.13.rc1~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb69cdfbcb5e9f235f5621fdfc66c70cac554dbd;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: message_header_encode() needs to encode control characters as well. --- diff --git a/src/lib-mail/message-header-encode.c b/src/lib-mail/message-header-encode.c index dc746802e9..fa387f0e57 100644 --- a/src/lib-mail/message-header-encode.c +++ b/src/lib-mail/message-header-encode.c @@ -13,9 +13,14 @@ 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; + /* =? */ 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]); } diff --git a/src/lib-mail/test-message-header-encode.c b/src/lib-mail/test-message-header-encode.c index 3989d70923..a2da561dd9 100644 --- a/src/lib-mail/test-message-header-encode.c +++ b/src/lib-mail/test-message-header-encode.c @@ -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;