well you can install Spamassassin via ipkg.
ipkg list | grep -i spamassassin
spamassassin - 3.1.8-1 - a spam filter for email which can be invoked from mail delivery agents
ipkg install spamassassin
it will install Spamassassin and modules dependent (perl 5.8.8 etc ...)
Then you have to configure SA :
it is done by editing local.cf in /opt/etc/spamassassin.
Here is my local.cf file :
- Code: Select all
# This is the right place to customize your installation of SpamAssassin.
#
# See 'perldoc Mail::SpamAssassin::Conf' for details of what can be
# tweaked.
#
# Only a small subset of options are listed below
#
###########################################################################
# Add *****SPAM***** to the Subject header of spam e-mails
#
rewrite_header Subject *****SPAM*****
# Save spam messages as a message/rfc822 MIME attachment instead of
# modifying the original message (0: off, 2: use text/plain instead)
#
report_safe 1
# Set which networks or hosts are considered 'trusted' by your mail
# server (i.e. not spammers)
#
# trusted_networks 212.17.35.
# Set file-locking method (flock is not safe over NFS, but is faster)
#
# lock_method flock
# Set the threshold at which a message is considered spam (default: 5.0)
#
required_score 5.0
# Use Bayesian classifier (default: 1)
#
use_bayes 1
use_bayes_rules 1
# Bayesian classifier auto-learning (default: 1)
#
bayes_auto_learn 1
# Set headers which may provide inappropriate cues to the Bayesian
# classifier
#
# bayes_ignore_header X-Bogosity
# bayes_ignore_header X-Spam-Flag
# bayes_ignore_header X-Spam-Status
skip_rbl_checks 0
ok_locales fr --- sorry i'm french :-)
Then you have to create a user (for me it is spamfilter).
after that you have to create a script (for me named spamfilter.sh) which is responsible to transfer to the user dedicated for spam.
Script can be found in spamassassin Wiki and is adapted to Synology.
mktemp package should be installed via ipkg.
- Code: Select all
#!/bin/sh
SENDMAIL="/usr/syno/mailstation/sbin/sendmail -i"
SPAMASSASSIN=/opt/bin/spamc
COMMAND="$SENDMAIL $@"
USER=`echo $COMMAND |awk '{print $NF}' | sed 's/@.*$//'`
NEW_COMMAND=`echo $COMMAND |awk '{ $6="spamfilter";NF=6; print }'`
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
umask 077
OUTPUT="`/opt/bin/mktemp /tmp/mailfilter.XXXXXXXXXX`"
if [ "$?" != 0 ]; then
/usr/bin/logger -s -p mail.warning -t filter "Unable to create temporary file."
exit $EX_TEMPFAIL
fi
# Clean up when done or when aborting.
trap "rm -f $OUTPUT" EXIT TERM
$SPAMASSASSIN -x -E -u $USER > $OUTPUT
return="$?"
if [ "$return" = 1 ]; then
$NEW_COMMAND < $OUTPUT
exit $?
elif [ "$return" != 0 ]; then
/usr/bin/logger -s -p mail.warning -t filter "Temporary SpamAssassin failure (spamc returned $return)"
exit $EX_TEMPFAIL
fi
$SENDMAIL "$@" < $OUTPUT
exit $?
This script is only replacing recipient with spamfilter user.
Change the right to spamfilter:spamfilter for script
chown spamfilter:spamfilter spamfilter.sh
chmod 744 spamfilter.sh
Then you have to modify master.cf in /usr/syno/mailstation/etc
replace
smtp inet n - n - - smtpd
by
smtp inet n - n - - smtpd -o content_filter=spamassassin
and add
spamassassin unix - n n - - pipe flags=Rq user=spamfilter argv=/opt/bin/spamfilter.sh -oi -f ${sender} ${recipient}
Well config for SA is ready.
Now you have to start Spamassassin, i do it with a script :
- Code: Select all
echo "Starting spamd"
/opt/bin/spamd -d -c -m 1 --max-conn-per-child=100 --pidfile=/var/run/spamd.pid -p 783 -u spamfilter
It means that spamd is running as daemon, is creating user_preferences and is running as spamfilter.
For every users, you have to change owner and group of .spamassassin directory.
you should find this directory under /volume1/homes/xxx/.spamassassin
chown -R spamfilter:spamfilter .spamassassin
Don't forget to create Bayes DB with sa-learn.
Reload Postfix :
/usr/syno/mailstation/sbin/postfix reload
If all is working, you should see in the /var/log/messages file, entries like this :
for "non-spam" :
postfix/smtpd[14547]: connect from unknown[78.101.197.82]
postfix/smtpd[14547]: 113E8528A23: client=unknown[78.101.197.82]
postfix/cleanup[14551]: 113E8528A23: message-id=<B72BA7E3.FBE04FD2@chocofan.com>
postfix/qmgr[2221]: 113E8528A23: from=<wycirinlasq@chocofan.com>, size=2789, nrcpt=1 (queue active)
spamd[3967]: spamd: connection from localhost [127.0.0.1] at port 2022
spamd[3967]: spamd: setuid to xxx succeeded
spamd[3967]: spamd: processing message <B72BA7E3.FBE04FD2@chocofan.com> for xxx:1026
postfix/smtpd[14547]: disconnect from unknown[78.101.197.82]
spamd[3967]: spamd: clean message (0.0/5.0) for xxx:1026 in 1.1 seconds, 2729 bytes.
spamd[3967]: spamd: result: . 0 - HTML_MESSAGE,MIME_HTML_ONLY,NO_RECEIVED,NO_RELAYS scantime=1.1,size=2729,user=xxx,uid=1026,required_score=5.0,rhost=localhost,raddr=127.0.0.1,rport=2022,mid=<B72BA7E3.FBE04FD2@chocofan.com>,autolearn=ham
spamd[3966]: prefork: child states: I
postfix/pipe[14552]: 113E8528A23: to=<xxx@xxx.xx>, relay=spamassassin, delay=5.1, delays=3.5/0.08/0/1.5, dsn=2.0.0, status=sent (delivered via spamassassin service)
postfix/qmgr[2221]: 113E8528A23: removed
postfix/pickup[14521]: 38C5E528A2B: uid=1029 from=<wycirinlasq@chocofan.com>
postfix/cleanup[14551]: 38C5E528A2B: message-id=<B72BA7E3.FBE04FD2@chocofan.com>
postfix/qmgr[2221]: 38C5E528A2B: from=<wycirinlasq@chocofan.com>, size=2999, nrcpt=1 (queue active)
postfix/local[14569]: 38C5E528A2B: to=<xxx@xxx.xx>, relay=local, delay=0.12, delays=0.06/0.05/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)
postfix/qmgr[2221]: 38C5E528A2B: removed
for spam :
postfix/smtpd[14976]: connect from xxx[xxx.xxx.xxx.xxx]
postfix/smtpd[14976]: 7196A528A29: client=xxx[xxx.xxx.xxx.xxx]
postfix/cleanup[14981]: 7196A528A29: message-id=<11267629.296163.1239709365194.JavaMail.www@wwinf1d18>
postfix/qmgr[14972]: 7196A528A29: from=<xxx@xxx.xx>, size=1075, nrcpt=1 (queue active)
postfix/smtpd[14976]: disconnect from xxx[xxx.xxx.xxx.xxx]
spamd[14753]: spamd: connection from localhost [127.0.0.1] at port 4036
spamd[14753]: spamd: setuid to xxx succeeded
spamd[14753]: spamd: processing message <11267629.296163.1239709365194.JavaMail.www@wwinf1d18> for xxx:1026
spamd[14753]: spamd: identified spam (1002.7/5.0) for xxx:1026 in 0.7 seconds, 1089 bytes.
Apr 14 13:42:51 spamd[14753]: spamd: result: Y 1002 - AWL,GTUBE,HTML_10_20,HTML_MESSAGE,HTML_SHORT_LENGTH,MISSING_SUBJECT,NO_RECEIVED,NO_RELAYS scantime=0.7,size=1089,user=xxx,uid=1026,required_score=5.0,rhost=localhost,raddr=127.0.0.1,rport=4036,mid=<11267629.296163.1239709365194.JavaMail.www@wwinf1d18>,autolearn=no
spamd[14749]: prefork: child states: I
postfix/pickup[14971]: 92F07528A2C: uid=1029 from=<xxx@xxx.xx>
postfix/cleanup[14981]: 92F07528A2C: message-id=<11267629.296163.1239709365194.JavaMail.www@wwinf1d18>
postfix/qmgr[14972]: 92F07528A2C: from=<xxx@xxx.xx>, size=3679, nrcpt=1 (queue active)
postfix/pipe[14982]: 7196A528A29: to=<xxx@xxx.xx>, relay=spamassassin, delay=2.3, delays=1.2/0.04/0/1.1, dsn=2.0.0, status=sent (delivered via spamassassin service)
postfix/qmgr[14972]: 7196A528A29: removed
postfix/local[14997]: 92F07528A2C: to=<spamfilter@xxx.xx>, orig_to=<spamfilter>, relay=local, delay=0.25, delays=0.03/0.16/0/0.05, dsn=2.0.0, status=sent (delivered to maildir)
postfix/qmgr[14972]: 92F07528A2C: removed
With this solution, you can forward your spam in the spamfilter mailbox and train Spamassassin periodically
sa-learn --showdots --spam /volume1/homes/spamfilter/new
You should train Spamassassin too with mails that are not spam in each mailbox :
sa-learn --showdots --ham /volume1/homes/xxx/new
you can check the status of SA with spamassassin --lint -D
and check the status of Bayes DB with :
sa-learn --dump magic
Hope this helps
ciaoooooo






