#! /bin/sh # $Id: faxrcvd.sh.in,v 1.17 2004/03/11 22:45:29 lhoward 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 # if [ $# -lt 4 ]; then echo "Usage: $0 file devID commID error-msg CIDNumber CIDName " exit 1 fi test -f etc/setup.cache || { SPOOL=`pwd` cat</dev/null 2>&1; then ERRORSTO=`$TTYCMD` else ERRORSTO=/dev/null fi # # Permit various types of attachment types: ps, tif, pdf # Note that non-ASCII filetypes require an encoder. # pdf requires tiff2ps and ps2pdf # FILETYPE=ps SENDTO= # # 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='192.168.0.254' # 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" CIDNAME="$6" FILENAME=`echo $FILE | $SED -e 's/\.tif//' -e 's/recvq\///'` SENDER="`$INFO $FILE | $AWK -F: '/Sender/ { print $2 }' 2>$ERRORSTO | $SED 's/^.//'`" SUBADDR="`$INFO $FILE | $AWK -F: '/SubAddr/ { print $2 }' 2>$ERRORSTO | $SED 's/^.//'`" # # Apply customizations. All customizable variables should # be set to their non-customized defaults prior to this. # if [ -f etc/FaxDispatch ]; then . etc/FaxDispatch # NB: FaxDispatch sets SENDTO fi # # Produce mailable encoding for binary files. # encode() { if [ -x "$MIMENCODE" ]; then $MIMENCODE $1 2>$ERRORSTO elif [ -x "$UUENCODE" ]; then if [ "$ENCODING" = "base64" ]; then $UUENCODE -m $1 $1 | grep -E -v "^begin|^====$" 2>$ERRORSTO else $UUENCODE $1 $1 | grep -E -v "^begin|^====$" 2>$ERRORSTO fi else # Do not use "-x" for backward compatibility; even if it fails # this is last chance to encode data, so there's nothing to lose. $MIMENCODE $1 2>$ERRORSTO fi } if [ -f $FILE ]; then # # Don't send FaxMaster duplicates, and FaxMaster may not even # want a message at all, depending on NOTIFY_FAXMASTER. # case $NOTIFY_FAXMASTER$MSG in never*) NOTIFY_FAXMASTER=no;; errors) NOTIFY_FAXMASTER=no;; *) NOTIFY_FAXMASTER=yes;; esac if [ "$TOADDR" != "$SENDTO" -a "$NOTIFY_FAXMASTER" != "no" ]; then (echo "To: $TOADDR" echo "From: Agente de fax de HylaFAX <$FROMADDR>" echo "Subject: Fax recibido de $SENDER"; echo "" echo "$FILE (ftp://$HOSTNAME:$PORT/$FILE):"; $INFO -n $FILE echo "ReceivedOn: $DEVICE" 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 [ -n "$SENDTO" ]; then echo "" echo "The facsimile was automatically dispatched to: $SENDTO." fi ) | 2>&1 $SENDMAIL -f$FROMADDR -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: Agente receptor de HylaFAX <$FROMADDR>" echo "Subject: Se ha recibido un fax de $SENDER"; echo "" echo "--$MIMEBOUNDARY" echo "Content-Type: text/plain; charset=us-ascii" echo "Content-Transfer-Encoding: 7bit" echo "" echo "Se ha recibido un fax. El documento ($FILE) se encuentra disponible para su descarga en " echo -n '\\server\faxes\' echo "$FILE" | $SED "s/recvq\///" echo "" echo "" echo "O en (ftp://$HOSTNAME:$PORT/$FILE):"; $INFO -n $FILE | $SED -e 's/Pages/Páginas/' -e 's/Quality/Calidad/' -e 's/Received/Fecha\/hora de recepción/' -e 's/SignalRate/Velocidad/' -e 's/DataFormat/Formato de datos/' echo "" echo "" echo "Recibido por: $DEVICE" if [ "$MSG" ]; then echo "" echo "El documento no se ha recibido completo por:" echo "" echo " $MSG" echo "" echo " ---- Tanscripción de la sesión ----" 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 " Transcripción no dispoinbie (CommID c$COMMID)." else echo " Transcripción no disponible." fi else echo " CommID: c$COMMID (ftp://$HOSTNAME:$PORT/log/c$COMMID)" fi echo "" echo "--$MIMEBOUNDARY" if [ "$FILETYPE" = "tif" ]; then echo "Content-Type: image/tiff; name=\"$FILENAME.tif\"" echo "Content-Description: documento de FAX" echo "Content-Transfer-Encoding: $ENCODING" echo "Content-Disposition: attachment; filename=\"$FILENAME.tif\"" echo "" encode $FILE; elif [ "$FILETYPE" = "pdf" ]; then echo "Content-Type: application/pdf; name=\"$FILENAME.pdf\"" echo "Content-Description: documento de FAX" echo "Content-Transfer-Encoding: $ENCODING" echo "Content-Disposition: attachment; filename=\"$FILENAME.pdf\"" echo "" GW=`$TIFFINFO $FILE 2>$ERRORSTO | $GREP "Image Width" | \ $SED 's/.*Image Width: \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'` GL=`$TIFFINFO $FILE 2>$ERRORSTO | $GREP "Image Length" | \ $SED 's/.*Image Length: \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'` RW=`$TIFFINFO $FILE 2>$ERRORSTO | $GREP "Resolution" | \ $SED 's/.*Resolution: \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'` RL=`$TIFFINFO $FILE 2>$ERRORSTO | $GREP "Resolution" | \ $SED 's/.*Resolution: [0-9]*, \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'` # keep any output from tiff2ps and ps2pdf from the message source $TIFF2PS -a -O $FILE.ps $FILE > $ERRORSTO 2>&1 # fax2ps output looks bad $PS2PDF -g$GW\x$GL -r$RW\x$RL $FILE.ps $FILE.pdf > $ERRORSTO 2>&1 encode $FILE.pdf $RM -f $FILE.ps $FILE.pdf 2>$ERRORSTO else # default as Postscript echo "Content-Type: application/postscript; name=\"$FILENAME.ps\"" echo "Content-Description: documento de FAX" echo "Content-Transfer-Encoding: 7bit" echo "Content-Disposition: attachment; filename=\"$FILENAME.ps\"" echo "" $FAX2PS $FILE 2>$ERRORSTO fi echo "" echo "--$MIMEBOUNDARY--" ) | 2>&1 $SENDMAIL -f$FROMADDR -oi $SENDTO fi else # # Generate notification mail for a failed attempt. # (echo "To: $TOADDR" echo "From: Agente de recepción de HylaFAX <$FROMADDR>" echo "Subject: fax NO recibido" echo "" echo "Hubo un intento de envío de fax por $DEVICE que falló por el siguiente motivo:" echo "" echo " $MSG" echo "" echo " ---- Transcripción de la sesión ----" 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 ) | 2>&1 $SENDMAIL -f$FROMADDR -oi $TOADDR fi