From: Carl Worth Date: Mon, 2 Nov 2009 22:32:20 +0000 (-0800) Subject: Fix to decode header values, (primarily subject). X-Git-Tag: 0.1~628 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6a7f4df6f709276e592e4ac376879e7f7476f348;p=notmuch.git Fix to decode header values, (primarily subject). Use GMime function to decode message-header values according to RFC 2047. --- diff --git a/message-file.c b/message-file.c index 0b39dc43..0cb85d84 100644 --- a/message-file.c +++ b/message-file.c @@ -22,6 +22,8 @@ #include "notmuch-private.h" +#include + #include /* GHashTable */ typedef struct { @@ -213,9 +215,15 @@ notmuch_message_file_get_header (notmuch_message_file_t *message, const char *header_desired) { int contains; - char *header, *value; + char *header, *decoded_value; const char *s, *colon; int match; + static int initialized = 0; + + if (! initialized) { + g_mime_init (0); + initialized = 1; + } message->parsing_started = 1; @@ -224,10 +232,10 @@ notmuch_message_file_get_header (notmuch_message_file_t *message, else contains = g_hash_table_lookup_extended (message->headers, header_desired, NULL, - (gpointer *) &value); + (gpointer *) &decoded_value); - if (contains && value) - return value; + if (contains && decoded_value) + return decoded_value; if (message->parsing_finished) return NULL; @@ -309,12 +317,12 @@ notmuch_message_file_get_header (notmuch_message_file_t *message, else match = (strcasecmp (header, header_desired) == 0); - value = xstrdup (message->value.str); + decoded_value = g_mime_utils_header_decode_text (message->value.str); - g_hash_table_insert (message->headers, header, value); + g_hash_table_insert (message->headers, header, decoded_value); if (match) - return value; + return decoded_value; } if (message->line)