Here’s a great way to cleanup unused or unchecked email accounts in cpanel.
find /home/*/mail/.*/new -name “1*” -mtime +180 -type f -exec rm -rf {} \;
This assumes a few things, however the logic works. The assumptions are that you’re using cpanel and that your user’s websites are located on /home. The format for cpanel email accounts is to place email in: /home/user/mail/.email/new. All new email is placed in the new folder. When a user checks the account using a pop or imap mail client the email is automatically moved into a folder called “cur”. It’s safe to then assume that any email files in the /new folder that are older than 6 months (180 days) can be deleted. This is very useful for performing an email cleanup. This one liner searches all of /home/ for files that are more than 180 days old in the /new folder that start with the number “1”. The following flags which include mtime, type, and the name are meant as a precaution to ensure you’re only deleting old email files and not folders. Use at your own risk.
Here’s another one liner that you can use to easily clear the mail queue on a cpanel server:
/etc/init.d/exim stop;find /var/spool/exim -mindepth 2 -type f -exec rm -rf {} \;;/etc/init.d/exim restart