From ed6ee7330d28c65cb3990cbe4a5ac6182bf23402 Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Tue, 20 Oct 2009 09:52:01 -0700
Subject: [PATCH] notmuch_message_get_header: Fix bogus return of NULL header.

A simple bug meant that the correct value was being inserted into
the hash table, but a NULL value would be returned in some cases.
(If the value was already in the hash table at the beginning of
the call the the correct value would be returned, but if the
function had to parse to reach it then it would return NULL.)

This was tripping up the recently-added code to ignore messages
with NULL From:, Subject:, and To: headers, (which is fortunate
since otherwise the broken parsing might have stayed hidden for
longer).
---
 message.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/message.c b/message.c
index 1a5994ff..bd551ccd 100644
--- a/message.c
+++ b/message.c
@@ -273,8 +273,9 @@ notmuch_message_get_header (notmuch_message_t *message,
 
 	match = (strcasecmp (header, header_desired) == 0);
 
-	g_hash_table_insert (message->headers, header,
-			     xstrdup (message->value.str));
+	value = xstrdup (message->value.str);
+
+	g_hash_table_insert (message->headers, header, value);
 
 	if (match)
 	    return value;
-- 
2.45.2