• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Mail Quota Incorrect from Webmail

Christopher McBride

Basic Pleskian
Hi,

I've created my own script to alert me when email accounts are reaching or exceeded their capacity.

This checks the size of the Maildir directory for each account (/var/qmail/mailnames/domain.com/user/Maildir) and compares it to the PSA database for the individual mailbox quota (if set) or general domain mailbox quota.

When logging into webmail (both Horde and Atmail), it shows a different value than I achieve from checking the actual used diskspace.

e.g.
# du /var/qmail/mailnames/domain.com/name/ --max-depth=2

652 /var/qmail/mailnames/domain.com/name/Maildir/.Sent Items
4 /var/qmail/mailnames/domain.com/name/Maildir/tmp
9640 /var/qmail/mailnames/domain.com/name/Maildir/cur
208 /var/qmail/mailnames/domain.com/name/Maildir/.Trash
52 /var/qmail/mailnames/domain.com/name/Maildir/.ham_learn
3768 /var/qmail/mailnames/domain.com/name/Maildir/.Deleted Items
4 /var/qmail/mailnames/domain.com/name/Maildir/new
528 /var/qmail/mailnames/domain.com/name/Maildir/courierimapkeywords
28 /var/qmail/mailnames/domain.com/name/Maildir/.junk_learn
32 /var/qmail/mailnames/domain.com/name/Maildir/.sent-mail
28 /var/qmail/mailnames/domain.com/name/Maildir/.Sent
28 /var/qmail/mailnames/domain.com/name/Maildir/.Spam
28 /var/qmail/mailnames/domain.com/name/Maildir/.Drafts
15044 /var/qmail/mailnames/domain.com/name/Maildir
4 /var/qmail/mailnames/domain.com/name/@attachments
15056 /var/qmail/mailnames/domain.com/name/

This totals around 15MB.

The quota is set at 1GB and I'd expect the percentage to be 1.46%.

Both Horde and Atmail show a percentage of 1.16%.


OK, so this isn't a problem for me - since I have a large quota.

Some of my clients are on a 100mb quota with disk usage of 86mb, but webmail showing ~40%.




Can anyone offer any advice as to:

*What provides the quota information - Courier IMAP?
*What directories (in the above listing) are included or excluded in this listing?
*How Plesk calculates the mailbox quota.



Thanks
 
Anyone able to offer any help on this?

A more concrete example is for this mailbox...

# du /var/qmail/mailnames/domain.com/username/ --max-depth=2 -h
4.0K /var/qmail/mailnames/domain.com/username/Maildir/tmp
12K /var/qmail/mailnames/domain.com/username/Maildir/cur
4.5M /var/qmail/mailnames/domain.com/username/Maildir/.Trash
4.0K /var/qmail/mailnames/domain.com/username/Maildir/new
4.0K /var/qmail/mailnames/domain.com/username/Maildir/courierimapkeywords
95M /var/qmail/mailnames/domain.com/username/Maildir/.sent-mail
20K /var/qmail/mailnames/domain.com/username/Maildir/.Sent
20K /var/qmail/mailnames/domain.com/username/Maildir/.Spam
20K /var/qmail/mailnames/domain.com/username/Maildir/.Drafts
99M /var/qmail/mailnames/domain.com/username/Maildir
4.0K /var/qmail/mailnames/domain.com/username/@attachments
99M /var/qmail/mailnames/domain.com/username/

This user has a quota of 100mb - they are using 99mb from the directory listing, but webmail shows only 39% being used!

When looking into the "Maildir" directory, the following is displayed from these commands:

# ls -lah
total 660K
drwx------ 6 popuser popuser 4.0K Oct 22 2009 .
drwx------ 11 popuser popuser 4.0K Apr 29 20:30 ..
-rw-r--r-- 1 popuser popuser 17 Oct 22 2009 courierimapacl
drwx------ 2 popuser popuser 4.0K Mar 24 14:09 courierimapkeywords
-rw-r--r-- 1 popuser popuser 251K Jul 18 18:37 courierimapuiddb
drwx------ 2 popuser popuser 376K Jul 18 18:37 cur
-rw------- 1 popuser popuser 0 Oct 22 2009 maildirfolder
drwx------ 2 popuser popuser 4.0K Oct 22 2009 new
drwx------ 2 popuser popuser 4.0K Jul 19 09:09 tmp

# du -h
4.0K ./tmp
94M ./cur
4.0K ./new
4.0K ./courierimapkeywords
95M .


Can anyone help me out here as to why I'm unable to get a disk usage calculation that matches the webmail one?


Thanks
 
The secret in that only mail files with "S=" in file name are handled and calculated by utility 'deliverquota' and it does not count in messages marked as deleted via IMAP, thus size of mailbox appears different in 'maildirsize' (and subsequently in Plesk, since this file is main point of reference about mailbox disk usage) and on disk. Details you can find here - http://www.inter7.com/courierimap/README.maildirquota.html
 
Thanks! That will help.

Is there, by chance, a PSA command to check the quota usage instead of me checking the filsize of files which contain "S="?
 
I have managed to get a PHP function to get the correct usage for each maildir.

This has been taken (and slightly modifed) from the Horde/Imp webmail source code.


Hopefully this will help someone else in the future.


function getQuota($pathToMaildirsizeFile){
$storage_limit = 0;
$message_limit = 0;
$storage_used = 0;
$message_used = 0;

// Read in the quota file and parse it, if possible.
if (is_file($full)) {
// Read in maildir quota file.
$lines = file($full);

// Parse the lines.
foreach ($lines as $line_number => $line) {
if ($line_number == 0) {
// First line, quota header.
$line = preg_replace('/[ \t\n\r\0\x0B]/', '', $line);
list($v1, $t1, $v2, $t2) = sscanf($line, '%ld%[CS],%ld%[CS]');
if ($v1 == null || $t1 == null) {
$v1 = 0;
}
if ($v2 == null || $t2 == null) {
$v2 = 0;
}

if ($t1 == 'S') {
$storage_limit = $v1;
}
if ($t1 == 'C') {
$message_limit = $v1;
}
if ($t2 == 'S') {
$storage_limit = $v2;
}
if ($t2 == 'C') {
$message_limit = $v2;
}
} else {
// Any line other than the first line.
// The quota used is the sum of all lines found.
list($storage, $message) = sscanf(trim($line), '%ld %d');
if ($storage != null) {
$storage_used += $storage;
}
if ($message != null) {
$message_used += $message;
}
}
}

return array('size' => $storage_used, 'quota' => $storage_limit);
}

return -1;
}
 
Back
Top