From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6EZQF7lC0GF7PgAAgWs5BA (envelope-from ) for ; Sat, 01 Jan 2022 13:02:01 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 8PcCELlC0GH2LQAAG6o9tA (envelope-from ) for ; Sat, 01 Jan 2022 13:02:01 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A207A313BD for ; Sat, 1 Jan 2022 13:02:00 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E07955F72B; Sat, 1 Jan 2022 12:01:46 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0D1165F710 for ; Sat, 1 Jan 2022 12:01:44 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 464035FC42; Sat, 1 Jan 2022 07:01:43 -0500 (EST) Received: (nullmailer pid 38209 invoked by uid 1000); Sat, 01 Jan 2022 12:01:40 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 3/3] CLI: print extra headers in structured output Date: Sat, 1 Jan 2022 08:01:36 -0400 Message-Id: <20220101120136.37988-4-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220101120136.37988-1-david@tethera.net> References: <20220101120136.37988-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: YLQRGOB37NFFFVSD7U3LT6QKQOILLKTQ X-Message-ID-Hash: YLQRGOB37NFFFVSD7U3LT6QKQOILLKTQ X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641038520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=Wb/vJgFnlkB4aWgARmnwbyxquCASsRvndSH025ebrDc=; b=L/l1t3jgzCkzJMBFqa+fjrr4O56YeD4UMyZ6GkydbnwpfJtZ/7rD6ZP74jL6T9xk9yr7u9 SUSRqDQWKo0xzfjYDnFIJUPqgbIsjZ5onDJwGZgjhwqrkPgrQYTKG2pZ3POTKfQIk5lq11 jHJ8xX5PK/oRZwsRCF2PcoyrxYodwkLqsYDpxo7r1JFP1yH+gI70+LmCop/hxGLSd8xKlN QdkeSgjpLCKSlM9TcdoxDxzxXPWVnY+FjA2QJpUBHEraLpPot8a6/0f7TA1R2zLkinQCjI llMhgVIov2DFVhs/LhitlF3daNMblSWRyKt+n0Xr/ps0iDg9wAj+CLpOOc0IXw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641038520; a=rsa-sha256; cv=none; b=Pd2uCjyWO7Sj24/l68Rph+6JUdSG2ixvH+yGnDPsbze2my95cvS+wafJHVkt5HRg5lE7Sr F+C5G7Zw8uhiV9hRLypxNZQQAYDxaLxmNw74cHJj8XDAPQukHS3bA5/3cwCufVyKMrmVbh n1HboESfpgAXiLXSd2/Tz46UJxKzOMw0bfYSc6y9/Q+xPO3Qe58ppp3OeplaDdMCnj+Rvs F8d7u5nJW9waitqAWrD18yc/BnV5bskY6H5JlTdDIGwYeKxA4UKOLnmIZUcESZWCVi0wH7 rwRRizVDtF5CQjGrKmAtNFgyUu5ZoqFD8Q7XbApwSCHwWmElNM3AWJ+kqtjgkg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.71 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A207A313BD X-Spam-Score: -1.71 X-Migadu-Scanner: scn0.migadu.com X-TUID: fTVAAqCt7q3m 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]=\"\"" "[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 ; 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 < 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 ", + "In-Reply-To": "", + "Received": "from mail.example.com (mail.example.com [1.1.1.1])\tby mail.notmuchmail.org (some MTA) with ESMTP id 12345678\tfor ; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)", + "Subject": "extra-headers", + "To": "Notmuch Test Suite " + }, + "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 \" :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]=\"\"" "[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 ; 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 < 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 " :To "Notmuch Test Suite " :Date "Sat, 01 Jan 2000 12:00:00 +0000" :In-Reply-To "" :Received "from mail.example.com (mail.example.com [1.1.1.1])\011by mail.notmuchmail.org (some MTA) with ESMTP id 12345678\011for ; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)")) ()))) +EOF +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.34.1