#27052 a script to let efax auto-convert faxes

Package:
efax
Source:
efax
Description:
programs to send and receive fax messages
Submitter:
Avery Pennarun
Date:
2005-07-18 03:39:04 UTC
Severity:
wishlist
#27052#5
Date:
1998-09-24 15:53:19 UTC
From:
To:
Hi,

I just wrote a wrapper script for /usr/bin/fax that will automatically
convert incoming faxes to multi-page compressed postscript files and e-mail
them to postmaster (or whoever you specify as MAILTO in /etc/efax.rc).

I find it pretty handy... and wow, efix is a great program!  Converting G3
to postscript in just 36k :)

You need the "metamail" package installed in order to send the
MIME-encapsulated mail with my script.

Maybe this can go into a later version of the Debian package.  You just need
to run the script in place of "fax answer" in /etc/inittab.

Have fun,

Avery


===========

#!/bin/bash
#
# /usr/bin/fax wrapper script for the efax package:
#   run "fax answer" and, if a fax is received, convert it to a multipage
#   compressed postscript document and e-mail it to $MAILTO (default is
#   postmaster)
#
# Copyright 1998 by Avery Pennarun <apenwarr@worldvisions.ca>
# Use, modify, and redistribute freely.
#

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

VERB=ewir
SPKR=-iM1

source /etc/efax.rc

#set -x

xmit()
{
    PAGES="$1"

    (
	cat <<-EOF
		From: <efax@$HOSTNAME>
		Mime-Version: 1.0
		Subject: $PAGES-page fax received
		Content-Type: multipart/mixed; boundary="-"

		This is a MIME encoded message.  Use a MIME-compatible e-mail
		package if you want to read it.

		EOF

	cat <<-EOF
		---
		Content-Type: application/postscript; name="fax.ps.gz"
		Content-Transfer-Encoding: base64
		Content-Disposition: inline; filename="$(basename fax.ps.gz)"

		EOF

	shift
	cat | gzip -c | mimencode

    ) | $MAILER $MAILTO
}

convert_faxes()
{
	set -e

	cd /var/spool/fax

	for d in [0-9]*.001; do
		BASE="$(basename $d .001)"
		FILES="$(echo $BASE.[0-9][0-9][0-9])"
		PAGES="$(echo $FILES | wc -w | sed 's/[ 	]*//g')"

		if [ "$BASE" = '[0-9]*' ]; then
			break;
		fi

		echo "Processing $BASE ($PAGES pages)"
		efix -ops $FILES 2>/dev/null | xmit $PAGES
		mkdir done 2>/dev/null || true
		mv $FILES done/
		rm -f $BASE.log
	done
}


fax VERB="$VERB" SPKR="$SPKR" answer
#true
FAXRET=$?

if [ "$FAXRET" = 0 ]; then
	convert_faxes &
fi

exit 0

#27052#8
Date:
1998-10-03 14:16:22 UTC
From:
To:
Ed,

Here is a script which Avery contributed. I'll put it into the next Debian
revision of efax. I just thought I should seek your input on what to name it.
Any suggestions?  Maybe faxreceive ?  That choice would be compatible with
the currently used commands (see the list of what Debian already has below).

Regards, Dirk

#27052#13
Date:
1998-10-08 00:02:29 UTC
From:
To:
Hi Avery,

Here's what Ed wrote regarding your wrapper script. It might be best to
proceed along the lines he suggested as the values needed are easily
available from within efax.

Regards, Dirk

#27052#18
Date:
1998-11-01 21:05:42 UTC
From:
To:
Hi guys,

I've re-written my fax-to-multipage-postscript-email conversion script to
use the NOTIFY features in the 'fax' script.  In doing so, I found some
problems with the NOTIFY feature itself -- it doesn't work if I use the "fax
receive" command, but only with "fax answer", and even then, only the _next_
time I run "fax answer" after receiving a fax!

This is pretty weird.  Below, I'm including a patch for the fax script that
makes it run NOTIFY even for fax receive, so it will work in my setup (where
I can't use fax answer... long story).

I also include my new and improved efax.convert script, which takes $REMID
$FILES on the command line.

Have fun,

Avery
--- /usr/bin/fax.old	Fri May  1 20:34:30 1998
+++ /usr/bin/fax	Sun Nov  1 15:42:44 1998
@@ -494,7 +494,7 @@
 	case $OWNER in '') ;; *) chown $OWNER /dev/$DEV ;; esac
 	case $MODE  in '') ;; *) chmod $MODE  /dev/$DEV ;; esac

-	for f in ${DEVN}.[0-9]*  	# clean up old log files
+	for f in ${DEVN}.[0-9]* *.log  	# clean up old log files
 	do
 	  grep "done, returning $NOLOG" $f >/dev/null 2>/dev/null
 	  case $? in
@@ -862,7 +862,22 @@
 	ERR=$?

 	case $ERR in
-	0)	$RM $logfile ; break ;;
+	0)	#AVE $RM $logfile ; break ;;
+		f=$logfile
+	        FILES=`sed -n -e  '/received ->/s/^.*-> \(.*\)$/\1/p' $f`
+		FILES=`echo $FILES`
+		REMID=`sed -n -e '/remote ID ->/s/^.*-> \(.*\)$/\1/p' \
+			-etok -eb -e:ok -eq $f`
+		case $REMID in '') REMID='?' ;; esac
+		eval $NOTIFY
+		# The following two lines changed for Debian's efax after
+		# consultation with Ed Casas   --edd 19 Oct 96
+		# echo >>${DEVN}.log
+		# cat $f >>${DEVN}.log
+                echo >>${FAXLOGDIR}/${DEVN}.log
+                cat $f >>${FAXLOGDIR}/${DEVN}.log
+	  	$RM $f
+		;;
 	1)	echo Busy... ;;
 	*)	echo "There were errors (see ${logfile})." ; break ;;
 	esac
----------------------->>> efax.convert starts here >>>----------------- #!/bin/bash # # fax conversion script for the efax package: # called by /usr/bin/fax when a fax is received. Convert it to a # multipage compressed postscript document and e-mail it to $MAILTO # (default is postmaster) # # Copyright 1998 by Avery Pennarun <apenwarr@worldvisions.ca> # Use, modify, and redistribute freely. # MAILTO="postmaster" MAILER=/usr/sbin/sendmail VERB=ewir SPKR=-iM1 # override all options from the efax config file source /etc/efax.rc # process the command line REMID="$(echo "$1" | sed 's/\(^\| \) */\1/g')" shift FILES="$*" #set -x xmit() { SUBJECT="$1" ( cat <<-EOF From: <efax@$HOSTNAME> Mime-Version: 1.0 Subject: $SUBJECT Content-Type: multipart/mixed; boundary="-" This is a MIME encoded message. Use a MIME-compatible e-mail package if you want to read it. EOF cat <<-EOF --- Content-Type: application/postscript; name="fax.ps.gz" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="$(basename fax.ps.gz)" EOF shift cat | gzip -c | mimencode ) | $MAILER $MAILTO } set -e cd /var/spool/fax PAGES="$(echo $FILES | wc -w | sed 's/[ ]*//g')" echo "Processing fax from $REMID ($PAGES pages)" efix -ops $FILES </dev/null 2>/dev/null \ | xmit "Fax: $PAGES pages from "\""$REMID"\" mkdir done 2>/dev/null || true mv $FILES done/ 2>/dev/null || true