spamassassin - Build From Source

最後更新: 2019-04-02

 


Install

 

yum install re2c -y

wget http://apache.01link.hk//spamassassin/source/Mail-SpamAssassin-3.4.2.tar.gz

tar -zxf Mail-SpamAssassin-3.4.2.tar.gz

cd Mail-SpamAssassin-3.4.2-*

perl Makefile.PL

.....

dependency check complete...

optional module missing: IO::Socket::IP
optional module out of date: IO::Socket::SSL
optional module missing: Net::Patricia
optional module missing: Net::DNS::Nameserver
optional module missing: BSD::Resource
optional binary missing or nonfunctional: fetch

warning: some functionality may not be available,
please read the above report before continuing!

Writing Makefile for Mail::SpamAssassin
Makefile written by ExtUtils::MakeMaker 6.5502

make

make install

/usr/local/bin/sa-update -v

Update finished, no fresh updates were available

useradd -s /sbin/nologin spamd

/etc/mail/spamassassin/local.cf

rewrite_header Subject ***SPAM*** (_SCORE_)
required_score 8
report_safe 0
use_bayes 1
bayes_auto_learn 1

# MX Server IP
trusted_networks n.n.n.n

report_safe

0    Show the SPAM rules in the email header and leave the message body intact.

1 Add the following attachments:

A document that details the spam rule offense.
The suspected spam email.

2 Cause the body of the email to include the spam rule offense text, and add the following attachments:

A document that details the spam rule offense.
The suspected spam email.

/root/scripts/start_spamd.sh

#!/bin/bash

USR=spamd
SPAMDOPTIONS="-d -c -m5 -H"
SPAMD_PID=/var/run/spamd.pid

# stop
killall spamd && sleep 3
# start
/usr/local/bin/spamd  -u $USR $SPAMDOPTIONS -r $SPAMD_PID

-d, --daemonize                          # Daemonize

-c, --create-prefs                        # Create user preferences files

-m num, --max-children=num     # Allow maximum num children

-r pidfile, --pidfile

-H [dir], --helper-home-dir[=dir] Specify a different HOME directory

Specify that external programs such as Razor, DCC, and Pyzor
should have a HOME environment variable set to a specific directory.  

The default is to use the HOME environment variable setting from the shell running spamd.  
By specifying no argument, spamd will use the spamc caller’s home directory instead.

-u username, --username=username  Run as username

Checking

netstat -ntl | grep :783

tcp        0      0 ::1:783                     :::*                        LISTEN

/usr/local/bin/spamc -K

SPAMD/1.5 0

 


Integrating SpamAssassin with Postfix

 

pipe incoming e-mail through a script or program that passes the e-mail to SpamAssassin for rewriting,

and then either chooses to send it on or discard it

/etc/postfix/master.cf

smtp     inet  n     -    -    -    -     smtpd -o content_filter=spamassassin

spamassassin unix - n n - - pipe
  flags=Rq user=spamd argv=/usr/local/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

postfix

R      Prepend a Return-Path: message header

q      Quote whitespace and other special characters in the command-line $sender,

        $original_recipient  and $recipient address localparts

spamc

-e, --pipe-to command

-f                                      # Now default, ignored

sendmail

-oi    When reading a message from standard input, don´t treat a line with only a . character as the end of input.

service postfix restart

log

Feb  4 15:10:04 mail spamd[5108]: spamd: connection from ::1 [::1]:45222 to port 783, fd 5
Feb  4 15:10:04 mail spamd[5108]: spamd: creating default_prefs: /usr/local/spamassassin/.spamassassin/user_prefs
Feb  4 15:10:04 mail spamd[5108]: config: created user preferences file: /usr/local/spamassassin/.spamassassin/user_prefs
Feb  4 15:10:04 mail spamd[5108]: spamd: processing message <443960c5-e651-37c8-9532-9f5d2511f9f2@SENDER> for spamd:2013
Feb  4 15:10:07 mail spamd[5108]: spamd: clean message (3.6/6.0) for spamd:2013 in 3.1 seconds, 1621 bytes.
Feb  4 15:10:07 mail spamd[5108]: spamd: result: . 3 - 
 HTML_FONT_FACE_BAD,HTML_MESSAGE,MIME_HTML_ONLY,RDNS_NONE,SPF_FAIL 
 scantime=3.1,size=1621,user=spamd,uid=2013,required_score=6.0,rhost=::1,raddr=::1,rport=45222,
 mid=<443960c5-e651-37c8-9532-9f5d2511f9f2@SENDER>,autolearn=no autolearn_force=no

 


sa-check_spamd

 

monitoring script for use with Nagios

monitor the status of "spamd" server processes.

-H hostname

-p port

/usr/local/bin/sa-check_spamd

SPAMD OK: 0.016 second ping repsonse time

 


More Configure

 

v320.pre

loadplugin Mail::SpamAssassin::Plugin::Shortcircuit
loadplugin Mail::SpamAssassin::Plugin::Rule2XSBody

v342.pre

loadplugin Mail::SpamAssassin::Plugin::HashBL
loadplugin Mail::SpamAssassin::Plugin::FromNameSpoof
loadplugin Mail::SpamAssassin::Plugin::Phishing

 

 


Discarding

 

/etc/postfix/master.cf

spamfilter unix - n n - - pipe
    flags=Rq user=spamd argv=/usr/bin/spamfilter.sh -oi -f ${sender} ${recipient}

/usr/bin/spamfilter.sh

#!/bin/bash

THRESHOLD_OFFSET=4.0
MAX_MESSAGE_SIZE=10485760

SENDMAIL=/usr/sbin/sendmail
SPAMASSASSIN=/usr/bin/spamc


logger -s -p mail.notice -t spamfilter <<<"Piping to SpamAssassin"
CAUGHT_OUTPUT=`${SPAMASSASSIN} -4 -x -E -s $MAX_MESSAGE_SIZE -T $THRESHOLD_OFFSET`
SPAMASSASSIN_EXITCODE=$?

if [ "$SPAMASSASSIN_EXITCODE" -gt 1 ]; then
    logger -s -p mail.warning -t spamfilter <<<"Error code $SPAMASSASSIN_EXITCODE processing spam!"
    exit $SPAMASSASSIN_EXITCODE
elif [ "$SPAMASSASSIN_EXITCODE" -eq 1 ]; then
    logger -s -p mail.notice -t spamfilter <<<"SpamAssassin says message is likely spam; discarding."
    exit 0
fi

logger -s -p mail.notice -t spamfilter <<<"OK. Piping to sendmail: $@"
${SENDMAIL} "$@" <<<"$CAUGHT_OUTPUT"
exit $?