This documentation is for Dovecot v1.x, see wiki2 for v2.x documentation.

Dovecot v1.1 quota

Dovecot v1.1 has different quota configuration. You can also get it as a quota-rewrite patch for v1.0. The configuration is split into multiple settings:

First you have the quota root backend configuration. Quota root is a concept from IMAP Quota specifications. Normally you'll have only one quota root, but in theory there could be e.g. "user quota" and "domain quota" roots. It's unspecified how the quota roots interact with each others (if at all). In some systems for example INBOX could have a completely different quota root from the rest of the mailboxes (e.g. INBOX in /var/mail/ partition and others in /home/ partition).

Quota root configuration includes the backend name, quota root name and its parameters, if there are any:

quota = <backend>[:<quota root name>[:<backend args>]]

The quota root name is just an arbitrary string that is sent to IMAP clients, which in turn may show it to the user. The name has no meaning. By default an empty string is used, but you may want to change that since some clients (Apple Mail) break and don't show quota at all then.

You can define multiple quota roots by appending an increasing number, for example:

plugin {
  quota = maildir:User quota
  quota2 = fs:Disk quota
  #quota3 = ...

Quota rules

Quota rules configure the actual quota limits. The syntax is:

quota_rule = <mailbox name>:<limit configuration>
#quota_rule2 = ...
#quota_rule3 = ..etc..

"*" as the mailbox name configures the default limit, which is applied on top of a mailbox-specific limit if found. So for example:

quota_rule = *:storage=1G
quota_rule2 = Trash:storage=100M
quota_rule3 = SPAM:ignore

This means that the user has 1GB quota, but when saving messages to Trash mailbox it's possible to use up to 1,1GB of quota. The quota isn't specifically assigned to Trash, so if you had 1GB of mails in Trash you could still save 100MB of mails to Trash, but nothing to other mailboxes. The idea of this is mostly to allow the clients' move-to-Trash feature work while user is deleting messages to get under quota. Additionally, any messages in the SPAM folder are ignored per the ignore directive and would not count against the quota.

"?" as the mailbox name works almost like "*". The difference is that "?" is used only if quota backend doesn't override the limit. For example with Maildir++ quota if maildirsize file exists the limits are taken from it, but if it doesn't exist the "?" limits are used.

"*" can't be used as a generic wildcard in mailbox names, so for example "box*" wouldn't match "boxes". As shown in the above example, the first quota rule is named quota_rule while the following rules have an increasing digit in them. You can have as many quota rules as you want.

Limit configuration

The following limit names are supported:

All of these support also b/k/M/G/T/% suffixes. So storage=100M and bytes=100M both mean the exact same thing. messages=1k also means 1024 messages (not 1000).

Percents are relative to the default rule. For example:

plugin {
  quota = maildir:User quota
  quota_rule = *:storage=1GB
  # 10% of 1GB = 100MB
  quota_rule2 = Trash:storage=10%%
  # 20% of 1GB = 200MB
  quota_rule3 = Spam:storage=20%%

Note that % is written twice to escape it, because %variables are expanded in plugin section. userdb configuration may or may not require this escaping.

Backend-specific configuration currently is used only with Maildir++ quota backend. It means you can have the quota in Maildir++ format (e.g. "10000000S").

Per-user quota

You can override quota rules in your userdb's extra fields. Keep all the global settings in plugin section and override only those settings you need to in your userdb. For example:

plugin {
  quota = maildir:User quota
  quota_rule = *:storage=1G
  quota_rule2 = Trash:storage=100M

Next override the default 1GB quota for users:

user_attrs = homeDirectory=home,quotaBytes=quota_rule=*:bytes=%$

# MySQL:
user_query = select uid, gid, home, \
  concat('*:bytes=', quota_bytes) as quota_rule \
  from users where userid = '%u'

# MySQL with userdb prefetch: Remember to prefix quota_rule with userdb_
# (just like all other userdb extra fields):
password_query = select userid as user, password, \
  uid as userdb_uid, gid as userdb_gid, \
  concat('*:bytes=', quota_bytes) as userdb_quota_rule \
  from users where userid = '%u'

# Example passwd-file entries:

Quota for public namespaces (v1.2+)

You can create a separate namespace-specific quota that's shared between all users. This is done simply by adding :ns=<namespace prefix> parameter to quota setting. For example you could have something like:

namespace public {
  prefix = Public/
  #location = ..

plugin {
  quota = maildir:User quota
  quota2 = maildir:Shared quota:ns=Public/
  #quota_rules and quota2_rules..

Custom Quota Exceeded Message

You can configure Dovecot to send a custom string instead of the default quota exceeded message. You could have something like:

plugin {
   quota_exceeded_message = Quota exceeded, please go to for instructions on how to fix this.

Quota warnings

You can configure Dovecot to run an external command when user's quota exceeds a specified limit. Note that the warning is ONLY executed at the exact time when the limit is being crossed, so when you're testing it you have to do it by crossing the limit by saving a new mail. If something else besides Dovecot updates quota so that the limit is crossed, the warning is never executed. The syntax is:

quota_warning = <limit configuration> <command to run>
#quota_warning2 = ...
#quota_warning3 = ..etc..

Limit configuration is the exact same as for rules. Usually you want to use percents instead of absolute limits. Only the command for the first exceeded limit is executed, so configure the highest limit first.

An example configuration:

plugin {
  quota_warning = storage=95%% /usr/local/bin/ 95
  quota_warning2 = storage=80%% /usr/local/bin/ 80

With the above example when user's quota exceeds 80%, is executed with parameter 80. The same goes for when quota exceeds 95%. If user suddenly receives a huge mail and the quota jumps from 70% to 99%, only the 95 script is executed.

You have to create the script yourself. Here is an example that sends a mail to the user:



msg="From: $FROM
Subject: Your email quota is $PERCENT% full
Content-Type: text/plain; charset=UTF-8

Your mailbox is now $PERCENT% full."

echo -e "$msg" | /usr/sbin/sendmail -f $FROM "$USER"

exit 0

An alternative script using deliver would be:

cat << EOF | /usr/local/libexec/dovecot/deliver -d $USER -c /usr/local/etc/dovecot-nowarning.conf
Subject: quota warning

Your mailbox is now $PERCENT% full.

where dovecot-nowarning.conf is the same as dovecot.conf, minus the quota warning bits. This to avoid looping.

Per-user quota limit configuration examples


# MySQL, quota in bytes:
user_query = SELECT home, uid, gid, concat('*:storage=', quota_bytes, 'B') AS quota_rule FROM users WHERE userid = '%u'
# PostgreSQL, SQLite, quota in bytes:
user_query = SELECT home, uid, gid, '*:storage=' || quota_bytes || 'B' AS quota_rule FROM users WHERE userid = '%u'


user_attrs = homeDirectory=home,uidNumber=uid,gidNumber=gid,quotaBytes=quota_rule=*:storage=%$B

None: Quota/1.1 (last edited 2011-04-12 17:02:24 by poseidon)