История изменений
Исправление post-factum, (текущая версия) :
Показываю, как сделано у меня.
В Dovecot:
protocol imap {
mail_plugins = antispam
plugin {
antispam_backend = pipe
antispam_trash = trash;Trash
antispam_spam = junk;Junk
antispam_allow_append_to_spam = no
antispam_pipe_program_spam_arg = --spam
antispam_pipe_program_notspam_arg = --ham
antispam_pipe_tmpdir = /tmp
antispam_pipe_program = /usr/local/bin/sa-learn-pipe.sh
}
}
Скрипт обучения:
#!/usr/bin/env bash
LOCK="/tmp/sa-learn.lock"
FIFO="/run/sa-learn-daemon.fifo"
RESPONSE="/run/sa-learn-client.fifo"
exec 200> $LOCK
flock -x 200
MSG=$(mktemp)
cat <&0 >$MSG
echo "$*;$MSG" >$FIFO
while true
do
if read line <$RESPONSE
then
if [[ "$line" == "OK" ]]
then
flock -u 200
exit 0
fi
fi
done
flock -u 200
exit 0
А это демон, который слушает FIFO и, собственно, вызывает sa-learn:
#!/usr/bin/env bash
LOG="/var/log/sa-learn.log"
FIFO="/run/sa-learn-daemon.fifo"
RESPONSE="/run/sa-learn-client.fifo"
rm -f $FIFO
rm -f $RESPONSE
mkfifo $FIFO
mkfifo $RESPONSE
chown nobody:nogroup $FIFO
chown nobody:nogroup $RESPONSE
while true
do
if read line <$FIFO
then
echo "$(date)" >>$LOG
echo "$line" >>$LOG
args=$(echo $line | cut -d ';' -f 1)
msg=$(echo $line | cut -d ';' -f 2)
/usr/bin/sa-learn --no-sync $args $msg >>$LOG 2>&1
/usr/bin/sa-learn --sync >>$LOG 2>&1
rm -f $msg
echo "OK" >$RESPONSE
fi
done <$FIFO
Исходная версия post-factum, :
Показываю, как сделано у меня.
В Dovecot:
protocol imap {
mail_plugins = antispam
plugin {
antispam_backend = pipe
antispam_trash = trash;Trash
antispam_spam = junk;Junk
antispam_allow_append_to_spam = no
antispam_pipe_program_spam_arg = --spam
antispam_pipe_program_notspam_arg = --ham
antispam_pipe_tmpdir = /tmp
antispam_pipe_program = /usr/local/bin/sa-learn-pipe.sh
}
}
Скрипт обучения:
#!/usr/bin/env bash
LOCK="/tmp/sa-learn.lock"
FIFO="/run/sa-learn-daemon.fifo"
RESPONSE="/run/sa-learn-client.fifo"
exec 200> $LOCK
flock -x 200
MSG=$(mktemp)
cat <&0 >$MSG
echo "$*;$MSG" >$FIFO
while true
do
if read line <$RESPONSE
then
if [[ "$line" == "OK" ]]
then
flock -u 200
exit 0
fi
fi
done
flock -u 200
exit 0
А это демон, который слушает сокет и, собственно, вызывает sa-learn:
#!/usr/bin/env bash
LOG="/var/log/sa-learn.log"
FIFO="/run/sa-learn-daemon.fifo"
RESPONSE="/run/sa-learn-client.fifo"
rm -f $FIFO
rm -f $RESPONSE
mkfifo $FIFO
mkfifo $RESPONSE
chown nobody:nogroup $FIFO
chown nobody:nogroup $RESPONSE
while true
do
if read line <$FIFO
then
echo "$(date)" >>$LOG
echo "$line" >>$LOG
args=$(echo $line | cut -d ';' -f 1)
msg=$(echo $line | cut -d ';' -f 2)
/usr/bin/sa-learn --no-sync $args $msg >>$LOG 2>&1
/usr/bin/sa-learn --sync >>$LOG 2>&1
rm -f $msg
echo "OK" >$RESPONSE
fi
done <$FIFO