diff --git a/defaults/main.yml b/defaults/main.yml index 984a321..468ec36 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -35,6 +35,9 @@ dovecot_mail_plugins_imap: $mail_plugins imap_quota dovecot_lda_mailbox_autosubscribe: "yes" dovecot_lda_mail_plugins_extra: sieve dovecot_junk_trash_autoexpunge: 30d +dovecot_sieve_location: /var/vmail/%d/%n/.dovecot.sieve +dovecot_sieve_before: /etc/dovecot/sieve-before/spam-to-junk.sieve +dovecot_sieve_max_redirects: 20 # See https://wiki.dovecot.org/LoginProcess for performance tuning dovecot_login_service_count: 1 diff --git a/files/sieve-before/spam-to-junk.sieve b/files/sieve-before/spam-to-junk.sieve new file mode 100644 index 0000000..476a52a --- /dev/null +++ b/files/sieve-before/spam-to-junk.sieve @@ -0,0 +1,4 @@ +require "fileinto"; +if header :contains "X-Spam-Flag" "YES" { + fileinto "Junk"; +} \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml index 9d25477..0ff3884 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -32,3 +32,8 @@ systemd: daemon_reload: true become: true + +- name: Compile sieve-before scripts # noqa no-changed-when + command: /usr/bin/sievec /etc/dovecot/sieve-before + notify: + - restart dovecot diff --git a/tasks/main.yml b/tasks/main.yml index 5facb57..0210a33 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -100,6 +100,9 @@ tags: - molecule-notest +- name: Import sieve-before tasks + import_tasks: sieve-before.yml + - name: Configure dovecot template: src: "{{ item }}.j2" @@ -115,7 +118,9 @@ - 15-lda.conf - 15-mailboxes.conf - 20-imap.conf + - 20-managesieve.conf - 90-quota.conf + - 90-sieve.conf - 90-stats.conf notify: Restart dovecot diff --git a/tasks/sieve-before.yml b/tasks/sieve-before.yml new file mode 100644 index 0000000..bcded36 --- /dev/null +++ b/tasks/sieve-before.yml @@ -0,0 +1,19 @@ +--- + +- name: Ensure sieve-before dir is present + file: + path: /etc/dovecot/sieve-before + owner: root + group: root + mode: 0755 + state: directory + +- name: Copy sieve-before script + copy: + src: sieve-before/spam-to-junk.sieve + dest: /etc/dovecot/sieve-before/spam-to-junk.sieve + owner: root + group: root + mode: 0644 + notify: + - Compile sieve-before scripts diff --git a/templates/20-managesieve.conf.j2 b/templates/20-managesieve.conf.j2 new file mode 100644 index 0000000..526a6a3 --- /dev/null +++ b/templates/20-managesieve.conf.j2 @@ -0,0 +1,84 @@ +## +## ManageSieve specific settings +## + +# Uncomment to enable managesieve protocol: +protocols = $protocols sieve + +# Service definitions + +service managesieve-login { + #inet_listener sieve { + # port = 4190 + #} + + #inet_listener sieve_deprecated { + # port = 2000 + #} + + # Number of connections to handle before starting a new process. Typically + # the only useful values are 0 (unlimited) or 1. 1 is more secure, but 0 + # is faster. + #service_count = 1 + + # Number of processes to always keep waiting for more connections. + #process_min_avail = 0 + + # If you set service_count=0, you probably need to grow this. + #vsz_limit = 64M +} + +service managesieve { + # Max. number of ManageSieve processes (connections) + #process_limit = 1024 +} + +# Service configuration + +protocol sieve { + # Maximum ManageSieve command line length in bytes. ManageSieve usually does + # not involve overly long command lines, so this setting will not normally + # need adjustment + #managesieve_max_line_length = 65536 + + # Maximum number of ManageSieve connections allowed for a user from each IP + # address. + # NOTE: The username is compared case-sensitively. + #mail_max_userip_connections = 10 + + # Space separated list of plugins to load (none known to be useful so far). + # Do NOT try to load IMAP plugins here. + #mail_plugins = + + # MANAGESIEVE logout format string: + # %i - total number of bytes read from client + # %o - total number of bytes sent to client + # %{put_bytes} - Number of bytes saved using PUTSCRIPT command + # %{put_count} - Number of scripts saved using PUTSCRIPT command + # %{get_bytes} - Number of bytes read using GETCRIPT command + # %{get_count} - Number of scripts read using GETSCRIPT command + # %{get_bytes} - Number of bytes processed using CHECKSCRIPT command + # %{get_count} - Number of scripts checked using CHECKSCRIPT command + # %{deleted_count} - Number of scripts deleted using DELETESCRIPT command + # %{renamed_count} - Number of scripts renamed using RENAMESCRIPT command + #managesieve_logout_format = bytes=%i/%o + + # To fool ManageSieve clients that are focused on CMU's timesieved you can + # specify the IMPLEMENTATION capability that Dovecot reports to clients. + # For example: 'Cyrus timsieved v2.2.13' + #managesieve_implementation_string = Dovecot Pigeonhole + + # Explicitly specify the SIEVE and NOTIFY capability reported by the server + # before login. If left unassigned these will be reported dynamically + # according to what the Sieve interpreter supports by default (after login + # this may differ depending on the user). + #managesieve_sieve_capability = + #managesieve_notify_capability = + + # The maximum number of compile errors that are returned to the client upon + # script upload or script verification. + #managesieve_max_compile_errors = 5 + + # Refer to 90-sieve.conf for script quota configuration and configuration of + # Sieve execution limits. +} diff --git a/templates/90-sieve.conf.j2 b/templates/90-sieve.conf.j2 new file mode 100644 index 0000000..ffb70c7 --- /dev/null +++ b/templates/90-sieve.conf.j2 @@ -0,0 +1,207 @@ +## +## Settings for the Sieve interpreter +## + +# Do not forget to enable the Sieve plugin in 15-lda.conf and 20-lmtp.conf +# by adding it to the respective mail_plugins= settings. + +# The Sieve interpreter can retrieve Sieve scripts from several types of +# locations. The default `file' location type is a local filesystem path +# pointing to a Sieve script file or a directory containing multiple Sieve +# script files. More complex setups can use other location types such as +# `ldap' or `dict' to fetch Sieve scripts from remote databases. +# +# All settings that specify the location of one ore more Sieve scripts accept +# the following syntax: +# +# location = [:]path[;