antispam plugin, pipe backend, how to make it work?

deano-dovecot at areyes.com deano-dovecot at areyes.com
Wed Apr 13 20:11:23 UTC 2016


Johannes -

I'm running 2.2.9 under Ubuntu 14.04.  I gave up on using the pipe 
backend, just could not get the damn thing to work.  I would up using 
spool2dir and incron, which works perfectly.  The issue was that 
sa-learn would cause a pthread_cancel error with libgcc_s.so.1

Below is an excerpt from my install script :

############################################
   # Enable antispam - Damn, not working right with pipe backend
   # now using spool2dir and incron
   if [ -e /etc/spamassassin ]; then
     sed -i "
       s/^  #mail_plugins.*/  mail_plugins = \$mail_plugins antispam 
${DOVENOTIFY}/
       s/^  #mail_max_userip.*/mail_max_userip_connections = 20/
	" /etc/dovecot/conf.d/20-imap.conf
     cat > /etc/dovecot/conf.d/99-Installerbox-antispam.conf << EOF
##
## antispam configuration
##
plugin {
   antispam_debug_target = syslog
   # antispam_verbose_debug = 1
   antispam_trash_pattern = Trash;Deleted *
   antispam_spam = Junk;Spam

   antispam_backend = spool2dir
   antispam_spool2dir_spam = 
/var/cache/dovecot-antispam/spam/%%020lu-%u-%%05luS
   antispam_spool2dir_notspam =  
/var/cache/dovecot-antispam/ham/%%020lu-%u-%%05luH

   # pipe backend not working with sa-learn - causes pthread_cancel error 
with libgcc_s.so.1
   # antispam_backend = pipe
   # antispam_pipe_program = /usr/local/bin/sa-learn-pipe.sh
   # antispam_pipe_program_args = --for;%u
   # antispam_pipe_program_spam_arg = --spam
   # antispam_pipe_program_notspam_arg = --ham
   # antispam_pipe_tmpdir = /tmp
}
EOF

     # incron watches the spam/ham spool dirs, calls sa-learn-pipe.sh to 
handle
     echo "root" >> /etc/incron.allow
     mkdir -p /var/cache/dovecot-antispam/spam 
/var/cache/dovecot-antispam/ham
     chown -R ${VMAIL_ID}.dovecot /var/cache/dovecot-antispam/
     cat > /var/spool/incron/root << "EOF"
/var/cache/dovecot-antispam/spam IN_CLOSE_WRITE 
/usr/local/bin/sa-learn-pipe.sh --spam 
/var/cache/dovecot-antispam/spam/$#
/var/cache/dovecot-antispam/ham IN_CLOSE_WRITE 
/usr/local/bin/sa-learn-pipe.sh --ham /var/cache/dovecot-antispam/ham/$#
EOF
     chgrp incron /var/spool/incron/root
     chmod 600 /var/spool/incron/root

     # inotify needs a little more room to breath - default of 128 too 
low
     cat > /etc/sysctl.d/60-inotify.conf << EOF
# inotify changes for Dovecot
# http://dovecot.org/list/dovecot/2011-March/058300.html

# Defaults are
# fs.inotify.max_queued_events = 16384
# fs.inotify.max_user_instances = 128
# fs.inotify.max_user_watches = 8192

fs.inotify.max_user_instances = 2048
EOF

     # spamassassin learning script
     cat > /usr/local/bin/sa-learn-pipe.sh << "EOFSPAM"
#!/bin/bash
# Pipe script to learn/unlearn single email file
# Set to read from file or from stdin
# From stdin to accomodate dovecot-antispam pipe backend (nor currently 
working)

# echo /usr/bin/sa-learn $* /tmp/sendmail-msg-$$.txt
FILE=`echo $* | sed "s/^.* //"`
echo "$$-start ($*)" >> /var/log/sa-learn-pipe.log
echo -n "$$ " >> /var/log/sa-learn-pipe.log
egrep --no-filename "^Subject: " /tmp/sendmail-msg-$$.txt ${FILE} | head 
-1 >> /var/log/sa-learn-pipe.log
cat<&0 >> /tmp/sendmail-msg-$$.txt
/usr/bin/sa-learn --progress $* /tmp/sendmail-msg-$$.txt >> 
/tmp/sa-learn-pipe.$$.log 2>&1
echo $$ sa-learn rc=$? id=$(id) HOME=$HOME >> /var/log/sa-learn-pipe.log

while read line; do
   echo $$-sa-learn "$line" >> /var/log/sa-learn-pipe.log
done < /tmp/sa-learn-pipe.$$.log

rm -f /tmp/sendmail-msg-$$.txt /tmp/sa-learn-pipe.$$.log
rm -f ${FILE}
echo "$$-end" >> /var/log/sa-learn-pipe.log

exit 0
EOFSPAM
     chmod 755 /usr/local/bin/sa-learn-pipe.sh
     touch /var/log/sa-learn-pipe.log
     chown ${VMAIL_ID}.dovecot /var/log/sa-learn-pipe.log
     chmod 660 /var/log/sa-learn-pipe.log
     cat > /etc/logrotate.d/sa-learn-pipe.log << EOFLOG
/var/log/sa-learn-pipe.log {
         daily
         missingok
         rotate 10
         compress
         delaycompress
         notifempty
         create 660 ${VMAIL_ID} dovecot
}
EOFLOG
   fi # spamassassin

############################################


On 2016-04-12 14:14, Johannes Rohr wrote:
> Hi, my setup is a dovecot 2.0.19 IMAP server on Ubuntu Precise with
> the antispam plugin in version  2.0+20120225-2 and spamassassin at
> version 3.2.2
> 
> I have been trying and failed to get the pipe backend of the antispam
> plugin to work. Spamassin by itself works, a manual call of sa-learn
> works fine. Bayes data is stored in a mysql DB.
> 
> I have the following configuration in 
> /etc/dovecot/conf.d/90-plugin.conf
> 
> plugin {
>   #setting_name = value
>   sieve=~/.dovecot.sieve
>   sieve_dir=~/sieve
>     antispam_pipe_program_spam_arg = --spam
>     antispam_pipe_program_notspam_arg  = --ham
>     antispam_pipe_program = /usr/local/bin/sa-learn-pipe.sh
>     antispam_pipe_program_args = --username=%u # % expansion done by 
> dovecot
>     antispam_trash = trash;Trash;Deleted Items;Deleted Messages
>     antispam_spam = SPAM;Junk
>     antispam_backend = pipe
>     antispam_verbose_debug = 1
>     antispam_debug_target = syslog
>     antispam_pipe_tmpdir = /tmp
> }
> 
> I have tried the following wrapper script:
> #!/bin/bash
> # set -x
> LOGFILE=/tmp/sa-learn-pipe.log
> echo "$$-start ($*)" >> $LOGFILE
> #echo $* > /tmp/sendmail-parms.txt
> cat<&0 >> /tmp/sendmail-msg-$$.txt
> /usr/bin/sa-learn $* -D /tmp/sendmail-msg-$$.txt >> $LOGFILE 2>&1 && \
> rm -f /tmp/sendmail-msg-$$.txt
> echo "$$-end" >> $LOGFILE
> exit 0
> 
> It somehow isn't working. I can call the wrapper script manually e.g.
> sudo -u vmail /usr/local/bin/sa-learn-pipe.sh --username=some at mail.user 
> --ham \
> < someham
> 
> But it doesn't work from dovecot. It seems the script is called. but
> no new patterns show up in the bayes DB. Unfortunately, the plugin
> seems to be documented poorly. How does it call the programme it pipes
> to? Is it something like $programme --par1 --par2 < message ? Why
> can't / shouldn't I call sa-learn directly? All the instructions I
> found on the in internet contained a wrapper script, but none bothered
> to explain why you would actually need it.
> 
> I would be very grateful, if someone could enlighten me on that...

-- 
Dean Carpenter
deano is at areyes dot com
203 six oh four 6644


More information about the dovecot mailing list