date: 2007-04-26 08:38:02+00:00

Postfix + SpamAssassin + ClamAV with procmail without amavisd-new

categories: - Howto - Linux - Postfix - Security

I used to use Amavisd-new on our email gateway at work. It sucks. It was a memory hog and was consuming around 400 Mb of swap. It was making it difficult to upgrade clamav, something would break anytime you upgraded. I had a very basic use of amavis, I needed to get rid of it and find a better setup.

Basically, I just wanted to pipe the mails into ClamAV then if no viruses were found, pipe them in SpamAssassin, ideally doing all that from procmail.

And then someone came up with "clamassassin" :

(available in the unstable Debian repository)

clamassassin is a simple virus filter wrapper for ClamAV for use in procmail filters and similiar applications. clamassassin's interface is similiar to that of spamassassin, making it easy to implement for those familiar with that tool. clamassassin is designed with an emphasis on security, robustness and simplicity.

Compile clamassassin as described in the docs.

This is my procmail filter (/etc/postfix/procmail/master.rc) :



# Virus checks
| /etc/postfix/clamassassin/clamassassin

# Virus found --> Sent to catchvirus
* ^X-Virus-Status: Yes

# No virus found --> SpamAssassin checks
|$SPAMC -u spamd -f -s 125000 -U /var/run/spamd.sock

# Spam score 10+ --> email destroyed
* ^X-Spam-Level: **********

# Spam score 8-10 --> Sent to catchspam with priority low
* ^X-Spam-Level: ********

# Spam score 6-8 --> Sent to catchspam with priority normal
* ^X-Spam-Level: ******

# Spam score 0-6 --> Delivered tagged if spam score 3+
! -f $FROM "$@"</code>

If a virus is found, it is sent to a special mailbox, or the mail continues its way in the procmail filter. Depending on the spam score, the procmail script is switching to another procmail script. Those scripts can be downloaded from this post : Postfix + virtual users/domains : kill or forward spam under SpamAssassin using procmail

I call the procmail script in Postfix by the following placed in master.rc :

<code>procmail                unix    -       n       n       -       10      pipe
        flags=Rq user=filter argv=/usr/bin/procmail -Y -m /etc/postfix/procmail/master.rc ${sender} ${recipient}      inet    n       -       y       -       10      smtpd
        -o content_filter=procmail
        -o smtpd_sasl_auth_enable=no
        -o smtpd_helo_restrictions=permit_mynetworks,reject_non_fqdn_hostname
        -o smtpd_client_connection_count_limit=5
        -o smtpd_client_connection_rate_limit=5</code>

If you want to rewrite subjects, this is an interesting article :

Thanks to for their howto about clamassassin :

This is the swap space state, can you guess when I stopped using amavis and switched to clamassassin ?

[Image Hosted by