Enable Sieve and ManageSieve for Dovecot

Enables both sieve and managesieved, and adds a global rule that moves
detected spam to a user's Junk folder automatically
This commit is contained in:
2026-08-15 17:29:41 -06:00
parent 7345eaceb1
commit 451903f663
7 changed files with 87 additions and 3 deletions
+1 -1
Submodule nodes updated: be7d719a1f...5fd2e23a01
@@ -0,0 +1,6 @@
require ["fileinto", "mailbox"];
if header :contains "X-Spam-Flag" "YES" {
fileinto :create "Junk";
stop;
}
+38 -2
View File
@@ -9,6 +9,8 @@
dovecot-ldap dovecot-ldap
dovecot-lmtpd dovecot-lmtpd
dovecot-pop3d dovecot-pop3d
dovecot-sieve
dovecot-managesieved
].each do |pkg| ].each do |pkg|
apt_package pkg apt_package pkg
end end
@@ -26,8 +28,8 @@ credentials = Chef::EncryptedDataBagItem.load('credentials', 'email')
template "/etc/dovecot/dovecot.conf" do template "/etc/dovecot/dovecot.conf" do
source "dovecot.conf.erb" source "dovecot.conf.erb"
mode 0644 mode 0644
# TODO variables protocols: "imap pop3 lmtp" # TODO variables protocols: "imap pop3 lmtp sieve"
variables protocols: "imap lmtp", variables protocols: "imap lmtp sieve",
# TODO find by email_proxy role # TODO find by email_proxy role
haproxy_trusted_networks: "10.1.1.167/32" haproxy_trusted_networks: "10.1.1.167/32"
notifies :restart, "service[dovecot]", :delayed notifies :restart, "service[dovecot]", :delayed
@@ -85,6 +87,40 @@ template "/etc/dovecot/conf.d/15-mailboxes.conf" do
notifies :restart, "service[dovecot]", :delayed notifies :restart, "service[dovecot]", :delayed
end end
template "/etc/dovecot/conf.d/20-lmtp.conf" do
source "dovecot_20-lmtp.conf.erb"
mode 0644
notifies :restart, "service[dovecot]", :delayed
end
template "/etc/dovecot/conf.d/90-sieve.conf" do
source "dovecot_90-sieve.conf.erb"
mode 0644
notifies :restart, "service[dovecot]", :delayed
end
# Directory for global Sieve scripts (applied after user scripts)
directory "/var/lib/dovecot/sieve" do
owner "dovecot"
group "dovecot"
mode 0755
end
# Global Sieve script run after every user script (sieve_after).
# Files spam flagged by SpamAssassin (X-Spam-Flag: YES) into the Junk folder.
cookbook_file "/var/lib/dovecot/sieve/after.sieve" do
source "after.sieve"
owner "dovecot"
group "dovecot"
mode 0644
notifies :run, "execute[compile after.sieve]", :immediately
end
execute "compile after.sieve" do
command "sievec /var/lib/dovecot/sieve/after.sieve"
action :nothing
end
service "dovecot" do service "dovecot" do
action [:enable, :start] action [:enable, :start]
end end
@@ -32,3 +32,9 @@ firewall_rule "IMAPS" do
port 993 port 993
protocol :tcp protocol :tcp
end end
firewall_rule "ManageSieve" do
command :allow
port 4190
protocol :tcp
end
@@ -60,6 +60,18 @@ service submission-login {
} }
} }
service managesieve-login {
inet_listener sieve {
port = 4190
ssl = yes
}
inet_listener sieve_haproxy {
port = 14190
ssl = yes
haproxy = yes
}
}
service lmtp { service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600 mode = 0600
@@ -0,0 +1,9 @@
##
## LMTP specific settings
##
# Enable the Sieve plugin for LMTP delivery so that Sieve scripts are
# executed for incoming mail handed over by Postfix.
protocol lmtp {
mail_plugins = $mail_plugins sieve
}
@@ -0,0 +1,15 @@
##
## Plugin settings (Sieve)
##
plugin {
# Per-user Sieve script storage. The "~" expands to mail_home
# (/var/vmail/%d/%n) set in 10-mail.conf, so scripts for LDAP virtual
# users are stored under ~/sieve/ with the active script symlinked at
# ~/.dovecot.sieve.
sieve = file:~/sieve;active=~/.dovecot.sieve
# Global Sieve script executed AFTER user scripts. Used to enforce
# server-side spam filing regardless of per-user rules.
sieve_after = /var/lib/dovecot/sieve/after.sieve
}