Automated Mbox Cleanup

There are many applications that use mail to message users about exceptional conditions. Sometimes it is the easiest thing to do. Of course there are better ways. I recently had to interface to a few systems that provide email messages as important application/system telemetry. I also like to store the original mail messages for those parts of the message that I don’t parse and use in case I need to go back to it later. The basic approach is to forward mail to a user account, write some program to extract mime parts if needed and process the data, insert into a database, attach more data and sms someone and so on. One of the problems I had been ignoring was purging the mailboxes. I found the following program very capable. Amazing how often the perl community has just what you need.

Use –n to test and you can use remove –no to actually delete the messages. The command below will list what will be deleted for mailboxes int eh current directory that are older than one week from the time the command was issued.

mbox-purge –eval ‘time – delivery_time > 60*60*24 * 7’ /var/mail/*

You will have to install handy documented here: scroll down to mailbox purge

Alternatives like getmail and fetchmail had too many options to read about it. They may be able to do the same thing. It wasn’t clear if fetchmail supports mbox format.

Related Posts

Leave a Reply