Update faxrcvd for Hylafax 4.4.4

tags/0.1.2_el5 0.1.2_el5
Daniel Berteaud 10 years ago
parent 943374c90c
commit 8ccd19ff54
  1. 352
      root/var/spool/hylafax/bin/faxrcvd-sme

@ -1,20 +1,5 @@
#! /bin/bash #! /bin/bash
# $Id: faxrcvd.sh.in,v 1.32 2008/04/29 23:34:25 faxguy Exp $ # $Id: faxrcvd.sh.in,v 1.49.4.1 2007/09/24 19:13:47 aidan Exp $
#
# ============================================
#
# A NOTE ON CUSTOMIZING this script:
#
# You are welcome (even encouraged) to customize this script to suit the
# needs of the deployment. However, be advised that this script is
# considered part of the package distribution and is subject to being
# overwritten by subsequent upgrades. Please consider copying this file
# to something like "etc/faxrcvd-custom", modifying that copy of the file,
# and then setting "FaxRcvdCmd: etc/faxrcvd-custom" in your modem config
# file to prevent your customizations from being overwritten during an
# upgrade process.
#
# ============================================
# #
# HylaFAX Facsimile Software # HylaFAX Facsimile Software
# #
@ -29,11 +14,11 @@
# Sam Leffler and Silicon Graphics may not be used in any advertising or # Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written # publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics. # permission of Sam Leffler and Silicon Graphics.
# #
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
# #
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
@ -50,165 +35,6 @@ if [ $# -lt 4 ]; then
exit 1 exit 1
fi fi
#
# If you want to change the presentation of the e-mail notification
# then this is the place to change that. We put it here, up-front,
# because this is most likely what most customizations will deal with.
#
faxrcvd_mail()
{
MAILTYPE="$1"
MAILTO="$2"
CCTO="$3"
BCCTO="$4"
(echo "Mime-Version: 1.0"
echo "Content-Type: Multipart/Mixed; Boundary=\"$MIMEBOUNDARY\""
echo "Content-Transfer-Encoding: 7bit"
echo "To: $MAILTO"
if [ -n "$CCTO" ]; then echo "Cc: $CCTO"; fi
if [ -n "$BCCTO" ]; then echo "Bcc: $BCCTO"; fi
printf "From: "
printf "$DICTRECEIVEAGENT" | LANG=C $AWK -f bin/rfc2047-encode.awk -v charset="$CHARSET"
echo " <$FROMADDR>"
printf "Subject: "
(
if [ -f "$FILE" ]; then
eval echo "$DICTRECEIVEDFROM";
else
eval echo "$DICTNOTRECEIVED";
fi
) | LANG=C $AWK -f bin/rfc2047-encode.awk -v charset="$CHARSET"; echo
echo ""
echo "--$MIMEBOUNDARY"
echo "Content-Type: text/plain; charset=$CHARSET"
echo "Content-Transfer-Encoding: quoted-printable"
echo ""
(
if [ -f $FILE ]; then
case "$MAILTYPE" in
textonly)
echo "$FILE (ftp://$HOSTNAME:$PORT/$FILE):";;
esac
faxInfo $FILE
echo "$DICTRECEIVEDON| $DEVICE" | printFormatted $INFOSIZE
if [ -z "$MSG" ]; then
case "$MAILTYPE" in
withattached)
echo "$DICTCOMMID| c$COMMID" | printFormatted $INFOSIZE
;;
textonly)
echo "$DICTCOMMID| c$COMMID (ftp://$HOSTNAME:$PORT/log/c$COMMID)" | printFormatted $INFOSIZE
if [ -f $FILE ] && [ -n "$SENDTO" ]; then
echo ""
eval echo "$DICTDISPATCHEDTO"
fi
;;
esac
fi
else
eval echo "$DICTATTEMPTEDFAXFAILED"
fi
) | LANG=C $AWK -f bin/qp-encode.awk
if [ "$MSG" ] || [ ! -f $FILE ]; then
(
echo ""
echo "$DICTMSGINTRO"
echo ""
echo " $ERRMSG"
echo ""
echo "$DICTLOGFOLLOWS"
echo ""
) | LANG=C $AWK -f bin/qp-encode.awk
if [ -f log/c$COMMID ]; then
echo ""
echo "--$MIMEBOUNDARY"
echo "Content-Type: text/plain; charset=US-ASCII; name=c$COMMID"
echo "Content-Description: FAX session log"
echo "Content-Transfer-Encoding: 7bit"
echo "Content-Disposition: inline"
echo ""
$SED -e '/-- data/d' \
-e '/start.*timer/d' -e '/stop.*timer/d' \
log/c$COMMID
elif [ -n "$COMMID" ]; then
( echo "$DICTNOLOGAVAIL ($DICTCOMMID c$COMMID)." ) | LANG=C $AWK -f bin/qp-encode.awk
else
( echo "$DICTNOLOGAVAIL." ) | LANG=C $AWK -f bin/qp-encode.awk
fi
fi
if [ -f $FILE ]; then
if [ "$MAILTYPE" = "withattached" ]; then
for type in $FILETYPE; do
echo ""
echo "--$MIMEBOUNDARY"
if [ "$type" = "tif" ]; then
echo "Content-Type: image/tiff; name=\"$FILENAME.tif\""
echo "Content-Description: FAX document"
echo "Content-Transfer-Encoding: $ENCODING"
echo "Content-Disposition: attachment; filename=\"$FILENAME.tif\""
echo ""
# This is useful because the majority of TIFF viewers won't
# be able to read JBIG compressed TIFF files, while
# G4 (MMR) is a much older and supported format.
if (tiffinfo $FILE | grep "JBIG" > /dev/null) then
tiffcp -c g4 $FILE $FILE.g4.tif
encode $FILE.g4.tif
$RM -f $FILE.g4.tif 2>$ERRORSTO
else
encode $FILE
fi
elif [ "$type" = "tif-r" ]; then
echo "Content-Type: image/tiff; name=\"$FILENAME.tif\""
echo "Content-Description: FAX document"
echo "Content-Transfer-Encoding: $ENCODING"
echo "Content-Disposition: attachment; filename=\"$FILENAME.tif\""
echo ""
if (tiffinfo $FILE | grep "JPEG" > /dev/null) then
tiffcp -c jpeg:R $FILE $FILE.r.tif
encode $FILE.r.tif
$RM -f $FILE.r.tif 2>$ERRORSTO
else
encode $FILE
fi
elif [ "$type" = "tif-y" ]; then
echo "Content-Type: image/tiff; name=\"$FILENAME.tif\""
echo "Content-Description: FAX document"
echo "Content-Transfer-Encoding: $ENCODING"
echo "Content-Disposition: attachment; filename=\"$FILENAME.tif\""
echo ""
if (tiffinfo $FILE | grep "JPEG" > /dev/null) then
tiffcp -c jpeg:Y $FILE $FILE.y.tif
encode $FILE.y.tif
$RM -f $FILE.y.tif 2>$ERRORSTO
else
encode $FILE
fi
elif [ "$type" = "pdf" ]; then
echo "Content-Type: application/pdf; name=\"$FILENAME.pdf\""
echo "Content-Description: FAX document"
echo "Content-Transfer-Encoding: $ENCODING"
echo "Content-Disposition: attachment; filename=\"$FILENAME.pdf\""
echo ""
$TIFF2PDF -o $FILE.pdf $FILE
encode $FILE.pdf
$RM -f $FILE.pdf 2>$ERRORSTO
else # default as Postscript
echo "Content-Type: application/postscript; name=\"$FILENAME.ps\""
echo "Content-Description: FAX document"
echo "Content-Transfer-Encoding: 7bit"
echo "Content-Disposition: attachment; filename=\"$FILENAME.ps\""
echo ""
$FAX2PS $FILE 2>$ERRORSTO
fi
done
fi
fi
echo ""
echo "--$MIMEBOUNDARY--"
) 2>$ERRORSTO | $SENDMAIL -f$FROMADDR -oi -t
}
test -f etc/setup.cache || { test -f etc/setup.cache || {
SPOOL=`pwd` SPOOL=`pwd`
cat<<EOF cat<<EOF
@ -228,10 +54,8 @@ EOF
# didn't re-run faxsetup; we set them before calling setup.cache for # didn't re-run faxsetup; we set them before calling setup.cache for
# backward compatibility. # backward compatibility.
ENCODING=base64 ENCODING=base64
MIMENCODE=mimencode
TIFF2PDF=bin/tiff2pdf TIFF2PDF=bin/tiff2pdf
TTYCMD=tty TTYCMD=tty
CHARSET=UTF-8 # this really gets set in dictionary
. etc/setup.cache . etc/setup.cache
. bin/common-functions . bin/common-functions
@ -243,7 +67,6 @@ TOADDR=FaxMaster
FROMADDR=fax FROMADDR=fax
TIFFINFO=tiffinfo TIFFINFO=tiffinfo
NOTIFY_FAXMASTER=always NOTIFY_FAXMASTER=always
MIMEBOUNDARY="NextPart$$"
# #
# Redirect errors to a tty, if possible, rather than # Redirect errors to a tty, if possible, rather than
@ -260,6 +83,9 @@ fi
# Permit various types of attachment types: ps, tif, pdf # Permit various types of attachment types: ps, tif, pdf
# Note that non-ASCII filetypes require an encoder. # Note that non-ASCII filetypes require an encoder.
# pdf requires tiff2ps and tiff2pdf # pdf requires tiff2ps and tiff2pdf
# Multiple file types may be specified by separating them with
# whitespace; in that case a separate attachment for each filetype
# will be created.
# #
FILETYPE=ps FILETYPE=ps
SENDTO= SENDTO=
@ -271,8 +97,8 @@ SENDTO=
# their needs; e.g. add a domain or use localhost so the loopback # their needs; e.g. add a domain or use localhost so the loopback
# interface is used. # interface is used.
# #
HOSTNAME=`hostname` # XXX no good way to find FQDN HOSTNAME=`hostname` # XXX no good way to find FQDN
PORT=4559 # XXX no good way to lookup service PORT=4559 # XXX no good way to lookup service
FILE="$1"; shift; FILE="$1"; shift;
DEVICE="$1"; shift; DEVICE="$1"; shift;
@ -283,6 +109,7 @@ while [ $# -ge 1 ]; do
# The eval has $1 set yet, and this forces a variable-to-variable # The eval has $1 set yet, and this forces a variable-to-variable
# assignment, allowing us to not need to do escaping # assignment, allowing us to not need to do escaping
eval CALLID$COUNT='$1' eval CALLID$COUNT='$1'
export CALLID$COUNT
shift shift
COUNT=`expr $COUNT + 1` COUNT=`expr $COUNT + 1`
done done
@ -290,97 +117,112 @@ CIDNUMBER="$CALLID1"
CIDNAME="$CALLID2" CIDNAME="$CALLID2"
FILENAME=`echo $FILE | $SED -e 's/\.tif//' -e 's/recvq\///'` FILENAME=`echo $FILE | $SED -e 's/\.tif//' -e 's/recvq\///'`
SENDER="`$INFO $FILE | $SED -n 's/ *Sender: //p' 2>$ERRORSTO`"
SUBADDR="`$INFO $FILE | $SED -n 's/ *SubAddr: //p' 2>$ERRORSTO`"
if [ ! -f $FILE ] && [ -z "$MSG" ]; then SetupPrivateTmp
MSG="unknown problem, file unavailable"
fi parseFaxInfo $FILE
MIMEBOUNDARY="NextPart$$"
export FILE
export COMMID
export DEVICE
export MSG
export FROMADDR
export HOSTNAME
export PORT
export SENDTO
export TOADDR
# #
# Apply customizations. All customizable variables should # Apply customizations. All customizable variables should
# be set to their non-customized defaults prior to this. # be set to their non-customized defaults prior to this.
# #
if [ -f etc/FaxDispatch ]; then if [ -f etc/FaxDispatch ]; then
. etc/FaxDispatch # NB: FaxDispatch sets SENDTO . etc/FaxDispatch # NB: FaxDispatch sets SENDTO
fi fi
# if [ -f etc/templates/$TEMPLATE/hook.sh ]
# Fetch language settings (after FaxDispatch for customization of $LANG). then
# # Any hooks that the templates need
. bin/dictionary . etc/templates/$TEMPLATE/hook.sh
if [ -f etc/FaxDictionary ]; then
. etc/FaxDictionary
fi fi
#
# Customize error message.
#
ERRNUM=`echo $MSG | sed 's/.*{\([^}]*\)}$/\1/g'`
if [ "$ERRNUM" != "$MSG" ]; then
eval ERRMSG="$"`echo $ERRNUM`
if [ -z "$ERRMSG" ]; then
ERRMSG="$MSG"
fi
else
ERRNUM=
ERRMSG="$MSG"
fi
setInfoSize $FILE ## MailWithFAX <type>
## Email the <type> template,adding the attachments according
## to $FILETYPE to $SENDTO
##
## We use the common CreateMailMessage <template> <f1> <t1> <n1> <d1>
## function, creating the file to mail as we go.
MailWithFAX ()
{
template="etc/templates/$TEMPLATE/faxrcvd-$1.txt"
files_1=$FILE;
filetype_1=TIFF;
nfiles=1;
for ft in $FILETYPE
do
ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
done
eval CreateMailMessage $template $ATTACH_ARGS \
2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$SENDTO"
}
# Convert TIFF file format/compression from JBIG to MMR (G4) if admin if [ -f $FILE ]; then
# requested for it in FaxDispatch. #
# The TIFF JBIG file as saved by HylaFAX is REPLACED with a MMR (G4) version. # Don't send FaxMaster duplicates, and FaxMaster may not even
if [ "$RECV_DATA_CONVERSION" = "JBIG:MMR" ]; then # want a message at all, depending on NOTIFY_FAXMASTER.
if (tiffinfo $FILE | grep "JBIG" > /dev/null) then #
$RM -f $FILE.g4 case $NOTIFY_FAXMASTER$MSG in
tiffcp -c g4 $FILE $FILE.g4 never*) NOTIFY_FAXMASTER=no;;
if [ $? = 0 -a -s $FILE.g4 ]; then errors) NOTIFY_FAXMASTER=no;;
# Using 'cp' and then 'rm' (instead of 'mv') preserves *) NOTIFY_FAXMASTER=yes;;
# owner/mode of the original file (at least on Linux) esac
#cp -p $FILE $FILE.jbig.tif if [ "$TOADDR" != "$SENDTO" ] && [ "$NOTIFY_FAXMASTER" != "no" ]; then
cp $FILE.g4 $FILE if [ -z "$MSG" ]; then
CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-notify-success.txt \
2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
else
CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-notify-error.txt \
2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
fi fi
$RM -f $FILE.g4
fi fi
fi if [ -n "$SENDTO" ]; then
# Create the document to attache
if [ -z "$MSG" ]; then
MailWithFAX success
else
MailWithFAX error
fi
# Archive et impression
DATE=`date +%F_%H:%M:%S`
FICNAME=`date +%F_%H_%M_%S`
YEAR=`date +%Y`
MONTH=`date +%b`
# If $PRINTER not empty, then print $FILE with $PRINTER
if [ -n "$PRINTER" ]; then
/usr/bin/tiff2ps -a $FILE | /usr/bin/psmark -i - -o - -x -390 -y 20 -r 0 -s 7 "DATE: $DATE EXPEDITEUR: $CIDNUMBER $CIDNAME" | /usr/bin/lp -d $PRINTER
fi
# If DSTDIR is not empty, then, we copy the pdf in DSTDIR
if [ -n "$DSTDIR" ]; then
if [ ! -d "$DSTDIR/$YEAR/$MONTH" ];then
/bin/mkdir -p "$DSTDIR/$YEAR/$MONTH"
fi fi
/usr/bin/tiff2ps -a $FILE | /usr/bin/psmark -i - -o - -x -410 -y 20 -r 0 -s 7 "DATE: $DATE EXPEDITEUR: $CIDNUMBER $CIDNAME" | /usr/bin/ps2pdf -sPAPERSIZE=a4 - "$DSTDIR/$YEAR/$MONTH/$FICNAME.pdf"
fi
# Archive et impression
# DATE=`date +%F_%H:%M:%S`
# Don't send FaxMaster duplicates, and FaxMaster may not even FICNAME=`date +%F_%H_%M_%S`
# want a message at all, depending on NOTIFY_FAXMASTER. YEAR=`date +%Y`
# MONTH=`date +%b`
case $NOTIFY_FAXMASTER$MSG in # If $PRINTER not empty, then print $FILE with $PRINTER
never*) NOTIFY_FAXMASTER=no;; if [ -n "$PRINTER" ]; then
errors) NOTIFY_FAXMASTER=no;; /usr/bin/tiff2ps -a $FILE | /usr/bin/psmark -i - -o - -x -390 -y 20 -r 0 -s 7 "DATE: $DATE EXPEDITEUR: $CIDNUMBER $CIDNAME" | /usr/bin/lp -d $PRINTER
*) NOTIFY_FAXMASTER=yes;;
esac
if [ "$NOTIFY_FAXMASTER" != "no" ]; then
if [ ! -f $FILE ] || [ "$TOADDR" != "$SENDTO" ]; then
faxrcvd_mail "textonly" "$TOADDR" "" ""
fi fi
fi # If DSTDIR is not empty, then, we copy the pdf in DSTDIR
if [ -n "$SENDTO" ] && [ -f $FILE ]; then if [ -n "$DSTDIR" ]; then
for toeml in $SENDTO; do if [ ! -d "$DSTDIR/$YEAR/$MONTH" ];then
faxrcvd_mail "withattached" "$toeml" "$CCTO" "$BCCTO" /bin/mkdir -p "$DSTDIR/$YEAR/$MONTH"
done fi
/usr/bin/tiff2ps -a $FILE | /usr/bin/psmark -i - -o - -x -410 -y 20 -r 0 -s 7 "DATE: $DATE EXPEDITEUR: $CIDNUMBER $CIDNAME" | /usr/bin/ps2pdf -sPAPERSIZE=a4 - "$DSTDIR/$YEAR/$MONTH/$FICNAME.pdf"
fi
else
#
# Generate notification mail for a failed attempt.
# There is no file to send...
#
CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-failure.txt \
2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
fi fi
CleanupPrivateTmp

Loading…
Cancel
Save