dovecot: Added mail_get_first_header_utf8() and mail_get_headers...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jul 20 12:36:41 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/00d1a94a94c6
changeset: 6120:00d1a94a94c6
user: Timo Sirainen <tss at iki.fi>
date: Fri Jul 20 12:36:38 2007 +0300
description:
Added mail_get_first_header_utf8() and mail_get_headers_utf8().
diffstat:
5 files changed, 88 insertions(+), 14 deletions(-)
src/lib-storage/index/index-mail-headers.c | 68 ++++++++++++++++++++++++----
src/lib-storage/index/index-mail.h | 6 +-
src/lib-storage/mail-storage-private.h | 6 +-
src/lib-storage/mail-storage.h | 4 +
src/lib-storage/mail.c | 18 ++++++-
diffs (175 lines):
diff -r 9607369b6bce -r 00d1a94a94c6 src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c Fri Jul 20 12:11:51 2007 +0300
+++ b/src/lib-storage/index/index-mail-headers.c Fri Jul 20 12:36:38 2007 +0300
@@ -7,6 +7,7 @@
#include "str.h"
#include "message-date.h"
#include "message-parser.h"
+#include "message-header-decode.h"
#include "istream-tee.h"
#include "istream-header-filter.h"
#include "imap-envelope.h"
@@ -547,9 +548,9 @@ index_mail_get_parsed_header(struct inde
return array_idx(&header_values, 0);
}
-const char *const *index_mail_get_headers(struct mail *_mail, const char *field)
-{
- struct index_mail *mail = (struct index_mail *)_mail;
+static const char *const *
+index_mail_get_raw_headers(struct index_mail *mail, const char *field)
+{
const char *headers[2], *value;
struct mailbox_header_lookup_ctx *headers_ctx;
unsigned char *data;
@@ -620,11 +621,62 @@ const char *const *index_mail_get_header
return array_idx(&header_values, 0);
}
-const char *index_mail_get_first_header(struct mail *mail, const char *field)
-{
- const char *const *list = index_mail_get_headers(mail, field);
-
- return list == NULL ? NULL : list[0];
+static const char *const *
+index_mail_headers_decode(struct index_mail *mail, const char *const *list,
+ unsigned int max_count)
+{
+ const char **decoded_list;
+ unsigned int i, count;
+ buffer_t *buf;
+
+ count = strarray_length(list);
+ if (count > max_count)
+ count = max_count;
+ decoded_list = p_new(mail->data_pool, const char *, count + 1);
+
+ t_push();
+ buf = buffer_create_dynamic(pool_datastack_create(), 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);
+ }
+ }
+ t_pop();
+ return decoded_list;
+}
+
+const char *const *index_mail_get_headers(struct mail *_mail, const char *field,
+ bool decode_to_utf8)
+{
+ struct index_mail *mail = (struct index_mail *)_mail;
+ const char *const *list;
+
+ list = index_mail_get_raw_headers(mail, field);
+ if (!decode_to_utf8 || list == NULL || *list == NULL)
+ return list;
+
+ return index_mail_headers_decode(mail, list, (unsigned int)-1);
+}
+
+const char *index_mail_get_first_header(struct mail *_mail, const char *field,
+ bool decode_to_utf8)
+{
+ struct index_mail *mail = (struct index_mail *)_mail;
+ const char *const *list;
+
+ list = index_mail_get_raw_headers(mail, field);
+ if (list == NULL || *list == NULL)
+ return NULL;
+
+ if (decode_to_utf8)
+ list = index_mail_headers_decode(mail, list, 1);
+ return list[0];
}
static void header_cache_callback(struct message_header_line *hdr,
diff -r 9607369b6bce -r 00d1a94a94c6 src/lib-storage/index/index-mail.h
--- a/src/lib-storage/index/index-mail.h Fri Jul 20 12:11:51 2007 +0300
+++ b/src/lib-storage/index/index-mail.h Fri Jul 20 12:36:38 2007 +0300
@@ -146,9 +146,11 @@ int index_mail_parse_headers(struct inde
struct mailbox_header_lookup_ctx *headers);
void index_mail_headers_get_envelope(struct index_mail *mail);
-const char *index_mail_get_first_header(struct mail *_mail, const char *field);
+const char *index_mail_get_first_header(struct mail *_mail, const char *field,
+ bool decode_to_utf8);
const char *const *
-index_mail_get_headers(struct mail *_mail, const char *field);
+index_mail_get_headers(struct mail *_mail, const char *field,
+ bool decode_to_utf8);
struct istream *
index_mail_get_header_stream(struct mail *_mail,
struct mailbox_header_lookup_ctx *headers);
diff -r 9607369b6bce -r 00d1a94a94c6 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h Fri Jul 20 12:11:51 2007 +0300
+++ b/src/lib-storage/mail-storage-private.h Fri Jul 20 12:36:38 2007 +0300
@@ -208,8 +208,10 @@ struct mail_vfuncs {
uoff_t (*get_virtual_size)(struct mail *mail);
uoff_t (*get_physical_size)(struct mail *mail);
- const char *(*get_first_header)(struct mail *mail, const char *field);
- const char *const *(*get_headers)(struct mail *mail, const char *field);
+ const char *(*get_first_header)(struct mail *mail, const char *field,
+ bool decode_to_utf8);
+ const char *const *(*get_headers)(struct mail *mail, const char *field,
+ bool decode_to_utf8);
struct istream *
(*get_header_stream)(struct mail *mail,
struct mailbox_header_lookup_ctx *headers);
diff -r 9607369b6bce -r 00d1a94a94c6 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h Fri Jul 20 12:11:51 2007 +0300
+++ b/src/lib-storage/mail-storage.h Fri Jul 20 12:36:38 2007 +0300
@@ -424,8 +424,12 @@ uoff_t mail_get_physical_size(struct mai
/* Get value for single header field */
const char *mail_get_first_header(struct mail *mail, const char *field);
+/* Like mail_get_first_header(), but decode MIME encoded words to UTF-8 */
+const char *mail_get_first_header_utf8(struct mail *mail, const char *field);
/* Return a NULL-terminated list of values for each found field. */
const char *const *mail_get_headers(struct mail *mail, const char *field);
+/* Like mail_get_headers(), but decode MIME encoded words to UTF-8 */
+const char *const *mail_get_headers_utf8(struct mail *mail, const char *field);
/* Returns stream containing specified headers. */
struct istream *
mail_get_header_stream(struct mail *mail,
diff -r 9607369b6bce -r 00d1a94a94c6 src/lib-storage/mail.c
--- a/src/lib-storage/mail.c Fri Jul 20 12:11:51 2007 +0300
+++ b/src/lib-storage/mail.c Fri Jul 20 12:36:38 2007 +0300
@@ -93,14 +93,28 @@ const char *mail_get_first_header(struct
{
struct mail_private *p = (struct mail_private *)mail;
- return p->v.get_first_header(mail, field);
+ return p->v.get_first_header(mail, field, FALSE);
+}
+
+const char *mail_get_first_header_utf8(struct mail *mail, const char *field)
+{
+ struct mail_private *p = (struct mail_private *)mail;
+
+ return p->v.get_first_header(mail, field, TRUE);
}
const char *const *mail_get_headers(struct mail *mail, const char *field)
{
struct mail_private *p = (struct mail_private *)mail;
- return p->v.get_headers(mail, field);
+ return p->v.get_headers(mail, field, FALSE);
+}
+
+const char *const *mail_get_headers_utf8(struct mail *mail, const char *field)
+{
+ struct mail_private *p = (struct mail_private *)mail;
+
+ return p->v.get_headers(mail, field, TRUE);
}
struct istream *
More information about the dovecot-cvs
mailing list