#!/bin/bash# Declaring our variablesVPOPHOME=`echo ~vpopmail`SPAMDIR="Maildir/.Spam/new"LOCKFILE="/var/tmp/spamlearn.lock"# Check to see if this process is already running, if so we should exit.if [ -e $LOCKFILE ] then echo "spamlearn is running, exiting now" exitelse # Write a lockfile, to show that the process is running. touch $LOCKFILEfilearnspam() { # We need our domain store directory. VDOMAIN=`$VPOPHOME/bin/vdominfo -d $DOMAIN` # Move spam older than 7 days to ISSPAM folder to be learned. for i in $( find $VDOMAIN/$1/$SPAMDIR/ -mtime +7 ); do if [ -f $i ] then mv $i $VDOMAIN/$1/$ISSPAM fi done}spamdomain() { DOMAIN=$1 # List the users of the domain. for i in $( $VPOPHOME/bin/vuserinfo -nD $DOMAIN ); do USER=$i USERDIR=`$VPOPHOME/bin/vuserinfo -d $USER@$DOMAIN` # Verify that the current users .Spam.IsSpam/cur directory exists. if [ -d $USERDIR/$SPAMDIR ] then # Run the learnspam function passing the $USER variable. learnspam $USER fi done}for i in $( $VPOPHOME/bin/vdominfo -n ); do spamdomain $idone