From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 2FC256DE0F07 for ; Fri, 22 Nov 2019 15:08:03 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.392 X-Spam-Level: X-Spam-Status: No, score=-0.392 tagged_above=-999 required=5 tests=[AWL=-0.192, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9FKOaqKVdsIA for ; Fri, 22 Nov 2019 15:08:02 -0800 (PST) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by arlo.cworth.org (Postfix) with ESMTPS id 55B356DE0EED for ; Fri, 22 Nov 2019 15:08:02 -0800 (PST) Received: by mail-lf1-f51.google.com with SMTP id d6so6764548lfc.0 for ; Fri, 22 Nov 2019 15:08:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YLg5126olsi3CsIQNhRsY5Qcw+/s2JN73iIkiaUHua4=; b=vAWMR0MTuC0sQ74F5mraLL3j2zWOQaCQ3AWAIEh4C/nD3lZkh1mxsVTWzIVT3HMPkk rvd2bYVK8MZ4ghjPIvwa1ZHXtKkTK5s6tcyg2LqyEH7HVis/fEo68aYg+6PTO8Ti3qa4 +D+6K2ON5pjYUwGGzaAIqOP4fxYrBejqN8BQad+3Wy17BXnw3i/jrN8/pqTxGvMumrDV kplAryHd/tpgFEy5Mm1Z34HsmaoVqJPj28kv3SmZnbpMY38Yggei4ccDiqrANDYgA+jE qXpILT/LJ2ASAewWzr76hMkmFEHFnXQX/QHeLTdq21VLBh9oXuQ8UgH0V+aYhbHWubno ewPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YLg5126olsi3CsIQNhRsY5Qcw+/s2JN73iIkiaUHua4=; b=lRS0V6CCP89v3CXuHn97HFY5NysxZDw8SDYrJKtP0V4j3M/SLg1wVa/f8QatDZnFhS hoyTpTiZgQ4H+UE9u1/jwMm0monXm+3Ew0gskohEaQo3WARgSVnEHINVEOi20NKwpUR3 Lqq05RBy//9BhIoCsZ3Ojq5bMt72oEcBjp3v23vB9Gvqol+YM09y3RR/76v+yNm4jBJo NcueG+NO4At03Uwvv6SyTEbPwqQgE+LOzP4szLHHDyz6FTj3Ll/ZLEGNb26971Gk3we0 XUoPa75gNcStb64t+BU0yusTH0g4/CwDNrWpe9zBvhGjnaJtOPmeiRR09esUN46g0b9Y 9H7w== X-Gm-Message-State: APjAAAWFr0nl1FW6qGXiD2gVLk8dWDNRgkwGC0J9C6OXmiH6du5Y4fyu 0GVN29vTqRFGkUjhgQZSYLkvdruOIhc= X-Google-Smtp-Source: APXvYqziCA2E6O5nofHVo8AD7Z5Pa3qZ1JfLXYosSGLfdH702pNRTHnQeliSOD/6xIvdqvPb/Zjv6Q== X-Received: by 2002:ac2:4476:: with SMTP id y22mr2708097lfl.169.1574464080031; Fri, 22 Nov 2019 15:08:00 -0800 (PST) Received: from localhost.localdomain (h88-129-82-160.cust.a3fiber.se. [88.129.82.160]) by smtp.gmail.com with ESMTPSA id n11sm365611ljg.15.2019.11.22.15.07.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Nov 2019 15:07:59 -0800 (PST) From: Johan Parin X-Google-Original-From: Johan Parin To: notmuch@notmuchmail.org Cc: Johan Parin Subject: [PATCH] Display extra headers for emacs-mua - cmd line option Date: Sat, 23 Nov 2019 00:07:29 +0100 Message-Id: <20191122230730.35712-2-johan.parin@gmail.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20191122230730.35712-1-johan.parin@gmail.com> References: <20191122230730.35712-1-johan.parin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Nov 2019 23:08:03 -0000 Add a new flag --extra-headers to notmuch show, in order to let the user specify displayed headers using `notmuch-message-headers' in the emacs mua. The flag will impact which headers are output in format_headers_sprinter. The emacs mua will generate the --extra-headers flag based on notmuch-message-headers. See this bug report: https://notmuchmail.org/pipermail/notmuch/2017/026069.html --- doc/man1/notmuch-show.rst | 7 +++++++ emacs/notmuch-lib.el | 14 ++++++++++++++ emacs/notmuch-query.el | 9 ++++++++- emacs/notmuch-show.el | 10 ---------- emacs/notmuch-tree.el | 16 +++++++++++----- notmuch-show.c | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 16 deletions(-) diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst index becd3e79..9f61acce 100644 --- a/doc/man1/notmuch-show.rst +++ b/doc/man1/notmuch-show.rst @@ -190,6 +190,13 @@ Supported options for **show** include "text/html" parts, no part with content type "text/html" is included in the output. +``--extra-headers=header[,header...]`` + A comma separated list of extra headers that will be output by + **notmuch show** with ``--format=sexp``, if present in the + message. + + Default: empty list. + A common use of **notmuch show** is to display a single thread of email messages. For this, use a search term of "thread:" as can be seen in the first column of output from the **notmuch search** command. diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 8acad267..50dfb743 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -148,6 +148,20 @@ For example, if you wanted to remove an \"inbox\" tag and add an :group 'notmuch-search :group 'notmuch-show) +(defconst notmuch-default-message-headers + '("Subject" "To" "Cc" "Date") + "Default set of headers to be displayed when showing a message") + +(defcustom notmuch-message-headers notmuch-default-message-headers + "Headers that should be shown in a message, in this order. + +For an open message, all of these headers will be made visible +according to `notmuch-message-headers-visible' or can be toggled +with `notmuch-show-toggle-visibility-headers'. For a closed message, +only the first header in the list will be visible." + :type '(repeat string) + :group 'notmuch-show) + (defvar notmuch-common-keymap (let ((map (make-sparse-keymap))) (define-key map "?" 'notmuch-help) diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el index 563e4acf..c834a6d8 100644 --- a/emacs/notmuch-query.el +++ b/emacs/notmuch-query.el @@ -30,7 +30,14 @@ A thread is a forest or list of trees. A tree is a two element list where the first element is a message, and the second element is a possibly empty forest of replies. " - (let ((args '("show" "--format=sexp" "--format-version=4"))) + ;; (let ((args '("show" "--format=sexp" "--format-version=4"))) + (let ((extra-headers + (cl-set-difference notmuch-message-headers notmuch-default-message-headers + :test #'string=)) + (args '("show" "--format=sexp" "--format-version=4"))) + (when extra-headers + (nconc args (list (concat "--extra-headers=" + (mapconcat #'identity extra-headers ","))))) (if notmuch-show-process-crypto (setq args (append args '("--decrypt=true")))) (setq args (append args search-terms)) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index e13ca3d7..069f0184 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -53,16 +53,6 @@ (declare-function notmuch-read-query "notmuch" (prompt)) (declare-function notmuch-draft-resume "notmuch-draft" (id)) -(defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date") - "Headers that should be shown in a message, in this order. - -For an open message, all of these headers will be made visible -according to `notmuch-message-headers-visible' or can be toggled -with `notmuch-show-toggle-visibility-headers'. For a closed message, -only the first header in the list will be visible." - :type '(repeat string) - :group 'notmuch-show) - (defcustom notmuch-message-headers-visible t "Should the headers be visible by default? diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index c00315e8..4f97e632 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -915,14 +915,20 @@ the same as for the function notmuch-tree." (let* ((search-args (concat basic-query (if query-context (concat " and (" query-context ")")) )) - (message-arg "--entire-thread")) + (message-arg "--entire-thread") + (extra-headers + (cl-set-difference notmuch-message-headers notmuch-default-message-headers + :test #'string=)) + (args '("notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel + "show" "--body=false" "--format=sexp" "--format-version=4"))) + (when extra-headers + (nconc args (list (concat "--extra-headers=" + (mapconcat #'identity extra-headers ","))))) + (nconc args search-args) (if (equal (car (process-lines notmuch-command "count" search-args)) "0") (setq search-args basic-query)) (notmuch-tag-clear-cache) - (let ((proc (notmuch-start-notmuch - "notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel - "show" "--body=false" "--format=sexp" "--format-version=4" - message-arg search-args)) + (let ((proc (apply #'notmuch-start-notmuch args)) ;; Use a scratch buffer to accumulate partial output. ;; This buffer will be killed by the sentinel, which ;; should be called no matter how the process dies. diff --git a/notmuch-show.c b/notmuch-show.c index 21792a57..1935c4ab 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -18,11 +18,20 @@ * Author: Carl Worth */ +#include +#include + #include "notmuch-client.h" #include "gmime-filter-reply.h" #include "sprinter.h" #include "zlib-extra.h" + +/* Extra headers to be output by format_headers_sprinter, if present + * in message */ +static const char* extra_headers = NULL; + + static const char * _get_tags_as_string (const void *ctx, notmuch_message_t *message) { @@ -195,6 +204,30 @@ _is_from_line (const char *line) return 0; } +/* Output extra headers if specifoed by --extra-headers */ +void +format_extra_headers_sprinter (sprinter_t *sp, GMimeMessage *message) +{ + GMimeHeaderList *header_list; + GMimeHeader *header; + char *str = strdup(extra_headers); + char *tofree = str; + char *header_name; + + header_list = g_mime_object_get_header_list (GMIME_OBJECT(message)); + + while ( (header_name = strsep(&str, ",")) != NULL) { + + 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)); + } + free (tofree); +} + void format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, bool reply, const _notmuch_message_crypto_t *msg_crypto) @@ -253,6 +286,10 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, } else { sp->map_key (sp, "Date"); sp->string (sp, g_mime_message_get_date_string (sp, message)); + + /* Output extra headers the user has configured in the database, if any */ + if (extra_headers != NULL) + format_extra_headers_sprinter (sp, message); } sp->end (sp); @@ -1193,6 +1230,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { .opt_bool = ¶ms.output_body, .name = "body" }, { .opt_bool = ¶ms.include_html, .name = "include-html" }, { .opt_inherit = notmuch_shared_options }, + { .opt_string = &extra_headers, .name = "extra-headers" }, { } }; -- 2.21.0 (Apple Git-122)