#!/bin/sh
# mgetty newfax script package Copyright (c) 1998 Tycho Softworks. 
# $Id: newfax2mime 1.1 Mon, 22 Jun 1998 06:22:52 -0400 dyfet $
#
# This converts a fax spool set into a valid mime document that can be
# piped back out to sendmail.  Using newfax2mime in this manner eliminates
# the need of the temporary workfiles that were used in many of the
# mgetty sample programs.

xscale=0.58
yscale=0.58

echo 'MIME-Version: 1.0'
echo 'Content-Type: multipart/mixed;'
echo '	boundary="attachment"'
echo 
echo 'TIFF Encoded MIME Fax Document split by individual page numbers'
echo 
pg=0
for fax in $* ; do
	pg=`expr $pg + 1`
	name=`basename $fax`
	res=`basename $fax | sed 's/.\(.\).*/\1/'`
	if test $res = 'n' ; then
		yscale='1.16'
	else
		yscale='0.58'
	fi
	echo '--attachment'

	echo 'Content-Type: image/gif;'
	echo '	name="'page'-'$pg'.gif"'
	echo 'Content-Transfer-Encoding: base64'
	echo ''

	g3topbm $fax \
	| pnmscale -xscale $xscale -yscale $yscale \
	| ppmtogif \
	| mmencode -b
	echo ''
done
echo '--attachment--'
