procmail
[Top] [All Lists]

Re: would this work in a recipe?

2002-05-02 10:53:37
On Thu, 2 May 2002, Pantelis Hadzipantelis wrote:

I want all incoming/outgoing emails with attachments other than *.doc
and *.xls to be deleted. Now... I tried something in procmail which is
the following:

:0 B
* ^Content-Disposition:.*
* !*.doc.*
* !*.xls.*
* !^FROM_DAEMON
* !^X-Loop: attach

I'm not sure what procmail is doing with !*.doc.* and !*.xls.* -- you
can't have a * without something before it for it to repeat.  So it might
be that those are ignored as invalid, or it might be that they're taken as
"zero or more exclamation points".  You want !.*\.doc and !.*\.xls there.
The trailing .* is useless and unnecessary in nearly all cases.

Regardless, condition lines are always ANDed, so even if you had the
syntax right, this means "Content-Disposition: AND NOT .doc AND NOT .xls
AND ..."

There are two ways to get an OR in procmail:  Use a pattern that has the
cases separated by vertical bars, e.g. \.(doc|xls), or use scoring as
described in "man procmailsc".

There are two ways to negate a condition in procmail:  A leading bang on
the condition line, or use scoring.  There's no way to negate just part of
a pattern.

In this particular case you want to know whether ALL Content-Disposition
lines contain .doc or .xls -- a regex pattern can only tell you whether
ANY of them do, or (with the leading bang) whether ANY of them do not.  
So you must use scoring:  Add one for every Content-Disposition line,
and deduct one for every .doc or .xls in such a line, and if the score
is positive the recipe matches.

:0 B
*  1^1 ^Content-Disposition:
* -1^1 ^Content-Disposition:.*\.(doc|xls)
{
 LOG="This message contains more Content-Disposition: lines
than it does Content-Disposition: lines having .doc or .xls
and therefore has at least one unwanted attachment.
"
}

Aside:  Rembember that there might be a file name in the Content-Type:  
parameters as well, or that the name might be absent even on an unwanted
type.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>