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 F41626DE0A6C for ; Wed, 20 Nov 2019 21:31:59 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -1.354 X-Spam-Level: X-Spam-Status: No, score=-1.354 tagged_above=-999 required=5 tests=[AWL=1.147, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 S6THf75TJfDf for ; Wed, 20 Nov 2019 21:31:59 -0800 (PST) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTPS id 3E1B66DE0A7E for ; Wed, 20 Nov 2019 21:31:59 -0800 (PST) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019; t=1574314316; h=from : to : cc : subject : in-reply-to : references : date : message-id : mime-version : content-type : from; bh=2wg0p8mlrIq5GIjcj3gKBzYccxWaIp7iM4zorqoG2cg=; b=w5YudAvxiDZDQCT1WXpSlj515eBv1Ojw60h2Dsu/otAsilWfceDm/Sjg GLCJlAZSEr/N+l2FGxbSFB9Jtk4bCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019rsa; t=1574314316; h=from : to : cc : subject : in-reply-to : references : date : message-id : mime-version : content-type : from; bh=2wg0p8mlrIq5GIjcj3gKBzYccxWaIp7iM4zorqoG2cg=; b=ZHtUZPGvSfxQYy46opfOWanAzOWnOKqZCRiEpZ0D+XyR+Jd/83fSZVzD H5E7DbtVuO2PoktXOq04ihs45dn0CUfWhRx6ef2B9oVmeHUKgfUg4ZC/OC Xi4j0sJahESNpfiMWa1XrK8sTQ9srkAzfXqbTkcecPTSqF1ddOQH7FVpDp F/b2wHwOGcy4nYh2TtCunSNc8dqfWw+fvK+CiDvy7TbG1TfMUz5i+6LXqC sLUcKdvLNAUIfTrkb7Hr2gxrgc1vRGjzGREIVcWaWlqsuyHfvKOks7weF8 76Uk50/hvkWhGycwQq35sydu1vP8jUpRQU+mFqfrHz0rhcnKhDKhKg== Received: from fifthhorseman.net (dhcp-9e77.meeting.ietf.org [31.133.158.119]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by che.mayfirst.org (Postfix) with ESMTPSA id B368BF9B0; Thu, 21 Nov 2019 00:31:56 -0500 (EST) Received: by fifthhorseman.net (Postfix, from userid 1000) id 6BCA02057C; Thu, 21 Nov 2019 10:48:13 +0800 (+08) From: Daniel Kahn Gillmor To: Johan Parin , notmuch@notmuchmail.org Cc: Johan Parin Subject: Re: [PATCH] Display extra headers for emacs-mua - db config option In-Reply-To: <20191116162723.18343-1-johan.parin@gmail.com> References: <20191116162723.18343-1-johan.parin@gmail.com> Autocrypt: addr=dkg@fifthhorseman.net; prefer-encrypt=mutual; keydata= mDMEXEK/AhYJKwYBBAHaRw8BAQdAr/gSROcn+6m8ijTN0DV9AahoHGafy52RRkhCZVwxhEe0K0Rh bmllbCBLYWhuIEdpbGxtb3IgPGRrZ0BmaWZ0aGhvcnNlbWFuLm5ldD6ImQQTFggAQQIbAQUJA8Jn AAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgBYhBMS8Lds4zOlkhevpwvIGkReQOOXGBQJcQsbzAhkB AAoJEPIGkReQOOXG4fkBAO1joRxqAZY57PjdzGieXLpluk9RkWa3ufkt3YUVEpH/AP9c+pgIxtyW +FwMQRjlqljuj8amdN4zuEqaCy4hhz/1DbgzBFxCv4sWCSsGAQQB2kcPAQEHQERSZxSPmgtdw6nN u7uxY7bzb9TnPrGAOp9kClBLRwGfiPUEGBYIACYWIQTEvC3bOMzpZIXr6cLyBpEXkDjlxgUCXEK/ iwIbAgUJAeEzgACBCRDyBpEXkDjlxnYgBBkWCAAdFiEEyQ5tNiAKG5IqFQnndhgZZSmuX/gFAlxC v4sACgkQdhgZZSmuX/iVWgD/fCU4ONzgy8w8UCHGmrmIZfDvdhg512NIBfx+Mz9ls5kA/Rq97vz4 z48MFuBdCuu0W/fVqVjnY7LN5n+CQJwGC0MIA7QA/RyY7Sz2gFIOcrns0RpoHr+3WI+won3xCD8+ sVXSHZvCAP98HCjDnw/b0lGuCR7coTXKLIM44/LFWgXAdZjm1wjODbg4BFxCv50SCisGAQQBl1UB BQEBB0BG4iXnHX/fs35NWKMWQTQoRI7oiAUt0wJHFFJbomxXbAMBCAeIfgQYFggAJhYhBMS8Lds4 zOlkhevpwvIGkReQOOXGBQJcQr+dAhsMBQkB4TOAAAoJEPIGkReQOOXGe/cBAPlek5d9xzcXUn/D kY6jKmxe26CTws3ZkbK6Aa5Ey/qKAP0VuPQSCRxA7RKfcB/XrEphfUFkraL06Xn/xGwJ+D0hCw== Date: Thu, 21 Nov 2019 10:48:13 +0800 Message-ID: <87imnej66q.fsf@fifthhorseman.net> MIME-Version: 1.0 Content-Type: text/plain 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: Thu, 21 Nov 2019 05:32:00 -0000 On Sat 2019-11-16 17:27:23 +0100, Johan Parin wrote: > 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. Thanks for this work, Johan, and for your persistence on this functionality. > 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; I'm a little weirded out by the move to a static notmuch_database_t *notmuch object. Are we doing this because we don't want to pass around the database to internal functions? I know that the scope of nomtuch-show.c is basically "global scope", but i worry that it makes the code more difficult to read and maintain. It's also not a common idiom in the rest of the codebase (at least not one that i've seen). Is it that much worse to pass around the notmuch_database_t *? --dkg