#!/bin/sh
# 20080314 _M Simplified from sniffer script.
# This version simply creates a temp file, scans it w/ SNFClient and
# sends it on it's way - presumably with headers injected.

# Setup These Variable. The rest of the script should be fine as is.

INSPECT_DIR=/var/spool/snfilter/msg
SNIFFER_EXE=/var/spool/snfilter/SNFClient.exe
SENDMAIL="/usr/sbin/sendmail -i"
SPAMC="/usr/bin/spamc"
MSGFILE=$INSPECT_DIR/`date +%Y%m%d%H%M%S`_$$_$RANDOM.msg

# Define Exit codes from <sysexits.h>

EX_OK=0
EX_TEMPFAIL=75
EX_UNAVAILABLE=69

# Clean up when when aborting.

trap "rm -f *$MSGFILE" 1 2 3 15

# Move to our filter directory where we perform our inspections.

cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }

# Copy the message to a temp file for processing.

cat > $MSGFILE || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }

# Scan the mesage w/ SNF. SNFServer will inject headers.

$SNIFFER_EXE $MSGFILE			# Scan the message
$SPAMC < $MSGFILE -e $SENDMAIL "$@"     # Reinject the message through SpamAssasin
rm -f $MSGFILE				# Remove the temp file

# All done.

exit $EX_OK;


