mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 12:28:09 +01:00
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.
This commit is contained in:
parent
c040464a7c
commit
439c5896b6
1 changed files with 32 additions and 25 deletions
|
@ -201,36 +201,11 @@ _notmuch_message_file_get_mime_message (notmuch_message_file_t *message,
|
|||
*
|
||||
* Return NULL on errors, empty string for non-existing headers.
|
||||
*/
|
||||
|
||||
static char *
|
||||
_notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
|
||||
const char *header)
|
||||
{
|
||||
GMimeHeaderList *headers;
|
||||
GMimeHeaderIter *iter;
|
||||
char *combined = NULL;
|
||||
|
||||
headers = g_mime_object_get_header_list (GMIME_OBJECT (message->message));
|
||||
if (! headers)
|
||||
return NULL;
|
||||
|
||||
iter = g_mime_header_iter_new ();
|
||||
if (! iter)
|
||||
return NULL;
|
||||
|
||||
if (! g_mime_header_list_get_iter (headers, iter))
|
||||
goto DONE;
|
||||
|
||||
do {
|
||||
const char *value;
|
||||
_extend_header (char *combined, 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) {
|
||||
|
@ -253,6 +228,38 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
|
|||
} else {
|
||||
combined = decoded;
|
||||
}
|
||||
DONE:
|
||||
return combined;
|
||||
}
|
||||
|
||||
static char *
|
||||
_notmuch_message_file_get_combined_header (notmuch_message_file_t *message,
|
||||
const char *header)
|
||||
{
|
||||
GMimeHeaderList *headers;
|
||||
GMimeHeaderIter *iter;
|
||||
char *combined = NULL;
|
||||
|
||||
headers = g_mime_object_get_header_list (GMIME_OBJECT (message->message));
|
||||
if (! headers)
|
||||
return NULL;
|
||||
|
||||
iter = g_mime_header_iter_new ();
|
||||
if (! iter)
|
||||
return NULL;
|
||||
|
||||
if (! g_mime_header_list_get_iter (headers, iter))
|
||||
goto DONE;
|
||||
|
||||
do {
|
||||
const char *value;
|
||||
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);
|
||||
|
||||
combined = _extend_header (combined, value);
|
||||
} while (g_mime_header_iter_next (iter));
|
||||
|
||||
/* Return empty string for non-existing headers. */
|
||||
|
|
Loading…
Reference in a new issue