#! /bin/bash # $Id$ # # 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. # # 2004/02/28 Frank Brock # # The notify shell now behaves in a manner like faxrcvd. # It is now written in shell with a little embedded awk as needed. . bin/common-functions . bin/common-functions-local # # notify qfile why jobtime [nextTry] # # Return mail to the submitter of a job when notification is needed. # #exec 2>/tmp/faxnotify-trace$$.log #set -x if [ $# != 3 ] && [ $# != 4 ]; then echo "Usage: $0 qfile why jobtime [nextTry]" hfExit 1 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. # notify_mail() { MAILSUBJECT="$1" MAILTO="$2" (echo "MIME-Version: 1.0" echo "X-Mailer: sendmail EisFAX on eisfair" echo "Content-Type: Multipart/Mixed; Boundary=\"$MIMEBOUNDARY\"" echo "Content-Transfer-Encoding: 7bit" echo "To: ${MAILTO}" echo "From: Fax daemon <${FROMADDR}>" ( header_field='Subject:' && printf '%s' "$header_field" && columns_used="${#header_field}" && rfc2047_encode "$columns_used" "$CHARSET" "$MAILSUBJECT" columns_used ) echo echo "" echo "This is a multi-part message in MIME format." echo "" echo "--$MIMEBOUNDARY" echo "Mime-Version: 1.0" echo "Content-Type: text/plain; charset=$CHARSET" echo "Content-Transfer-Encoding: quoted-printable" echo "" ( if [ -z "$THISJOBTYPE" ]; then printf "$jobtag $DICTTO $number" else eval printf \"$DICTYOURJOBTO\" fi if [ "$WHY" = "done" ]; then echo "$DICTCOMPLETEDSUCCESSFULLY" echo "" else case "$WHY" in failed) printf " $DICTFAILEDBECAUSE\n " echo "$FAXSTATUSMSG";; rejected) printf " $DICTREJECTEDBECAUSE\n " echo "$FAXSTATUSMSG";; blocked) printf " $DICTDELAYEDBECAUSE\n " echo "$FAXSTATUSMSG" echo "" echo "$DICTASSOONASPOSSIBLE";; requeued) printf " $DICTWASNOTSENT\n " echo "$FAXSTATUSMSG" echo "" echo "$DICTWILLBERETRIED $NEXT.";; killed|removed) echo " $DICTWASDELETED";; timedout) echo " $DICTTIMEDOUT";; format_failed) echo " $DICTCONVERSION1" echo "$DICTCONVERSION2" echo "" echo "$FAXSTATUSMSG" echo "" echo "$DICTCONVERSION3";; no_formatter) echo " $DICTNOFORMATTER1" echo "$DICTNOFORMATTER2";; poll_*) printf "$DICTPOLLINGFAILED" if [ "$WHY" = "poll_rejected" ] ; then echo "$DICTREMOTEREJECTED" elif [ "$WHY" = "poll_no_document" ] ; then echo "$DICTNODOCTOPOLL" elif [ "$WHY" = "poll_failed" ] ; then echo "$DICTUNSPECIFIEDPROBLEM" fi;; *) echo " $DICTUNKNOWNREASON1" echo "$DICTUNKNOWNREASON2" echo "$DICTUNKNOWNREASON3" echo "" echo "why: $WHY" echo "jobTime: $JTIME" echo "nextTry: $NEXT" echo "" echo "$DICTUNKNOWNREASON4";; esac echo "" echo " ---- $DICTUNSENTJOBSTATUS ----" echo "" fi echo "$DICTDESTINATION| $number" | printFormatted $ITEMSIZE echo "$DICTSENDER| $sender" | printFormatted $ITEMSIZE echo "$DICTMAILADDR| $mailaddr" | printFormatted $ITEMSIZE if [ "$jobtype" = "facsimile" ] then if [ "$npages" -gt 0 ] then echo "$DICTPAGES| $npages" | printFormatted $ITEMSIZE fi if [ -n "$faxstatus" ] && [ -n "$dirnum" ] then echo "$DICTDIRNUM| $dirnum ($DICTDIRNEXTPAGE)" | printFormatted $ITEMSIZE fi if [ -n "$csi" ] then echo "$DICTRECEIVER| $csi" | printFormatted $ITEMSIZE fi if [ "$RETURNTECHINFO" = "yes" ] && [ "$totdials" -gt 0 ] || [ "`echo ${modemused} | cut -c-7`" = "faxCAPI" ] then case "$resolution" in 196) echo "$DICTQUALITY| $DICTFINE" | printFormatted $ITEMSIZE;; 98) echo "$DICTQUALITY| $DICTNORMAL" | printFormatted $ITEMSIZE;; *) echo "$DICTRES| $resolution (lpi)" | printFormatted $ITEMSIZE;; esac echo "$DICTPAGEWIDTH| $pagewidth (mm)" | printFormatted $ITEMSIZE echo "$DICTPAGELENGTH| $pagelength (mm)" | printFormatted $ITEMSIZE echo "$DICTSIGNALRATE| $signalrate" | printFormatted $ITEMSIZE echo "$DICTDATAFORMAT| $dataformat" | printFormatted $ITEMSIZE # hb 2008-06-14 echo "${DICTSENDDATETIME}| ${SEND_DATE_TIME}" | printFormatted $ITEMSIZE if [ -n "$equipment" ] then echo "$DICTREMOTEEQUIPMENT| $equipment" | printFormatted $ITEMSIZE fi if [ -n "$station" ] then echo "$DICTREMOTESTATION| $station" | printFormatted $ITEMSIZE fi fi fi if [ "$RETURNTECHINFO" = "yes" ] then if [ "$tottries" != "1" ] then echo "$DICTDIALOGS| $tottries ($DICTREMOTEEXCHANGES)" | printFormatted $ITEMSIZE fi if [ "$totdials" != "1" ] && [ "`echo ${modemused} | cut -c-7`" != "faxCAPI" ] then echo "$DICTCALLS| $totdials ($DICTTOTALCALLS)" | printFormatted $ITEMSIZE fi if [ "$ndials" != "0" ] then echo "$DICTDIALS| $ndials ($DICTFAILEDCALLS)" | printFormatted $ITEMSIZE fi # hb 2009-03-01 echo "$DICTMODEM| $modem" | printFormatted $ITEMSIZE # echo "$DICTMODEM| $modemused" | printFormatted $ITEMSIZE if [ -n "$faxstatus" ] then echo "$DICTSTATUS| $FAXSTATUSMSG" | printFormatted $ITEMSIZE fi echo "$DICTSUBMITTEDFROM| $client" | printFormatted $ITEMSIZE echo "$DICTJOBID| $jobid" | printFormatted $ITEMSIZE echo "$DICTGROUPID| $groupid" | printFormatted $ITEMSIZE if [ -n "$commid" ] then echo "$DICTCOMMID| c$commid" | printFormatted $ITEMSIZE fi if [ -n "$JTIME" ] then printf "\n$DICTPROCESSINGTIME %s.\n" "$JTIME" fi fi if [ "$jobtype" = "facsimile" ]; then if [ $nfiles -gt 0 ] && [ "$RETURNTECHINFO" = "yes" ] ; then echo "" echo " ---- $DICTDOCSSUBMITTED ----" echo "" eval echo "$DICTDOCSTEXT1" eval echo "$DICTDOCSTEXT2" eval echo "$DICTDOCSTEXT3" eval echo "$DICTDOCSTEXT4" echo "" printf "%-20s %8s %s\n" "$DICTFILENAME" "$DICTSIZE" "$DICTTYPE" for i in `local_seq 1 $nfiles`; do name="files_$i" eval filename=`echo "$"$name` if [ -f $filename ] ; then set - `wc -c "$filename"` FILESIZE=$1 type="filetype_$i" eval filetype=`echo "$"$type` # # Because Ghostscript accepts PDF identically to PostScript # and because HylaFAX has historically handled PDF named as # "postscript" we have to double-check the PostScript filetype. # if [ "$filetype" = "PostScript" ]; then if [ "`fileType $filename`" != "PostScript" ]; then filetype=PDF fi fi printf "%-20s %8d %s\n" "$filename" "$FILESIZE" "$filetype" fi done fi elif [ "$jobtype" = "pager" ] && [ "$WHY" != "done" ] then if [ $npins -ne 0 ] then echo "" echo " ---- $DICTUNSENTPAGES ----" echo "" for i in `local_seq 1 $npins`; do name="files_$i" eval pin=`echo "$"$name` printf "%15s\n" "$DICTPIN" $pin done fi if [ $nfiles -ne 0 ] && [ -s $files_0 ] then echo "" echo " ---- $DICTMESSAGETEXT ----" echo "" cat $files_0 fi fi ) | LANG=C $AWK -f bin/qp-encode.awk if [ -n "$faxstatus" ] && [ "$RETURNTRANSCRIPT" = "yes" ] then ( # use -e in echo to interpret escape characters in faxstatus echo "" echo "$DICTADDITIONALINFO" echo "" # we need to change the '\n' in the strings to real newlines echo " $ERRMSG" | sed -e 's/\\n/\n/g' echo "" echo " ---- $DICTLOGFOLLOWS2 ----" echo "" ) | LANG=C $AWK -f bin/qp-encode.awk COMFILE="log/c$commid" if [ -f "$COMFILE" ] ; 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 "" # dump the comfile to output except for '-- data' lines cat $COMFILE | $SED -e '/-- data/d' \ -e '/start.*timer/d' -e '/stop.*timer/d' else ( printf "$DICTNOLOGAVAIL" if [ -n "$commid" ] ; then # non 0 len commid value printf "($DICTCOMMID c$commid)" fi echo "." ) | LANG=C $AWK -f bin/qp-encode.awk fi fi for type in $RETURNFILETYPE; do if [ $nfiles -gt 0 ] ; then for i in `local_seq 1 $nfiles`; do name="files_$i" eval filename=`echo "$"$name` if [ -s $filename ] ; then # file is > 0 size ftype="filetype_$i" eval FROMFMT=`echo "$"$ftype` # # Because Ghostscript accepts PDF identically to PostScript # and because HylaFAX has historically handled PDF named as # "postscript" we have to double-check the PostScript filetype. # if [ "$FROMFMT" = "PostScript" ]; then if [ "`fileType $filename`" != "PostScript" ]; then FROMFMT=PDF fi fi FILEEXTEN="$type" if [ "$FILEEXTEN" = "original" ]; then case "$FROMFMT" in "TIFF") FILEEXTEN=tif;; "PostScript") FILEEXTEN=ps;; "PDF") FILEEXTEN=pdf;; esac fi MIMETYPE="application/octet-stream" case "$FILEEXTEN" in tif) MIMETYPE="image/tiff";; ps) MIMETYPE="application/postscript";; pdf) MIMETYPE="application/pdf";; png) MIMETYPE="image/png";; esac case "$FILEEXTEN" in tif|ps|pdf) echo "" echo "--$MIMEBOUNDARY" # hb 2008-06-15 echo "Content-Type: $MIMETYPE; name=\"${DATUM}-$number-$i.$FILEEXTEN\"" #echo "Content-Type: $MIMETYPE; name=\"$number-$i.$FILEEXTEN\"" echo "Content-Description: FAX document" echo "Content-Transfer-Encoding: $ENCODING" # hb 2008-6-15 echo "Content-Disposition: attachment; filename=\"${DATUM}-$number-$i.$FILEEXTEN\"" #echo "Content-Disposition: attachment; filename=\"$number-$i.$FILEEXTEN\"" echo "" ;; esac case "$FILEEXTEN" in tif) putTifEncodedImage "$filename" "$FROMFMT";; ps) putPsEncodedImage "$filename" "$FROMFMT";; pdf) putPdfEncodedImage "$filename" "$FROMFMT";; png) putPngEncodedImage "$filename" "$FROMFMT";; *) encode "$filename";; esac fi done fi done # put out a terminating MIME boundary echo "" echo "--$MIMEBOUNDARY--" ) 2>$ERRORSTO | $SENDMAIL -f$FROMADDR -oi -t } # hb 2008-06-15 notify_info () { ( echo echo "EisFAX Sendebericht" echo echo echo "$1" echo THISJOBTYPE=`eval echo "$"DICT$jobtype` # ( if [ -z "$THISJOBTYPE" ] then printf "$jobtag $DICTTO $number" else eval printf \"$DICTYOURJOBTO\" fi if [ "$WHY" = "done" ] then echo "$DICTCOMPLETEDSUCCESSFULLY" echo "" else case "$WHY" in failed) printf " $DICTFAILEDBECAUSE\n " echo "$FAXSTATUSMSG";; rejected) printf " $DICTREJECTEDBECAUSE\n " echo "$FAXSTATUSMSG";; blocked) printf " $DICTDELAYEDBECAUSE\n " echo "$FAXSTATUSMSG" echo "" echo "$DICTASSOONASPOSSIBLE";; requeued) printf " $DICTWASNOTSENT\n " echo "$FAXSTATUSMSG" echo "" echo "$DICTWILLBERETRIED $NEXT.";; killed|removed) echo " $DICTWASDELETED";; timedout) echo " $DICTTIMEDOUT";; format_failed) echo " $DICTCONVERSION1" echo "$DICTCONVERSION2" echo "" echo "$FAXSTATUSMSG" echo "" echo "$DICTCONVERSION3";; no_formatter) echo " $DICTNOFORMATTER1" echo "$DICTNOFORMATTER2";; poll_*) printf "$DICTPOLLINGFAILED" if [ "$WHY" = "poll_rejected" ] then echo "$DICTREMOTEREJECTED" elif [ "$WHY" = "poll_no_document" ] then echo "$DICTNODOCTOPOLL" elif [ "$WHY" = "poll_failed" ] then echo "$DICTUNSPECIFIEDPROBLEM" fi;; *) echo " $DICTUNKNOWNREASON1" echo "$DICTUNKNOWNREASON2" echo "$DICTUNKNOWNREASON3" echo "" echo "why: $WHY" echo "jobTime: $JTIME" echo "nextTry: $NEXT" echo "" echo "$DICTUNKNOWNREASON4";; esac echo "" echo " ---- $DICTUNSENTJOBSTATUS ----" echo "" fi echo "$DICTDESTINATION| $number" | printFormatted $ITEMSIZE echo "$DICTSENDER| $sender" | printFormatted $ITEMSIZE echo "$DICTMAILADDR| $mailaddr" | printFormatted $ITEMSIZE if [ "$jobtype" = "facsimile" ] then if [ "$npages" -gt 0 ] then echo "$DICTPAGES| $npages" | printFormatted $ITEMSIZE fi if [ -n "$faxstatus" ] && [ -n "$dirnum" ] then echo "$DICTDIRNUM| $dirnum ($DICTDIRNEXTPAGE)" | printFormatted $ITEMSIZE fi if [ -n "$csi" ] then echo "$DICTRECEIVER| $csi" | printFormatted $ITEMSIZE fi if [ "$RETURNTECHINFO" = "yes" ] && [ "$totdials" -gt 0 ] || [ "`echo ${modemused} | cut -c-7`" = "faxCAPI" ] then case "$resolution" in 196) echo "$DICTQUALITY| $DICTFINE" | printFormatted $ITEMSIZE;; 98) echo "$DICTQUALITY| $DICTNORMAL" | printFormatted $ITEMSIZE;; *) echo "$DICTRES| $resolution (lpi)" | printFormatted $ITEMSIZE;; esac echo "$DICTPAGEWIDTH| $pagewidth (mm)" | printFormatted $ITEMSIZE echo "$DICTPAGELENGTH| $pagelength (mm)" | printFormatted $ITEMSIZE echo "$DICTSIGNALRATE| $signalrate" | printFormatted $ITEMSIZE echo "$DICTDATAFORMAT| $dataformat" | printFormatted $ITEMSIZE # hb 2008-06-14 echo "${DICTSENDDATETIME}| ${SEND_DATE_TIME}" | printFormatted $ITEMSIZE if [ -n "$equipment" ] then echo "$DICTREMOTEEQUIPMENT| $equipment" | printFormatted $ITEMSIZE fi if [ -n "$station" ] then echo "$DICTREMOTESTATION| $station" | printFormatted $ITEMSIZE fi fi fi if [ "$RETURNTECHINFO" = "yes" ] then if [ "$tottries" != "1" ] then echo "$DICTDIALOGS| $tottries ($DICTREMOTEEXCHANGES)" | printFormatted $ITEMSIZE fi if [ "$totdials" != "1" ] && [ "`echo ${modemused} | cut -c-7`" != "faxCAPI" ] then echo "$DICTCALLS| $totdials ($DICTTOTALCALLS)" | printFormatted $ITEMSIZE fi if [ "$ndials" != "0" ] then echo "$DICTDIALS| $ndials ($DICTFAILEDCALLS)" | printFormatted $ITEMSIZE fi # hb 2009-03-01 echo "$DICTMODEM| $modem" | printFormatted $ITEMSIZE # echo "$DICTMODEM| $modemused" | printFormatted $ITEMSIZE if [ -n "$faxstatus" ] then echo "$DICTSTATUS| $FAXSTATUSMSG" | printFormatted $ITEMSIZE fi echo "$DICTSUBMITTEDFROM| $client" | printFormatted $ITEMSIZE echo "$DICTJOBID| $jobid" | printFormatted $ITEMSIZE echo "$DICTGROUPID| $groupid" | printFormatted $ITEMSIZE if [ -n "$commid" ] then echo "$DICTCOMMID| c$commid" | printFormatted $ITEMSIZE fi if [ -n "$JTIME" ] then printf "\n$DICTPROCESSINGTIME %s.\n" "$JTIME" fi fi if [ "$jobtype" = "facsimile" ] then if [ $nfiles -gt 0 ] && [ "$RETURNTECHINFO" = "yes" ] then echo "" echo " ---- $DICTDOCSSUBMITTED ----" echo "" eval echo "$DICTDOCSTEXT1" eval echo "$DICTDOCSTEXT2" eval echo "$DICTDOCSTEXT3" eval echo "$DICTDOCSTEXT4" echo "" printf "%-20s %8s %s\n" "$DICTFILENAME" "$DICTSIZE" "$DICTTYPE" for i in `local_seq 1 $nfiles` do name="files_$i" eval filename=`echo "$"$name` if [ -f $filename ] then set - `wc -c "$filename"` FILESIZE=$1 type="filetype_$i" eval filetype=`echo "$"$type` # # Because Ghostscript accepts PDF identically to PostScript # and because HylaFAX has historically handled PDF named as # "postscript" we have to double-check the PostScript filetype. # if [ "$filetype" = "PostScript" ] then if [ "`fileType $filename`" != "PostScript" ] then filetype=PDF fi fi printf "%-20s %8d %s\n" "$filename" "$FILESIZE" "$filetype" fi done fi elif [ "$jobtype" = "pager" ] && [ "$WHY" != "done" ] then if [ $npins -ne 0 ] then echo "" echo " ---- $DICTUNSENTPAGES ----" echo "" for i in `local_seq 1 $npins` do name="files_$i" eval pin=`echo "$"$name` printf "%15s\n" "$DICTPIN" $pin done fi if [ $nfiles -ne 0 ] && [ -s $files_0 ] then echo "" echo " ---- $DICTMESSAGETEXT ----" echo "" cat $files_0 fi fi # ) | LANG=C $AWK -f bin/qp-encode.awk if [ -n "$faxstatus" ] && [ "$RETURNTRANSCRIPT" = "yes" ] then # ( # use -e in echo to interpret escape characters in faxstatus echo "" echo "$DICTADDITIONALINFO" echo "" # we need to change the '\n' in the strings to real newlines echo " $ERRMSG" | sed -e 's/\\n/\n/g' echo "" echo " ---- $DICTLOGFOLLOWS2 ----" echo "" # ) | LANG=C $AWK -f bin/qp-encode.awk COMFILE="log/c$commid" if [ -f "$COMFILE" ] then echo "" echo "Content-Description: FAX session log" echo "" # dump the comfile to output except for '-- data' lines cat $COMFILE | $SED -e '/-- data/d' \ -e '/start.*timer/d' -e '/stop.*timer/d' else # ( printf "$DICTNOLOGAVAIL" if [ -n "$commid" ] then # non 0 len commid value printf "($DICTCOMMID c$commid)" fi echo "." # ) | LANG=C $AWK -f bin/qp-encode.awk fi fi # TechInfo create ) | ${A2PS} -o tmp/$$notifyfax.ps -q \ -1 \ -R \ -f 10 \ -M a4 \ -B \ --header=%a \ --borders=no \ -s 1 } # --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- test -f etc/setup.cache || { SPOOL=`pwd` cat</dev/null 2>&1; then ERRORSTO=`$TTYCMD` else ERRORSTO=/dev/null fi adjustNotifyFaxMaster() { # Determine what NOTIFY_FAXMASTER should be set to based # on the current value of NOTIFY_FAXMASTER and on other # attributes set about this notification. # NOTIFY_FAXMASTER can be set to # yes - send everything # no - send nothing # errors - send only failed type faxes that are not from busy, no answer or no carrier # always - send everything # never - send nothing # # known $WHY values we can test to set NOTIFY_FAXMASTER are # "done" "failed" "rejected" "blocked" "requeued" "removed" "killed" "timedout" # "format_failed" "no_formatter" "poll_rejected" "poll_no_document" "poll_failed" case $NOTIFY_FAXMASTER in never|no) NOTIFY_FAXMASTER=no;; always|yes) NOTIFY_FAXMASTER=yes;; errors) case $WHY in timedout|rejected|format_failed|no_formatter|poll_rejected|poll_no_document) NOTIFY_FAXMASTER=yes;; "done"|blocked|removed|killed) NOTIFY_FAXMASTER=no;; *) if (match "$faxstatus" "Busy signal") || (match "$faxstatus" "No answer") || (match "$faxstatus" "No carrier") then NOTIFY_FAXMASTER=no else NOTIFY_FAXMASTER=yes fi ;; esac ;; *) NOTIFY_FAXMASTER=no;; esac } setCustomValues() { # # Apply customizations. All customizable variables should # be set to their non-customized defaults prior to this. # if [ -f etc/FaxNotify ]; then # source notify preferences . etc/FaxNotify fi # hb 2008-06-15 SENDADR= # # Language settings... # . bin/dictionary # hb 2008-06-15 . bin/dictionary-local if [ -f etc/FaxDictionary ]; then . etc/FaxDictionary fi # # Customize error message. # if [ -n "$errorcode" ]; then eval ERRMSG="$"`echo $errorcode` if [ -z "$ERRMSG" ]; then ERRMSG="$faxstatus" fi else ERRMSG="$faxstatus" fi setItemSize } fileType() # determine the type of file passed using the unix 'file' command # with the '-i' option (mime type output) { FILENAME=$1 if [ -f "$FILENAME" ] ; then FILETYPE=`file $FILENAME` if (match "$FILETYPE" "postscript") ; then echo "PostScript" elif (match "$FILETYPE" "tiff") ; then echo "TIFF" elif (match "$FILETYPE" "pdf") ; then echo "PDF" elif (match "$FILETYPE" "pcl") ; then echo "PCL" else echo "$DICTUNKNOWNDOCTYPE" fi else echo "$DICTNOFILEEXISTS" fi } putPdfEncodedImage() # Convert the source file from the CONVERTFROM type into a pdf file and # then do a mimeEndode of the file { SOURCEFILE=$1 CONVERTFROM=$2 OUTFILE="tmp/conv2pdf$$.out" if [ "$CONVERTFROM" = "PDF" ] then encode "$SOURCEFILE" return # all done here elif [ "$CONVERTFROM" = "TIFF" ] then CONVERTCMD="$TIFF2PDF -o $OUTFILE $SOURCEFILE" elif [ "$CONVERTFROM" = "PostScript" ] then CONVERTCMD="${PS2PDF} -sPAPERSIZE=a4 ${SOURCEFILE} ${OUTFILE}" elif [ "$CONVERTFROM" = "PCL" ] then CONVERTCMD="$PCL2PDF $SOURCEFILE $OUTFILE" else return # unknow convert from format fi $CONVERTCMD > $ERRORSTO 2>&1 encode "$OUTFILE" $RM -f $OUTFILE > $ERRORSTO 2>&1 } putPsEncodedImage() # Convert the source file from the CONVERTFROM type into a ps file and # then do a mimeEndode of the file { SOURCEFILE=$1 CONVERTFROM=$2 OUTFILE="tmp/conv2ps$$.out" ; if [ "$CONVERTFROM" = "PostScript" ] then encode "$SOURCEFILE" return # all done here elif [ "$CONVERTFROM" = "TIFF" ] then # tiff2ps -a for all pages, CONVERTCMD="$TIFF2PS -a $SOURCEFILE > $OUTFILE" elif [ "$CONVERTFROM" = "PDF" ] then CONVERTCMD="$PDF2PS $SOURCEFILE $OUTFILE" elif [ "$CONVERTFROM" = "PCL" ] then CONVERTCMD="$PCL2PS $SOURCEFILE $OUTFILE" else return # unknow convert from format fi $CONVERTCMD > $ERRORSTO 2>&1 encode "$OUTFILE" $RM -f $OUTFILE > $ERRORSTO 2>&1 } putTifEncodedImage() # Convert the source file from the CONVERTFROM type into a tif file and # then do a mimeEndode of the file { SOURCEFILE=$1 CONVERTFROM=$2 OUTFILE="tmp/conv2tif$$.out" if [ $CONVERTFROM = "TIFF" ] then encode "$SOURCEFILE" return # all done here elif [ $CONVERTFROM = "PDF" ] then CONVERTCMD="$PDF2FAX -r $resolution -o $OUTFILE $SOURCEFILE" elif [ $CONVERTFROM = "PostScript" ] then CONVERTCMD="$PS2FAX -r $resolution -o $OUTFILE $SOURCEFILE" elif [ $CONVERTFROM = "PCL" ] then CONVERTCMD="$PCL2FAX -r $resolution -o $OUTFILE $SOURCEFILE" else return # unknow convert from format fi $CONVERTCMD > $ERRORSTO 2>&1 encode "$OUTFILE" $RM -f $OUTFILE > $ERRORSTO 2>&1 } # hb 2008-06-17 putPngEncodedImage() # Convert the source file from the CONVERTFROM type into a png file and # then do a mimeEndode of the file { SOURCEFILE=$1 CONVERTFROM=$2 OUTFILE="tmp/conv2png$$.out" if [ "$CONVERTFROM" = "PDF" ] then cp "$SOURCEFILE" "${OUTFILE}" elif [ "$CONVERTFROM" = "TIFF" ] then CONVERTCMD="$TIFF2PDF -o $OUTFILE $SOURCEFILE" elif [ "$CONVERTFROM" = "PostScript" ] then CONVERTCMD="${PS2PDF} -sPAPERSIZE=a4 ${SOURCEFILE} ${OUTFILE}" elif [ "$CONVERTFROM" = "PCL" ] then CONVERTCMD="$PCL2PDF $SOURCEFILE $OUTFILE" # if [ $CONVERTFROM = "TIFF" ] # then # cp $SOURCEFILE $OUTFILE # elif [ $CONVERTFROM = "PDF" ] # then # CONVERTCMD="$PDF2FAX -r $resolution -w 1728 -l 297 -o $OUTFILE #$SOURCEFILE" # elif [ $CONVERTFROM = "PostScript" ] # then # if [ "${dataformat}" = "JPEG Full-Color" ] # then # color='-color' # fi # CONVERTCMD="$PS2FAX -U ${color} -r $resolution -w 1728 -l 297 -o $OUTFILE $SOURCEFILE" # elif [ $CONVERTFROM = "PCL" ] # then # CONVERTCMD="$PCL2FAX -r $resolution -w 1728 -l 297 -o $OUTFILE $SOURCEFILE" else return # unknow convert from format fi $CONVERTCMD > $ERRORSTO 2>&1 # PAGES="$(${INFO} ${OUTFILE} | ${SED} -n 's/ *Pages: //p' 2>${ERRORSTO})" # PAGES=$( ${GSRIP} -q -dNODISPLAY \ # -c "(${OUTFILE}) (r) file runpdfbegin pdfpagecount = quit" ) PAGES=$(grep -c showpage ${SOURCEFILE}) if [ "${dataformat}" = "JPEG Full-Color" ] then _device=png256 else _device=pnggray fi # 2014-04-12 change to GS to create PNG convert from PDF # ${TIFF2PDF} -o ${OUTFILE}.pdf ${OUTFILE} ${GSRIP} -dNOPAUSE \ -sDEVICE=${_device} \ -dBATCH \ -sPAPERSIZE=a4 \ -dFirstPage=1 \ -dLastPage=${PAGES} \ -sOutputFile=${OUTFILE}-%d.png \ -r300 \ -q ${OUTFILE} # # 2011-10-30 # # fax2png can only handle 1-bit tiff files -> black and white # # first split tiff to single page files... # ${TIFFSPLIT} ${OUTFILE} ${OUTFILE%.tif}_ 2>/dev/null # for _i in $(find ${OUTFILE%.tif}_*.tif) # do # ${TIFF2PNG} -destdir ${DOCQDIR} -faxpect ${_i} 2>${ERRORSTO} # done # ${RM} ${OUTFILE%.tif}_*.tif 2>${ERRORSTO} idx=1 for _i in $( find ${OUTFILE}-*.png ) do echo "" echo "--$MIMEBOUNDARY" echo "Content-Type: $MIMETYPE; name=\"${DATUM}-${number}-${i}${_i#${OUTFILE}}\"" echo "Content-Description: FAX document" echo "Content-Transfer-Encoding: $ENCODING" echo "Content-Disposition: attachment; filename=\"${DATUM}-${number}-${i}${_i#${OUTFILE}}\"" echo "" encode ${_i} idx=$((${idx} + 1)) done ${RM} -f ${OUTFILE} 2>${ERRORSTO} ${RM} -f ${OUTFILE}{.ps,-*.png,.pstif,.pdf} 2>${ERRORSTO} # else # # idx=1 # while [ "${idx}" -le "${PAGES}" ] # do # ${FAX2PNG} ${OUTFILE} ${OUTFILE}-${idx}.png -p ${idx} -a -w "${PNGWIDTH}" # # echo "" # echo "--$MIMEBOUNDARY" # echo "Content-Type: $MIMETYPE; name=\"${DATUM}-${number}-${i}-${idx}.$FILEEXTEN\"" # echo "Content-Description: FAX document" # echo "Content-Transfer-Encoding: $ENCODING" # echo "Content-Disposition: attachment; filename=\"${DATUM}-${number}-${i}-${idx}.$FILEEXTEN\"" # echo "" # encode ${OUTFILE}-${idx}.png # idx=$(/usr/bin/expr ${idx} + 1) # done # ${RM} -f ${OUTFILE}* > $ERRORSTO 2>&1 # fi } match() # look for substring in fullsting. substring can be a regular expression # or plain string if the substring is found anywhere in the full string, # true(0) is returned. { FULLSTR="$1" SUBSTR="$2" echo "$FULLSTR" | $GREP -i "$SUBSTR" > /dev/null 2>&1 if [ $? -eq 0 ] ; then return 0 else return 1 fi } ########## ## MAIN ########## SetupPrivateTmp # exports used for debug tracing #export -f putTifEncodedImage #export -f putPdfEncodedImage #export -f parseQfile #export -f match # sh -x # we parse the q file first in case any of the varialbe setting # operations may want to know about the details of the fax parseQfile #process the FaxNotify script after parse q file in case the admin wants to # set any values based on what is in the q file setCustomValues # adjust faxmaster notify based on some rules and what is found # possibly in the q file. adjustNotifyFaxMaster THISJOBTYPE="" if [ -z "$jobtag" ] ; then THISJOBTYPE=`eval echo "$"DICT$jobtype` jobtag="`eval echo $DICTJOB`" fi if [ "$doneop" = "default" ] ; then doneop="remove" fi if [ "$jobtype" = "pager" ] ; then number=$pagernum fi DESTINATION="$receiver" if [ -n "$receiver" ] && [ -n "$company" ]; then DESTINATION="$receiver $DICTAT " fi DESTINATION="$DESTINATION$company" if [ -n "$DESTINATION" ]; then DESTINATION="$DESTINATION ($number)" else DESTINATION="$number" fi if [ -z "$faxstatus" ] ; then # 0 string len FAXSTATUSMSG="<$DICTNOREASON>" else # we need to change the '\n' in the strings to real newlines FAXSTATUSMSG=`echo "$ERRMSG" | sed -e 's/\\n/\n/g'` fi # hb 2008-06-15 if [ -n "${SENDADR}" ] then case "$WHY" in "done") notify_mail "$jobtag $DICTTO $DESTINATION $DICTCOMPLETED" "$mailaddr";; failed) notify_mail "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; rejected) notify_mail "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; blocked) notify_mail "$jobtag $DICTTO $DESTINATION $DICTBLOCKED" "$mailaddr";; requeued) notify_mail "$jobtag $DICTTO $DESTINATION $DICTREQUEUED" "$mailaddr";; removed|killed) notify_mail "$jobtag $DICTTO $DESTINATION $DICTREMOVEDFROMQUEUE" "$mailaddr";; timedout) notify_mail "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; format_failed) notify_mail "$jobtag to $DESTINATION $DICTFAILED" "$mailaddr";; no_formatter) notify_mail "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; poll_*) notify_mail "$DICTNOTICEABOUT $jobtag" "$mailaddr";; *) notify_mail "$DICTNOTICEABOUT $jobtag" "$mailaddr";; esac fi if [ -n "${PRINTINFO}" -o -n "${COPYTO}" ] then case "$WHY" in "done") notify_info "$jobtag $DICTTO $DESTINATION $DICTCOMPLETED" "$mailaddr";; failed) notify_info "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; rejected) notify_info "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; blocked) notify_info "$jobtag $DICTTO $DESTINATION $DICTBLOCKED" "$mailaddr";; requeued) notify_info "$jobtag $DICTTO $DESTINATION $DICTREQUEUED" "$mailaddr";; removed|killed) notify_info "$jobtag $DICTTO $DESTINATION $DICTREMOVEDFROMQUEUE" "$mailaddr";; timedout) notify_info "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; format_failed) notify_info "$jobtag to $DESTINATION $DICTFAILED" "$mailaddr";; no_formatter) notify_info "$jobtag $DICTTO $DESTINATION $DICTFAILED" "$mailaddr";; poll_*) notify_info "$DICTNOTICEABOUT $jobtag" "$mailaddr";; *) notify_info "$DICTNOTICEABOUT $jobtag" "$mailaddr";; esac # beginn hb 2006-04-02 if [ -n "${PRINTTO}" ] then . bin/faxprint-local fi if [ -n "${COPYTO}" ] then . bin/faxcopy-local fi # Reste entsorgen ${RM} -f tmp/$$notifyfax.ps > $ERRORSTO 2>&1 fi if [ -n "${DBUSER}" ] then . bin/faxdatabase-local fi # hb end 2006-04-17 if [ "$NOTIFY_FAXMASTER" = "yes" ] then # make sure that FAXMASTER gets all information in email by forcing some RETURN values # and then reset them later origRETURNTRANSCRIPT=$RETURNTRANSCRIPT origRETURNTECHINFO=$RETURNTECHINFO origRETURNFILETYPE=$RETURNFILETYPE RETURNTRANSCRIPT="yes" RETURNTECHINFO="yes" RETURNFILETYPE="" if [ -z "$jobtag" ] then jobtag="$jobtype job $jobid" fi notify_mail "$jobtag to $number $WHY" "$TOADDR" RETURNTRANSCRIPT=$origRETURNTRANSCRIPT RETURNTECHINFO=$origRETURNTECHINFO RETURNFILETYPE=$origRETURNFILETYPE fi