#!/bin/sh

SPAMLIMIT=${1-0.900}
SRSDIR=`dirname $0`

## To use an alternate database, put its basename here:
#SRS=$HOME/.srs-test/srs; export SRS

A0=`basename $0`
tmpf=${TMPDIR:-/tmp}/$A0.$$

cat >${tmpf}.1
${SRSDIR}/check.pl -v ${tmpf}.1 >${tmpf}.2
score=`/usr/bin/awk 'NR==1 {print $NF}' ${tmpf}.2`

(
	echo "SRS reports:"
	tail +2 ${tmpf}.2 #| grep -v '=='
	echo
) >${tmpf}.3

looks_like_spam=`dc <<X
[[yes]p]sT
$score $SPAMLIMIT <T
X`

## Choose one of these:
flag="-I 'X-Label: SRS: $score'"	# Modify X-Label: if spam
#flag="-t 'SRS: $score'"			# Modify Subject: if spam

if [ -n "$looks_like_spam" ]; then
	## yes
	$HOME/bin/mime-encap -I "X-SRS-Score: $score" $flag -f ${tmpf}.1 -r ${tmpf}.3
else
	## no
	cat ${tmpf}.1
fi

rm -f ${tmpf}.1 ${tmpf}.2 ${tmpf}.3

