|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:

soup4you2
February 6th, 2003, 20:23
Verry nice.....

another good thing to use w/ your mailserver is amavis which is a virus scanner for mac / windows and nix viruses.. pretty simple to setup..

elmore
June 24th, 2003, 16:24
Any Chance we're gonna see that updated how-to this century? Just curious ;)

soup4you2
June 24th, 2003, 16:34
Actually since you bring it up i've been working on a improved howto that covers your postfix howto spamassasin, procmail imap imaps, amavis-new, and SASL authentication, TLS, LDAP

just got to give me a little more time to fully understand LDAP and POSIX and a few other things.... but if somebody else want to it's all them

elmore
June 24th, 2003, 16:41
awesome soup!

|MiNi0n|
June 25th, 2003, 02:13
Any Chance we're gonna see that updated how-to this century? Just curious ;)

Dig :shock:

I'll get to it elmore... I am on a vacation of sorts right now... albeit a rather permanent one if I don't find a new gig soon :evil:

I haven't sat at the trusty keyboard for any longer than 10 minutes for close to the last month now. I'm getting rusty and antiquated.

Anyone in need to hire a Guru? Have keyboard, will travel.

soup4you2
June 25th, 2003, 09:20
Anyone in need to hire a Guru? Have keyboard, will travel.

Can i pay you in beer?

|MiNi0n|
June 25th, 2003, 11:54
Always :D

soup4you2
June 27th, 2003, 11:49
oh ya just 1 observation..

should

SPAM="/var/mail/spam"

not be

SPAM="/var/mail/spam/new"

if your using /Maildir's

so you could use mutt -f /var/mail/spam

tarballed
September 18th, 2003, 23:08
Just of curiosity, I was playing with this at my computer at home.

With this particular setup, you are running spamassassin in daemon mode correct?

Everything is passed off to spamassassin and then back to procmail for filtering correct?

What I was trying to do was modify this.
I want to set something up like this very similar, but set it up on a mail gateway. Thus, everything would then be relayed to my internal mail server once completed...For instance, have everything checked on the gateway and then forwarded correctly. If something is spam, i'd like it forwarded to a spam account so I can view it with an account, like spam (using mutt of course)

Just something i'd like to work with.

I'm playing with it (new to procmail) so I have some tweaking to do.

Tarballed