Exim - Step3: dovecot + pigeonhole

/etc/dovecot/dovecot.conf
base_dir = /var/run/dovecot/
listen = *
protocols = pop3 imap sieve

disable_plaintext_auth = no
ssl = yes
#ssl = required
ssl_verify_client_cert = no
ssl_cipher_list = ALL:!LOW:!SSLv2:!EXP:!aNULL
ssl_cert =  method=%m rip=%r lip=%l %c
login_log_format = %$: %s
syslog_facility = mail
log_path=/var/log/dovecot.log
info_log_path=/var/log/dovecot/dovecot-info.log
verbose_proctitle = yes
verbose_ssl=no
lda_mailbox_autocreate=yes

namespace inbox {
  inbox = yes
  location = maildir:/data/mail/%d/%n/Maildir
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Spam {
    special_use = \Junk
  }
  mailbox junkmail {
    special_use = \Junk
  }
  mailbox "&BB0ENQQ2BDUEOwQwBEIENQQ7BEwEPQQwBE8- &BD8EPgRHBEIEMA-" {
    special_use = \Junk
  }
  mailbox Trash {
    special_use = \Trash
  }
  mailbox "Deleted Messages" {
    special_use = \Trash
  }
  mailbox "&BCMENAQwBDsENQQ9BD0ESwQ1-" {
    special_use = \Trash
  }
  mailbox Sent {
    special_use = \Sent
    auto=subscribe
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox "&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-" {
    special_use = \Sent
  }
  prefix =
  separator = /
  type = private
}

passdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf
}
userdb {
 driver = sql
 args = /etc/dovecot/dovecot-sql.conf
}
service auth {
  unix_listener auth-client {
    mode = 0660
    user = mail
    group = mail
  }
  unix_listener auth-master {
    mode = 0664
    user = mail
    group = mail
  }
  client_limit = 1024
  user = root
}
service imap-login {
  chroot = login
  client_limit = 1024
  service_count = 0
  user = mail
}
service pop3-login {
  chroot = login
  service_count = 1
  user = mail
  vsz_limit = 64 M
}
protocol pop3 {
  pop3_lock_session = yes
  mail_max_userip_connections = 5
  pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
  pop3_uidl_format = %08Xu%08Xv
  mail_plugins = quota mail_log notify
}
protocol imap {
  imap_client_workarounds = delay-newmail tb-extra-mailbox-sep tb-lsub-flags
  imap_idle_notify_interval = 2 mins
  imap_logout_format = in=%i out=%o
  imap_max_line_length = 64 k
  mail_max_userip_connections = 30
  mail_plugins = quota imap_quota mail_log notify
}
protocol lda {
  auth_socket_path = /var/run/dovecot/auth-master
  postmaster_address = [email protected]
  sendmail_path = /usr/sbin/sendmail
  mail_plugins = sieve quota
}
service managesieve {
 user = mail
}
service managesieve-login {
 inet_listener sieve {
  port = 4190
 }
 service_count = 1
 user = mail
 process_min_avail = 1
 vsz_limit = 64M
}
protocol sieve {
  mail_max_userip_connections = 1024
  managesieve_logout_format = bytes=%i/%o
  managesieve_implementation_string = Cyrus timsieved v2.2.13
  managesieve_max_compile_errors = 5
}
plugin {
 mail_log_events = delete undelete expunge copy mailbox_delete mailbox_rename flag_change save
 mail_log_fields = uid box msgid size from subject
 quota = maildir:User quota
 #quota_rule = *:storage=1GB
 quota_rule2 = Trash:ignore
 quota_rule3 = Spam:ignore
 quota_rule4 = Sent:storage=+10%%
 quota_exceeded_message = Mailbox is full!
# quota_warning = storage=80%% quota-warning 80 %u
# quota_warning2 = storage=90%% quota-warning 90 %u
# quota_warning3 = -storage=100%% quota-warning below %u # user is no longer over quota

 sieve = ~/.dovecot.sieve
 sieve_dir = ~/sieve
 # before users scripts
 sieve_before = /etc/dovecot/.dovecot_discard_spam.sieve
 # after user scripts
 #sieve_after = /var/lib/dovecot/sieve/after.d/
 # default filter
 # sieve_global_path = /etc/dovecot/.dovecot.sieve
 sieve_global_dir = /data/mail/_sieve/
 sieve_max_script_size = 1M
 sieve_max_actions = 32
 sieve_max_redirects = 8
 sieve_quota_max_scripts = 30
 autocreate = Trash
 autocreate2 = Sent
 autocreate3 = Drafts
 autocreate4 = Junk
 autocreate5 = Archive
 expire = Trash
 expire2 = Trash/*
 expire3 = Junk
}

sql prefs
cat << EOF >> /etc/dovecot/dovecot-sql.conf
driver = mysql
connect = host=localhost dbname=exim user=exim [email protected]
default_pass_scheme = PLAIN
password_query = SELECT EXIM_GET_PWD('%u') as password
user_query = SELECT 'mail' as uid, 'mail' as gid, '/data/mail/%d/%n' as home, '/data/mail/%d/%n/Maildir' as mail, CONCAT('*:storage=', quota, 'M') as quota_rule FROM users WHERE login = '%u' LIMIT 1
#--- MySQL Function ---
#delimiter //
#CREATE FUNCTION `EXIM_GET_PWD` (p VARCHAR(128))
# RETURNS VARCHAR(64)
#BEGIN
# UPDATE `users` SET `lastactive`=CONCAT(curdate(),' ',curtime()) WHERE `login` = TRIM(p) LIMIT 1;
# RETURN (SELECT `passwd` FROM `users` WHERE `login` = TRIM(p) LIMIT 1);
#END;
#//
EOF
logrotate
cat << EOF >> /etc/logrotate.d/dovecot
/var/log/dovecot/dovecot*.log {
  weekly
  rotate 52
  missingok
  notifempty
  compress
  sharedscripts
  postrotate
    doveadm log reopen
  endscript
}
EOF
service rsyslog restart
Default filter to move marked mails to Junk
cat << EOF >> /etc/dovecot/.dovecot_discard_spam.sieve
require ["imap4flags","fileinto"];
if exists "X-Spam-Junk" {
        setflag "\\Seen";
        fileinto "Junk";
        stop;
}
EOF

sievec /etc/dovecot/.dovecot_discard_spam.sieve
service dovecot restart