[Dovecot] Reviewing end-user ham/spam submissions before feeding them to sa-learn via Dovecot Antispam plug-in

Ben Johnson ben at indietorrent.org
Fri Feb 1 18:18:12 EET 2013



On 2/1/2013 8:45 AM, Steffen Kaiser wrote:
> On Thu, 31 Jan 2013, Ben Johnson wrote:
> 
>> On 1/17/2013 4:31 AM, Steffen Kaiser wrote:
>>> On Wed, 16 Jan 2013, Ben Johnson wrote:
>>> 
>> I am using the Maildir format indeed.
> 
>>>> any of your mail users need write permission those
>>>> directories, the admin needs read permissions for the spooled
>>>> files,
> 
>> By "mail users", do you mean, e.g., the "vmail" user account (I'm
>> on Debian/Ubuntu)? My understanding is that the "vmail" user
>> account
> 
> Yes, I mean that Unix account, Dovecot accesses the fils with. In
> a setup with virtual users "vmail" makes sense.
> 
>> handles all IMAP transactions; if this is true, then are you
>> saying that the only requisite to your suggestions is that the
>> "vmail" user has read/write access to the following two
>> directories?
> 
>> /path/to/admin/Maildir/.TrainingReview.spam/new/
> 
>> and
> 
>> /path/to/admin/Maildir/.TrainingReview.not_spam/new/
> 
> Yes.
> 
>>>> you need some method to pass the reviewed messages to
>>>> sa-learn.
> 
>> In the past, I have simply sorted the messages into "Ham" and
>> "Spam" sub-folders of the admin's training Inbox, and called
>> sa-learn, with the appropriate --ham/--spam switch on each, using
>> a cron job. It sounds as though this is what you are suggesting,
>> and I can continue
> 
> That's what I mean.
> 
>> with this approach.
> 
>> I went ahead and tried to reconfigure Dovecot's Antispam plug-in
>> to use the spool2dir backend, but I'm receiving a
>> less-than-helpful message from the plug-in when I try to move a
>> message from Inbox to Junk or vice versa: "CANNOT: antispam
>> plugin not configured".
> 
>> Please note that I am using Dovecot 1.2.9 in Ubuntu 10.04 LTS.
>> By
> 
> Oh, I have no experience with Dovecot v1.2; in v1.0 you have to
> compile one particular backend into antispam-plugin. Maybe,
> distributors have another, non-Dovecot way to select between the
> backends.
> 
>> extension, I am using the Antispam plug-in for Dovecot 1 (not 2),
>> the manpage for which is at 
>> http://manpages.ubuntu.com/manpages/lucid/man7/dovecot-antispam.7.html
>>
>> 
. So, the configuration option names and expected values differ
>> slightly from those in your example.
> 
> The man-page contains:
> 
> "INSTALLATION
> 
> First copy the ‘defconfig’ file to ‘.config’ and edit it as 
> necessary. You  need  to  have  the  dovecot  headers installed and
> possibly other things depending on the backend you choose.  Then,
> assuming  you have configured the INSTALLDIR correctly, simply run
> ‘make install’. "
> 
> -and-
> 
> "BACKENDS
> 
> The  plugin supports multiple backends, there are currently two 
> working backends included in the distribution: "
> 
> This suggests that my guess is true - although I don't understand
> the "there are currently two backends included" part.
> 
> ======
> 
> So you could re-compile another antispam-plugin with spool2dir
> backend, or - - you are using these settings, right?
> 
> #===================== # mail sending plugin # # Because of the way
> this plugin works, you can also use it # to train via an arbitrary
> program that receives the message # on standard input, in that case
> you can use the config # options antispam_mail_spam and
> antispam_mail_notspam for # the argument that distinguishes between
> ham and spam. # For example: #   antispam_mail_sendmail =
> /path/to/mailtrain #   antispam_mail_sendmail_args = --for;%u #
> antispam_mail_spam = --spam #   antispam_mail_notspam = --ham
> 
> change antispam_mail_sendmail into a script, that drops the
> message into the correct mail folder, e.g.:
> 
> #!/bin/bash
> 
> mode= for opt; do if test "x$opt" == x--ham; then mode=HAM break 
> elif test "x$opt" == x--ham; then mode=SPAM break fi done
> 
> if test -n "$mode"; then # options from
> http://wiki1.dovecot.org/LDA /path/to/dovecot-deliver -d spamadmin
> -m Training.$mode fi
> 
> This sends the message bypassing a MTA to the spamadmin user.
> 
> Kind regards,
> 
> -- Steffen Kaiser

Steffen,

It seems you're correct in that the spool2dir back-end isn't included
with version 1 of the plug-in. I like the idea of using a pipe script
better than changing the back-end.

Thank you for providing a solid example; it works beautifully with a
couple of small changes. Here's the final script:

---------------------------------------
#!/bin/bash

mode=
for opt; do
	if test "x$*" == "x--ham"; then
		mode=HAM
		break
	elif test "x$*" == "x--spam"; then
		mode=SPAM
		break
	fi
done

if test -n "$mode"; then
	# options from http://wiki1.dovecot.org/LDA
	/usr/lib/dovecot/deliver -d user at example.com -m Training.$mode
fi

exit 0
---------------------------------------

For anyone who is curious, here are the Antispam plug-in options:

---------------------------------------
  # For Dovecot < 2.0.
  antispam_spam_pattern_ignorecase = SPAM;JUNK
  antispam_mail_tmpdir = /tmp
  antispam_mail_sendmail = /usr/bin/sa-learn-pipe.sh
  antispam_mail_spam = --spam
  antispam_mail_notspam = --ham
---------------------------------------

Looks like we're in business!

Thanks again for sharing your valuable insights; your help is greatly
appreciated.

-Ben



More information about the dovecot mailing list