How to delete emails older than x days

I used the method in this message to delete old Trash and Spam. It seemed to work:

However, this link shows a method using dovecot itself. I have not tried it.

It seems to me that the latter should be better. Am I right?

To activate auto delete trash edit this file:

./etc/dovecot/conf.d/15-mailboxes.conf

Change by adding autoexpunge = 30d. e.g.:

namespace {
mailbox Junk {
special_use = \Junk
auto = subscribe
autoexpunge = 30d
}

mailbox Trash {
special_use = \Trash
auto = subscribe
autoexpunge = 30d
}
}

In this case anything older than 30 days is purged. But it won’t have any affect on mails that are already in the trash/spam folders, only ones deleted going forward.

p.s. This needs to be applied again if mail-in-a-box is updated.

1 Like