Quota Support in Postfix
8th Jan 2006, 17:58:07
Quota support is compiled in to current versions of postfix
Since a fair few people are using my mail server now and also because I am not Google, I thought I'd put some quotas in place. This turned out not to be as simple as I was hoping...
First, I needed to add a field to the MySQL table is use to store user details:
mysql> alter table useraccounts add column quota int(10) unsigned not null;
mysql> update useraccounts set quota='524288000';
Next, I told courier about this:
# echo " MYSQL_QUOTA_FIELD quota" >> /etc/courier/authmysqlrc
Didn't work. Bugger it. Apparently, one has to patch postfix to work with quotas. Here's the crack:
# cd /usr/src
# apt-get source postfix
# wget http://web.onda.com.br/nadal/postfix/VDA/postfix-2.1.5-trash.patch.gz
# gunzip postfix-2.1.5-trash.patch.gz
# cd postfix-2.1.5
# patch -p1 < ../postfix-2.1.5-trash.patch
# cd ..
# dpkg -i postfix_2.1.5-9_i386.deb
# dpkg -i postfix-mysql_2.1.5-9_i386.deb
# dpkg -i postfix-tls_2.1.5-9_i386.deb
When you get the dpkg-buildpackage part, it'll complain about missing dependencies, just use apt to install them.
user = yourmysqluser
password = yourmysqlpassword
dbname = nameofmysqldb
table = tablecontainingquota
select_field = quotafieldname
where_field = email
hosts = 127.0.0.1
Now, insert some lines into /etc/postfix/main.cf
# Override the message_size_limit setting
virtual_mailbox_limit_override = yes
# Follow Maildir++ specs
virtual_maildir_extended = yes
# Create the maildirsize file (Vital for Courier-IMAP)
virtual_create_maildirsize = yes
# Bounce rather than defer when over quota
virtual_overquota_bounce = yes
Restart postfix with /etc/init.d/postfix restart.
Your accounts now have a 500MB quota, which any decent mail client should tell you. The quota only seems to be implemented once the account has received new mail.