aboutsummaryrefslogtreecommitdiff
path: root/notmuch-show.c
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2022-01-01 08:01:36 -0400
committerDavid Bremner <david@tethera.net>2022-01-18 08:11:06 -0400
commitc5cf92aa3534b27c0dda4794d14571b1b5439da8 (patch)
treef766b3f0b39e6e679bc0578faee3bcf9246baf7d /notmuch-show.c
parent79936ac93e486d8ff82729840154bf8c2212ebb6 (diff)
CLI: print extra headers in structured output
This is based on a patch from Johan Parin [1], which is in turn responding to a bug report / feature requiest from Jan Malkhovski. The update to the structured output documented in schemata is intended to be upward compatible, so the format version stays the same [1]: id:20191116162723.18343-1-johan.parin@gmail.com [2]: id:87h8sdemnr.fsf@oxij.org
Diffstat (limited to 'notmuch-show.c')
-rw-r--r--notmuch-show.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/notmuch-show.c b/notmuch-show.c
index 2848c9c3..136f4439 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -209,6 +209,30 @@ _is_from_line (const char *line)
return 0;
}
+/* Output extra headers if configured with the `show.extra_headers'
+ * configuration option
+ */
+static void
+format_extra_headers_sprinter (sprinter_t *sp, GMimeMessage *message)
+{
+ GMimeHeaderList *header_list = g_mime_object_get_header_list (GMIME_OBJECT (message));
+
+ for (notmuch_config_values_t *extra_headers = notmuch_config_get_values (
+ sp->notmuch, NOTMUCH_CONFIG_EXTRA_HEADERS);
+ notmuch_config_values_valid (extra_headers);
+ notmuch_config_values_move_to_next (extra_headers)) {
+ GMimeHeader *header;
+ const char *header_name = notmuch_config_values_get (extra_headers);
+
+ header = g_mime_header_list_get_header (header_list, header_name);
+ if (header == NULL)
+ continue;
+
+ sp->map_key (sp, g_mime_header_get_name (header));
+ sp->string (sp, g_mime_header_get_value (header));
+ }
+}
+
void
format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
bool reply, const _notmuch_message_crypto_t *msg_crypto)
@@ -269,6 +293,8 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
sp->string (sp, g_mime_message_get_date_string (sp, message));
}
+ /* Output extra headers the user has configured, if any */
+ format_extra_headers_sprinter (sp, message);
sp->end (sp);
talloc_free (local);
}