[PATCH] Add ~M pattern to match mime Content-Types.

Ammon Riley ammon.riley at gmail.com
Fri Apr 27 00:14:27 UTC 2018


On Thu, Apr 26, 2018 at 4:23 PM, Kevin J. McCarthy <kevin at 8t8.us> wrote:
> > diff --git a/doc/manual.xml.head b/doc/manual.xml.head
>
> > +<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>
>
> There is no need to add '=M' documentation.  This is covered below in
> the documentation where it says:
>   You can force Mutt to treat EXPR as a simple string instead of a
>   regular expression by using = instead of ~ in the pattern name."
>
> The =b/=B/=h are explicity mentioned because of their IMAP behavior.

I did copy the =b/=B.  I hadn't considered IMAP for this feature, as I'm
not using it.  Since we have to parse the message to match content-type,
how would this behave under IMAP?  Would it work on the server, or
does it have to be local?  If it can work on the server, then perhaps I
should distinguish that -- I can imagine an IMAP user might not want to
download large PDF-containing messages while performing this limit.

I'll remove the =M lines for now.

> > diff --git a/pattern.c b/pattern.c
> > +static int match_content_type(const pattern_t* pat, BODY *b)
> > +{
> > +  char buffer[STRING];
> > +  if (b == 0)
> > +    return 0;
>
> We more commonly compare to NULL or just !b in the mutt source code.

Fixed.

> > +  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;
>
> I don't believe subtype should be NULL.  Is the check necessary?

Looks like mutt_parse_content_type() always sets subtype to
a non-NULL value.  Check has been dropped (and it was
in the wrong place anyway, since by this point it's baked
into buffer).

Updated patch attached.

A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-M-pattern-to-match-mime-Content-Types.patch
Type: text/x-patch
Size: 3877 bytes
Desc: not available
URL: <http://lists.mutt.org/pipermail/mutt-dev/attachments/20180426/d6378f50/attachment.bin>


More information about the Mutt-dev mailing list