HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

[hylafax-users] New faxrcvd



I have finished working on a new faxrcvd. Have a look and if you like what you
see, by all means use it. I have made a lot of changes so I decided to post the
whole file instead of just a patch. -Jeremy
#! /bin/sh
#	$Id: faxrcvd.sh.in,v 1.1 2001/04/15 03:48:16 darren Exp $
#
# HylaFAX Facsimile Software
#
# Copyright (c) 1990-1996 Sam Leffler
# Copyright (c) 1991-1996 Silicon Graphics, Inc.
# HylaFAX is a trademark of Silicon Graphics
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

#
# faxrcvd file devID commID error-msg [CIDNumber]
#
if [ $# -lt 4 ] || [ $# -gt 5 ]; then # makes CIDNumber optional 
    echo "Usage: $0 file devID commID error-msg [CIDNumber] "
    exit 1
fi

test -f etc/setup.cache || {
    SPOOL=`pwd`
    cat<<EOF

FATAL ERROR: $SPOOL/etc/setup.cache is missing!

The file $SPOOL/etc/setup.cache is not present.  This
probably means the machine has not been setup using the faxsetup(8C)
command.  Read the documentation on setting up HylaFAX before you
startup a server system.

EOF
    exit 1
}
. etc/setup.cache

INFO=$SBIN/faxinfo

#
# Programs used to convert the tiff image to Postscript and PDF. Previous 
# versions of faxrcvd used fax2ps to convert to a compressed Postscript 
# format which quality was very poor.  
#
#TIFF2PS=$TIFFBIN/fax2ps                   # fax2ps looks bad
#TIFF2PS_OPTS=""                           # leave blank for fax2ps
TIFF2PS=tiff2ps
TIFF2PS_OPTS="-a -O recvq/\${FILENAME}.ps" 
PS2PDF=ps2pdf
PS2PDF_OPTS=""

#
# Notifications are sent to TOADDR by default, SENDTO is the address 
# attachments (tif, ps, pdf) are sent. All changes to variables should 
# be done in etc/FaxDispatch
#
TOADDR=FaxMaster
NTFYTOADDR="yes"                           # Send a notification to $TOADDR
SENDTO=

#
# Default encoding of Postscript attachments is 7bit ascii
#
ENCODING="7bit"                            # 7bit or base64
MIMENCODE=mimencode                        # program used to base64 encode 

#
# Permit various types of attachment types: ps, tif, pdf
# Note that non-ASCII filetypes require metamail.
# pdf requires tiff2ps and ps2pdf
#
FILETYPE=ps

#
# There is no good portable way to find out the fully qualified
# domain name (FQDN) of the host or the TCP port for the hylafax
# service so we fudge here.  Folks may want to tailor this to
# their needs; e.g. add a domain or use localhost so the loopback
# interface is used.
#
HOSTNAME=`hostname`			# XXX no good way to find FQDN
PORT=4559				# XXX no good way to lookup service

FILE="$1"
DEVICE="$2"
COMMID="$3"
MSG="$4"
CIDNUMBER="$5"

#
# Filename used for attachments 
#
FILENAME=`echo $FILE | $SED -e 's/\.tif//' -e 's/recvq\///'`

#
# This function prints the fax information details; it is used to remove 
# repeated code from faxrcvd. 
#
printfaxinfo ()
{
    echo "$FILE (ftp://$HOSTNAME:$PORT/$FILE):"; $INFO -n $FILE
    echo "ReceivedOn: $DEVICE"
    if [ "$CIDNUMBER" ]; then
	echo " CIDNumber: $CIDNUMBER"
    fi
    if [ "$MSG" ]; then
	echo ""
	echo "The full document was not received because:"
	echo ""
	echo "    $MSG"
	echo ""
	echo "    ---- Transcript of session follows ----"
	echo ""
	if [ -f log/c$COMMID ]; then
	    $SED -e '/-- data/d' \
		 -e '/start.*timer/d' -e '/stop.*timer/d' \
		 log/c$COMMID
	elif [ -n "$COMMID" ]; then
	    echo "    No transcript available (CommID: c$COMMID)."
	else
	    echo "    No transcript available."
	fi
    else
	 echo "    CommID: c$COMMID (ftp://$HOSTNAME:$PORT/log/c$COMMID)"
    fi
}

if [ -f $FILE ]; then
    #
    # Check the sender's TSI and setup to dispatch
    # facsimile received from well-known senders.
    #
    SENDER="`$INFO $FILE | $AWK -F: '/Sender/ { print $2 }' 2>/dev/null`"
    if [ -f etc/FaxDispatch ]; then
	#
	# NB: FaxDispatch sets SENDTO, FILETYPE, ENCODING, and other options
	#
	. etc/FaxDispatch  
    fi
    #
    # Don't send duplicate notification if $TOADDR = $SENDTO and only send 
    # notification if there is an error or NTFYTOADDR = "yes"(default).
    #
    if [ "$TOADDR" != "$SENDTO" ] && \
       [ -n "$MSG" -o "$NTFYTOADDR" = "yes" ]; then 
	(echo "To: $TOADDR"
	 echo "From: The HylaFAX Receive Agent <fax>"
	 echo "Subject: Facsimile Received From: $SENDER"
	 echo ""
	 printfaxinfo  #function that prints the Fax info and/or error messages 
	if [ -n "$SENDTO" ]; then
	    echo ""
	    echo "The facsimile was automatically dispatched to: $SENDTO." 
	fi
	) | 2>&1 $SENDMAIL -ffax -oi $TOADDR
    fi
    if [ -n "$SENDTO" ]; then
	(MIMEBOUNDARY="NextPart$$"
	 echo "Mime-Version: 1.0"
	 echo "Content-Type: Multipart/Mixed; Boundary=\"$MIMEBOUNDARY\""
	 echo "Content-Transfer-Encoding: 7bit"
	 echo "To: $SENDTO"
	 echo "From: The HylaFAX Receive Agent <fax>"
	 echo "Subject: Facsimile Received From: $SENDER"
	 echo ""
	 echo "--$MIMEBOUNDARY"
	 echo "Content-Type: text/plain; charset=us-ascii"
	 echo "Content-Transfer-Encoding: 7bit"
	 echo ""
	 printfaxinfo  #prints the Fax info and/or error messages 
	 echo ""
	 echo "--$MIMEBOUNDARY"
	 if [ -n "$FILETYPE" ]; then  # check to see if we include an attachment
	    if [ "$FILETYPE" = "tif" ]; then
		CONTTYPE="image/tiff"; ENCODING="base64" # must be base64 encoded
	    else 
		eval "$TIFF2PS $TIFF2PS_OPTS $FILE 2>/dev/null" #convert to postscript
		if [ "$FILETYPE" = "pdf" ]; then 
		    CONTTYPE="application/pdf"; ENCODING="base64"
		    $PS2PDF $PS2PDF_OPTS recvq/${FILENAME}.ps \
		    recvq/${FILENAME}.pdf 2>/dev/null
		else #  default as Postscript
		    CONTTYPE="application/postscript"
		fi
	    fi
	    echo "Content-Type: ${CONTTYPE}; name=\"${FILENAME}.${FILETYPE}\""
	    echo "Content-Description: FAX document"
	    echo "Content-Transfer-Encoding: $ENCODING"
	    echo "Content-Disposition: attachment; filename=\"${FILENAME}.${FILETYPE}\""
	    echo ""	
	    if [ "$ENCODING" = "base64" ]; then
		$MIMENCODE recvq/${FILENAME}.${FILETYPE} 2>/dev/null
		$RM -f recvq/${FILENAME}.ps recvq/${FILENAME}.pdf 2>/dev/null
	    else 
		$CAT recvq/${FILENAME}.${FILETYPE} 2>/dev/null 
	    fi
	 fi
	 echo ""
	 echo "--$MIMEBOUNDARY--"
	) | 2>&1 $SENDMAIL -ffax -oi $SENDTO
    fi
else
    #
    # Generate notification mail for a failed attempt.
    #
    if [ -f log/c$COMMID ]; then
     #parse TSI entry from the comm log
     SENDER=`$AWK -F: '/REMOTE TSI/ { print $5 }' log/c$COMMID | \
	     $SED -e 's/.*TSI "//' -e 's/"//'`
     COMMLOG="$SED -e '/-- data/d' \
	     -e '/start.*timer/d' -e '/stop.*timer/d' \
	     log/c$COMMID"
    elif [ -n "$COMMID" ]; then
     COMMLOG="echo '    No transcript available (CommID: c$COMMID).'"
    else 
     COMMLOG="echo '    No transcript available.'"
    fi
    (echo "To: $TOADDR"
     echo "From: The HylaFAX Receive Agent <fax>"
     echo "Subject: Facsimile NOT Received From: ${SENDER}"
     echo ""
     echo "An attempt to receive facsimile on $DEVICE failed because:"
     echo ""
     echo "    $MSG"
     echo ""
     echo "    ---- Transcript of session follows ----"
     echo ""
     eval $COMMLOG
    ) | 2>&1 $SENDMAIL -ffax -oi $TOADDR
fi
exit 0





Project hosted by iFAX Solutions