User Tools

Site Tools


bash:reportspam

Quick script I wrote to fetch spam-mails from users junk folders.

reportspam.sh
#!/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
bash/reportspam.txt · Last modified: 2015/08/15 22:56 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki