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 B1E376DE0289 for ; Sat, 23 Nov 2019 01:44:31 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.393 X-Spam-Level: X-Spam-Status: No, score=-0.393 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, RCVD_IN_MSPIKE_H2=-0.001, 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 UwB01LBQbICV for ; Sat, 23 Nov 2019 01:44:31 -0800 (PST) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by arlo.cworth.org (Postfix) with ESMTPS id AF1D86DE0274 for ; Sat, 23 Nov 2019 01:44:30 -0800 (PST) Received: by mail-lj1-f193.google.com with SMTP id y23so10098374ljh.10 for ; Sat, 23 Nov 2019 01:44:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=qPW0NG0Lt5HmMp7JuntKclS8OIpGEC0j7k5Cm2QQI5E=; b=kK5HG5y2irtRDAugjVmzA4/9B6/ssAoHXsHUX8IAxdSNkx3QYgFzRIj1iqZ9OTBbhU 8BZAjXFAvou5qkCr9GRdlBydtP2HqeZZ/rphJyiJsEbJhZqbXhHwP8yHZGlwFIqozmhs OV1ChATKEoBJmq6IUnH3yGu6uP+a90/g7xN5ruXgbf2p/z+ez8Rf0qxCAf0/U3Vg1aEz EHHuhcAGipMMV0f8iZH/914mLBROZmBmTCNDlm/A34nmBOc0fU2OMoM/2p5CWPxxLz9z sWn6NiMUKyBFxsO/6+2LZGMgXKAaeRkeJos/PI9kOmnI2k4Wtn2lDipTYth0ezPyP3Sw J8lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=qPW0NG0Lt5HmMp7JuntKclS8OIpGEC0j7k5Cm2QQI5E=; b=FxRATTfm9bx/Tf6iKUh8hiDRDKVsI3ohzdGUXvp9C8Ow/p3P74fliJo37aG6G8gT8Q 1q22H2bpBtQNxIrBR9w9MrSen176WKY7M7l1qQgi7MkaOyTxWeM9ojRRvDG1znBUcjzw qkQsY/EMiWu7sjjzwR0pAYCppJwM8MrB2xA14IjeyN+M//1dkRkwYTotwsY1+FR7rpVo ztYf3x7R+FJgKM6gngV/jI7MGhKPNL/AFCm3zPByViVSdViy/v2ygnbdK1VbUbLTY0kU 7MvGsX8mUe1M1rxy4p+Yn7aqQDzgnpmfua9dvqx4SdISsy8t4r2rKXzpwkHEkqBaAR3V JuHA== X-Gm-Message-State: APjAAAW3j4c/eqA89JfKPMvvH0KUkr8aHcEMEqCVH4oUCS9hDvuSNBx6 KkOaX/Facr/4ZV44MXhwFQH0Qc3Vt7w= X-Google-Smtp-Source: APXvYqwh4Cq/TeGJMr//lb5zAlsv/FwQFGMj6fAB2zFF4VKKYK1cUxgblg+sUBz8W3axEAtwIKYZzg== X-Received: by 2002:a2e:9c94:: with SMTP id x20mr15225197lji.64.1574502267177; Sat, 23 Nov 2019 01:44:27 -0800 (PST) Received: from Johans-mbp-wifi.parin.ddns.net (h88-129-82-160.cust.a3fiber.se. [88.129.82.160]) by smtp.gmail.com with ESMTPSA id f5sm485809ljn.24.2019.11.23.01.44.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2019 01:44:25 -0800 (PST) From: Johan Parin X-Google-Original-From: Johan Parin To: notmuch@notmuchmail.org Subject: Re: [PATCH] Display extra headers for emacs-mua - cmd line option References: <20191122230730.35712-1-johan.parin@gmail.com> <20191122230730.35712-2-johan.parin@gmail.com> Date: Sat, 23 Nov 2019 10:44:24 +0100 In-Reply-To: <20191122230730.35712-2-johan.parin@gmail.com> (Johan Parin's message of "Sat, 23 Nov 2019 00:07:29 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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: Sat, 23 Nov 2019 09:44:31 -0000 --=-=-= Content-Type: text/plain The elisp was a little buggy. Here is another version which should hopefully be 100% working. Also cleaned up and aligned style to the surrounding code. /Johan --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Display-extra-headers-for-emacs-mua-cmd-line-option.patch Content-Description: 0001-Display-extra-headers-for-emacs-mua-cmd-line-option.patch >From ed26005481d824c0f7b0518a934470e4c4231d0a Mon Sep 17 00:00:00 2001 From: Johan Parin Date: Fri, 22 Nov 2019 23:06:14 +0100 Subject: [PATCH] Display extra headers for emacs-mua - cmd line option 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 | 26 ++++++++++++++++++++++++++ emacs/notmuch-query.el | 5 ++++- emacs/notmuch-show.el | 10 ---------- emacs/notmuch-tree.el | 13 ++++++++----- notmuch-show.c | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 83 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..4609a63a 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) @@ -1017,6 +1031,18 @@ region if the region is active, or both `point' otherwise." (list (region-beginning) (region-end)) (list (point) (point)))) +(defun notmuch-show-build-extra-headers-arg () + "Build the --extra-headers arg to notmuch-show + +Returns the argument as a string if relevant, otherwise NIL +" + (let ((extra-headers + (cl-set-difference notmuch-message-headers notmuch-default-message-headers + :test #'string=))) + (if extra-headers + (concat "--extra-headers=" + (mapconcat #'identity extra-headers ","))))) + (define-obsolete-function-alias 'notmuch-search-interactive-region 'notmuch-interactive-region diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el index 563e4acf..03ba90ea 100644 --- a/emacs/notmuch-query.el +++ b/emacs/notmuch-query.el @@ -30,7 +30,10 @@ 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 ((extra-headers-arg (notmuch-show-build-extra-headers-arg)) + (args '("show" "--format=sexp" "--format-version=4"))) + (if extra-headers-arg + (setq args (append args (list extra-headers-arg)))) (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..939c77a9 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -915,14 +915,17 @@ 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-arg (notmuch-show-build-extra-headers-arg)) + (args `("notmuch-tree" ,(current-buffer) ,#'notmuch-tree-process-sentinel + "show" "--body=false" "--format=sexp" "--format-version=4"))) + (if extra-headers-arg + (setq args (append args (list extra-headers-arg)))) + (setq args (append args (list 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) --=-=-=--