[PATCH 20/23] lib: add version of _n_m_f_get_combinded_header for gmime 3.0

Subject: [PATCH 20/23] lib: add version of _n_m_f_get_combinded_header for gmime 3.0

Date: Sat, 3 Jun 2017 14:47:51 -0300

To: notmuch@notmuchmail.org, notmuch@freelists.org

Cc:

From: David Bremner


The iterator is gone, so we need a new loop structure.
---
 lib/message-file.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/lib/message-file.c b/lib/message-file.c
index 7d38ebd0..d7acf0d5 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -232,6 +232,7 @@ _extend_header (char *combined, const char *value) {
     return combined;
 }
 
+#if (GMIME_MAJOR_VERSION < 3)
 static char *
 _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
 					   const char *header)
@@ -271,6 +272,39 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
 
     return combined;
 }
+#else
+static char *
+_notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
+					   const char *header)
+{
+    char *combined = NULL;
+    GMimeHeaderList *headers;
+
+    headers = g_mime_object_get_header_list (GMIME_OBJECT (message->message));
+    if (! headers)
+	return NULL;
+
+
+    for (int i=0; i < g_mime_header_list_get_count (headers); i++) {
+	const char *value;
+	GMimeHeader *g_header = g_mime_header_list_get_header_at (headers, i);
+
+	if (strcasecmp (g_mime_header_get_name (g_header), header) != 0)
+	    continue;
+
+	/* GMime retains ownership of value, we hope */
+	value = g_mime_header_get_value (g_header);
+
+	combined = _extend_header (combined, value);
+    }
+
+    /* Return empty string for non-existing headers. */
+    if (! combined)
+	combined = g_strdup ("");
+
+    return combined;
+}
+#endif
 
 const char *
 _notmuch_message_file_get_header (notmuch_message_file_t *message,
-- 
2.11.0


Thread: