#!/bin/sh
# This file is from the mgetty program and changed for use with the
# blinkd program by W. Borgert <debacle@debian.org>
# $Id: new_fax,v 1.3 1999/06/29 07:59:48 debacle Exp $
#
# 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
#

# The following three lines are one way to activate blinking of the
# Num-Lock LED with blinkd:
## NUMBER_MSGS=`ls /var/spool/fax/incoming | sed 's/\..*//' | \
##     sort -u | wc -l | sed 's/ //g'`
## /usr/bin/blink --scrolllockled --rate=$NUMBER_MSGS
# The other way is the easy one:
/usr/bin/blink --scrolllockled --rate=+

exit

MAILTO="postmaster"
MAILER=/usr/sbin/sendmail

PATH=$PATH:/usr/local/bin
G3TOPBM=g32pbm
#
#
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="-s"
	else
		STRETCH=""
	fi

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

	shift
	P=`expr $P + 1`
done

exit 0
