Quick script to add a rule to spamassassin

My spam volume has been ‘up’ lately, probably due to the holidays.

I find myself adding rules to match simple phrases that I seem to get a lot of  to my local.cf, and I figured I’d write a quick dirty script to make the process easier.

Feel free to copy/paste this into a new file in the same directory as your local.cf and don’t forget to chmod 755.  Execute with ./yourfilename (I used rule_creator).  There’s some comments in there to pay attention to, but as long as you place this into the same dir as your local.cf, and use ’service’ for spamd (typical for a qmailtoaster), there’s nothing to do.

Enjoy!

#$/bin/bash
#
# This script must be run from *INSIDE* the directory where your local.cf lives.
#

clear
echo “What should we name this rule? (ex. ‘RICH_DIRECTBUY’)”
echo “”
read RULENAME
echo “”
echo “Should the rule apply to the header or body? (enter: ‘header’ or ‘body’)”
echo “”
read RULETYPE
echo “”
echo “What phrase should the rule match? (ex. ‘get your free credit score’)”
echo “”
read PHRASE
echo “”
echo “How many points should I assign for this rule? (ex. ‘5.0′)”
echo “”
read SCORE
echo “”
echo “”

if [ $RULETYPE = body ]

then
RULELINE=$(echo “body $RULENAME /$PHRASE/i”)

elif [ $RULETYPE = header ]

then
RULELINE=$(echo “header $RULENAME ALL =~ /$PHRASE/i”)

else

echo “Ruletype entered wrong, exiting”
echo “”
exit

fi

SCORELINE=$(echo “score $RULENAME $SCORE”)

clear
echo “”
echo “Ok, I’ll add the following rule to ‘local.cf’:”
echo “”
echo “—————————————————-”
echo $RULELINE
echo $SCORELINE
echo “—————————————————-”
echo “”
echo “”
echo “** Press any key to add the rule, or CTRL+C to exit **”
echo “”
read
echo “” >> local.cf
echo $RULELINE >> local.cf
echo $SCORELINE >> local.cf
echo “”

# This section will restart spamd if you use ’service’ to control it.  If you don’t, you’ll probably just want to comment the whole below section out and restart spamassassin manually

echo “OK – rule added, restarting spamd”
echo “”
cd /service
echo “Stopping spamd”
svc -d spamd
echo “”
echo “Starting spamd”
svc -u spamd
echo “”
echo “Checking spamd status”
sleep 3
echo “”
svstat spamd
echo “”

Leave a Comment

* are Required fields