##
## Dovecot config file
##

# logging
log_path = /var/log/dovecot.log
#mail_debug=yes

disable_plaintext_auth = no
ssl = yes

protocols = imap pop3 lmtp sieve
auth_mechanisms = plain login

passdb {
  driver = sql
  args = /etc/dovecot/dovecot-mysql.conf
}

userdb {
  driver = sql
  args = /etc/dovecot/dovecot-mysql.conf
}

mail_location = maildir:/home/vmail/%d/%n

mail_uid = vmail
mail_gid = mail

first_valid_uid = 101
last_valid_uid = 101
first_valid_gid = 12
last_valid_gid = 12
mail_privileged_group = mail

mailbox_idle_check_interval = 30 secs
maildir_copy_with_hardlinks = yes

service imap-login {
  inet_listener imap {
    port = 143
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}

#service pop3-login {
#  inet_listener pop3 {
#    port = 110
#  }
#  inet_listener pop3s {
#    port = 995
#    ssl = yes
#  }
#}

service imap {
  vsz_limit = 256M
}

service pop3 {
}

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0600
    user = postfix
    group = postfix
  }
}

service auth {
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
    group = mail
  }

# postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }
}

service auth-worker {
  user = vmail
}

service dict {
  unix_listener dict {
    mode = 0660
    user = vmail
    group = mail
  }
}
service managesieve-login {
  inet_listener sieve {
    port = 4190
  }
  service_count = 1
  process_min_avail = 0
  vsz_limit = 64M
}
service managesieve {
}

ssl = yes
ssl_key = </etc/letsencrypt/live/zira.898.ro/privkey.pem
ssl_cert = </etc/letsencrypt/live/zira.898.ro/fullchain.pem
#ssl_protocols = !SSLv2 !SSLv3
ssl_min_protocol = TLSv1.2
ssl_cipher_list = AES128+EECDH:AES128+EDH
ssl_prefer_server_ciphers = yes # >Dovecot 2.2.6
#ssl_dh_parameters_length = 4096 # >Dovecot 2.2
ssl_verify_client_cert = no

lda_mailbox_autocreate = yes
lda_mailbox_autosubscribe = yes

protocol lda {
  mail_plugins = quota sieve
  postmaster_address = bogdan@898.ro
  auth_socket_path = /var/run/dovecot/auth-master
}

auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@

dict {
}

plugin {
  quota = maildir
}

protocol imap {
  mail_plugins = quota imap_quota trash
  imap_client_workarounds = delay-newmail
}

lmtp_save_to_detail_mailbox = yes

protocol lmtp {
  mail_plugins = sieve
}

protocol pop3 {
  mail_plugins = quota
  pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
}

protocol sieve {
  managesieve_max_line_length = 65536
  managesieve_implementation_string = Dovecot Pigeonhole
  managesieve_max_compile_errors = 5
}

#dict {
#  quotadict = mysql:/etc/dovecot/dovecot-dict-quota.conf
#}

plugin {
  quota = dict:User quota::proxy::sqlquota
  quota_rule = *:storage=5GB
  quota_rule2 = Trash:storage=+100M
  quota_grace = 10%%
  quota_exceeded_message = Quota exceeded, please contact your system administrator.
  quota_warning = storage=100%% quota-warning 100 %u
  quota_warning2 = storage=95%% quota-warning 95 %u
  quota_warning3 = storage=90%% quota-warning 90 %u
  quota_warning4 = storage=85%% quota-warning 85 %u
}

service quota-warning {
  executable = script /usr/bin/quota-warning.sh
  user = vmail

  unix_listener quota-warning {
    group = mail
    mode = 0660
    user = vmail
  }
}

dict {
  sqlquota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}

namespace inbox {
  #prefix = INBOX. # the namespace prefix isn't added again to the mailbox names.
  inbox = yes
  # ...

  mailbox Trash {
    auto = no
    special_use = \Trash
  }
  mailbox Drafts {
    auto = no
    special_use = \Drafts
  }
  mailbox Sent {
    auto = subscribe # autocreate and autosubscribe the Sent mailbox
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    auto = no
    special_use = \Sent
  }
  mailbox Spam {
    auto = create # autocreate Spam, but don't autosubscribe
    special_use = \Junk
  }
  mailbox virtual/All { # if you have a virtual "All messages" mailbox 
    auto = no
    special_use = \All
  }
}
