You may get your email from multiple sources to cater for failures or just handy to have access while on the road. For example retrieve email from your ISP from both a home mail server and your Gmail. In this case your want to instruct both your home mail server and Gmail to not delete email from the ISP’s pop mail server, the problem is neither Gmail or my home server will provide a setting of delete the pop mail after so many days and my pop mailboxes fill up over time.
Using a simple one line script and adding it to a cronjob does the job of deleting this old mail still sitting up on the ISP.
CAUTION: The script will delete mail, test it first with a different command or on a test mailbox that does not matter to you.
The script:
find /home/user/mail/[email protected]_com/cur/* -mtime +30 -exec rm -rf {} ;
The above script will delete all mail in the users mailbox that is 30 days or older.
If you have an account such as spam where all mail that is meant to be spam is sent to the spam mailbox, you can setup a script to just delete all new mail after 30 days like so:
find /home/user2/mail/[email protected]_com/new/* -mtime +30 -exec rm -rf {} ;