Skip to main content

procmail

Here's a little recipe I normally use to put the usual crap attachments into it's own folder:

# Testing zone
# here's a recipe, all credits go to Philip Guenther, I've just added
# extensions I need to filter to his regexp.
# The regexp for matching whitespace in the embedded header field
# of a multipart message.  We have to handle wrapped lines.
ws = '[     ]*($[   ]+)*'
# The regexp for matching 'anything' inside an embedded header
# field of a multipart message.  That is, it matches anything
# except the newline (not followed by a whitespace character)
# that terminates the header field.
dotstar = '.*($[    ].*)*'
# A single double-quote.  For use in variable expanded regexps to
# avoid problems related to how procmail implements the variable
# expansion
dq = '"'
# Any condition that uses any of these variables in a its regexp
# must have the '$' special before the regexp to tell procmail to
# do variable expansion on the regexp.
# That matches if there exists a embedded Content-whatever header field
# whose value, ignoring legal whitespace, matches the regexp
#   .*name="filename"
ext = '.(scr|vbs|shs|bat|com|exe|pif|pps|avi|mpg|mpeg|doc)'
SUBJ_=`formail -xSubject:
| expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
# Here i put the mails with [BAD Attachment] in their folder since
# otherwise we'd have a massive loop
#:0
#* ^Subject:*BAD Attachment*
#silly-attachments
:0 B
* $ ^Content-(Type|Disposition)*:${dotstar}name${ws}=${ws}${dq}.*${ext}${dq}
{
:0 fwh
| formail -I"Subject: [BAD Attachment] ${SUBJ_}"
:0:
silly-attachments
}