Dovecot Plugin - quota (doveadm-quota)

最後更新: 2016-06-27

介紹

  • user quota
  • domain quota

 


Backend

 

Backends: keeps track of the current quota usage.

format

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

backend

  • fs: Filesystem quota
  • dict: dictionary quota backend (Store quota usage in Files, Redis, SQL)
  • maildir: Store quota usage in Maildir++ maildirsize files.

Remark: dict

[1] quota limits

The dictionary stores only the current quota usage.

The quota limits are still configured in userdb the same way as with other quota backends.

用 SQL User backend 時是 "user_query =  SELECT email as user, maildir as home ..."

[2] flat file

The Dovecot user process (imap, pop3 or lda) needs write access to this file

dict:user::file:/var/vmail/%d/%n/.quotausage

"quota root name":

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.

i.e. Setting

[1]

plugin {
  quota = dict:user::proxy::quotadict
}

[2]

plugin {
  quota = maildir:User quota
}

 


quota_rule

 

Quota rules configure the actual quota limits.

Syntax

quota_rule = <mailbox name>:<limit configuration>

i.e.

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

"*"

as the mailbox name configures the default limit, which is applied on top of a mailbox-specific limit if found.

"Trash:storage=+100M"

when saving messages to Trash 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.

Limit configuration

0 means unlimited

  • storage: Quota limit in kilobytes,
  • bytes: Quota limit in bytes
  • messages: Quota limit in number of messages. This probably isn't very useful
  • backend: Quota backend-specific limit configuration
  • ignore: Don't include the specified mailbox in quota at all

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%%
}

 


quota exceeded message

 

# You can configure Dovecot to send a custom string instead of the default quota exceeded message.

quota_exceeded_message = </path/to/quota_exceeded_message.txt

 


quota_warning

 

quota_warning = <limit configuration> <quota-warning_socket_name> <parameters>

* warning is ONLY executed at the exact time when the limit is being crossed

* If user suddenly receives a huge mail and the quota jumps from 70% to 99%, only the 95 script is executed.

* Only the command for the first exceeded limit is executed, so configure the highest limit first.

* use percents instead of absolute limits

i.e.

plugin {
  quota_warning = storage=90%% quota-warning 90 %u
  quota_warning1 = storage=80%% quota-warning 80 %u
  ....
}

Socket

service quota-warning {
  executable = script /usr/local/bin/quota-warning.sh
  # use some unprivileged user for executing the quota warnings
  user = vmail
  unix_listener quota-warning {
  }
}

executable (script)

#!/bin/sh

PERCENT=$1
FROM="[email protected]"

msg="From: $FROM
To: $USER
To: [email protected]
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

 


Summary

 

/etc/dovecot/dovecot.conf

mail_plugins = quota

plugin {
    auth_socket_path = /var/run/dovecot/auth-master

    quota = dict:user::proxy::quotadict
    quota_rule = *:storage=1G
    quota_rule1 = Trash:storage=1G

    # Quota warning.
    quota_warning  = storage=95%% quota-warning 95 %u
    quota_warning2 = storage=90%% quota-warning 90 %u
    quota_warning3 = storage=85%% quota-warning 85 %u

    ....
}

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

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

    ....
}

/etc/dovecot/dovecot-used-quota.conf

connect = host=127.0.0.1 dbname=vmail user=vmailadmin password=????
map {
    pattern = priv/quota/storage
    table = used_quota
    username_field = username
    value_field = bytes
}
map {
    pattern = priv/quota/messages
    table = used_quota
    username_field = username
    value_field = messages
}

/usr/local/bin/dovecot-quota-warning.sh

 


doveadm quota command

 

# get

doveadm quota get -u x@y

Quota name                                              Type      Value   Limit  %
user                                                    STORAGE 3071999 3072000 99
user                                                    MESSAGE    3347       -  0

# recalc

doveadm quota recalc -u x@y

  * dict quota is recalculated only if the quota goes below zero

     ( delete from used_quota where username='U@D' limit 1;)

# Recalculate ALL mail accounts:

doveadm quota recalc -A

  * When the SQL userdb module is used make sure that

     the iterate_query setting in /etc/dovecot/dovecot-sql.conf.ext matches your database layout.

Troubleshoot

[1] 與 "du -sh" 有不同的 result

maildir_copy_with_hardlinks=yes (default):

When copying a message, do it with hard links whenever possible.

This makes the performance much better, and it's unlikely to have any side effects.

Only reason to disable this is if you're using a filesystem where hard links are slow (e.g. HFS+).

[2]

doveadm(root): Fatal: Unknown command 'quota', but plugin quota exists. Try to set mail_plugins=quota

global setting 要有 "mail_plugins=quota" (protocol imap, pop3 依然要有 "mail_plugins = $mail_plugins imap_quota" )

imap_quota: For reporting quota information via IMAP.

 

Creative Commons license icon Creative Commons license icon