いくつかの方法がありますが、これが私がうまくいった方法です。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)
procmail を介してメールをフィルター処理するように構成されたフォルダーのセットアップと postfix を使用して、次のようにします。
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"
(.fetchmailrc ファイルに対して実行するだけでサーバーのフィンガープリントを取得できます。サーバーのフィンガープリントが出力されfetchmail --verbose
、現在のフィンガープリントがチェックされ、一致しないことが通知され、接続が閉じられますが、正しいフィンガープリントが取得されました。次回のために:-)
最後に、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
私はこのようなサーバーを 10 年近く実行してきましたが、うまく機能しています。トレーニング ファイルはユーザーのホーム ディレクトリにあり、ボックスからボックスへ簡単に移動して、新しいユーザーに適切な基本セットを提供できます。幸運を。数年前にopenSuSE 11.0のこのセットアップについて簡単なハウツーを作成しました。もう少し詳しい情報があるかもしれません。
PS Rayzorはロードする価値があります。