15

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?

2
  • 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, 2016 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, 2016 at 14:34

1 Answer 1

18

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
1
  • On my system, just running the expunge command make all old mails dissapear instantly, didn't need to purge
    – m3nda
    Oct 22, 2021 at 10:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .