| Current File : //usr/local/share/doc/dovecot/wiki/HowTo.AntispamWithSieve.txt |
Replacing antispam plugin with IMAPSieve
========================================
You will need at least pigeonhole v0.4.14 for this. If you have already
configured sieve, please adjust the following to match your setup.
Please note the following caveats and possible pitfalls:
* INBOX name is case-sensitive
* <IMAP Sieve> [Pigeonhole.Sieve.Plugins.IMAPSieve.txt] will *only* apply to
IMAP. It *will not* apply to LDA or LMTP. Use <Sieve> [Pigeonhole.Sieve.txt]
normally for LDA/LMTP.
* With this configuration, moving mails will slow down due to learn being done
per email. If you want to avoid this, you need to think of something else.
Probably piping things into a FIFO or perhaps using a socket based worker
might work better.
Please see <Pigeonhole.Sieve.Plugins.txt> for more information about sieve
extensions.
Changes:
* 2017/02/13 - Improved documentation and added instructions for Spam->Trash.
(Thanks for everyone who commented on mailing list)
* 2017/02/10 - Removed imap_stats (it's not needed)
Dovecot configuration
---%<-------------------------------------------------------------------------
protocol imap {
mail_plugins = $mail_plugins imap_sieve
}
plugin {
sieve_plugins = sieve_imapsieve sieve_extprograms
# From elsewhere to Spam folder
imapsieve_mailbox1_name = Spam
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_before = file:/usr/lib/dovecot/sieve/report-spam.sieve
# From Spam folder to elsewhere
imapsieve_mailbox2_name = *
imapsieve_mailbox2_from = Spam
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:/usr/lib/dovecot/sieve/report-ham.sieve
sieve_pipe_bin_dir = /usr/lib/dovecot/sieve
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.execute
}
---%<-------------------------------------------------------------------------
Create directory /usr/lib/dovecot/sieve and put following files to that:
report-spam.sieve
---%<-------------------------------------------------------------------------
require ["vnd.dovecot.pipe", "copy"];
pipe :copy "sa-learn-spam.sh";
---%<-------------------------------------------------------------------------
report-ham.sieve
---%<-------------------------------------------------------------------------
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
if string "${mailbox}" "Trash" {
stop;
}
pipe :copy "sa-learn-ham.sh";
---%<-------------------------------------------------------------------------
sa-learn-spam.sh
---%<-------------------------------------------------------------------------
exec /usr/bin/sa-learn --spam
---%<-------------------------------------------------------------------------
sa-learn-ham.sh
---%<-------------------------------------------------------------------------
exec /usr/bin/sa-learn --ham
---%<-------------------------------------------------------------------------
Then run following commands:
---%<-------------------------------------------------------------------------
sievec /usr/lib/dovecot/sieve/report-spam.sieve
sievec /usr/lib/dovecot/sieve/report-ham.sieve
chmod +x /usr/lib/dovecot/sieve/sa-learn-ham.sh
/usr/lib/dovecot/sieve/sa-learn-spam.sh
---%<-------------------------------------------------------------------------
Now your learn scripts should be invoked when you move mails between folders.
Debugging
---------
To debug, you need to import "vnd.dovecot.debug" extension. Then you can put,
when required
---%<-------------------------------------------------------------------------
debug_log "something"
---%<-------------------------------------------------------------------------
variables are supported in this.
(This file was created from the wiki on 2017-02-24 04:44)