#!/bin/sh
#
# sample script to automatically convert incoming faxes to pbm, uuencode
# and gzip them, and send them to "MAILTO".
# (FAX_NOTIFY_PROGRAM in policy.h)
#
# gert@greenie.muc.de
#
# MAILTO="you@yourhost.do.main"
MAILTO="root"
MAILER=/usr/sbin/sendmail

PATH=$PATH:/usr/bin
G3TOPBM=g3topbm
#
#
HUP="$1"
SENDER="$2"
PAGES="$3"

shift 3
P=1

while [ $P -le $PAGES ]
do
	FAX=$1
	RES=`basename $FAX | sed 's/.\(.\).*/\1/'`

	if [ "$RES" = "n" ]
	then
		STRETCH="-stretch"
	else
		STRETCH=""
	fi

	(
	    echo "Subject: fax from $SENDER, page $P of $PAGES"
	    echo "To: $MAILTO"
	    echo ""
	    $G3TOPBM $STRETCH $FAX \
	    | gzip -9 \
	    | uuencode $FAX.pbm
	) $MAILER $MAILTO

	shift
	P=`expr $P + 1`
done

exit 0
