Skip to content
Barry O'Donovan edited this page Feb 14, 2014 · 1 revision

This page explains how to use ViMbAdmin to set per user quotas with Dovecot.

Before you read this document, it is important that you understand how Dovecot implements quotas:

ViMbAdmin Quota Configuration Settings

From Domain Settings in Configuration, there were two options relating to quotas:

defaults.domain.quota = 0
defaults.domain.maxquota = 0

These are the default settings when creating a new domain. Zero means no / unlimited quotas.

quota defines the default quota to set when creating new mailboxes in ViMbAdmin. maxquota defines the maximum quota an admin can set for a mailbox when adding / editing them.

NB: maxquota does not define a maximum allowed quota over the entire domain. It just sets an upper limit that non-super admins can set per mailbox. You can achieve an overall quota by limited the number of mailboxes along with this option:

$max_quota_for_domain = $max_mailboxes_allowed * $maxquota

Configuring Quotas in Dovecot

The sample configuration for Dovecot in this Gist supports quotas as it is. You now need to augment this by setting the Dovecot /etc/dovecot/conf.d/90-quota.conf (or as appropriate for your system) as follows:

plugin {
  quota_rule = *:storage=1G
  quota_rule2 = Trash:storage=+100M
  quota_rule3 = Sent:storage=+100M
}

plugin {
  quota_warning = storage=95%% quota-warning 95 %u
  quota_warning2 = storage=80%% quota-warning 80 %u
}

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

plugin {
  quota = maildir:User quota
}

The above:

  • sets a default quota of 1GB per mailbox if there is no quota setting otherwise. As ViMbAdmin always sets a quota (0 - unlimited - by default), this will not have any effect for those mailboxes;
  • allows a 100MB grace for Sent and Trash folders;
  • sends a warning to the user when their quota reaches 80% and 95%;
  • uses the Maildir++ quota method (see Dovecot docs above).

You need to create the /usr/local/bin/quota-warning.sh file with something like the following:

#!/bin/sh

PERCENT=$1
USER=$2

cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing"
From: [email protected]
Subject: Mail service quota warning

Your mailbox is now $PERCENT% full.

You should delete some messages from the server.


WARNING: Do not ignore this message as if your mailbox
reaches 100% of quota, new mail will be rejected.

EOF

And make sure this is executable:

chmod a+x `/usr/local/bin/quota-warning.sh

Quotas should now be working. One configuration option that you should consider is form 15-lda.conf:

quota_full_tempfail = no

This determines how a mail is returned because a mailbox is full:

  • if no, then it's a hard bounce returned immediately to the sender;
  • if yes, then it's temp failed and the sender will not know for sometime.

FAQs / Notes

  • The Maildir++ record of the quota used may not be undated as frequently as you might like. This will only really affect mailboxes with small quotas (or huge emails). You can force quota refreshes by:
    • Compacting folders in your mail client;
    • Restarting Dovecot;
    • Executing doveadm quota recalc
  • Updating a quota on ViMbAdmin should have immediate effect on Dovecot for the next mail received (unless you're caching userdb information).