Ammon Riley
2018-04-26 19:15:18 UTC
Hi,
I'm scratching an itch, here. I want to limit email messages to those with
pdf attachments, or text/calendar, or images, etc. Is a merge request
on gitlab preferable to a patch like this?
Cheers,
Ammon
---
doc/manual.xml.head | 2 ++
doc/muttrc.man.head | 6 ++++++
mutt.h | 1 +
pattern.c | 30 +++++++++++++++++++++++++++++-
4 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/doc/manual.xml.head b/doc/manual.xml.head
index 0188803..3596c1b 100644
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -5199,6 +5199,8 @@ 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>=M <emphasis>STRING</emphasis></entry><entry>messages which
contain a mime Content-Type containing
<emphasis>STRING</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..b72e31d 100644
--- a/doc/muttrc.man.head
+++ b/doc/muttrc.man.head
@@ -575,6 +575,12 @@ 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
+=M \fISTRING\fP
+messages which contain a mime Content-Type containing \fISTRING\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..2c70d5c 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,29 @@ 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 == 0)
+ return 0;
+
+ if (snprintf(buffer, STRING, "%s/%s", TYPE (b), b->subtype) >= STRING)
+ buffer[STRING-1] = '\0';
+
+ if (b->subtype != 0 && (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. */
@@ -1158,7 +1183,6 @@ static int is_pattern_cache_set (int cache_entry)
return cache_entry != 0;
}
-
/*
* flags: MUTT_MATCH_FULL_ADDRESS - match both personal and machine address
* cache: For repeated matches against the same HEADER, passing in
non-NULL will
@@ -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));
}
I'm scratching an itch, here. I want to limit email messages to those with
pdf attachments, or text/calendar, or images, etc. Is a merge request
on gitlab preferable to a patch like this?
Cheers,
Ammon
---
doc/manual.xml.head | 2 ++
doc/muttrc.man.head | 6 ++++++
mutt.h | 1 +
pattern.c | 30 +++++++++++++++++++++++++++++-
4 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/doc/manual.xml.head b/doc/manual.xml.head
index 0188803..3596c1b 100644
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -5199,6 +5199,8 @@ 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>=M <emphasis>STRING</emphasis></entry><entry>messages which
contain a mime Content-Type containing
<emphasis>STRING</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..b72e31d 100644
--- a/doc/muttrc.man.head
+++ b/doc/muttrc.man.head
@@ -575,6 +575,12 @@ 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
+=M \fISTRING\fP
+messages which contain a mime Content-Type containing \fISTRING\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..2c70d5c 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,29 @@ 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 == 0)
+ return 0;
+
+ if (snprintf(buffer, STRING, "%s/%s", TYPE (b), b->subtype) >= STRING)
+ buffer[STRING-1] = '\0';
+
+ if (b->subtype != 0 && (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. */
@@ -1158,7 +1183,6 @@ static int is_pattern_cache_set (int cache_entry)
return cache_entry != 0;
}
-
/*
* flags: MUTT_MATCH_FULL_ADDRESS - match both personal and machine address
* cache: For repeated matches against the same HEADER, passing in
non-NULL will
@@ -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
2.8.0.rc3