From 7eb6cc52e8be2571d270404ea63ffd6494626d0a Mon Sep 17 00:00:00 2001 From: shirenn <shirenn@crans.org> Date: Sat, 15 Jan 2022 17:47:39 +0100 Subject: [PATCH] [dovecot] Add quota --- roles/dovecot/tasks/main.yml | 1 + .../templates/dovecot/conf.d/10-mail.conf.j2 | 2 +- .../templates/dovecot/conf.d/90-quota.conf.j2 | 85 +++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 roles/dovecot/templates/dovecot/conf.d/90-quota.conf.j2 diff --git a/roles/dovecot/tasks/main.yml b/roles/dovecot/tasks/main.yml index 6886b145..417e5e2e 100644 --- a/roles/dovecot/tasks/main.yml +++ b/roles/dovecot/tasks/main.yml @@ -22,6 +22,7 @@ - conf.d/10-mail.conf - conf.d/10-master.conf - conf.d/10-ssl.conf + - conf.d/90-quota.conf - conf.d/auth-system.conf.ext - dovecot-ldap.conf.ext notify: Restart dovecot diff --git a/roles/dovecot/templates/dovecot/conf.d/10-mail.conf.j2 b/roles/dovecot/templates/dovecot/conf.d/10-mail.conf.j2 index 5e63d1b6..f74f10a8 100644 --- a/roles/dovecot/templates/dovecot/conf.d/10-mail.conf.j2 +++ b/roles/dovecot/templates/dovecot/conf.d/10-mail.conf.j2 @@ -202,7 +202,7 @@ mail_privileged_group = mail # Space separated list of plugins to load for all services. Plugins specific to # IMAP, LDA, etc. are added to this list in their own .conf files. -mail_plugins = $mail_plugins mail_log notify +mail_plugins = $mail_plugins mail_log notify quota ## ## Mailbox handling optimizations diff --git a/roles/dovecot/templates/dovecot/conf.d/90-quota.conf.j2 b/roles/dovecot/templates/dovecot/conf.d/90-quota.conf.j2 new file mode 100644 index 00000000..377c15d6 --- /dev/null +++ b/roles/dovecot/templates/dovecot/conf.d/90-quota.conf.j2 @@ -0,0 +1,85 @@ +## +## Quota configuration. +## + +# Note that you also have to enable quota plugin in mail_plugins setting. +# <doc/wiki/Quota.txt> + +## +## Quota limits +## + +# Quota limits are set using "quota_rule" parameters. To get per-user quota +# limits, you can set/override them by returning "quota_rule" extra field +# from userdb. It's also possible to give mailbox-specific limits, for example +# to give additional 100 MB when saving to Trash: + +plugin { + quota_rule = *:storage=10G + #quota_rule2 = Trash:storage=+100M + + # LDA/LMTP allows saving the last mail to bring user from under quota to + # over quota, if the quota doesn't grow too high. Default is to allow as + # long as quota will stay under 10% above the limit. Also allowed e.g. 10M. + #quota_grace = 10%% + + # Quota plugin can also limit the maximum accepted mail size. + #quota_max_mail_size = 100M +} + +## +## Quota warnings +## + +# You can execute a given command when user exceeds a specified quota limit. +# Each quota root has separate limits. Only the command for the first +# exceeded limit is executed, so put the highest limit first. +# The commands are executed via script service by connecting to the named +# UNIX socket (quota-warning below). +# Note that % needs to be escaped as %%, otherwise "% " expands to empty. + +plugin { +# quota_warning = storage=95%% quota-warning 95 %u +# quota_warning2 = storage=80%% quota-warning 80 %u + quota_warning = storage=95%% quota-warning 95 %u + quota_warning2 = storage=80%% quota-warning 80 %u +} + +# Example quota-warning service. The unix listener's permissions should be +# set in a way that mail processes can connect to it. Below example assumes +# that mail processes run as vmail user. If you use mode=0666, all system users +# can generate quota warnings to anyone. +service quota-warning { +# executable = script /usr/local/bin/quota-warning.sh + user = dovecot + unix_listener quota-warning { + user = vmail + } +} + +## +## Quota backends +## + +# Multiple backends are supported: +# dirsize: Find and sum all the files found from mail directory. +# Extremely SLOW with Maildir. It'll eat your CPU and disk I/O. +# dict: Keep quota stored in dictionary (eg. SQL) +# maildir: Maildir++ quota +# fs: Read-only support for filesystem quota + +plugin { + #quota = dirsize:User quota + quota = maildir:User quota + #quota = dict:User quota::proxy::quota + #quota = fs:User quota +} + +# Multiple quota roots are also possible, for example this gives each user +# their own 100MB quota and one shared 1GB quota within the domain: +plugin { + #quota = dict:user::proxy::quota + #quota2 = dict:domain:%d:proxy::quota_domain + #quota_rule = *:storage=102400 + #quota2_rule = *:storage=1048576 +} -- GitLab