lib: add version of _n_m_f_get_combinded_header for gmime 3.0
authorDavid Bremner <david@tethera.net>
Wed, 17 May 2017 10:40:09 +0000 (07:40 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 15 Jul 2017 00:23:52 +0000 (21:23 -0300)
The iterator is gone, so we need a new loop structure.

lib/message-file.c

index 7d38ebd0fc04c6c6621c14492516599161599b3d..d7acf0d5b4e2739eac56756c1ca35f30eeacf424 100644 (file)
@@ -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,