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 testuser@sv.dev 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?

  • 2
    I have valuable 10 yr+ old emails that I will continue to keep; I sure hope you're notifying your users...what is the 'safety' argument? – pete Apr 9 '16 at 14:32
  • 1
    @pete management argument. We've a process to stored legally relevant messages in specific IMAP folders, however messages in INBOX, Trash and Sent should be discarded after 5 years... – TCB13 Apr 9 '16 at 14:34

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

doveadm expunge -u testuser@sv.dev mailbox INBOX SENTBEFORE 1-Jan-2011
doveadm expunge -u testuser@sv.dev mailbox INBOX.Sent SENTBEFORE 1-Jan-2011
doveadm expunge -u testuser@sv.dev mailbox INBOX.Trash SENTBEFORE 1-Jan-2011
doveadm purge -u testuser@sv.dev

Note: You can replace -u testuser@sv.dev 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.