unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] Fix format_headers_sprinter to return all headers (v2)
@ 2019-11-09 22:13 Johan Parin
  2019-11-09 22:21 ` Johan Parin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Johan Parin @ 2019-11-09 22:13 UTC (permalink / raw)
  To: notmuch; +Cc: Johan Parin

Modify format_headers_sprinter so that it returns some additional headers in the
sexp, instead of a small fixed set of headers.

This version includes the following headers:

- Maildir
- Mailing-list
- Tags
- Attachments
- Signature
- Decryption
- User-agent
- X-Mailer

This is required in order for the elisp variable
`notmuch-message-headers' to work to some extent.

See this bug report:

  https://notmuchmail.org/pipermail/notmuch/2017/026069.html
---
 notmuch-show.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/notmuch-show.c b/notmuch-show.c
index 21792a57..86ddb491 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -205,6 +205,12 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     char *recipients_string;
     const char *reply_to_string;
     void *local = talloc_new (sp);
+    GMimeHeaderList *header_list;
+    GMimeHeader *header;
+    const char* interesting_headers[] = {
+	"Maildir", "Mailing-list", "Tags", "Attachments", "Signature",
+	"Decryption", "User-agent", "X-Mailer"};
+    const int interesting_header_count = sizeof(interesting_headers) / sizeof(char *);
 
     sp->begin_map (sp);
 
@@ -255,6 +261,19 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
 	sp->string (sp, g_mime_message_get_date_string (sp, message));
     }
 
+    header_list  = g_mime_object_get_header_list (GMIME_OBJECT(message));
+
+    for (int i = 0; i < interesting_header_count; i++) {
+
+	header = g_mime_header_list_get_header(
+	    header_list, interesting_headers[i]);
+	if (header == NULL)
+	    continue;
+
+	sp->map_key (sp, g_mime_header_get_name(header));
+	sp->string (sp, g_mime_header_get_value(header));
+    }
+
     sp->end (sp);
     talloc_free (local);
 }
-- 
2.21.0 (Apple Git-122)

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix format_headers_sprinter to return all headers (v2)
  2019-11-09 22:13 [PATCH] Fix format_headers_sprinter to return all headers (v2) Johan Parin
@ 2019-11-09 22:21 ` Johan Parin
  2019-11-09 22:36 ` Tomi Ollila
  2019-11-10 14:03 ` David Edmondson
  2 siblings, 0 replies; 7+ messages in thread
From: Johan Parin @ 2019-11-09 22:21 UTC (permalink / raw)
  To: notmuch


So this version only returns a fixed limited set of extra
headers. Hopefully this eliminates any concern for a performance
penalty. Of course it limits the usefulness of the
notmuch-message-headers variable.

/Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix format_headers_sprinter to return all headers (v2)
  2019-11-09 22:13 [PATCH] Fix format_headers_sprinter to return all headers (v2) Johan Parin
  2019-11-09 22:21 ` Johan Parin
@ 2019-11-09 22:36 ` Tomi Ollila
  2019-11-10  9:41   ` Jani Nikula
  2019-11-10 14:03 ` David Edmondson
  2 siblings, 1 reply; 7+ messages in thread
From: Tomi Ollila @ 2019-11-09 22:36 UTC (permalink / raw)
  To: notmuch


Subject line not updated

On Sat, Nov 09 2019, Johan Parin wrote:

> So this version only returns a fixed limited set of extra
> headers. Hopefully this eliminates any concern for a performance
> penalty. Of course it limits the usefulness of the
> notmuch-message-headers variable.

headers to request based on command line parameter (and default to current
set) could be an option (kinda Jani already suggested). Quick (not perhaps
well thought) one could be:

   --message-headers=To,Cc,X-Face


and in the other mail -- mostly style comments (for future reference)

On Sat, Nov 09 2019, 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.
>
> This version includes the following headers:
>
> - Maildir
> - Mailing-list
> - Tags
> - Attachments
> - Signature
> - Decryption
> - User-agent
> - X-Mailer
>
> This is required in order for the elisp variable
> `notmuch-message-headers' to work to some extent.
>
> See this bug report:
>
>   https://notmuchmail.org/pipermail/notmuch/2017/026069.html
> ---
>  notmuch-show.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/notmuch-show.c b/notmuch-show.c
> index 21792a57..86ddb491 100644
> --- a/notmuch-show.c
> +++ b/notmuch-show.c
> @@ -205,6 +205,12 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
>      char *recipients_string;
>      const char *reply_to_string;
>      void *local = talloc_new (sp);
> +    GMimeHeaderList *header_list;

> +    GMimeHeader *header;

could be dropped here and had only in scope where it is used below...

> +    const char* interesting_headers[] = {
> +	"Maildir", "Mailing-list", "Tags", "Attachments", "Signature",
> +	"Decryption", "User-agent", "X-Mailer"};
> +    const int interesting_header_count = sizeof(interesting_headers) / sizeof(char *);

more "idiomatic" could be ... sizeof (interesting_headers) / sizeof (interesting_headers[0]);

>      sp->begin_map (sp);
>  
> @@ -255,6 +261,19 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
>  	sp->string (sp, g_mime_message_get_date_string (sp, message));
>      }
>  
> +    header_list  = g_mime_object_get_header_list (GMIME_OBJECT(message));

two (2) spaces, then no space after GMIME_OBJECT

> +
> +    for (int i = 0; i < interesting_header_count; i++) {
> +

... here GMimeHeader *header; is only used

> +	header = g_mime_header_list_get_header(
> +	    header_list, interesting_headers[i]);
> +	if (header == NULL)
> +	    continue;
> +
> +	sp->map_key (sp, g_mime_header_get_name(header));
> +	sp->string (sp, g_mime_header_get_value(header));

spaces before '('

> +    }
> +
>      sp->end (sp);
>      talloc_free (local);
>  }
> -- 
> 2.21.0 (Apple Git-122)
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix format_headers_sprinter to return all headers (v2)
  2019-11-09 22:36 ` Tomi Ollila
@ 2019-11-10  9:41   ` Jani Nikula
  0 siblings, 0 replies; 7+ messages in thread
From: Jani Nikula @ 2019-11-10  9:41 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

On Sun, 10 Nov 2019, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> Subject line not updated
>
> On Sat, Nov 09 2019, Johan Parin wrote:
>
>> So this version only returns a fixed limited set of extra
>> headers. Hopefully this eliminates any concern for a performance
>> penalty. Of course it limits the usefulness of the
>> notmuch-message-headers variable.
>
> headers to request based on command line parameter (and default to current
> set) could be an option (kinda Jani already suggested). Quick (not perhaps
> well thought) one could be:
>
>    --message-headers=To,Cc,X-Face

Yes, something like this is what I had in mind.

But this needs to be carefully thought out. Obviously we need a default
set. Is it possible to remove headers from the default set? Does
--message-headers=Foo override the default set too? Should we force the
inclusion of certain "fundamental" headers? Etc. As I said, the
notmuch-show interface is a bit confusing already, better not make it
more confusing.

> and in the other mail -- mostly style comments (for future reference)
>
> On Sat, Nov 09 2019, 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.
>>
>> This version includes the following headers:
>>
>> - Maildir
>> - Mailing-list
>> - Tags
>> - Attachments
>> - Signature
>> - Decryption
>> - User-agent
>> - X-Mailer
>>
>> This is required in order for the elisp variable
>> `notmuch-message-headers' to work to some extent.
>>
>> See this bug report:
>>
>>   https://notmuchmail.org/pipermail/notmuch/2017/026069.html
>> ---
>>  notmuch-show.c | 19 +++++++++++++++++++
>>  1 file changed, 19 insertions(+)
>>
>> diff --git a/notmuch-show.c b/notmuch-show.c
>> index 21792a57..86ddb491 100644
>> --- a/notmuch-show.c
>> +++ b/notmuch-show.c
>> @@ -205,6 +205,12 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
>>      char *recipients_string;
>>      const char *reply_to_string;
>>      void *local = talloc_new (sp);
>> +    GMimeHeaderList *header_list;
>
>> +    GMimeHeader *header;
>
> could be dropped here and had only in scope where it is used below...
>
>> +    const char* interesting_headers[] = {
>> +	"Maildir", "Mailing-list", "Tags", "Attachments", "Signature",
>> +	"Decryption", "User-agent", "X-Mailer"};
>> +    const int interesting_header_count = sizeof(interesting_headers) / sizeof(char *);
>
> more "idiomatic" could be ... sizeof (interesting_headers) / sizeof (interesting_headers[0]);

Yes, but please use ARRAY_SIZE() instead. ;)

BR,
Jani.

>
>>      sp->begin_map (sp);
>>  
>> @@ -255,6 +261,19 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
>>  	sp->string (sp, g_mime_message_get_date_string (sp, message));
>>      }
>>  
>> +    header_list  = g_mime_object_get_header_list (GMIME_OBJECT(message));
>
> two (2) spaces, then no space after GMIME_OBJECT
>
>> +
>> +    for (int i = 0; i < interesting_header_count; i++) {
>> +
>
> ... here GMimeHeader *header; is only used
>
>> +	header = g_mime_header_list_get_header(
>> +	    header_list, interesting_headers[i]);
>> +	if (header == NULL)
>> +	    continue;
>> +
>> +	sp->map_key (sp, g_mime_header_get_name(header));
>> +	sp->string (sp, g_mime_header_get_value(header));
>
> spaces before '('
>
>> +    }
>> +
>>      sp->end (sp);
>>      talloc_free (local);
>>  }
>> -- 
>> 2.21.0 (Apple Git-122)
>>
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> https://notmuchmail.org/mailman/listinfo/notmuch
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix format_headers_sprinter to return all headers (v2)
  2019-11-09 22:13 [PATCH] Fix format_headers_sprinter to return all headers (v2) Johan Parin
  2019-11-09 22:21 ` Johan Parin
  2019-11-09 22:36 ` Tomi Ollila
@ 2019-11-10 14:03 ` David Edmondson
  2019-11-10 17:12   ` Johan Parin
  2019-11-10 20:10   ` Tomi Ollila
  2 siblings, 2 replies; 7+ messages in thread
From: David Edmondson @ 2019-11-10 14:03 UTC (permalink / raw)
  To: Johan Parin, notmuch; +Cc: Johan Parin

On Saturday, 2019-11-09 at 23:13:58 +01, Johan Parin wrote: 

> +    const char* interesting_headers[] = { +	"Maildir", 
> "Mailing-list", "Tags", "Attachments", "Signature", + 
> "Decryption", "User-agent", "X-Mailer"}; 

It would be convenient to specify these in ~/.notmuch-config 
rather than hard-coding them (or specifying them as command line 
arguments).

dme.
-- 
And you can't hold me down, 'cause I belong to the hurricane.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix format_headers_sprinter to return all headers (v2)
  2019-11-10 14:03 ` David Edmondson
@ 2019-11-10 17:12   ` Johan Parin
  2019-11-10 20:10   ` Tomi Ollila
  1 sibling, 0 replies; 7+ messages in thread
From: Johan Parin @ 2019-11-10 17:12 UTC (permalink / raw)
  To: notmuch

David Edmondson <dme@dme.org> writes:

> On Saturday, 2019-11-09 at 23:13:58 +01, Johan Parin wrote: 
>
>> +    const char* interesting_headers[] = { +	"Maildir",
>> "Mailing-list", "Tags", "Attachments", "Signature", + "Decryption",
>> "User-agent", "X-Mailer"}; 
>
> It would be convenient to specify these in ~/.notmuch-config rather
> than hard-coding them (or specifying them as command line arguments).
>

I agree that is a better solution, maybe even better than using command
line args.

I can look into this as well. Will not have much time the next few days
though. 

/Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix format_headers_sprinter to return all headers (v2)
  2019-11-10 14:03 ` David Edmondson
  2019-11-10 17:12   ` Johan Parin
@ 2019-11-10 20:10   ` Tomi Ollila
  1 sibling, 0 replies; 7+ messages in thread
From: Tomi Ollila @ 2019-11-10 20:10 UTC (permalink / raw)
  To: notmuch

On Sun, Nov 10 2019, David Edmondson wrote:

> On Saturday, 2019-11-09 at 23:13:58 +01, Johan Parin wrote: 
>
>> +    const char* interesting_headers[] = { +	"Maildir", 
>> "Mailing-list", "Tags", "Attachments", "Signature", + 
>> "Decryption", "User-agent", "X-Mailer"}; 
>
> It would be convenient to specify these in ~/.notmuch-config 
> rather than hard-coding them (or specifying them as command line 
> arguments).

If we take the command line option approach, then the frontend can
request the headers, and have it configured in one location
(setting notmuch-message-headers in emacs affects how emacs mua
calls notmuch-show)...

Also, different frontends may have different usable headers, for
example `X-Face:` probably only works w/ emacs mua =D

Tomi

>
> dme.
> -- 
> And you can't hold me down, 'cause I belong to the hurricane.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-10 20:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-09 22:13 [PATCH] Fix format_headers_sprinter to return all headers (v2) Johan Parin
2019-11-09 22:21 ` Johan Parin
2019-11-09 22:36 ` Tomi Ollila
2019-11-10  9:41   ` Jani Nikula
2019-11-10 14:03 ` David Edmondson
2019-11-10 17:12   ` Johan Parin
2019-11-10 20:10   ` Tomi Ollila

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).