Configuring Domain & User Mailbox Quotas in Dovecot via PostfixAdmin on Ubuntu 12.04LTS

piaoling  2014-07-10 13:25:24

Background

This article attempts to document how to configure Dovecot and domain & users’ mailbox quota sizes using information contained within PostfixAdmin and its associated tables.

During PostfixAdmin install time, the database is requested where PostfixAdmin can store additional tables.  Selecting the same database as postfix itself neatly installs these additional tables, that can then be used by Dovecot to monitor mailbox quota sizes.

Domain & User Quota Sizes

There are two different types of quota sizes, one is set for the entire domain, the other can be done on a per user mailbox basis.  These domain or user mailbox quotas can be administered within PostfixAdmin, with the SuperAdmin account setting the domain quota limit, and mail domain admins setting the user mailbox quota limit, on a user by user basis.  This control is obviously useful, as if all user mailboxes had unlimited space disk space could easily run out jeopardising the whole system.

Configuring PostfixAdmin To Enable Quota Limits

Within the file/etc/postfixadmin/config.inc.phpthe following parameters need altering :

File Exercpt: /etc/postfixadmin/config.inc.php
1
2
3
4
$CONF['quota'] ='YES';
 
$CONF['used_quota_table'] ='YES';
$CONF['new_quota_table'] ='YES';

These enable the quota configuration withinPostfixAdmin, note that thenew_quota_tableparameter is to be enabled for version of Dovecot 1.2 and above.

After enabling these various setting abovePostfixAdminwill now populate the Postfix MySQL fields :

  • quotain the tablemailboxthis is the user quota limit which postfixadmin enters in Megabytes and is stored in bytes.
  • maxquotain thedomaintable – this is the domain quota limit stored.  The SuperAdmin within PostfixAdmin has control over this value.

This concludes the configuration for PostfixAdmin, next we will need to configure Dovecot so that it recognises quota limits.

Enabling Quota Mailbox Limits in Dovecot

Tracking quotas for domain and users’ mailboxes are stored within MySQL tables domain and the quota field, and the table quota2 field bytes respectively.  Dovecot needs to be informed of these tables as follows:

  • /etc/dovecot/dovecot-dict-sql-user.conf– this file contains mapping information for the users’ mailbox quota size.
  • /etc/dovecot/dovecot-dict-sql-domain.conf– this file contains mapping information for the domain mailbox quota size, referencing the domain table.
  • /etc/dovecot/dovecot.conf– changes need to be made to this so that dovecot is aware it needs its quota plugins for POP3 and IMAP, and that it is to store the current quota sizes in MySQL tables referred in the/etc/dovecot-dict*.conffiles.
  • /etc/dovecot/dovecot-sql.conf– changes to this file are needed, as the quota limits are retrieved from thedomain, and/ormailboxtables, and returned as additional fields back to dovecot.

Create file/etc/dovecot/dovecot-dict-sql-user.conf, and populate it with the following information ensure that you change"postfix_complex_password"to the MySQL mail access account that can select, update, delete thequota2table:

File :/etc/dovecot/dovecot-dict-sql-user.conf

connect = host=localhost dbname=postfix user=postfix password=postfix_complex_password
 
map {
  pattern = priv/quota/storage
  table = quota2
  username_field = username
  value_field = bytes
}
map {
  pattern = priv/quota/messages
  table = quota2
  username_field = username
  value_field = messages
}

Create/etc/dovecot/dovecot-dict-sql-domain.conf, again change"postfix_complex_password"to match the user account the postfix uses to adminster its tables as follows:

File: /etc/dovecot/dovecot-dict-sql-domain.conf

connect = host=localhost dbname=postfix user=postfix password=postfix_complex_password
 
map {
    pattern = priv/quota/storage
    table = domain
    username_field = domain
    value_field = quota
}
 
map {
    pattern = priv/quota/messages
    table = quota2
    username_field = username
    value_field = messages
}

Next, the file/etc/dovecot/dovecot.confneeds the following changes to be made, this will allowDovecotto be able to write the domain, and users mailboxes current quota sizes to thedomainandquota2tables respectively.

File: /etc/dovecot/dovecot.conf

mail_plugins = $mail_plugins quota
 
userdb {
    args = /etc/dovecot/dovecot-sql.conf
    driver = sql
}
 
passdb {
    args = /etc/dovecot/dovecot-sql.conf
    driver = sql
}
 
service dict {
    unix_listener dict {
        mode = 0600
        user = vmail
    }
}
 
protocol imap {
    mail_plugins = $mail_plugins imap_quota
}
 
plugin {
    # Using SQL Tables to store current quota size
    quota = dict:Quota:%d:proxy::sqldomainquota
    quota = dict:User Quota::proxy::sqluserquota
 
    # Allow 10% more for Trash Folder
    quota_rule2 = Trash:storage=+10%%
}
 
dict {
    sqluserquota = mysql:/etc/dovecot/dovecot-dict-sql-user.conf
    sqldomainquota = mysql:/etc/dovecot/dovecot-sql-domain.conf
}

To determine the quota limit,Dovecotretrieves these when it authenticates a POP3/IMAP account, against themailboxanddomain tables. Additional fields need to be retrieved from these tables to obtain the domain and/or user mailbox limits. The/etc/dovecot/dovecot-sql.confneeds to be amended as follows :

File: /etc/dovecot/dovecot-sql.conf

default_pass_scheme = MD5
 
user_query = SELECT CONCAT("/home/vmail/",maildir) as home,
                    CONCAT('maildir:/home/vmail/',maildir) as mail,
                    CONCAT("*:bytes=",
                     IF(mailbox.quota = 0, domain.maxquota*1024000, mailbox.quota))
                    as quota_rule
             FROM mailbox, domain
             WHERE username = "%u" AND mailbox.active = "1" AND
                   domain.domain = "%d" AND domain.active = "1"
 
password_query = SELECT username as user, password,
                        CONCAT("/home/vmail/",maildir) AS userdb_home,
                        CONCAT("maildir:/home/vmail/"maildir) AS userdb_mail
                 FROM mailbox WHERE username = "%u" AND active = "1"

There is some additional logic in theuser_querywhich needs explaining. When applying to a system that has had no quota i.e. unlimited, it was found that if applying a domain quota, each user’s mailbox would still have a zero against the quota limit, and still be treated as an unlimited. When usingPostfixAdminto edit the user email account, it would force the user mailbox quota to the limit of the domain quota limit. Since it was undesirable to got into every user account and change the quota limit, the above logic in theuser_querysolves this.

If the user mailbox quota limit is set to zero (unlimited) then use the domain quota limit instead, otherwise if the user’s mailbox account is set to a limit use that limit. Therefore if the user’s mailbox is unlimited use the domain quota limit instead.

Next it is neccessary to restartDovecotas follows (you may have to run this with sudo or as root ) :

service dovecot restart

Check the/var/log/syslogto see if theDovecotservice has successfully started. Also check the/var/log/mail.logto see if it is successfully processing imap calls.

Check Dovecot Quota Size Works

To diagnose any problems the following debug options can be switched on within the /etc/dovecot.conf:

File: /etc/dovecot/dovecot.conf
1
2
3
4
auth_debug = yes
auth_debug_passwords = yes
auth_verbose = yes
mail_debug =yes

This concludes setting up Quotas on domain, and/or users’ mailbox, and controlling these limits viaPostfixAdmin.



from: http://blog.shines.me.uk/?p=346

类别 :  默认(739)  |  浏览(6742)  |  评论(1)
发表评论(评论将通过邮件发给作者):

Email:
userhead
2022-07-21 21:04:32
a