## Dovecot configuration file

protocols = imap lmtp

auth_mechanisms = plain

{% if debug == true %}
auth_verbose = yes
auth_debug = yes
auth_debug_passwords = yes
auth_verbose_passwords = plain
auth_cache_size = 100M
mail_debug = yes
{% endif %}


mail_plugins = quota

# these are the capabilities Delta Chat cares about actually 
# so let's keep the network overhead per login small
# https://github.com/deltachat/deltachat-core-rust/blob/master/src/imap/capabilities.rs
imap_capability = IMAP4rev1 IDLE MOVE QUOTA CONDSTORE NOTIFY


# Authentication for system users.
passdb {
  driver = dict
  args = /etc/dovecot/auth.conf
}
userdb {
  driver = dict
  args = /etc/dovecot/auth.conf
}
##
## Mailbox locations and namespaces
##

# Mailboxes are stored in the "mail" directory of the vmail user home.
mail_location = maildir:/home/vmail/mail/%d/%u

namespace inbox {
  inbox = yes

  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Trash {
    special_use = \Trash
  }

  # For \Sent mailboxes there are two widely used names. We'll mark both of
  # them as \Sent. User typically deletes one of them if duplicates are created.
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
}

mail_uid = vmail
mail_gid = vmail
mail_privileged_group = vmail

##
## Mail processes
##

# Enable IMAP COMPRESS (RFC 4978).
# <https://datatracker.ietf.org/doc/html/rfc4978.html>
protocol imap {
  mail_plugins = $mail_plugins imap_zlib imap_quota
}

protocol lmtp {
  mail_plugins = $mail_plugins quota
}

plugin {
  imap_compress_deflate_level = 6
}

plugin {
  # for now we define static quota-rules for all users 
  quota = maildir:User quota
  quota_rule = *:storage={{ config.max_mailbox_size }}
  quota_max_mail_size=30M
  quota_grace = 0
  # quota_over_flag_value = TRUE
}



service lmtp {
  user=vmail

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

service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }
}

service auth-worker {
  # Default is root.
  # Drop privileges we don't need.
  user = vmail
}

service imap-login {
    # High-security mode.
    # Each process serves a single connection and exits afterwards.
    # This is the default, but we set it explicitly to be sure.
    # See <https://doc.dovecot.org/admin_manual/login_processes/#high-security-mode> for details.
    service_count = 1

    # Inrease the number of simultaneous connections.
    #
    # As of Dovecot 2.3.19.1 the default is 100 processes.
    # Combined with `service_count = 1` it means only 100 connections
    # can be handled simultaneously.
    process_limit = 10000

    # Avoid startup latency for new connections.
    process_min_avail = 10
}

ssl = required
ssl_cert = </var/lib/acme/live/{{ config.mail_domain }}/fullchain
ssl_key = </var/lib/acme/live/{{ config.mail_domain }}/privkey
ssl_dh = </usr/share/dovecot/dh.pem
ssl_min_protocol = TLSv1.2
ssl_prefer_server_ciphers = yes
