Quick script I wrote to fetch spam-mails from users junk folders. #!/bin/bash # Report all mails as spam from the junk folders of every user. # Only take mails from cur, as new is unread and we don't want to report unread messages (right?) # Initial vars and stuff SPAMCOUNT=0 for x in `ls -d /var/vmail/vmail01/*/*/Maildir/.Junk/cur/`; do # Reset spam counter for each loop UCOUNT=0 UCOUNT=`ls $x | wc -l` # Fetch username + domain from path UDOMAIN=`echo $x | cut -f5 -d'/'` UNAME=`echo $x | cut -f6 -d'/'` UMAIL="$UNAME@$UDOMAIN" if [ $UCOUNT -gt 0 ]; then SPAMCOUNT=`expr $UCOUNT + $SPAMCOUNT` echo -n "`date +"%Y-%m-%d %X"` - $UMAIL: " >> /home/biggi/AutoSpamReporter.log sa-learn --no-sync --spam $x >> /home/biggi/AutoSpamReporter.log rm $x* else echo "No spam mails found for $UMAIL" fi done # Was any mails reported as bad? If so, sync! if [ $SPAMCOUNT -gt 0 ]; then echo "Total spam count for the day: $SPAMCOUNT." sa-learn --sync fi