dovecot-1.2: mail_get_headers_utf8() and mail_get_first_header_u...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Nov 19 19:54:45 EET 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/1d542b149bed
changeset: 8453:1d542b149bed
user: Timo Sirainen <tss at iki.fi>
date: Wed Nov 19 19:54:41 2008 +0200
description:
mail_get_headers_utf8() and mail_get_first_header_utf8() return headers unfolded now.
diffstat:
2 files changed, 46 insertions(+), 14 deletions(-)
src/lib-storage/index/index-mail-headers.c | 54 +++++++++++++++++++++-------
src/lib-storage/mail-storage.h | 6 ++-
diffs (97 lines):
diff -r 7dcffe7ee7f5 -r 1d542b149bed src/lib-storage/index/index-mail-headers.c
--- 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 @@ index_mail_get_raw_headers(struct index_
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;
}
diff -r 7dcffe7ee7f5 -r 1d542b149bed src/lib-storage/mail-storage.h
--- 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 @@ int mail_get_physical_size(struct mail *
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. */
More information about the dovecot-cvs
mailing list