Maintain Trash and Spam folder
#!/bin/bash
# qtprune.sh # # This file can be put in /etc/cron.daily # and will prune Trash/Spam directories # Nov 7, 2006 # # 3/5/2007 Added date configuration capability # # Erik A. Espinoza <espinoza@kabewm.com # # # # Number of days for Trasn TRASH_DAYS="28" # Number of days for Spam SPAM_DAYS="28" # Find Trash Dir PATH_TRASH="`find /home/vpopmail/domains -type d -name .Trash`" # Find Spam Dir PATH_SPAM="`find /home/vpopmail/domains -type d -name .Spam`"
# Exit if no spam or trash directories found if [ -z "${PATH_TRASH}" ] && [ -z "${PATH_SPAM}" ]; then exit 0 fi
# Delete Trash older than $TRASH_DAYS days # if Trash directories found if [ -n "${PATH_TRASH}" ]; then for each in "${PATH_TRASH}" ; do FILES_TO_DELETE="`find ${each} -type f -ctime +${TRASH_DAYS}`" if [ -n "${FILES_TO_DELETE}" ]; then for file in ${FILES_TO_DELETE} ; do if [ -n ${file} ]; then rm -f ${file} >/dev/null 2>&1 fi done fi done fi
# Learn and Delete Spam older than $SPAM_DAYS # days if Spam directories found if [ -n "${PATH_SPAM}" ]; then for each in "${PATH_SPAM}" ; do FILES_TO_DELETE="`find ${each} -type f -ctime +${SPAM_DAYS}`" if [ -n "${FILES_TO_DELETE}" ]; then for file in ${FILES_TO_DELETE} ; do if [ -n ${file} ]; then sudo -u vpopmail -H sa-learn --spam ${file} >/dev/null 2>&1 rm -f ${file} >/dev/null 2>&1 fi done fi done fi
exit 0 # EOF
Below is the modified script to maintain Draft, Sent, Trash and Spam in one shots.
#!/bin/bash # qtprune.sh # # This file can be put in /etc/cron.daily # and will prune Trash/Spam directories # Nov 7, 2006 # # 3/5/2007 Added date configuration capability # # Erik A. Espinoza <espinoza@kabewm.com> # # # 8/20/2007 Added pruning for Sent dan Draft folders # PakOgah <pakogah@pala.bo-tak.info> # # Number of days for Trash TRASH_DAYS="30" # Number of days for Spam SPAM_DAYS="30" # Number of days for Sent SENT_DAYS="90" # Number of days for Drafts DRAFTS_DAYS="90" # Number of days for keeping email EMAIL_DAYS="31" # Find Trash Dir PATH_TRASH="`find /home/vpopmail/domains -type d -name .Trash`" # Find Spam Dir PATH_SPAM="`find /home/vpopmail/domains -type d -name .Spam`" # Find Sent Dir PATH_SENT="`find /home/vpopmail/domains -type d -name .Sent`" # Find Drafts Dir PATH_DRAFTS="`find /home/vpopmail/domains -type d -name .Drafts`" # Find Email dir ( cur ) PATH_EMAIL="`find /home/vpopmail/domains -type d -name .cur`" # Exit if no spam or trash directories found if [ -z "${PATH_TRASH}" ] && [ -z "${PATH_SPAM}" ] && [ -z "${PATH_SENT}" ] && [ -z "${PATH_DRAFTS}" ]; then exit 0 fi # Delete Trash older than $TRASH_DAYS days # if Trash directories found if [ -n "${PATH_TRASH}" ]; then for each in "${PATH_TRASH}" ; do FILES_TO_DELETE="`find ${each} -type f -ctime +${TRASH_DAYS}`" if [ -n "${FILES_TO_DELETE}" ]; then for file in ${FILES_TO_DELETE} ; do if [ -n ${file} ]; then rm -f ${file} >/dev/null 2>&1 fi done fi done fi # Delete Sent older than $SENT_DAYS days # if Sent directories found if [ -n "${PATH_SENT}" ]; then for each in "${PATH_SENT}" ; do FILES_TO_DELETE="`find ${each} -type f -ctime +${SENT_DAYS}`" if [ -n "${FILES_TO_DELETE}" ]; then for file in ${FILES_TO_DELETE} ; do if [ -n ${file} ]; then rm -f ${file} >/dev/null 2>&1 fi done fi done fi # Delete Drafts older than $DRAFTS_DAYS days # if Drafts directories found if [ -n "${PATH_DRAFTS}" ]; then for each in "${PATH_DRAFTS}" ; do FILES_TO_DELETE="`find ${each} -type f -ctime +${DRAFTS_DAYS}`" if [ -n "${FILES_TO_DELETE}" ]; then for file in ${FILES_TO_DELETE} ; do if [ -n ${file} ]; then rm -f ${file} >/dev/null 2>&1 fi done fi done fi # Learn and Delete Spam older than $SPAM_DAYS # days if Spam directories found if [ -n "${PATH_SPAM}" ]; then for each in "${PATH_SPAM}" ; do FILES_TO_DELETE="`find ${each} -type f -ctime +${SPAM_DAYS}`" if [ -n "${FILES_TO_DELETE}" ]; then for file in ${FILES_TO_DELETE} ; do if [ -n ${file} ]; then sudo -u vpopmail -H sa-learn --spam ${file} >/dev/null 2>&1 rm -f ${file} >/dev/null 2>&1 fi done fi done fi # Delete Emails older than $EMAIL_DAYS days # if EMAIL directories found if [ -n "${PATH_EMAIL}" ]; then for each in "${PATH_EMAIL}" ; do FILES_TO_DELETE="`find ${each} -type f -ctime +${EMAIL_DAYS}`" if [ -n "${FILES_TO_DELETE}" ]; then for file in ${FILES_TO_DELETE} ; do if [ -n ${file} ]; then rm -f ${file} >/dev/null 2>&1 fi done fi done fi exit 0 # EOF
Or if you just want to maintain Spam folder you can run
# qtp-clean-spam
from QTP tools