#!/bin/sh

SPAMLIMIT=${1-0.900}
SRS=/opt/pkgs/srs-0.1

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

cat >${tmpf}.1
${SRS}/bin/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`

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

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

