]> granicus.if.org Git - mutt/commitdiff
Add ~M pattern to match mime Content-Types.
authorAmmon Riley <ammon.riley@gmail.com>
Fri, 27 Apr 2018 01:00:00 +0000 (18:00 -0700)
committerKevin McCarthy <kevin@8t8.us>
Tue, 1 May 2018 16:41:48 +0000 (09:41 -0700)
doc/manual.xml.head
doc/muttrc.man.head
mutt.h
pattern.c

index 92f6df892caae3fc971c693d9259d28ed81ff5be..1bff0d170783dba3f6c0d8c0f93b4eb84bdba64f 100644 (file)
@@ -5203,6 +5203,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>
index 28591f071634269e1b30d1ee90797e6722904774..f73e5cf2decf33881baca3e1dfff1aa8792e7745 100644 (file)
@@ -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 7c5af17363e2f1291ba21c42de39670df8fbc5fb..663beb4ff031ce01cd91663b09417afe19208253 100644 (file)
--- 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,
index 285cbfa6f384cfa2caef1e4690fe06f28f13ed72..7ce968ab00c57a5451245e53ce3e6f5d81052acd 100644 (file)
--- 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));
   }