[PATCH] Fix format_headers_sprinter to return all headers (v2)

Johan Parin johanparin at gmail.com
Sat Nov 9 14:13:58 PST 2019


Modify format_headers_sprinter so that it returns some additional headers in the
sexp, instead of a small fixed set of headers.

This version includes the following headers:

- Maildir
- Mailing-list
- Tags
- Attachments
- Signature
- Decryption
- User-agent
- X-Mailer

This is required in order for the elisp variable
`notmuch-message-headers' to work to some extent.

See this bug report:

  https://notmuchmail.org/pipermail/notmuch/2017/026069.html
---
 notmuch-show.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/notmuch-show.c b/notmuch-show.c
index 21792a57..86ddb491 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -205,6 +205,12 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     char *recipients_string;
     const char *reply_to_string;
     void *local = talloc_new (sp);
+    GMimeHeaderList *header_list;
+    GMimeHeader *header;
+    const char* interesting_headers[] = {
+	"Maildir", "Mailing-list", "Tags", "Attachments", "Signature",
+	"Decryption", "User-agent", "X-Mailer"};
+    const int interesting_header_count = sizeof(interesting_headers) / sizeof(char *);
 
     sp->begin_map (sp);
 
@@ -255,6 +261,19 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
 	sp->string (sp, g_mime_message_get_date_string (sp, message));
     }
 
+    header_list  = g_mime_object_get_header_list (GMIME_OBJECT(message));
+
+    for (int i = 0; i < interesting_header_count; i++) {
+
+	header = g_mime_header_list_get_header(
+	    header_list, interesting_headers[i]);
+	if (header == NULL)
+	    continue;
+
+	sp->map_key (sp, g_mime_header_get_name(header));
+	sp->string (sp, g_mime_header_get_value(header));
+    }
+
     sp->end (sp);
     talloc_free (local);
 }
-- 
2.21.0 (Apple Git-122)



More information about the notmuch mailing list