fix notmuch_message_file_get_header
authorDirk Hohndel <hohndel@infradead.org>
Tue, 6 Apr 2010 19:45:30 +0000 (12:45 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 7 Apr 2010 01:47:28 +0000 (18:47 -0700)
fix notmuch_message_file_get_header to always return the first instance
 of the header you are looking for

Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
lib/message-file.c

index 3a1a681de5299eeca679800c8e045b83d6507b0d..0c152a3973ac719a8dc7bf51f1050c8a52604ceb 100644 (file)
@@ -318,9 +318,15 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
            match = (strcasecmp (header, header_desired) == 0);
 
        decoded_value = g_mime_utils_header_decode_text (message->value.str);
-
-       g_hash_table_insert (message->headers, header, decoded_value);
-
+       if (g_hash_table_lookup (message->headers, header) == NULL) {
+           /* Only insert if we don't have a value for this header, yet.
+            * This way we always return the FIRST instance of any header
+            * we search for
+            * FIXME: we should be returning ALL instances of a header
+            *        or at least provide a way to iterate over them
+            */
+           g_hash_table_insert (message->headers, header, decoded_value);
+       }
        if (match)
            return decoded_value;
     }