doveadm: Delete messages older than date

I've a situation where some users keep very old messages (+5 years) on their mailboxes that are just a waste of space and due to safety reasons should also be deleted.

I find out that I could use doveadm for this, however running something like:

doveadm expunge -u [email protected] mailbox INBOX savedbefore 1-Jan-2011

Doesn't have any effect. From my understanding email clients mark email for deletion before the expunge is run on the server to actually remove them.

How can I mark them for deletion using doveadm and then run the doveadm command before or directly and completely delete them?


Apparently my solution was almost right, I can do what I need with:

doveadm expunge -u [email protected] mailbox INBOX SENTBEFORE 1-Jan-2011
doveadm expunge -u [email protected] mailbox INBOX.Sent SENTBEFORE 1-Jan-2011
doveadm expunge -u [email protected] mailbox INBOX.Trash SENTBEFORE 1-Jan-2011
doveadm purge -u [email protected]

Note: You can replace -u [email protected] with -A to target all users on the system.


Extra for WHM/cPanel Based E-Mail Systems:

If you're running a WHM/cPanel machine you need to update the size of your mail directories manually:

/scripts/generate_maildirsize --confirm --verbose account_username

Or, for all accounts:

/scripts/generate_maildirsize --allaccounts --confirm --verbose