Automatic purging of old email in all mailboxes

Sean Greenslade sean at seangreenslade.com
Mon Aug 29 19:47:37 UTC 2016


On Mon, Aug 29, 2016 at 07:40:41PM +0000, Scott W. Sander wrote:
> I am using a postfix + Dovecot server as a test mail server for which some
> applications in our test environment use as a target to deliver email so
> that our real endusers don't receive messages from our test servers.
> 
> A few of the mailboxes in Dovecot receive hundreds of emails per day.  I'd
> like to automatically remove all emails in all mailboxes and mailbox
> folders that were received more than 90 days prior to the received date.
> As I'm a novice Dovecot administrator, I'm not exactly sure what the best
> way to accomplish this is, but I've started looking at the "doveadm
> expunge" command.  I figure I could create a cron job that calls this
> command with the -A switch and that has a search query that finds all
> emails older than 90 days.
> 
> I'm aware that I can test my query by using the "doveadm search" command.
> The problem is that when I do any sort of search query with that command
> (e.g. "doveadm search -A NEW"), I receive the following error messages:
> 
> Error: User listing returned failure
> doveadm: Error: Failed to iterate through some users
> 
> I've searched for help with this error, but most of the guidance I'm seeing
> refers to making sure that dovecot-sql is configured correctly; however,
> I'm using "passwd-file" for the passdb and not a true database.

Since you're using maildirs as the storage backend, it might be easier
to just write a small script in the language of your preference (bash,
python, perl, etc.) that walks the directory tree and deletes files
based on their mtime.

I personally use a python script to delete messages that have been in my
trash folder for more than 30 days, and it works very well.

--Sean



More information about the dovecot mailing list