# Courier-imap+Postfix quota setup

## k00ma

I have Courier-imap and Postfix installed and now I would like to assing quota to .maildir folders, what changes I have to for example to Postfix config files  :Idea: 

 *Quote:*   

> 
> 
> How to implement the quota
> 
> The best way to do that is to modify your mail server to implement the protocol defined by this document. Not everyone, of course, has this ability. Therefore, an alternate approach is available.
> ...

 

That example is about Qmail what changes I have make to Postfix config  :Question: 

----------

## stealthy

For starters you need to have "vda" as one of your use flags when compiling postfix to enable quota support.

See:

http://web.onda.com.br/nadal/

http://brunny.com/content/view/9/50/

I personally use postfix, courier for email along with amavisd using spamassassin & clamav

All the front end is being managed by postfixadmin(not in portage, although I am lost as to why not)

http://high5.net/postfixadmin/

----------

## hanj

Hello

I'm thinking of going with quota handling with postfix. I've been doing some research with vda, and found some older threads on the subject. I have a few questions.. maybe you or someone can help.

1. I see there is a vquota map file you can use in main.cf.

From the website (http://web.onda.com.br/nadal/)...

```
vquota maps file

This file contains in bytes the maximum diskspace authorised per emails.

# domain.com.br are unlucky one... they have a max to 2M diskquota

user1@domain.com.br   2048000 

user2@domain.com.br   2048000 

# domain.net.br are more lucky... and some don't have any limits (0 !)

user1@domain.net.br   5192000

user2@domain.net.br   0
```

Now.. Is it possible to hook into the quota field in the virtual-mail mysql user's table? Maybe create the wrapper...

```
# Maps of virtuals users

virtual_mailbox_maps = hash:/etc/postfix/vmailbox
```

to

```
# Maps of virtuals users

virtual_mailbox_maps = mysql:/etc/postfix/mysql-userquota.cf
```

mysql-userquota.cf would contain:

```
user        = user

password        = password

dbname          = mailsql

table           = users

select_field    = quota

where_field   = email

additional_conditions = and postfix = 'y'

hosts        = 127.0.0.1

```

2. Also, I would like to have a 'global' quota, and then adjust it for per user. Would the best way be setting the quota in the database to the 'global' value, and then adjust specific values to specific users in the database? Or would I leave quota to 0 for everyone, and set it in main.cf (virtual_mailbox_limit = 100000000) but then adjust on a per user basis via the database? 

3. Also, their documentation states:

 *Quote:*   

> set the transport to VIRTUAL, or this patch not work!
> 
> transport_maps = hash:/etc/postfix/transport 

 

Now is this different than the virtual values we have set with virtmail?

```
virtual_transport = virtual

virtual_mailbox_domains = mysql:/etc/postfix/mysql-transport.cf
```

My current MTA set up is as follows:

postfix-2.2.5

courier-imap-4.0.1

courier-authlib-0.58

spamassassin-3.1.0

amavisd-new-2.3.3-r2

clamav-0.88

mysql-4.1.14

Thanks in advance!

hanji

----------

## hanj

Ok. I got things pretty well figured out. I'm having trouble with soft limits.. I'll provide what I did,...

emerge postfix with vda flag (either with USE or /etc/portage/package.use)

```
USE="vda" emerge -v postfix
```

Edit authmysqlrc

/etc/courier/authlib/authmysqlrc

```
MYSQL_QUOTA_FIELD       quota
```

Edit /etc/postfix/main.cf

```
##############################################

# VIRTMAIL QUOTA                             #

##############################################

virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql-virtual-mailbox-limit-maps.cf

virtual_mailbox_limit_override = yes

virtual_maildir_extended = yes

virtual_create_maildirsize = yes

virtual_overquota_bounce = yes

virtual_mailbox_limit_override = yes

virtual_mailbox_limit = 30720000

virtual_mailbox_limit_inbox = no
```

Create /etc/postfix/mysql-virtual-mailbox-limit-maps.cf

```
user           = user

password        = password

dbname          = mailsql

table           = users

select_field    = quota

where_field     = email

additional_conditions = and postfix = 'y'

hosts           = 127.0.0.1
```

Make sure your permissions are set for that. Readable by your postfix user.

I see that leaving a 'blank' value in 'quota' field will default to 'no quota' which will work for me. I'm still having problems with bounces. Is there a way to have a 'soft' limit so message will be sent to sender with a 'warning'? I wasn't able to get that part to work. I was playing around with the virtual_overquota_bounce configuration option, but would always bounce at my quota value.

I was also successful with using the quota usage plugin for squirrelmail.

http://www.squirrelmail.org/plugin_download.php?id=59&rev=1114

Reference to the configuration changes above..

http://brunny.com/content/view/9/50/

http://web.onda.com.br/nadal/

Thanks!

hanji

----------

## ebnerjoh

Hi!

I am alos using postfix --> courier-imap --> squirrelmail and postfixadmin to manage mailboxes.

Quota is working for me, so when the mailbox is full additional mails will get bounced. But I can not display the quota in squirrelmail with the plugin "quota_usage". The debug shows: 

```
IMAP command sent: a001 GETQUOTAROOT "INBOX"

IMAP response recieved:

Array

(

    [0] => * QUOTAROOT "INBOX" "ROOT"

    [1] => * QUOTA "ROOT"

)

Usage is:

Array

(

    [0] => NOQUOTA

)

```

Any Ideas?

Regards,

Johannes

----------

## hanj

Are you seeing your quota_usage 'box' at least? Also, have you confirmed that quotas are working on your system? I'm assuming so, just want to verify that it's working first.

hanji

----------

## ebnerjoh

No, I dont see any kind of box. Nothing is shown on the frontend.

Yes, quota is working. But I am not sure if it is the courier-imap-quota.

I followed the virtual-mailserver howto (postfix - courier -mysql) and the quota is stored in the mysql database (with postfixadmin).

When the mailbox-size is over the quota, no new mails are excepted.

Regards,

Johannes

----------

## hanj

I'm wondering if the plugin hook is not working correctly. I might be wrong, but I think you should see the quota box regardless of no quota vs. a quota set.  Do you have quota_plugin enabled in config.php?

I would look at the 'display_quota_usage_left_do()' in function.php and squirrelmail_plugin_init_quota_usage() in setup.php

hanji

----------

