Networking

Hardware

Software

Consultation

 

Clear SPAM Folder Weekly

 
 

My SPAM folder gets out of hand in a hurry, so here is what I do to keep it under control.

This assumes that all of your spam folders are under a vmail directory, this could be adjusted to suit any base directory.

Move to your /etc/cron.weekly folder, and create a file called clean-spam-folder.sh

cd /etc/cron.weekly
touch clean-spam-folder.sh
chmod guo+x clean-spam-folder.sh

Now add the following to the file you've just created

#!/bin/bash

BASEDIR=/home/vmail

for i in `find $BASEDIR -iname *spam`
do
        echo "Moving to $i";
        cd $i;
        echo "Currently Contains:";
        ls;
        logger -s -t ClearSPAM "Clearing $i with \"rm -rdf ${i}/*\"";
        rm -vrdf ${i}/* | logger -s -t ClearSPAM
        echo; echo;
done

This will also log what is done to your syslog.

Done...