[Mailman-Users] Rejecting emails with certain types of attachments

Mark Sapiro mark at msapiro.net
Tue Mar 1 14:23:00 EST 2016


On 02/29/2016 03:53 PM, Titus von der Malsburg wrote:
> 
> is it possible to automatically reject emails that have attachments with
> certain MIME types (e.g., application/msword, …)?
> 
> Since there are so many types of files that are unsafe, I also wonder
> whether it is possible to specify a white list of safe MIME types (e.g.,
> application/PDF) and to reject everything else.  Is that possible?
> 
> I did some searching but only found solutions for automatically
> stripping attachments, which is not what I want.


You can remove such attachments either by "blacklisting" bad MIME types
(Content filtering -> filter_mime_types) or "whitelisting" good ones
(Content filtering -> pass_mime_types), but you say you don't want that,
and you want to reject (or discard might be better) the mail outright.

You might consider your MTA's features for this, e.g., Postfix's
mime_header_checks. Then the MTA can reject the mail at incoming SMTP
which is a better solution.If your requirements are more complex you
might still use a milter (or some coding in exim).

In Mailman, your only option is Privacy options... -> Spam filters ->
header_filter_rules (see the 'details' for this in the admin web UI.

For example, a rule with a regexp like

^Content-Type:.*application/(?!pdf)

and an action of Discard should discard any message with a MIME part of
mail type application and sub part not starting with 'pdf'. See
<https://docs.python.org/2/library/re.html#regular-expression-syntax>.

If you try this, I suggest initially setting your rule actions to hold
until you are confident that your rules do what you want.

-- 
Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/mailman-users/attachments/20160301/a2c1a945/attachment.sig>


More information about the Mailman-Users mailing list