嗯,有几种方法,但这是我发现的工作。在你安装好 postfix、dovecot、spamassassin 和(我推荐 procmail)之后,你可以告诉 procmail/spamassassin 如何将垃圾邮件分发到不同的文件夹中。带鸽舍。我使用以下 4 个文件夹:
spam (for known spam based on Bayes setting)
spam-learn (for spam that slipped through, you move it here)
spam-probably (for spam ID'd as probably spam by Bayes setting)
spam-unlearn (messages flagged as spam, that are NOT spam go here)
将文件夹 setup 和 postfix 配置为通过 procmail 过滤邮件:
mailbox_command = /usr/bin/procmail -a "$EXTENSION"
您现在可以设置您的 procmailrc 以将垃圾邮件放在收件箱中的正确位置。你的 ~/.procmailrc 应该是这样的:
PATH=/usr/bin/vendor_perl:/usr/bin:/bin:/usr/local/bin:.
MAILDIR=$HOME/Mail/
LOGDIR=$HOME/log
#DEFAULT=$HOME/Mail/
LOGFILE=$LOGDIR/procmail.log
VERBOSE=ON
## with spamc
:0fw: spamc.lock
* < 256000
| spamc
#| /usr/bin/vendor_perl/spamc
# Mails with a score of 15 or higher are almost certainly spam (with 0.05%
# false positives according to rules/STATISTICS.txt). Let's put them in a
# different mbox. (This one is optional.)
:0:
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
spam
#Mail/spam
# All mail tagged as spam (eg. with a score higher than the set threshold)
# is moved to "probably-spam".
:0:
* ^X-Spam-Status: Yes
spam-probably
#Mail/spam-probably
# Work around procmail bug: any output on stderr will cause the "F" in "From"
# to be dropped. This will re-add it.
:0
* ^^rom[ ]
{
LOG="*** Dropped F off From_ header! Fixing up. "
:0 fhw
| sed -e '1s/^/F/'
}
现在,使其全部自动运行的最后一个关键是使用fetchmail
扫描邮件,当它们到达您的收件箱时,将它们移交给 procmail,以将垃圾邮件/垃圾邮件可能放在正确的文件夹中,并阅读垃圾邮件中的邮件(删除)和spam-unlearn(学习为ham
)。一个典型的 fetchmail 脚本是你的 ~/.fetchmailrc。它只包含轮询邮箱的命令:
poll mail.yourserver.com protocol IMAP : user yourname with password yourpass ssl \
sslfingerprint "D9:73:1A:FE:C6:7C:E7:9B:F1:31:F8:A1:A0:E1:F9:27"
(您可以通过简单fetchmail --verbose
地对 .fetchmailrc 文件运行来获取服务器指纹,它将打印服务器指纹,检查您当前的指纹,告诉您它们不匹配并关闭连接 - 但是 - 您刚刚获得了正确的指纹下次:-)
最后,通过阅读 spam-learn 和 spam-unlearn 文件夹来设置几个 cron 作业来运行整个过程。每小时就够了。该脚本可能如下所示:
#!/bin/bash
## log file location and per-user name
LDIR=/home/admin/log
LFN="${LDIR}/${USER}.log"
## Retrieve and Process Spam & Ham from 'spam-learn' & 'spam-unlearn' folders
/usr/bin/fetchmail -a -s -n --folder spam-learn -m '/usr/bin/vendor_perl/sa-learn --spam' &>/dev/null
mss=$?
sleep 2
/usr/bin/fetchmail -a -s -n --folder spam-unlearn -m '/usr/bin/vendor_perl/sa-learn --ham' &>/dev/null
mhs=$?
## test and create log dir in noexist
[[ -d "$LDIR" ]] || mkdir -p "$LDIR"
if [[ -w "$LDIR" ]]; then
## check return from fetchmail and write log info
if [[ $(($mhs+$mss)) -le 2 ]]; then
echo "$(date +'%b %e %R:%S') $HOSTNAME ${0##*/}: sa-learn completed successfully for user $USER" >>$LFN
else
echo "$(date +'%b %e %R:%S') $HOSTNAME ${0##*/}: sa-learn FAILED for user $USER" >>$LFN
fi
fi
而 cron 作业只需执行上面的 spamv.sh 文件:
05 * * * * /usr/local/bin/spamv.sh
我已经运行这样的服务器近十年了,它运行良好。培训文件位于用户的主目录中,可以轻松地逐个移动,为新用户提供良好的基础集。祝你好运。几年前,我为openSuSE 11.0做了一个简短的操作指南。那里可能还有更多信息。
PS Rayzor 值得加载。