Commit b9533d02 authored by ale's avatar ale
Browse files

Implement user spam feedback loop

Users can now feed back ham/spam status into Spamassassin by
moving emails from/to the "Spam" folder. This is implemented
via imap-sieve as detailed in https://wiki2.dovecot.org/HowTo/AntispamWithSieve.
parent 9a22af1e
#!/bin/sh
exec /usr/bin/spamc -u "$1" -L ham -C report
#!/bin/sh
exec /usr/bin/spamc -u "$1" -L spam -C report
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
if string "${mailbox}" "Trash" {
stop;
}
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
pipe :copy "learn-ham.sh" [ "${username}" ];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
pipe :copy "learn-spam.sh" [ "${username}" ];
......@@ -80,16 +80,39 @@
state: directory
mode: 0755
- name: Install default sieve filter
- set_fact:
sieve_filters:
- default.sieve
- report-spam.sieve
- report-ham.sieve
- name: Install default sieve filters
copy:
src: default.sieve
dest: /var/lib/dovecot/sieve/default.sieve
src: "{{ item }}"
dest: "/var/lib/dovecot/sieve/{{ item }}"
mode: 0644
register: dovecot_default_sieve
loop: "{{ sieve_filters }}"
register: dovecot_sieve_scripts
- name: Compile the default sieve filters
shell: "env HOME=/tmp sievec /var/lib/dovecot/sieve/{{ item.0 }}"
when: "item.1.changed"
loop: "{{ sieve_filters | zip(dovecot_sieve_scripts) }}"
- name: Create dovecot sieve scripts directory
file:
path: /usr/lib/dovecot/sieve
state: directory
mode: 0755
- name: Compile the default sieve filter
shell: "env HOME=/tmp sievec /var/lib/dovecot/sieve/default.sieve"
when: dovecot_default_sieve.changed
- name: Install dovecot sieve scripts
copy:
src: "{{ item }}"
dest: "/usr/lib/dovecot/sieve/{{ item }}"
mode: 0755
loop:
- "learn-spam.sh"
- "learn-ham.sh"
# Copy some other various files, for instance because they are outside
# the /etc/dovecot tree, or because they need special permissions.
......
......@@ -67,7 +67,7 @@ imap_client_workarounds = delay-newmail tb-extra-mailbox-sep tb-lsub-flags
protocol imap {
# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $mail_plugins imap_zlib #antispam
mail_plugins = $mail_plugins imap_sieve imap_zlib
# Maximum number of IMAP connections allowed for a user from each IP address.
# NOTE: The username is compared case-sensitively.
......
......@@ -104,14 +104,14 @@ plugin {
# `sieve_extensions' setting, with the difference that extensions are
# enabled or disabled for exclusive use in global scripts. Currently, no
# extensions are marked as such by default.
#sieve_global_extensions =
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
# The Pigeonhole Sieve interpreter can have plugins of its own. Using this
# setting, the used plugins can be specified. Check the Dovecot wiki
# (wiki2.dovecot.org) or the pigeonhole website
# (http://pigeonhole.dovecot.org) for available plugins.
# The sieve_extprograms plugin is included in this release.
#sieve_plugins =
sieve_plugins = sieve_imapsieve sieve_extprograms
# The separator that is expected between the :user and :detail
# address parts introduced by the subaddress extension. This may
......@@ -211,4 +211,15 @@ plugin {
# Enables showing byte code addresses in the trace output, rather than only
# the source line numbers.
#sieve_trace_addresses = no
sieve_pipe_bin_dir = /usr/lib/dovecot/sieve
imapsieve_mailbox1_name = Spam
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_before = file:/var/lib/dovecot/sieve/report-spam.sieve
imapsieve_mailbox2_name = *
imapsieve_mailbox2_from = Spam
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:/var/lib/dovecot/sieve/report-ham.sieve
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment