Add to Favourites Add to Favourites    Print this Article Print this Article

How to purge the Maildir inbox for all system accounts: /home/user/Maildir

If you're noticing that your User's System Accounts are not being checked often enough (or ever) and you wish to purge them, you can use the following script.


#Deletes emails older than this number of days

for i in `ls /usr/local/directadmin/data/users`; do
       if [ ! -d /home/$i/Maildir ]; then

       for file in `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`; do
               rm -fv $file;
exit 0;

Save the script, chmod to 755, and run.
This script needs to be run as root.

You can run this script as often as you wish with a cronjob to keep the system accounts trimmed.

Keep in mind that if you're deleting their data, Users may not appreciate this, so only run it if you're certain they're not checking this account.

Was this answer helpful?

Also Read