|MiNi0n|
February 6th, 2003, 18:06
K,
At elmore's request I'm adding in a quick how-to on how to add spamassasin and vipul's razor to postfix. This will also include a few simple kluges to allow the mail admin to approve caught messages for delivery via mutt.
Requirements:
Existing postfix install. See this post for more (http://screamingelectron.org/phpBB2/viewtopic.php?t=3)
spamassasin
vipul's razor
procmail
mutt
Let it be known that this particular how-to pertains to a Maildir style delivery. At the end I will note the few minor changes required for mbox style.
First things first, make sure you have all the requirments setup and working. Do some tests of razor and spamassassin to create the necessary files etc. As the setup of these is somewhat different than the "normal" setup because razor and spamass will be operating on a site-wide basis as opposed to a per user. It's best to config these to run as a particular user (ie postifx, or nobody)... for sake of simplicity I'm using root in this example... let it be noted I don't really recommend it :twisted:
Next, add the following line to postfix's main.cf:
mailbox_command = /usr/local/bin/procmail -m /etc/procmailrc
Easy. Now, you need to create /etc/procmailrc with the following:
--- /etc/procmailrc ---
# tell procmail we use Maildir style
DEFAULT="$HOME/Maildir/"
# specify the location for identified spam
SPAM="/var/mail/spam"
# various debugging stuff uncomment if needed
# VERBOSE=no
# LOGFILE=/var/log/procmailrc
# LOGABSTRACT=no
# Allow previously identified spam to be delivered since it
# must have been approved to get back here with the
# X-Spam-Deferred: YES flag set
:0 w
* ^X-Spam-Deferred: YES
$DEFAULT
# SPAM time
# first send to razor
:0 Wc
|/bin/nice usr/bin/razor-check -home=/root -logfile=/var/log/razor-agent.log
# if previous procmail recipe successfully completed then
# message is spam. prepare for quarantine. use formail to
# rip Delivered-To out (else you'll get loop errors) and tag
# with identifying headers
:0 Waf
| formail -I "Delivered-To:" -A "X-Razor2-Warning: SPAM" -A "X-Spam-Deferred: YES"
# drop razor identified spam into $SPAM (see above)
:0:
* ^X-Razor2-Warning: SPAM
$SPAM
# got this far, time to hand it off to spamassassin
:0fw
| /usr/bin/spamc
# Redirect definitive spam add identifying tags and rip
# postfix Delivered-To headers
:0 f
* ^X-Spam-Flag: YES
| formail -I "Delivered-To:" -A "X-Spam-Deferred: YES"
# quarantine it
:0:
* ^X-Spam-Flag: YES
$SPAM
--- end /etc/procmailrc ---
A quick note on the X-Spam-Deferred: YES flag. We need to add this as mail gets identified so that if we later determine that we want to actually approve that message on to deliver to the intended recipient we can sneak it back through procmail without getting tossed back into the spam trap.
Ok, almost done! The next thing is to add a means to easily examine the messages in the the spam trap. For this we rely on the mighty mutt! We want to add one simple line to Muttrc (usually /etc/mutt/Muttrc):
# Approve message identified as spam and deliver it
macro index A "| /usr/sbin/sendmail"
Now we can just use mutt to view /var/mail/spam:
mutt -f /var/mail/spam
You can now browse through identified and quarantined spam looking for incorrectly identified spam etc. If you find a message you want to approve, from the index screen just hit Shift A. This will prompt you asking if you want to pipe to /usr/sbin/sendmail, hit enter to do it and the message will get delivered, bypassing further spam detection. Don't forget to delete the message!!! You can, if you so desire, tack some additional commands on the macro added to mutt to delete the message after approval.
NOTE: If you use mbox style delivery as opposed to Maildir, simply remove the top line of the procmailrc that tells procmail to deliver Maildir style.
There you have it. Fu Q spammers :twisted:
At elmore's request I'm adding in a quick how-to on how to add spamassasin and vipul's razor to postfix. This will also include a few simple kluges to allow the mail admin to approve caught messages for delivery via mutt.
Requirements:
Existing postfix install. See this post for more (http://screamingelectron.org/phpBB2/viewtopic.php?t=3)
spamassasin
vipul's razor
procmail
mutt
Let it be known that this particular how-to pertains to a Maildir style delivery. At the end I will note the few minor changes required for mbox style.
First things first, make sure you have all the requirments setup and working. Do some tests of razor and spamassassin to create the necessary files etc. As the setup of these is somewhat different than the "normal" setup because razor and spamass will be operating on a site-wide basis as opposed to a per user. It's best to config these to run as a particular user (ie postifx, or nobody)... for sake of simplicity I'm using root in this example... let it be noted I don't really recommend it :twisted:
Next, add the following line to postfix's main.cf:
mailbox_command = /usr/local/bin/procmail -m /etc/procmailrc
Easy. Now, you need to create /etc/procmailrc with the following:
--- /etc/procmailrc ---
# tell procmail we use Maildir style
DEFAULT="$HOME/Maildir/"
# specify the location for identified spam
SPAM="/var/mail/spam"
# various debugging stuff uncomment if needed
# VERBOSE=no
# LOGFILE=/var/log/procmailrc
# LOGABSTRACT=no
# Allow previously identified spam to be delivered since it
# must have been approved to get back here with the
# X-Spam-Deferred: YES flag set
:0 w
* ^X-Spam-Deferred: YES
$DEFAULT
# SPAM time
# first send to razor
:0 Wc
|/bin/nice usr/bin/razor-check -home=/root -logfile=/var/log/razor-agent.log
# if previous procmail recipe successfully completed then
# message is spam. prepare for quarantine. use formail to
# rip Delivered-To out (else you'll get loop errors) and tag
# with identifying headers
:0 Waf
| formail -I "Delivered-To:" -A "X-Razor2-Warning: SPAM" -A "X-Spam-Deferred: YES"
# drop razor identified spam into $SPAM (see above)
:0:
* ^X-Razor2-Warning: SPAM
$SPAM
# got this far, time to hand it off to spamassassin
:0fw
| /usr/bin/spamc
# Redirect definitive spam add identifying tags and rip
# postfix Delivered-To headers
:0 f
* ^X-Spam-Flag: YES
| formail -I "Delivered-To:" -A "X-Spam-Deferred: YES"
# quarantine it
:0:
* ^X-Spam-Flag: YES
$SPAM
--- end /etc/procmailrc ---
A quick note on the X-Spam-Deferred: YES flag. We need to add this as mail gets identified so that if we later determine that we want to actually approve that message on to deliver to the intended recipient we can sneak it back through procmail without getting tossed back into the spam trap.
Ok, almost done! The next thing is to add a means to easily examine the messages in the the spam trap. For this we rely on the mighty mutt! We want to add one simple line to Muttrc (usually /etc/mutt/Muttrc):
# Approve message identified as spam and deliver it
macro index A "| /usr/sbin/sendmail"
Now we can just use mutt to view /var/mail/spam:
mutt -f /var/mail/spam
You can now browse through identified and quarantined spam looking for incorrectly identified spam etc. If you find a message you want to approve, from the index screen just hit Shift A. This will prompt you asking if you want to pipe to /usr/sbin/sendmail, hit enter to do it and the message will get delivered, bypassing further spam detection. Don't forget to delete the message!!! You can, if you so desire, tack some additional commands on the macro added to mutt to delete the message after approval.
NOTE: If you use mbox style delivery as opposed to Maildir, simply remove the top line of the procmailrc that tells procmail to deliver Maildir style.
There you have it. Fu Q spammers :twisted: