unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Johan Parin <johanparin@gmail.com>, notmuch@notmuchmail.org
Cc: Johan Parin <johan.parin@gmail.com>
Subject: Re: [PATCH] Display extra headers for emacs-mua - db config option
Date: Thu, 21 Nov 2019 10:48:13 +0800	[thread overview]
Message-ID: <87imnej66q.fsf@fifthhorseman.net> (raw)
In-Reply-To: <20191116162723.18343-1-johan.parin@gmail.com>

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 <cworth@cworth.org>
>   */
>  
> +#include <string.h>
> +
>  #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

  parent reply	other threads:[~2019-11-21  5:31 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-16 16:27 [PATCH] Display extra headers for emacs-mua - db config option Johan Parin
2019-11-16 16:35 ` Tomi Ollila
2019-11-16 16:53 ` Johan Parin
2019-11-21  2:48 ` Daniel Kahn Gillmor [this message]
2019-11-21 12:16   ` David Bremner
2019-11-21 18:29   ` Johan Parin
2019-11-21 21:56     ` Johan Parin
2019-11-22  2:51       ` Daniel Kahn Gillmor
2019-11-22 17:46       ` Carl Worth
2019-11-21 12:27 ` David Bremner
2019-11-21 19:47   ` Daniel Kahn Gillmor
2019-11-21 21:38     ` Tomi Ollila
2019-11-22  2:43       ` moving the config into the database [was: Re: [PATCH] Display extra headers for emacs-mua - db config option] Daniel Kahn Gillmor
2019-12-08 16:47         ` Jorge P. de Morais Neto
2019-12-08 17:12           ` Jameson Graef Rollins
2019-12-08 18:19             ` Jorge P. de Morais Neto
2019-12-09 18:31               ` Daniel Kahn Gillmor
2019-12-10 12:46                 ` Jorge P. de Morais Neto
2019-12-10 17:01                   ` Daniel Kahn Gillmor
2019-12-12 11:59                     ` Jorge P. de Morais Neto
2019-12-10 16:11               ` Jameson Graef Rollins
2019-12-11 10:53                 ` David Edmondson
2019-12-11 14:00                   ` David Bremner
2019-12-11 14:21                     ` David Edmondson
2019-12-12 16:25                     ` Daniel Kahn Gillmor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imnej66q.fsf@fifthhorseman.net \
    --to=dkg@fifthhorseman.net \
    --cc=johan.parin@gmail.com \
    --cc=johanparin@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).