dovecot-2.2: lib-storage: mail_get_headers_utf8() now replaces N...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 5 13:03:33 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/4e5f816b59d5
changeset: 17321:4e5f816b59d5
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 05 16:01:58 2014 +0300
description:
lib-storage: mail_get_headers_utf8() now replaces NULs with spaces.
Perhaps there should also be another API function which actually allows
returning strings with NULs in them.

diffstat:

 src/lib-storage/index/index-mail-headers.c |  20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diffs (38 lines):

diff -r 63361f087d1f -r 4e5f816b59d5 src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c	Mon May 05 16:00:52 2014 +0300
+++ b/src/lib-storage/index/index-mail-headers.c	Mon May 05 16:01:58 2014 +0300
@@ -707,6 +707,17 @@
 	return 0;
 }
 
+static void str_replace_nuls(string_t *str)
+{
+	char *data = str_c_modifiable(str);
+	unsigned int i, len = str_len(str);
+
+	for (i = 0; i < len; i++) {
+		if (data[i] == '\0')
+			data[i] = ' ';
+	}
+}
+
 static int
 index_mail_headers_decode(struct index_mail *mail, const char *const **_list,
 			  unsigned int max_count)
@@ -731,9 +742,14 @@
 
 		/* decode MIME encoded-words. decoding may also add new LFs. */
 		message_header_decode_utf8((const unsigned char *)input,
-					   strlen(input), str, FALSE);
-		if (strcmp(str_c(str), input) != 0)
+					   strlen(input), str, NULL);
+		if (strcmp(str_c(str), input) != 0) {
+			if (strlen(str_c(str)) != str_len(str)) {
+				/* replace NULs with spaces */
+				str_replace_nuls(str);
+			}
 			input = p_strdup(mail->mail.data_pool, str_c(str));
+		}
 		decoded_list[i] = input;
 	}
 	*_list = decoded_list;


More information about the dovecot-cvs mailing list