Dovecot’s Quota Plugin

The below assumes your using mdbox so dirsize or dict:sql will be the fastest. Since we already have sql setup, were going to go with that.

Enabling the Quota Plugin

mail_plugins = $mail_plugins quota

protocol imap {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins imap_quota
}

plugin {
  # SQL backend:
  quota = dict:User quota::proxy::quota
  quota_rule = *:storage=1024M:messages=100000
  quota_rule2 = Trash:storage=+20%%
  quota_rule3 = Junk:storage=+20%%
}dict {
  quota = mysql:/etc/dovecot/dovecot-dict-mysql.conf
}

The dovecot-dict-mysql.conf file should containe something like this

connect = host=localhost dbname=postfix user=postfix password=postfix
map {
  pattern = priv/quota/storage
  table = quota
  username_field = username
  value_field = bytes
}
map {
  pattern = priv/quota/messages
  table = quota
  username_field = username
  value_field = messages
}

And lastly, add the following table to your email servers database in mySQL.

CREATE TABLE quota (
  username varchar(100) not null,
  bytes bigint not null default 0,
  messages integer not null default 0,
  primary key (username)
);
Advertisements

Doveadm Notes

Dovecot‘s administration utility can be used to manage various parts of Dovecot, as well as access users’ mailboxes. Here’s a list of some commonly used commands.

  • Show all messages older then 30 days in user matt’s Inbox
doveadm search -u matt mailbox INBOX savedbefore 30d
  • Expunge (delete) all messages older then 7 days in matt’s Trash folder
doveadm expunge -u matt mailbox Trash savedbefore 7d
  • List current quota status for a user (-u) or all users (-A)
doveadm quota get -u matt