dovecot-2.2: lib-mail: message_header_encode() needs to encode c...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 5 11:57:49 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/88a8e7d9f2e9
changeset: 17316:88a8e7d9f2e9
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 05 14:57:13 2014 +0300
description:
lib-mail: message_header_encode() needs to encode control characters as well.

diffstat:

 src/lib-mail/message-header-encode.c      |  9 +++++++--
 src/lib-mail/test-message-header-encode.c |  2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diffs (45 lines):

diff -r 1e099feb1dea -r 88a8e7d9f2e9 src/lib-mail/message-header-encode.c
--- a/src/lib-mail/message-header-encode.c	Mon May 05 14:28:33 2014 +0300
+++ b/src/lib-mail/message-header-encode.c	Mon May 05 14:57:13 2014 +0300
@@ -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;
 
+	/* <LWSP>=? */
 	if (input[i] == '=' && input[i+1] == '?' &&
 	    (i == 0 || IS_LWSP(input[i-1])))
 		return TRUE;
@@ -65,12 +70,12 @@
 		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 -r 1e099feb1dea -r 88a8e7d9f2e9 src/lib-mail/test-message-header-encode.c
--- a/src/lib-mail/test-message-header-encode.c	Mon May 05 14:28:33 2014 +0300
+++ b/src/lib-mail/test-message-header-encode.c	Mon May 05 14:57:13 2014 +0300
@@ -168,6 +168,8 @@
 		"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;


More information about the dovecot-cvs mailing list