Enables both sieve and managesieved, and adds a global rule that moves detected spam to a user's Junk folder automatically
127 lines
3.5 KiB
Ruby
127 lines
3.5 KiB
Ruby
#
|
|
# Cookbook:: kosmos_email
|
|
# Recipe:: dovecot
|
|
#
|
|
|
|
%w[
|
|
dovecot-core
|
|
dovecot-imapd
|
|
dovecot-ldap
|
|
dovecot-lmtpd
|
|
dovecot-pop3d
|
|
dovecot-sieve
|
|
dovecot-managesieved
|
|
].each do |pkg|
|
|
apt_package pkg
|
|
end
|
|
|
|
domain = node["email"]["domain"]
|
|
hostname = node["email"]["hostname"]
|
|
root_dir = node["email"]["root_directory"]
|
|
ip_addr = node["knife_zero"]["host"]
|
|
|
|
ldap_search_base = node["email"]["ldap_search_base"]
|
|
ldap_user_filter = "(&(objectClass=person)(mailRoutingAddress=%u))"
|
|
|
|
credentials = Chef::EncryptedDataBagItem.load('credentials', 'email')
|
|
|
|
template "/etc/dovecot/dovecot.conf" do
|
|
source "dovecot.conf.erb"
|
|
mode 0644
|
|
# TODO variables protocols: "imap pop3 lmtp sieve"
|
|
variables protocols: "imap lmtp sieve",
|
|
# TODO find by email_proxy role
|
|
haproxy_trusted_networks: "10.1.1.167/32"
|
|
notifies :restart, "service[dovecot]", :delayed
|
|
end
|
|
|
|
template "/etc/dovecot/dovecot-ldap.conf.ext" do
|
|
source "dovecot-ldap.conf.ext.erb"
|
|
mode 0600
|
|
variables uris: "ldap://ldap.kosmos.local", # TODO add list of all IPs instead?
|
|
dn: credentials['ldap_dn'],
|
|
dnpass: credentials['ldap_dnpass'],
|
|
base: ldap_search_base,
|
|
user_filter: ldap_user_filter,
|
|
user_attrs: "",
|
|
pass_filter: ldap_user_filter,
|
|
pass_attrs: "mailRoutingAddress=user,mailpassword=password",
|
|
default_pass_scheme: "BLF-CRYPT"
|
|
notifies :restart, "service[dovecot]", :delayed
|
|
end
|
|
|
|
template "/etc/dovecot/conf.d/10-auth.conf" do
|
|
source "dovecot_10-auth.conf.erb"
|
|
mode 0644
|
|
notifies :restart, "service[dovecot]", :delayed
|
|
end
|
|
|
|
template "/etc/dovecot/conf.d/10-mail.conf" do
|
|
source "dovecot_10-mail.conf.erb"
|
|
mode 0644
|
|
variables mail_uid: "vmail",
|
|
mail_gid: "mail",
|
|
mail_location: "mbox:~/mail:INBOX=~/mail/INBOX",
|
|
mail_home: "#{root_dir}/%d/%n"
|
|
notifies :restart, "service[dovecot]", :delayed
|
|
end
|
|
|
|
template "/etc/dovecot/conf.d/10-master.conf" do
|
|
source "dovecot_10-master.conf.erb"
|
|
mode 0644
|
|
notifies :restart, "service[dovecot]", :delayed
|
|
end
|
|
|
|
template "/etc/dovecot/conf.d/10-ssl.conf" do
|
|
source "dovecot_10-ssl.conf.erb"
|
|
mode 0644
|
|
variables ssl: "required",
|
|
ssl_cert: node['postfix']['main']['smtpd_tls_cert_file'],
|
|
ssl_key: node['postfix']['main']['smtpd_tls_key_file']
|
|
notifies :restart, "service[dovecot]", :delayed
|
|
end
|
|
|
|
template "/etc/dovecot/conf.d/15-mailboxes.conf" do
|
|
source "dovecot_15-mailboxes.conf.erb"
|
|
mode 0644
|
|
notifies :restart, "service[dovecot]", :delayed
|
|
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
|
|
action [:enable, :start]
|
|
end
|