aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2017-05-17 07:18:55 -0300
committerDavid Bremner <david@tethera.net>2017-07-14 21:23:52 -0300
commit439c5896b6ec4306d428101bbf59c07288e96c71 (patch)
tree0c2b133852602cc7e7a2cd56a76df077b64b2887 /lib
parentc040464a7c8f339d15f691113b8f5fd901229bcb (diff)
lib: refactor _notmuch_messsage_file_get_combined_header
We need to rewrite the loop for gmime-3.0; move the loop body to its own function to avoid code duplication. Keep the common exit via "goto DONE" to make this pure code movement. It's important to note that the existing exit path only deallocates the iterator.
Diffstat (limited to 'lib')
-rw-r--r--lib/message-file.c57
1 files changed, 32 insertions, 25 deletions
diff --git a/lib/message-file.c b/lib/message-file.c
index db18b163..7d38ebd0 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -201,6 +201,37 @@ _notmuch_message_file_get_mime_message (notmuch_message_file_t *message,
*
* Return NULL on errors, empty string for non-existing headers.
*/
+
+static char *
+_extend_header (char *combined, const char *value) {
+ char *decoded;
+
+ decoded = g_mime_utils_header_decode_text (value);
+ if (! decoded) {
+ if (combined) {
+ g_free (combined);
+ combined = NULL;
+ }
+ goto DONE;
+ }
+
+ if (combined) {
+ char *tmp = g_strdup_printf ("%s %s", combined, decoded);
+ g_free (decoded);
+ g_free (combined);
+ if (! tmp) {
+ combined = NULL;
+ goto DONE;
+ }
+
+ combined = tmp;
+ } else {
+ combined = decoded;
+ }
+ DONE:
+ return combined;
+}
+
static char *
_notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
const char *header)
@@ -222,37 +253,13 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
do {
const char *value;
- char *decoded;
-
if (strcasecmp (g_mime_header_iter_get_name (iter), header) != 0)
continue;
/* Note that GMime retains ownership of value... */
value = g_mime_header_iter_get_value (iter);
- /* ... while decoded needs to be freed with g_free(). */
- decoded = g_mime_utils_header_decode_text (value);
- if (! decoded) {
- if (combined) {
- g_free (combined);
- combined = NULL;
- }
- goto DONE;
- }
-
- if (combined) {
- char *tmp = g_strdup_printf ("%s %s", combined, decoded);
- g_free (decoded);
- g_free (combined);
- if (! tmp) {
- combined = NULL;
- goto DONE;
- }
-
- combined = tmp;
- } else {
- combined = decoded;
- }
+ combined = _extend_header (combined, value);
} while (g_mime_header_iter_next (iter));
/* Return empty string for non-existing headers. */