Postfix: How to make complex attachment filtering

postfixspam-filter

I have Postfix on our server.
I need to filter attachments in incoming mail not only by it type, but also check what inside of it. Exactly by now I need to filter attachment that:

  • is a .zip archive
  • contains .exe inside archive
  • is about 10-20k of size

Is it possible to pass attachment to external script? (Actually I'm able to write script that analyze the above conditions) Is it possible using Postfix only or do I need some external tool like spammassasin or Amavis?

Best Answer

Is it possible to pass attachment to external script? (Actually I'm able to write script that analyze the above conditions)

If you have some capabilities to creating a script to checks such conditions, then you may interested in this page: Postfix simple content filter. With this feature, your script will read email content via stdin. You can also pass some variable like sender, recipient, etc.

Of course the script needs to extract the attachment as postfix doesn't have capabilities to extract it. Another downside is you can't filter email submitted by mail command, such as email generated by PHP script in your server.

If this feature doesn't meet your needs, then you may look into advanced content filter section.

Related Topic