- void *local = talloc_new (ctx);
- InternetAddressList *recipients;
- const char *recipients_string;
-
- printf ("{%s: %s",
- json_quote_str (local, "Subject"),
- json_quote_str (local, g_mime_message_get_subject (message)));
- printf (", %s: %s",
- json_quote_str (local, "From"),
- json_quote_str (local, g_mime_message_get_sender (message)));
- recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
- recipients_string = internet_address_list_to_string (recipients, 0);
- if (recipients_string)
- printf (", %s: %s",
- json_quote_str (local, "To"),
- json_quote_str (local, recipients_string));
- recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
- recipients_string = internet_address_list_to_string (recipients, 0);
- if (recipients_string)
- printf (", %s: %s",
- json_quote_str (local, "Cc"),
- json_quote_str (local, recipients_string));
- printf (", %s: %s}",
- json_quote_str (local, "Date"),
- json_quote_str (local, g_mime_message_get_date_as_string (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)
+{
+ /* Any changes to the JSON or S-Expression format should be
+ * reflected in the file devel/schemata. */
+
+ char *recipients_string;
+ const char *reply_to_string;
+ void *local = talloc_new (sp);
+
+ sp->begin_map (sp);
+
+ sp->map_key (sp, "Subject");
+ if (msg_crypto && msg_crypto->payload_subject) {
+ sp->string (sp, msg_crypto->payload_subject);
+ } else
+ sp->string (sp, g_mime_message_get_subject (message));
+
+ sp->map_key (sp, "From");
+ sp->string (sp, g_mime_message_get_from_string (message));
+
+ recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
+ if (recipients_string) {
+ sp->map_key (sp, "To");
+ sp->string (sp, recipients_string);
+ g_free (recipients_string);
+ }
+
+ recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
+ if (recipients_string) {
+ sp->map_key (sp, "Cc");
+ sp->string (sp, recipients_string);
+ g_free (recipients_string);
+ }
+
+ recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_BCC);
+ if (recipients_string) {
+ sp->map_key (sp, "Bcc");
+ sp->string (sp, recipients_string);
+ g_free (recipients_string);
+ }
+
+ reply_to_string = g_mime_message_get_reply_to_string (local, message);
+ if (reply_to_string) {
+ sp->map_key (sp, "Reply-To");
+ sp->string (sp, reply_to_string);
+ }