SpamAssassin 是基於規則評分的郵件過濾器,檢查郵件標頭、內文、寄件者資訊,分數超過門檻即判定為垃圾郵件。
yum -y install spamassassin
編輯 /var/www/cgi-bin/openwebmail/etc/openwebmail.conf:
enable_spamcheck yes
enable_learnspam yes
learnspam_pipe /usr/bin/sa-learn --spam
learnham_pipe /usr/bin/sa-learn --ham
/etc/mail/spamassassin/local.cf# 判定門檻
required_hits 6.5
# 標記主旨
rewrite_subject 1
subject_tag [SPAM]
# 隔離垃圾郵件為附件
report_safe 1
use_terse_report 0
# 貝葉斯分類器
use_bayes 1
auto_learn 1
# 網路檢查(RBL、Razor2、DCC、Pyzor)
skip_rbl_checks 0
use_razor2 1
use_dcc 1
use_pyzor 1
# 語言/地區白名單(中英不視為外語垃圾郵件)
ok_languages zh en
ok_locales zh en
# 發件人白名單
whitelist_from *@example.com
# 針對中文環境調整分數(降低誤判)
score HEADER_8BITS 0
score HTML_COMMENT_8BITS 0
score SUBJ_FULL_OF_8BITS 0
score UPPERCASE_25_50 0
score UPPERCASE_50_75 0
score UPPERCASE_75_100 0
score BASE64_ENC_TEXT 0
score DATE_IN_PAST_03_06 0
score FROM_NAME_NO_SPACES 0
score X_MSMAIL_PRIORITY_HIGH 0
score X_PRIORITY_HIGH 0
# 自訂加分規則(提高特徵權重)
score SUBJ_ILLEGAL_CHARS 1.0
score HEAD_ILLEGAL_CHARS 1.0
score FROM_ILLEGAL_CHARS 0.7
# 極高分規則(直接判定垃圾郵件)
score TO_TXT 100
score RATWARE_HASH_2 100
score RATWARE_HASH_2_V2 100
score RATWARE_JIXING 100
# 自訂中文規則範例
header FOXMAIL X-Mailer =~ /FoxMail /
describe FOXMAIL Foxmail
score FOXMAIL 3.5
header QSUBJ Subject =~ /嗎|哦|?|!/
describe QSUBJ 中文主旨含問號/嘆號
score QSUBJ 1
body UNSUBSCRIBE_ZH /取消.*訂閱/
describe UNSUBSCRIBE_ZH 內文含退訂字樣
score UNSUBSCRIBE_ZH 1
body SPAM1_ZH /發信軟體/
describe SPAM1_ZH 群發軟體特徵
score SPAM1_ZH 1
body WINDOWOPEN /window\.open\(/i
describe WINDOWOPEN JS 彈窗代碼
score WINDOWOPEN 3.5
service spamassassin start
chkconfig spamassassin on
# 測試
spamassassin -t < test.eml
sa-learn --spam / --ham 訓練貝葉斯資料庫。/var/log/maillog 中 Hits: 數值調整門檻。