Orange is my favorite color

I use Thunderbird as my email client and have been converting my accounts from POP3 to IMAP to access my mail from multiple devices (Laptop, Internet Cafe, Phone, etc).

Our fantastic anti-spam solution, DSPAM, occasionally misses a message. With a POP3 account I would forward it to a special address on our server configured to reclassify spam.

When you click the “Junk” button for an email in Thunderbird (or press the “J” key), it automatically marks it in Thunderbird’s bayesian database and moves the message to the default “Junk” folder. Rather than reconfigure every Thunderbird user on our server, I used some code from wimble.info to create a server-wide IMAP reclassification script that would work out of the box with Thunderbird. This script assumes that all users with a Junk folder are protected by DSPAM:

#!/bin/sh

VPOPDIR=/home/vpopmail
DSPAMDIR=/var/dspam/current

for FOLDER in `find $VPOPDIR/domains/ -name '.Junk' -type d -print`; do
DOMAIN=`echo $FOLDER | awk -F/ '{print $(NF-3)}'`
USER=`echo $FOLDER | awk -F/ '{print $(NF-2)}'`

cd $FOLDER/cur/
for NAME in `ls -1`; do
cat $NAME | $DSPAMDIR/bin/dspam --user [email protected]$DOMAIN --mode=teft --class=spam --source=error
rm -f $NAME
done

done

Save that as reclass.sh. The $DOMAIN and $USER variables will work with any depth directory structure so long as the Junk folder is a top level folder in the user mailbox. E.g., for a VPOPMAIL setup, it assumes the path looks something like:

/some/path/to/domains/foo.com/username/Maildir/.Junk

Since Thunderbird automatically creates the Junk folder, this script looks for all .Junk directories and then loops over each email to reclassify and delete them. Just change the permissions on the file and pop this into your vpopmail (or root) cron on an hourly or daily basis:

0 4 * * * /path/to/your/reclass.sh

Comments are closed.