From 66f9709e0c7604e2282b930b6a48fe9f0dd20ab8 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 5 May 2014 16:01:58 +0300 Subject: [PATCH] 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. --- src/lib-storage/index/index-mail-headers.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib-storage/index/index-mail-headers.c b/src/lib-storage/index/index-mail-headers.c index 8fc00b515b..db4179d5b1 100644 --- a/src/lib-storage/index/index-mail-headers.c +++ b/src/lib-storage/index/index-mail-headers.c @@ -707,6 +707,17 @@ static int unfold_header(pool_t pool, const char **_str) 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 @@ index_mail_headers_decode(struct index_mail *mail, const char *const **_list, /* 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; -- 2.47.3