Laurent Wacrenier


Maildir::Quota - Perl extension for Maildir++ soft quotas handling


  use Maildir::Quota;

  sub Maildir::Quota::error {  # error handler
  my $q = new Maildir::Quota;

  my $bytes = $q->bytes;
  my $max_bytes = $q->max_bytes;
  my $files = $q->files;
  my $max_files = $q->max_files;

  if ($q->test($nbytes, $nfiles)) {
    if ( add the files in the maildir ) {
       $q->add($nbytes, $nfiles);

  if (... message removed ...) {
    $q->add(-$message_size, -1);

  unless ($q->test) {
     die "overquota";

  undef $q;  # flush quota description


Maildir::Quota is a perl module to edit and check Maildir++ soft quota cache.



Create a Maildir::Quota. It recieve the directory where the Maildir is and a optional quota description.

Quota description are a coma (,) separated list of quota specifications. A quota specification consists of a number, followed by a letter specifying the type of quota. Currently the following quota types are used: S - maximum size of messages in the maildir; C - message count in the maildir.

If quota description is not given, the value is taken from the quota cache file.


test ( [ NBYTES [, NFILES ]] )

Return true if the Maildir can store NFILES messages of a total NBYTES bytes. If NBYTES or NFILES are not defined, check is the Maildir is overquota.

add ( [ NBYTES [, NFILES ]] ) Adds NFILES messages of a total NBYTES bytes to the soft quota cache. If you plan remove messages, use negatives values to NFILE and NBYTES.
bytes Returns the cached number of bytes or undef if an error occurs
max_bytes Returns the number of bytes allowed in the Maildir or undef is this value is not defined
files Returns the cached number of files or undef if an error occurs
max_files Returns the number of files allowed in the Maildir or undef is this value is not defined


If a Maildir::Quota::error subroutine is defined, all errors are send to it. Maildir not found, invalid or empty quota description are not errors.


Quota file is opened in read-write mode. If cache recalculation occurs, a new file is created. So, all add() operations must be done with Mailbox owner UID/GID.

Trash folder is not counted within the quota.

Library just manage the size cache, it does not supperss nor add message by itself.


(Laurent Wacrenier)


mdq(3), maildirquota(7)