Hello
If you use Postfix for your mail server, but deliver the actual mail through Procmail, you might notice that quotas stop working properly.
This is because if you use Procmail then Postfix itself is no longer responsible for creating the actual directories on the filesystem, nor is it responsible for keeping track of how many emails are on the server. Therefore, by default, quotas will not be recorded.
You can manually recreate the quotas using the following command on your mail server:
maildirmake -q -10024S /home/vmail/$DOMAIN/$USER/
But it would be impossible to manually run that command for each user every time a new email is received. It would be nice to automate this process, but the problem is that we need to know the size of the mailbox, and that value is kept in the database. Therefore, we need to run a script with procmail that will go in to the database, find a given user’s quota and regenerate the maildir.
Here is a script I wrote many years ago; it’s in PHP, because back then that’s all I knew, but it still holds its own and can easily be done in a better script language.
<?php
$config = array(
'dbname' => '-', # Database name
'dbhost' => '-', # Database host
'dbuser' => '-', # Database user
'dbpass' => '-', # Database password
'quota_field' =>'quota', # Field containing quota
'email_field' => 'username', # Field containing email
'user_table' => 'mailbox', # Field containing mail users
);
$dsn = 'mysql:dbname=%s;host=%s';
$dsn = sprintf($dsn, $config['dbname'], $config['dbhost']);
try
{
$dbh = new PDO($dsn, $config['dbuser'], $config['dbpass']);
}
catch (PDOException $e)
{
die('Connection fail: ' . $e->getMessage());
}
$email = sprintf('%s@%s', $argv[1], $argv[2]);
$sql = 'SELECT `' . $config['quota_field'] . '` FROM `' . $config['user_table']. '` WHERE `' . $config['email_field'] . "` = '$email'";
$stmt = $dbh->prepare($sql);
$stmt->execute();
$command = 'maildirmake -q %dS /home/vmail/%s/%s/';
$chown = 'chown vmail:vmail /home/vmail/%s/%s/maildirsize';
while ($row = $stmt->fetch())
{
exec(sprintf($command, $row['quota'], $argv[2], $argv[1]));
exec(sprintf($chown, $argv[2], $argv[1]));
}
Create it somewhere on your server, ensure it is owned by vmail, executable and only vmail can read your passwords from it. Then, at the end of your existing procmail script (probably /usr/local/bin/procmailed) add
#!/bin/sh #/usr/bin/procmail -m /etc/procmailrc ... /usr/bin/procmail -p -m /etc/procmailrc $DOMAIN $USER php /usr/local/bin/procmailed-quotas $USER $DOMAIN # ADD THIS LINE
