I have been running Dovecot for sometime, but I have just used someone else efforts on customizing it. Many of these throw out the dovecot/conf.d files for a single dovecot.conf with no explanation on what does what. So tell you a few conf.d files to edit.

So over the past few days, I have rolled up my sleeves and did my best to work out how to modify the proper conf.d files. To 'stay true' to the Dovecot maintainer's config organization.

The target is Centos7 with Dovecot 2.2.10-7

It was HARD!

Besides dovecot.conf, I had to modify 13 conf.d files. Add 3 .ext files in /etc/dovecot, and set up sieve.

I will soon have my total instructions available on my server, but to share with you what I have done for Dovecot customization and maybe to get some recommendations on improvements. For the most part, I have used SED to modify the conf files.

I use a few env variables:

your_domain_tld=
your_host_only=
your_host_tld=$your_host_only.$your_domain_tld
Postfix_Database_Password=


What follows are the pieces of my customization, all comments welcomed (this is NOT adequately tested! That is later in the week!):

sed -i -e "/^#protocols/s/$/ sieve/w /dev/stdout" /etc/dovecot/dovecot.conf
sed -i -e "s/^#protocols/protocols/w /dev/stdout" /etc/dovecot/dovecot.conf
sed -i -e "s/#quota = /sqlquota = /w /dev/stdout" /etc/dovecot/dovecot.conf

sed -i -e "/^auth_mechanisms/s/$/ login/w /dev/stdout" /etc/dovecot/conf.d/10-auth.conf sed -i -e 's/^#!include auth-sql.conf.ext/!include auth-sql.conf.ext/w /dev/stdout' /etc/dovecot/conf.d/10-auth.conf

sed -i -e "0,/#userdb {/ s/#userdb {/userdb {/w /dev/stdout" /etc/dovecot/conf.d/auth-sql.conf.ext sed -i -e "s/# driver = prefetch/ driver = prefetch\n }/w /dev/stdout" /etc/dovecot/conf.d/auth-sql.conf.ext

sed -i -e "/^#mail_location/s/$/maildir:\/home\/vmail\/%d\/%n/w /dev/stdout" /etc/dovecot/conf.d/10-mail.conf sed -i -e "s/^#mail_location/mail_location/w /dev/stdout" /etc/dovecot/conf.d/10-mail.conf sed -i -e "s/first_valid_uid = 1000/first_valid_uid = 101/w /dev/stdout" /etc/dovecot/conf.d/10-mail.conf sed -i -e "s/#first_valid_gid = 1/first_valid_gid = 12/w /dev/stdout" /etc/dovecot/conf.d/10-mail.conf

sed -i "/unix_listener auth-userdb/ a mode = 0666\n user = vmail\n group = mail" /etc/dovecot/conf.d/10-master.conf sed -i "/#unix_listener \/var\/spool/ a mode = 0666\n user = postfix\n group = postfix\n }" /etc/dovecot/conf.d/10-master.conf sed -i -e "s/#unix_listener \/var\/spool/unix_listener \/var\/spool/w /dev/stdout" /etc/dovecot/conf.d/10-master.conf sed -i "/unix_listener dict/ a mode = 0666\n user = vmail\n group = mail" /etc/dovecot/conf.d/10-master.conf sed -i -e "s/^mode/ mode/w /dev/stdout" /etc/dovecot/conf.d/10-master.conf

sed -i -e "s/dovecot\/certs\/dovecot.pem/tls\/certs\/$your_host_tld.crt/w /dev/stdout" /etc/dovecot/conf.d/10-ssl.conf sed -i -e "s/dovecot\/private\/dovecot.pem/tls\/private\/$your_host_tld.key/w /dev/stdout" /etc/dovecot/conf.d/10-ssl.conf

sed -i -e "/^#postmaster_address/s/$/ postmaster@$your_domain_tld/w /dev/stdout" /etc/dovecot/conf.d/15-lda.conf sed -i -e "s/^#postmaster_address/postmaster_address/w /dev/stdout" /etc/dovecot/conf.d/15-lda.conf sed -i "/#mail_plugins/ a mail_plugins = quota sieve" /etc/dovecot/conf.d/15-lda.conf sed -i -e "s/^mail_plugins/ mail_plugins/w /dev/stdout" /etc/dovecot/conf.d/15-lda.conf sed -i -e "s/^#lda_mailbox_autocreate = no/lda_mailbox_autocreate = yes/w /dev/stdout" /etc/dovecot/conf.d/15-lda.conf sed -i -e "s/^#lda_mailbox_autosubscribe = no/lda_mailbox_autosubscribe = yes/w /dev/stdout" /etc/dovecot/conf.d/15-lda.conf

sed -i "/#mail_plugins / a mail_plugins = quota imap_quota trash" /etc/dovecot/conf.d/20-imap.conf sed -i -e "s/^mail_plugins/ mail_plugins/w /dev/stdout" /etc/dovecot/conf.d/20-imap.conf sed -i "/#imap_client_workarounds/ a imap_client_workarounds = delay-newmail" /etc/dovecot/conf.d/20-imap.conf

sed -i "/#mail_plugins/ a mail_plugins = sieve" /etc/dovecot/conf.d/20-lmtp.conf sed -i -e "s/^mail_plugins/ mail_plugins/w /dev/stdout" /etc/dovecot/conf.d/20-lmtp.conf sed -i -e "s/^#lmtp_save_to_detail_mailbox = no/lmtp_save_to_detail_mailbox = yes/w /dev/stdout" /etc/dovecot/conf.d/20-lmtp.conf

sed -i -e "s/#service managesieve-login/service managesieve-login/w /dev/stdout" /etc/dovecot/conf.d/20-managesieve.conf sed -i -e "s/#inet_listener sieve {/inet_listener sieve {/w /dev/stdout" /etc/dovecot/conf.d/20-managesieve.conf sed -i -e "s/# port = 4190/ port = 4190\n }/w /dev/stdout" /etc/dovecot/conf.d/20-managesieve.conf
sed -i "/#vsz_limit/ a }" /etc/dovecot/conf.d/20-managesieve.conf

sed -i "/#mail_plugins/ a mail_plugins = quota" /etc/dovecot/conf.d/20-pop3.conf sed -i -e "s/^mail_plugins/ mail_plugins/w /dev/stdout" /etc/dovecot/conf.d/20-pop3.conf sed -i "/#pop3_client_workarounds/ a pop3_client_workarounds = outlook-no-nuls oe-ns-eoh" /etc/dovecot/conf.d/20-pop3.conf

sed -i -e "s/#acl = /acl = /w /dev/stdout" /etc/dovecot/conf.d/90-acl.conf

sed -i -e "s/#sieve_before =/sieve_before = \/home\/sieve\/globalfilter.sieve/w /dev/stdout" /etc/dovecot/conf.d/90-sieve.conf

cat <<EOF>>/etc/dovecot/conf.d/90-quota.conf || exit 1
plugin {
  quota = dict:user::proxy::sqlquota
  trash = /etc/dovecot/dovecot-trash.conf.ext
}
EOF

cat <<EOF>/etc/dovecot/dovecot-trash.conf.ext || exit 1
# Spam mailbox is emptied before Trash
1 Spam
# Trash mailbox is emptied before Sent
# 2 Trash
# If both Sent and "Sent Messages" mailboxes exist, the next oldest message
# to be deleted is looked up from both of the mailboxes.
# 3 Sent
# 3 Sent Messages
EOF

cat <<EOF>/etc/dovecot/dovecot-sql.conf.ext || exit 1
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=$Postfix_Database_Password
default_pass_scheme = MD5-CRYPT

# following should all be on one line.
password_query = SELECT username as user, password, concat('/home/vmail/', maildir) as userdb_home, concat('maildir:/home/vmail/', maildir) as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'

# following should all be on one line
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 101 AS uid, 12 AS gid, CONCAT('*:messages=30000:bytes=', quota) as quota_rule FROM mailbox WHERE username = '%u' AND active = '1'
EOF

cat <<EOF>/etc/dovecot/dovecot-dict-sql.conf.ext || exit 1
connect = host=localhost dbname=postfix user=postfix password=$Postfix_Database_Password
map {
  pattern = priv/quota/storage
  table = quota2
  username_field = username
  value_field = bytes
}
map {
  pattern = priv/quota/messages
  table = quota2
  username_field = username
  value_field = messages
}
EOF

mkdir /home/sieve
cat <<EOF>/home/sieve/globalfilter.sieve || exit 1
require "fileinto";
  if header :contains "X-Spam-Flag" "YES" {
    fileinto "Spam";
  }
  if header :contains "subject" "***SPAM***" {
    fileinto "Spam";
  }
EOF

sievec /home/sieve/globalfilter.sieve
chown -R vmail:mail /home/sieve

Reply via email to