From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 3/3] CLI: print extra headers in structured output
Date: Sat, 1 Jan 2022 08:01:36 -0400 [thread overview]
Message-ID: <20220101120136.37988-4-david@tethera.net> (raw)
In-Reply-To: <20220101120136.37988-1-david@tethera.net>
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
---
devel/schemata | 4 +++-
notmuch-show.c | 26 ++++++++++++++++++++++++++
test/T160-json.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
test/T170-sexp.sh | 14 ++++++++++++++
4 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/devel/schemata b/devel/schemata
index 01e3a3df..01810888 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -145,9 +145,11 @@ headers = {
Cc?: string,
Bcc?: string,
Reply-To?: string,
- Date: string
+ Date: string,
+ extra_header_pair*
}
+extra_header_pair= (header_name: string)
# Encryption status (format_part_sprinter)
encstatus = [{status: "good"|"bad"}]
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);
}
diff --git a/test/T160-json.sh b/test/T160-json.sh
index 6a3e5812..ec7b1461 100755
--- a/test/T160-json.sh
+++ b/test/T160-json.sh
@@ -156,4 +156,46 @@ EOF
output=$(notmuch show --format=json --body=false --format-version=2 id:message-id@example.com)
test_expect_equal_json "$output" "$(cat EXPECTED)"
+test_begin_subtest "show extra headers"
+add_message "[subject]=\"extra-headers\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[in-reply-to]=\"<parent@notmuch-test-suite>\"" "[body]=\"extra-headers test\""\
+ "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
+ by mail.notmuchmail.org (some MTA) with ESMTP id 12345678
+ for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
+
+notmuch config set show.extra_headers "in-reply-to;received"
+output=$(notmuch show --format=json --body=false id:${gen_msg_id} | notmuch_json_show_sanitize)
+cat <<EOF > EXPECTED
+[
+ [
+ [
+ {
+ "crypto": {},
+ "date_relative": "2000-01-01",
+ "excluded": false,
+ "filename": [
+ "YYYYY"
+ ],
+ "headers": {
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000",
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
+ "In-Reply-To": "<parent@notmuch-test-suite>",
+ "Received": "from mail.example.com (mail.example.com [1.1.1.1])\tby mail.notmuchmail.org (some MTA) with ESMTP id 12345678\tfor <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)",
+ "Subject": "extra-headers",
+ "To": "Notmuch Test Suite <test_suite@notmuchmail.org>"
+ },
+ "id": "XXXXX",
+ "match": true,
+ "tags": [
+ "inbox",
+ "unread"
+ ],
+ "timestamp": 946728000
+ },
+ []
+ ]
+ ]
+]
+EOF
+test_expect_equal_json "${output}" "$(cat EXPECTED)"
+
test_done
diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh
index 18084273..0d32560c 100755
--- a/test/T170-sexp.sh
+++ b/test/T170-sexp.sh
@@ -47,4 +47,18 @@ filename=$(notmuch search --output=files "id:$id")
attachment_length=$(( $(base64 $NOTMUCH_SRCDIR/test/README | wc -c) - 1 ))
test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename (\"$filename\") :timestamp 946728000 :date_relative \"2000-01-01\" :tags (\"inbox\") :body ((:id 1 :content-type \"multipart/mixed\" :content ((:id 2 :content-type \"text/plain\" :content \"This is a test message with inline attachment with a filename\") (:id 3 :content-type \"application/octet-stream\" :content-disposition \"inline\" :filename \"README\" :content-transfer-encoding \"base64\" :content-length $attachment_length)))) :crypto () :headers (:Subject \"sexp-show-inline-attachment-filename\" :From \"Notmuch Test Suite <test_suite@notmuchmail.org>\" :To \"test_suite@notmuchmail.org\" :Date \"Sat, 01 Jan 2000 12:00:00 +0000\")) ())))"
+test_begin_subtest "show extra headers"
+add_message "[subject]=\"extra-headers\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[in-reply-to]=\"<parent@notmuch-test-suite>\"" "[body]=\"extra-headers test\""\
+ "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
+ by mail.notmuchmail.org (some MTA) with ESMTP id 12345678
+ for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
+
+notmuch config set show.extra_headers "in-reply-to;received"
+notmuch show --format=sexp --body=false id:${gen_msg_id} | \
+ notmuch_dir_sanitize | sed 's/msg-[0-9]*/MSG/g'> OUTPUT
+cat <<EOF > EXPECTED
+((((:id "MSG@notmuch-test-suite" :match t :excluded nil :filename ("MAIL_DIR/MSG") :timestamp 946728000 :date_relative "2000-01-01" :tags ("inbox" "unread") :crypto () :headers (:Subject "extra-headers" :From "Notmuch Test Suite <test_suite@notmuchmail.org>" :To "Notmuch Test Suite <test_suite@notmuchmail.org>" :Date "Sat, 01 Jan 2000 12:00:00 +0000" :In-Reply-To "<parent@notmuch-test-suite>" :Received "from mail.example.com (mail.example.com [1.1.1.1])\011by mail.notmuchmail.org (some MTA) with ESMTP id 12345678\011for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)")) ())))
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
test_done
--
2.34.1
prev parent reply other threads:[~2022-01-01 12:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-01 12:01 support extra headers in notmuch show v2 David Bremner
2022-01-01 12:01 ` [PATCH 1/3] CLI: stash pointer to database in sprinter structs David Bremner
2022-01-18 12:14 ` David Bremner
2022-01-18 13:26 ` [PATCH] doc: document new option `show.extra_headers` David Bremner
2022-01-25 11:57 ` David Bremner
2022-01-01 12:01 ` [PATCH 2/3] lib/config: add known config key "show.extra_headers" David Bremner
2022-01-01 12:01 ` David Bremner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220101120136.37988-4-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).