]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail_get_headers_utf8() and mail_get_first_header_utf8() return headers unfolded...
authorTimo Sirainen <tss@iki.fi>
Wed, 19 Nov 2008 17:54:41 +0000 (19:54 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 19 Nov 2008 17:54:41 +0000 (19:54 +0200)
--HG--
branch : HEAD

src/lib-storage/index/index-mail-headers.c
src/lib-storage/mail-storage.h

index 0a5c0ba791cdc939036d5b94573cdda4716d14b7..848c0b2c11825bd8c6d7bf5d2b2192f2f0616c36 100644 (file)
@@ -650,30 +650,60 @@ index_mail_get_raw_headers(struct index_mail *mail, const char *field,
        return 0;
 }
 
+static const char *unfold_header(pool_t pool, const char *str)
+{
+       char *new_str;
+       unsigned int i, j;
+
+       for (i = 0; str[i] != '\0'; i++) {
+               if (str[i] == '\n')
+                       break;
+       }
+       if (str[i] == '\0')
+               return str;
+
+       /* @UNSAFE */
+       new_str = p_malloc(pool, i + strlen(str+i) + 1);
+       memcpy(new_str, str, i);
+       for (j = i; str[i] != '\0'; i++) {
+               if (str[i] == '\n') {
+                       new_str[j++] = ' ';
+                       i++;
+                       if (str[i] == '\0')
+                               break;
+                       i_assert(str[i] == ' ' || str[i] == '\t');
+               } else {
+                       new_str[j++] = str[i];
+               }
+       }
+       new_str[j] = '\0';
+       return new_str;
+}
+
 static const char *const *
 index_mail_headers_decode(struct index_mail *mail, const char *const *list,
                          unsigned int max_count)
 {
-       const char **decoded_list;
+       const char **decoded_list, *input;
        unsigned int i, count;
-       buffer_t *buf;
+       string_t *str;
 
        count = str_array_length(list);
        if (count > max_count)
                count = max_count;
        decoded_list = p_new(mail->data_pool, const char *, count + 1);
 
-       buf = buffer_create_dynamic(pool_datastack_create(), 512);
-
+       str = t_str_new(512);
        for (i = 0; i < count; i++) {
-               buffer_set_used_size(buf, 0);
-               if (!message_header_decode_utf8((const unsigned char *)list[i],
-                                               strlen(list[i]), buf, FALSE))
-                       decoded_list[i] = list[i];
-               else {
-                       decoded_list[i] = p_strndup(mail->data_pool,
-                                                   buf->data, buf->used);
-               }
+               str_truncate(str, 0);
+               input = list[i];
+               if (message_header_decode_utf8((const unsigned char *)input,
+                                              strlen(list[i]), str, FALSE))
+                       input = str_c(str);
+               input = unfold_header(mail->data_pool, input);
+               if (input == str->data)
+                       input = p_strdup(mail->data_pool, input);
+               decoded_list[i] = input;
        }
        return decoded_list;
 }
index 63acc91c290e849e623d2b24a336b1f104f4e44d..af1f0f33a25ee3017f0f94ef353ace0839ecd0c8 100644 (file)
@@ -554,13 +554,15 @@ int mail_get_physical_size(struct mail *mail, uoff_t *size_r);
    Returns 1 if header was found, 0 if not, -1 if error. */
 int mail_get_first_header(struct mail *mail, const char *field,
                          const char **value_r);
-/* Like mail_get_first_header(), but decode MIME encoded words to UTF-8 */
+/* Like mail_get_first_header(), but decode MIME encoded words to UTF-8.
+   Also multiline headers are returned unfolded. */
 int mail_get_first_header_utf8(struct mail *mail, const char *field,
                               const char **value_r);
 /* Return a NULL-terminated list of values for each found field. */
 int mail_get_headers(struct mail *mail, const char *field,
                     const char *const **value_r);
-/* Like mail_get_headers(), but decode MIME encoded words to UTF-8 */
+/* Like mail_get_headers(), but decode MIME encoded words to UTF-8.
+   Also multiline headers are returned unfolded. */
 int mail_get_headers_utf8(struct mail *mail, const char *field,
                          const char *const **value_r);
 /* Returns stream containing specified headers. */