]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail_get_headers_utf8() now replaces NULs with spaces.
authorTimo Sirainen <tss@iki.fi>
Mon, 5 May 2014 13:01:58 +0000 (16:01 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 5 May 2014 13:01:58 +0000 (16:01 +0300)
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

index 8fc00b515b86851b3a6f465398d6d4a3f13df501..db4179d5b1fec075765049c53c9afc802af71046 100644 (file)
@@ -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;