This documentation is for Dovecot v2.x, see wiki1 for v1.x documentation.
Differences between revisions 1 and 29 (spanning 28 versions)
Revision 1 as of 2010-08-31 21:52:49
Size: 1832
Editor: interfaSys
Comment:
Revision 29 as of 2017-02-10 07:49:27
Size: 5233
Editor: officewifi
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

'''This plugin is deprecated, please see [[HowTo/AntispamWithSieve]] how to replace it with IMAPSieve'''

Line 3: Line 7:
The antispam plugin allows you to retrain the spam filter by simply moving emails in and out of the Spam folder. The original project can be found [[http://johannes.sipsolutions.net/Projects/dovecot-antispam|HERE]]. The antispam plugin allows you to retrain the spam filter by simply moving emails in and out of the Spam folder. This is the fork of the analogous plugin for Dovecot versions prior to v2.0. The original project can be found [[http://johannes.sipsolutions.net/Projects/dovecot-antispam|HERE]].
Line 6: Line 10:
Currently there are no antispam-plugin releases for v2.0, but you can get them from the the Mercurial repository: === Releases ===
None so far.

=== Mercurial ===
Execute the following commands in order to get the source from the Mercurial repository:
Line 12: Line 20:
There is a web interface available [[http://hg.dovecot.org/dovecot-antispam-plugin/|HERE]].
Line 14: Line 24:

If you installed Dovecot from sources, antispam-plugin's configure script should be able to find the files it needs automatically, just make sure the {{{--prefix=<path>}}} is specified correctly:
Line 15: Line 28:
# ./autogen.sh # ./configure --prefix=/usr
# make
# make install
Line 17: Line 32:
If you installed Dovecot from sources, antispam-plugin's configure script should be able to find the files it needs automatically If you get a {{{DC_DOVECOT: not found"}}} error message when running configure, make sure dovecot.m4 is in your aclocal folder. If you installed dovecot in an unusual location, you can also specify the path to the directory containing dovecot.m4 when you run autogen.sh like so:
Line 19: Line 35:
./configure
make
make install
# ACLOCAL='aclocal -I /path/to/directory' ./autogen.sh
Line 23: Line 37:
In this case, you will probably also want to append {{{--with-dovecot=/path/to/dovecot/include/directory}}} when you run {{{./configure}}}.
Line 24: Line 39:
If this doesn't work, you can use the {{{--prefix=<path>}}} configure option: == Configuration and Use ==
Please refer to the manual page dovecot-antispam(7) installed during the {{{make install}}} or view the textual version online [[http://hg.dovecot.org/dovecot-antispam-plugin/raw-file/tip/doc/dovecot-antispam.7.txt|HERE]].

=== Sieve filter ===
If you would like to have Dovecot move the spam tagged emails simply place the following into '.dovecot.sieve', and place the file into the users root mail folder (the folder with 'Maildir' in it).
Line 26: Line 46:
./configure --prefix=/usr
make
make install
}}}

If you get a {{{DC_DOVECOT: not found"}}} error message when running configure, make sure dovecot.m4 is in your aclocal folder.
== Configuration and Use ==

== conf.d/20-imap.conf ==
{{{
protocol imap {
...
  mail_plugins = $mail_plugins antispam
...
require ["fileinto","imap4flags"];
if header :contains "subject" ["[SPAM]"] {
        setflag "\\seen";
        fileinto "SPAM";
        stop;
} else {
        # The rest goes into INBOX
        # default is "implicit keep", we do it explicitly here
        keep;
Line 42: Line 57:
== conf.d/90-plugin.conf ==
Here is an example using the mailtrain backend
=== Backend - mailtrain realtime sa-learn ===
If you intend to use the mailtrain backend linked to sa-learn you will need to pipe the output to a file though a wrapper script as sa-learn does not support piped input. The script below needs to be put in /usr/bin/sa-learn-pipe.sh and chmod'ed to allow dovecot to execute it. Note that the script below has a couple extra lines used to create a log of when it has been run.
Line 45: Line 60:
===== /usr/bin/sa-learn-pipe.sh =====
{{{#!highlight sh

#!/usr/bin/env bash

pid=$$

# remove the # from next line to background learner
#(
{
echo "$(date) ${pid}-start ($*) /tmp/sendmail-msg-$$.txt"
# set -x
# id -a
# env
cat > /tmp/sendmail-msg-${pid}.txt
/usr/bin/sa-learn "$@" /tmp/sendmail-msg-${pid}.txt
echo "$(date) $$-end rc=$?"
} >/tmp/antispam.${pid}.log 2>&1

cat /tmp/antispam.${pid}.log >>/tmp/sa-learn-pipe.log
rm -f /tmp/antispam.${pid}.log /tmp/sendmail-msg-${pid}.txt
true

# remove the # from next line to background learner
# ) &

exit 0
}}}
This wrapper captures some debug information and all output of {{{/usr/bin/sa-learn}}} and dumps it into {{{/tmp/sa-learn-pipe.log}}}. It uses a temp file, in order to avoid mangled output in the log file, if two or more scripts run simultaneously. Remove the {{{#}}} hash mark from the two indicated lines, in order to background the processing. The braces redirect all error messages from the learner program and bash into the temp file.

===== 90-plugin.conf =====
Line 46: Line 92:
plugin {
...
  antispam_backend = mailtrain
  antispam_mail_notspam = nospam-%u
  antispam_mail_sendmail = /usr/sbin/sendmail
  antispam_mail_spam = spam-%u
  antispam_mail_tmpdir = /tmp
  antispam_signature = X-DSPAM-Signature
  antispam_signature_missing = move
  antispam_spam_pattern_ignorecase = INBOX.spam;INBOX.junk;spam;junk
  antispam_trash_pattern_ignorecase = trash;deleted
...
}
    #=====================
    # mailtrain plugin
    #
    # This plug can be used to train via an arbitrary program that
    # receives the message on standard input. Since sendmail can be
    # such a program, it can be used to send the message to another
    # email address for training there.
    #
    # For example:
    # (defaults to /usr/sbin/sendmail)
    #antispam_mail_sendmail_args = --for;%u
    antispam_mail_spam = --spam
    antispam_mail_notspam = --ham
    #antispam_mail_sendmail = /usr/sbin/sendmail
    antispam_mail_sendmail = /usr/bin/sa-learn-pipe.sh
    #antispam_mail_sendmail_args = -f;%u@example.com # % expansion done by dovecot
Line 60: Line 109:
== Feedback ==
Please report the bugs, feature requests, or anything else regarding this plugin to its author and maintainer: [[mailto:eugene@raptor.kiev.ua?subject=dovecot-antispam plugin feedback|Eugene Paskevich]].

== Chrooting ==
'''''Note:''''' Do '''not''' use [[Chrooting|chrooting]] because otherwise it might be impossible to find the binary the antispam plugin tries to execute. ''Or make sure the executed binary and the spam db is available in all home directories.''

Antispam plugin

This plugin is deprecated, please see HowTo/AntispamWithSieve how to replace it with IMAPSieve

Introduction

The antispam plugin allows you to retrain the spam filter by simply moving emails in and out of the Spam folder. This is the fork of the analogous plugin for Dovecot versions prior to v2.0. The original project can be found HERE.

Getting the sources

Releases

None so far.

Mercurial

Execute the following commands in order to get the source from the Mercurial repository:

# hg clone http://hg.dovecot.org/dovecot-antispam-plugin
# cd dovecot-antispam-plugin

There is a web interface available HERE.

Compiling

If you downloaded the sources using Mercurial, you will need to execute ./autogen.sh first to build the automake structure in your source tree. This process requires autotools and libtool to be installed.

If you installed Dovecot from sources, antispam-plugin's configure script should be able to find the files it needs automatically, just make sure the --prefix=<path> is specified correctly:

# ./configure --prefix=/usr
# make
# make install

If you get a DC_DOVECOT: not found" error message when running configure, make sure dovecot.m4 is in your aclocal folder. If you installed dovecot in an unusual location, you can also specify the path to the directory containing dovecot.m4 when you run autogen.sh like so:

# ACLOCAL='aclocal -I /path/to/directory' ./autogen.sh

In this case, you will probably also want to append --with-dovecot=/path/to/dovecot/include/directory when you run ./configure.

Configuration and Use

Please refer to the manual page dovecot-antispam(7) installed during the make install or view the textual version online HERE.

Sieve filter

If you would like to have Dovecot move the spam tagged emails simply place the following into '.dovecot.sieve', and place the file into the users root mail folder (the folder with 'Maildir' in it).

require ["fileinto","imap4flags"];
if header :contains "subject" ["[SPAM]"] {
        setflag "\\seen";
        fileinto "SPAM";
        stop;
} else {
        # The rest goes into INBOX
        # default is "implicit keep", we do it explicitly here
        keep;
}

Backend - mailtrain realtime sa-learn

If you intend to use the mailtrain backend linked to sa-learn you will need to pipe the output to a file though a wrapper script as sa-learn does not support piped input. The script below needs to be put in /usr/bin/sa-learn-pipe.sh and chmod'ed to allow dovecot to execute it. Note that the script below has a couple extra lines used to create a log of when it has been run.

/usr/bin/sa-learn-pipe.sh

   1 #!/usr/bin/env bash
   2 
   3 pid=$$
   4 
   5 # remove the # from next line to background learner
   6 #(
   7 {
   8 echo "$(date) ${pid}-start ($*) /tmp/sendmail-msg-$$.txt"
   9 # set -x
  10 # id -a
  11 # env
  12 cat > /tmp/sendmail-msg-${pid}.txt
  13 /usr/bin/sa-learn "$@" /tmp/sendmail-msg-${pid}.txt
  14 echo "$(date) $$-end rc=$?"
  15 } >/tmp/antispam.${pid}.log 2>&1
  16 
  17 cat /tmp/antispam.${pid}.log >>/tmp/sa-learn-pipe.log
  18 rm -f /tmp/antispam.${pid}.log /tmp/sendmail-msg-${pid}.txt
  19 true
  20 
  21 # remove the # from next line to background learner
  22 # ) &
  23 
  24 exit 0

This wrapper captures some debug information and all output of /usr/bin/sa-learn and dumps it into /tmp/sa-learn-pipe.log. It uses a temp file, in order to avoid mangled output in the log file, if two or more scripts run simultaneously. Remove the # hash mark from the two indicated lines, in order to background the processing. The braces redirect all error messages from the learner program and bash into the temp file.

90-plugin.conf

    #=====================
    # mailtrain plugin
    #
    # This plug can be used to train via an arbitrary program that
    # receives the message on standard input. Since sendmail can be
    # such a program, it can be used to send the message to another
    # email address for training there.
    #
    # For example:
    #        (defaults to /usr/sbin/sendmail)
    #antispam_mail_sendmail_args  = --for;%u
    antispam_mail_spam  = --spam
    antispam_mail_notspam  = --ham
    #antispam_mail_sendmail = /usr/sbin/sendmail
    antispam_mail_sendmail = /usr/bin/sa-learn-pipe.sh
    #antispam_mail_sendmail_args = -f;%u@example.com # % expansion done by dovecot

Feedback

Please report the bugs, feature requests, or anything else regarding this plugin to its author and maintainer: Eugene Paskevich.

Chrooting

Note: Do not use chrooting because otherwise it might be impossible to find the binary the antispam plugin tries to execute. Or make sure the executed binary and the spam db is available in all home directories.

None: Plugins/Antispam (last edited 2017-02-10 07:49:27 by officewifi)