dnf install spamassasin
normalize_charset 1
ok_languages ja en
ok_locales ja en
score FROM_EXCESS_BASE64 0
score MIME_BASE64_TEXT 0
score TVD_SPACE_RATIO 0
loadplugin Mail::SpamAssassin::Plugin::TextCat
SPAMDOPTIONS="-c -m5 -H --razor-home-dir='/var/lib/razor/' --razor-log-file='sys-syslog' -l -s /var/log/spamd.log"
spamassassin --lint
# no output
systemctl enable spamassassin --now
spamcが動くかサンプルで確認します。実行後$?を出力して、エラーコードが0である事を確認します。
spamc -L spam < /usr/share/doc/spamassassin/sample-spam.txt
echo $?
# 0 が出力される
namespace inbox {
#...
mailbox Junk {
special_use = \Junk
# 自動生成して購読を追加
auto = subscribe
}
protocol imap {
# imap_sieveを追加
mail_plugins = $mail_plugins imap_sieve
}
plugin {
sieve_plugins = sieve_extprograms sieve_imapsieve
sieve_implicit_extensions = +vnd.dovecot.report
# From elsewhere to Spam folder
imapsieve_mailbox1_name = Junk
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_before = file:/usr/local/lib/dovecot/sieve/spam/report-spam.sieve
# From Spam folder to elsewhere
imapsieve_mailbox2_name = *
imapsieve_mailbox2_from = Junk
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:/usr/local/lib/dovecot/sieve/spam/report-ham.sieve
sieve_pipe_bin_dir = /usr/local/lib/dovecot/sieve/spam
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
}
スクリプト用フォルダとファイルを作成します。
mkdir /usr/local/lib/dovecot/sieve/spam
chown vmb.vmb /usr/local/lib/dovecot/sieve/spam
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
pipe :copy "sa-learn-spam.sh" [ "${username}" ];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
if string "${mailbox}" "Trash" {
stop;
}
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
pipe :copy "sa-learn-ham.sh" [ "${username}" ];
#!/bin/sh
exec /usr/bin/spamc -u vmb -L spam
exit 0
#!/bin/sh
exec /usr/bin/spamc -u vmb -L ham
exit 0
chown vmb.vmb /usr/local/lib/dovecot/sieve/spam/*
chmod +x /usr/local/lib/dovecot/sieve/spam/sa-learn-*.sh
spamd: connection from ::1 [::1]:57804 to port 783, fd 5
spamd: setuid to vmb succeeded
spamd: Tell: Setting local for vmb:5000 in 0.0 seconds, 1113 bytes
info: prefork: child states: II
チェック用にコマンドラインで迷惑メールフォルダのメールファイルをspamcで食わせると、既に学習済と出ました。
spamc -L spam -u vmb < /var/mail/vhosts/virtual.localdomain/Maildir/aikawa/.Junk/cur/[メールファイル]
# Message was already un/learned
Tags: pigeonhole, SpamAssassin