bash script to rewrite spam method
This is a simple method to integrate SpamAssassin. All spam e-mail will still come through to your address(es), but it will be clearly marked as spam.
1) Create a bash script to receive e-mail from Postfix and pipe it to SpamAssassin for rewriting. Then forward the rewritten version to Postfix's sendmail implementation:
{{{#!highlight bash
#!/bin/bash
#
# spamfilter.sh
#
# Simple filter to plug SpamAssassin into the Postfix MTA
#
# Modified by Jeremy Morton
#
# This script should probably live at /usr/bin/spamfilter.sh
# ... and have 'chown root:root' and 'chmod 755' applied to it.
#
# For use with:
# Postfix 20010228 or later
# SpamAssassin 2.42 or later
# Note: Modify the file locations to suit your particular
# server and installation of SpamAssassin.
# File locations:
# (CHANGE AS REQUIRED TO SUIT YOUR SERVER) SENDMAIL=/usr/sbin/sendmail SPAMASSASSIN=/usr/bin/spamc
logger <<<"Spam filter piping to SpamAssassin, then to: $SENDMAIL $@"
${SPAMASSASSIN} | ${SENDMAIL} "$@"
exit $?
}}}
This, of course, assumes you're using the spamd/spamc implementation of SpamAssassin
to improve performance - spamc is the command you'll want to invoke to
check an e-mail (by setting SPAMASSASSIN to its location).
2) Ensure the newly-created /usr/bin/spamfilter.sh has correct permissions (0755), and is owned by root:root.
3) Modify the /etc/postfix/master.cf file; first, change the first 'smtp' line of the file to:
smtp inet n - - - - smtpd -o content_filter=spamfilter
Then, add the following (a call to our newly-created spamfilter script) at the end:
spamfilter unix - n n - - pipe flags=Rq user=spamd argv=/usr/bin/spamfilter.sh -oi -f ${sender} ${recipient}
This setup assumes you have a 'spamd' user for the script to be run as. If you wish to run it as a different user, modify the 'user' argument above.
4) Restart the Postfix service.
Now, Postfix should be sending every incoming e-mail through the spamfilter.sh script (which means it's going through SpamAssassin), with the e-mail headers (and maybe the rest of the e-mail, if it's spam) being rewritten before being delivered to the target mailbox. Optionally, you may wish to tweak SpamAssassin's configuration to cause it to rewrite the e-mails in a more useful way (only rewrite spam mail subject but not whole e-mail, add a 'ham' header to give detailed info on even non-spam, etc.)
5) (optional) Tweak SpamAssasin's configuration. Ensure that the below is in /etc/mail/spamassassin/local.cf and then restart SpamAssassin:
# Rewrite the subject of suspected spam e-mails #rewrite_header Subject *****SPAM***** rewrite_header Subject *****SPAM***** (_SCORE_) # Just add an X-Spam-Report header to suspected spam, rather than rewriting the content of the e-mail report_safe 0 # Also we want to add a detailed ham report header to even e-mail that ISN'T suspected to be spam add_header ham HAM-Report _REPORT_ # Set the threshold at which a message is considered spam (3 is usually sufficient) required_score 3.0
Source
Niciun comentariu:
Trimiteți un comentariu