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 74B9C6DE0F58 for ; Sat, 16 Nov 2019 08:27:36 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.39 X-Spam-Level: X-Spam-Status: No, score=-0.39 tagged_above=-999 required=5 tests=[AWL=-0.189, 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 XOsfUgeB_arW for ; Sat, 16 Nov 2019 08:27:35 -0800 (PST) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by arlo.cworth.org (Postfix) with ESMTPS id CB0176DE0EC5 for ; Sat, 16 Nov 2019 08:27:35 -0800 (PST) Received: by mail-lj1-f178.google.com with SMTP id d5so13974066ljl.4 for ; Sat, 16 Nov 2019 08:27:35 -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:mime-version :content-transfer-encoding; bh=rmxgyOI/mpKV/Ud/q1R8Gd7ZD71F398BHt2FCGwzPxE=; b=YsPMuvVznkgGzCTQ0JfHU9VgDn3pEJKUIn5TYMjYBpBNqEwlFkzYkkYMJe+5Vju+HV H312fvwUe5zLyO53zSa++kIOWXwlYY6jP29omHlyLLJE/SRYMyg89ZqkEuy3Dxn8sb5K uhfMToFVQdfwUrufsjpKtjJCxVd2q1wbzWUegoF6HcCYSp+PoK7J6n4Aneh1TFxL0JzB D2IJCBvS2+qf/mUhneGWnT1PCuAhueoXC9CJKfaVn0k2mHYHl2bfC7PFLdyPAPdtGFM+ iPIZtob0GngCVXd8Jg1rjON4YeQZMSigqAbNIk7Jd7OhFOVkonJnOw6qdPcvvZOnbkJT 4QIA== 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:mime-version :content-transfer-encoding; bh=rmxgyOI/mpKV/Ud/q1R8Gd7ZD71F398BHt2FCGwzPxE=; b=MHyNtEgBc/6wBrbno3IQ9xnCoKnIFumQ++pfzssDmcv0MNtle6OPJEpAh1R8r6sBH/ qnI/n7dWVKTjT/B6wovncNIiNqXPfRVJrEA90WblY5LowjF44lHpHPWUVk0thT8Ot+Nc A4LPTKnjbev7Yg5WkVPFGt9rYvleFKRz+yi5xfwdfm85KWMB+CCDsWbo02FfBg4XWbdY DILV6gVVaLrPkmam1HyeCXFUXb7rtEg4LWLFhUGj5ERlBZQZNLcX9GgIZ8Vs+xfg3UCX b5K40MGgNoepSqcuPguNpgs9WneLJagwfALY4na0QHz1sFhwL25qtgtxa0vHLxltbkHG I8Fw== X-Gm-Message-State: APjAAAVF9AF+NVH447fRt2rwb2MEOPQSUZgzBDy1IJ6YsOv2OVynUg7E 95ciZtkdqJ3CezCnRaUH0YbevpmZZ/g= X-Google-Smtp-Source: APXvYqwVUrTfxMIq89uOg01n/RmCpXc6CiuvaVV9XYIirsyv45R7naUyGaTAQDfAkJ8zCodHKEH3pw== X-Received: by 2002:a2e:b007:: with SMTP id y7mr3963097ljk.69.1573921653448; Sat, 16 Nov 2019 08:27:33 -0800 (PST) Received: from localhost.localdomain (h88-129-82-160.cust.a3fiber.se. [88.129.82.160]) by smtp.gmail.com with ESMTPSA id o196sm6324951lff.59.2019.11.16.08.27.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Nov 2019 08:27:32 -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 - db config option Date: Sat, 16 Nov 2019 17:27:23 +0100 Message-Id: <20191116162723.18343-1-johan.parin@gmail.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) 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: Sat, 16 Nov 2019 16:27:36 -0000 Modify format_headers_sprinter so that it returns some additional headers in the sexp, instead of a small fixed set of headers. The extra header list is configured by the database config option `show.extra_headers'. This is required in order for the elisp variable `notmuch-message-headers' to work. See this bug report: https://notmuchmail.org/pipermail/notmuch/2017/026069.html --- doc/man1/notmuch-config.rst | 6 ++++++ notmuch-config.c | 7 ++++--- notmuch-show.c | 41 ++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst index 28487079..0eb59883 100644 --- a/doc/man1/notmuch-config.rst +++ b/doc/man1/notmuch-config.rst @@ -204,6 +204,12 @@ The available configuration items are described below. supported. See **notmuch-search-terms(7)** for a list of existing prefixes, and an explanation of probabilistic prefixes. +**show.extra_headers** + A list of extra headers that will be output by **notmuch show** + with ``--format=sexp``, if present in the message. + + Default: empty list. + **built_with.** Compile time feature . Current possibilities include "compact" (see **notmuch-compact(1)**) and "field_processor" (see diff --git a/notmuch-config.c b/notmuch-config.c index 1b079e85..6554ad9b 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -841,9 +841,10 @@ typedef struct config_key { static struct config_key config_key_table[] = { - { "index.decrypt", true, false, NULL }, - { "index.header.", true, true, validate_field_name }, - { "query.", true, true, NULL }, + { "index.decrypt", true, false, NULL }, + { "index.header.", true, true, validate_field_name }, + { "query.", true, true, NULL }, + { "show.extra_headers", true, false, NULL } }; static config_key_info_t * diff --git a/notmuch-show.c b/notmuch-show.c index 21792a57..4c77468f 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -18,11 +18,16 @@ * Author: Carl Worth */ +#include + #include "notmuch-client.h" #include "gmime-filter-reply.h" #include "sprinter.h" #include "zlib-extra.h" +static notmuch_database_t *notmuch = NULL; + + static const char * _get_tags_as_string (const void *ctx, notmuch_message_t *message) { @@ -195,6 +200,38 @@ _is_from_line (const char *line) return 0; } +/* Output extra headers if configured with the `show.extra_headers' + * database configuration option + */ +void +format_extra_headers_sprinter (sprinter_t *sp, GMimeMessage *message) +{ + GMimeHeaderList *header_list; + GMimeHeader *header; + char *extra_headers, *tofree, *header_name; + + if (notmuch == NULL) + return; + + if (notmuch_database_get_config (notmuch, "show.extra_headers", + &extra_headers) != NOTMUCH_STATUS_SUCCESS) + return; + + header_list = g_mime_object_get_header_list (GMIME_OBJECT(message)); + + tofree = extra_headers; + while ( (header_name = strsep(&extra_headers, ";")) != 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 +290,9 @@ 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 */ + format_extra_headers_sprinter (sp, message); } sp->end (sp); @@ -1152,7 +1192,6 @@ static const notmuch_show_format_t *formatters[] = { int notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { - notmuch_database_t *notmuch; notmuch_query_t *query; char *query_string; int opt_index, ret; -- 2.21.0 (Apple Git-122)