Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8453:1d542b149bed HEAD
mail_get_headers_utf8() and mail_get_first_header_utf8() return headers unfolded now.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 19 Nov 2008 19:54:41 +0200 |
parents | 7dcffe7ee7f5 |
children | ba5f7a4b89d6 |
files | src/lib-storage/index/index-mail-headers.c src/lib-storage/mail-storage.h |
diffstat | 2 files changed, 46 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-mail-headers.c Wed Nov 19 19:42:46 2008 +0200 +++ b/src/lib-storage/index/index-mail-headers.c Wed Nov 19 19:54:41 2008 +0200 @@ -650,30 +650,60 @@ 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; }
--- a/src/lib-storage/mail-storage.h Wed Nov 19 19:42:46 2008 +0200 +++ b/src/lib-storage/mail-storage.h Wed Nov 19 19:54:41 2008 +0200 @@ -554,13 +554,15 @@ 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. */