#!/bin/ksh # # Handle the tagging and bouncing of spam messages for customers. The # customer's email address is extracted from the environment information # and is then passed to "spamc" for examination. The message is then # either delivered (tagged) to the mailbox, or if requested, bounced # back to the sender as an undeliverable message. # # It should be installed in the .qmail file as so: # |spamassassin.sh # # or, if you want to deliver the tagged mail somewhere else: # |spamassassin.sh email_address # # Requires: spamc, spamd, qmail, 822field (from the mess822 package), # reformail, maildir (which is a script that calls safecat correctly.) # # Copyright (c) 2002 by Robert James Kaes # All rights reserved. # PATH=/bin:/usr/bin:/usr/local/bin # RECIPIENT is an environmental variable which contains an email address # like: flarenet-com-rjkaes@flarenet.com # In other words, the domain is prepended to the email address. This # script removes the prepended part and returns just the email address. recip=$(echo "$RECIPIENT" | tr "A-Z" "a-z") encoded_domain=$(echo "$recip" | sed -e 's/.*@\(.*\)$/\1/' | tr '.' '-') user=$(echo "$recip" | sed -e "s/$encoded_domain-//") # Scan the message message_name=$(/usr/bin/spamc -f -u"$user" | reformail -A"X-SA-UserName: $user" | maildir ./Maildir/) if [ $? -ne 0 ]; then # soft failure exit 111 fi # Find the message's score; again, need to scale it message_score=$(cat ./Maildir/new/$message_name | 822field 'X-Spam-Status' | grep -i 'yes' | sed -e 's/^.*hits=\([0-9.]*\).*$/\1/') # Check to see if the message was tagged as spam if [ -n "$message_score" ]; then # it's a none empty string, so scale the value message_score=$(echo "$message_score * 100" | bc | sed -e 's/\..*$//') # Get the bounce spam value; it's an float so it needs to be scaled bounce_spam=$(echo "$user" | spam_bounce | awk -F: '{print $2}') # If the score is zero, change it to the default score (13.75) if [ $bounce_spam = "0" ]; then bounce_spam="1375" else bounce_spam=$(echo "$bounce_spam * 100" | bc | sed -e 's/\..*$//') fi # If the message's score it greater than the bounce limit, bounce # the message if [[ $message_score -ge $bounce_spam ]]; then rm -f ./Maildir/new/$message_name # stop further processing of .qmail file exit 100 fi fi # Pick an output command based on whether an email address was given # on the first line if [ $# -gt 0 ]; then cat ./Maildir/new/$message_name | /usr/sbin/qmail-inject $1 ret=$? rm -f ./Maildir/new/$message_name if [ $ret -ne 0 ]; then exit 111 fi fi # Message has been delivered successfully. exit 0