On Thu, Apr 26, 2018 at 5:34 PM, Kevin J. McCarthy <ke...@8t8.us> wrote: > On Thu, Apr 26, 2018 at 05:14:27PM -0700, Ammon Riley wrote: > Your new patch was too fast. :-) I realized I forgot to include one > other comment, below. I have to run, but I'll take another closer look > at the revised patch later tonight.
3rd time's the charm, right? > snprintf (unlike strncpy) will always add the terminating null byte. Fixed. I should have remembered that, as I've had to deal with the nonsense of Microsoft's _snprintf() *not* doing it. A
From a9ffae9a8e11f0e2dc730dd92593b5321045a01c Mon Sep 17 00:00:00 2001 From: Ammon Riley <ammon.ri...@gmail.com> Date: Thu, 26 Apr 2018 11:18:31 -0700 Subject: [PATCH] Add ~M pattern to match mime Content-Types. --- doc/manual.xml.head | 1 + doc/muttrc.man.head | 3 +++ mutt.h | 1 + pattern.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 0188803..7f75d0e 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -5199,6 +5199,7 @@ shows several ways to select messages. <row><entry>%L <emphasis>GROUP</emphasis></entry><entry>message either originated or received by any member of <emphasis>GROUP</emphasis></entry></row> <row><entry>~l</entry><entry>messages addressed to a known mailing list</entry></row> <row><entry>~m [<emphasis>MIN</emphasis>]-[<emphasis>MAX</emphasis>]</entry><entry>messages in the range <emphasis>MIN</emphasis> to <emphasis>MAX</emphasis> *)</entry></row> +<row><entry>~M <emphasis>EXPR</emphasis></entry><entry>messages which contain a mime Content-Type matching <emphasis>EXPR</emphasis></entry></row> <row><entry>~n [<emphasis>MIN</emphasis>]-[<emphasis>MAX</emphasis>]</entry><entry>messages with a score in the range <emphasis>MIN</emphasis> to <emphasis>MAX</emphasis> *)</entry></row> <row><entry>~N</entry><entry>new messages</entry></row> <row><entry>~O</entry><entry>old messages</entry></row> diff --git a/doc/muttrc.man.head b/doc/muttrc.man.head index 28591f0..f73e5cf 100644 --- a/doc/muttrc.man.head +++ b/doc/muttrc.man.head @@ -575,6 +575,9 @@ messages either originated or received by any member of \fIGROUP\fP ~m \fIMIN\fP-\fIMAX\fP message in the range \fIMIN\fP to \fIMAX\fP .TP +~M \fIEXPR\fP +messages which contain a mime Content-Type matching \fIEXPR\fP +.TP ~n \fIMIN\fP-\fIMAX\fP messages with a score in the range \fIMIN\fP to \fIMAX\fP .TP diff --git a/mutt.h b/mutt.h index 4fe7ce4..7c5bec2 100644 --- a/mutt.h +++ b/mutt.h @@ -253,6 +253,7 @@ enum MUTT_PGP_KEY, MUTT_XLABEL, MUTT_MIMEATTACH, + MUTT_MIMETYPE, /* Options for Mailcap lookup */ MUTT_EDIT, diff --git a/pattern.c b/pattern.c index 285cbfa..7ce968a 100644 --- a/pattern.c +++ b/pattern.c @@ -25,6 +25,7 @@ #include "keymap.h" #include "mailbox.h" #include "copy.h" +#include "mime.h" #include <string.h> #include <stdlib.h> @@ -76,6 +77,7 @@ Flags[] = { 'l', MUTT_LIST, 0, NULL }, { 'L', MUTT_ADDRESS, 0, eat_regexp }, { 'm', MUTT_MESSAGE, 0, eat_range }, + { 'M', MUTT_MIMETYPE, MUTT_FULL_MSG, eat_regexp }, { 'n', MUTT_SCORE, 0, eat_range }, { 'N', MUTT_NEW, 0, NULL }, { 'O', MUTT_OLD, 0, NULL }, @@ -1138,6 +1140,28 @@ static int match_threadchildren(struct pattern_t *pat, pattern_exec_flag flags, return 0; } +static int match_content_type(const pattern_t* pat, BODY *b) +{ + char buffer[STRING]; + if (!b) + return 0; + + snprintf (buffer, STRING, "%s/%s", TYPE (b), b->subtype); + + if (patmatch (pat, buffer) == 0) + return 1; + if (match_content_type (pat, b->parts)) + return 1; + if (match_content_type (pat, b->next)) + return 1; + return 0; +} + +static int match_mime_content_type(const pattern_t *pat, CONTEXT *ctx, HEADER *hdr) +{ + mutt_parse_mime_message(ctx, hdr); + return match_content_type(pat, hdr->content); +} /* Sets a value in the pattern_cache_t cache entry. * Normalizes the "true" value to 2. */ @@ -1338,6 +1362,10 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, return (pat->not ^ (count >= pat->min && (pat->max == MUTT_MAXRANGE || count <= pat->max))); } + case MUTT_MIMETYPE: + if (!ctx) + return 0; + return (pat->not ^ match_mime_content_type (pat, ctx, h)); case MUTT_UNREFERENCED: return (pat->not ^ (h->thread && !h->thread->child)); } -- 2.8.0.rc3