Hylafax Mailing List Archives

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

[hylafax-users] auto printing and emailing of received faxes- setup




Hi  All,

A few days ago I posted a question on how to setup hylafax to automatically print or email a fax depending upon its destination extension. Well I have not had any replies but think I have worked out a solution which works well for us, although the scripting could no doubt do with some cleaning up!

The setup we have is a hylafax server with an eicon BRI card plugged into our Mitel telephone system with the DAD (DDI) and CLI information passed through to hylafax from the Eicon card.

I have included the scripts below but they are the standard files extended to cope with the possibility to forward vi both SMTP and CUPS.

Firstly I added an extra column to fax/etc/users called method. This takes either SMTP or CUPS. as its value.

Secondly I added an extra variable to FaxDispatch called METHOD. This picks out the  value of the extra column in fax/etc/users.

I then modified fax/bin/faxrcvd to test for $METHOD and carry out the appropriate actions (print or email).

The files are below, I hope this helps someone and if you have any ideas on how to do this better please let me know, and yes I know I dont have any error checking in there to verify that the method is valid!

Sam

FaxDispatch:
---------------------------------------------------------------------------------------------------------------------------------------------
#
# Dispatch fax to email depending on own MSN or extention (ISDN lines)
# sourced from faxrcvd
#
FILETYPE=pdf
MIMENCODE=mimencode
ENCODING=base64
if [ "$DADNUMBER" != "" ]; then
    PHONEMATCH=$DADNUMBER
    USERENTRY=`grep -v "^#" etc/users | grep "$PHONEMATCH"`
    if [ "$USERENTRY" != "" ]; then
        METHOD=`echo $USERENTRY | awk '{print $3}'`
        USERNAME=`echo $USERENTRY | awk '{print $1}'`
        SENDTO="$USERNAME"
    fi
fi

faxrcvd:
---------------------------------------------------------------------------------------------------------------------------------------------
#! /bin/sh
#        $Id: faxrcvd.sh.in,v 1.9 2003/02/09 02:39:33 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
#
if [ $# -lt 4 ]; then
    echo "Usage: $0 file devID commID error-msg [CIDNumber] [CIDName] [destination]"
    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
FAX2PS=$TIFFBIN/fax2ps
ENCODING=base64
TIFF2PS=tiff2ps
PS2PDF=ps2pdf
TOADDR=admin@xxxxxxxxxxxxx
TIFFINFO=tiffinfo
NOTIFY_FAXMASTER=always
TIFFTOPNM=/usr/bin/tifftopnm
GOCR=/usr/local/bin/gocr
METHOD="SMTP"
#
# wraper for base64 encoding
#
# first try uuencode if it is not installed fallback to
# metamails mimencode if it is also not installed give an
# error message
#
function base64 {

    if [ -x /usr/bin/uuencode ]; then
        /usr/bin/uuencode -m $1 $1 | /usr/bin/sed '1d;$d'
    elif [ -x /usr/bin/mimencode ]; then
        /usr/bin/mimencode $1
    else
        echo "Error: No encoder for base64 found."
        echo "Please install sharutils or metamail."
    fi
}

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

#
# 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="`echo $5 | $AWK -F ';' '{ print $1 }'`"
DADNUMBER="`echo $5 | $AWK -F ';' '{ print $2 }'`"
CIDNAME="$6-$CIDNUMBER-$DADNUMBER"
DESTINATION="$7"


FILENAME=`echo $FILE | $SED -e 's/\.tif//' -e 's/recvq\///'`
# FAXTEXT="`tifftopnm /var/spool/fax/$FILE | gocr -`"

if [ -f $FILE ]; then
    #
    # Check the sender's TSI and setup to dispatch
    # facsimile received from well-known senders.
    #
    SUBADDR="`$INFO $FILE | $AWK -F: '/SubAddr/ { print $2 }' 2>/dev/null`"
    SENDER="`$INFO $FILE | $AWK -F: '/Sender/ { print $2 }' 2>/dev/null`"
    SENDTO="$TOADDR"
    if [ -f bin/FaxDispatch ]; then
        . bin/FaxDispatch        # NB: FaxDispatch sets SENDTO based on $7
    fi
    #
    # 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: The HylaFAX Receive Agent <fax>"
         echo "Subject: Facsimile received from $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 [ "$CIDNUMBER" ]; then
            echo " CIDNumber: $CIDNUMBER"
        fi
        if [ "$CIDNAME" ]; then
            echo "   CIDName: $CIDNAME"
        fi
        if [ "$DADNUMBER" ]; then
            echo " DADNUMBER: $DADNUMBER"
        fi
        if [ "$DESTINATION" ]; then
            echo ""
            echo "Destination: $DESTINATION."
        fi
        if [ -n "$SENDTO" ]; then
            echo ""
            echo "The facsimile was automatically dispatched to: $SENDTO via $METHOD."
        fi
#        echo ""
#        echo "Text of first page:"
#        echo ""
#        echo "$FAXTEXT"
        ) | 2>&1 $SENDMAIL -ffax -oi $TOADDR
    fi
    if [ -n "$SENDTO" -a "$METHOD" = "SMTP" ]; 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 ""
         echo "The fax is atached to this email as a PDF document."
         echo "Please Double click the attachment to view it"
         echo ""
         echo "------------------------------------------------------------"
         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 [ "$CIDNUMBER" ]; then
            echo " CIDNumber: $CIDNUMBER"
         fi
         if [ "$CIDNAME" ]; then
            echo "   CIDName: $CIDNAME"
         fi
         if [ "$DADNUMBER" ]; then
            echo " DADNUMBER: $DADNUMBER"
         fi
         echo ""
         echo "--$MIMEBOUNDARY"
         if [ "$FILETYPE" = "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 ""
             base64 $FILE 2>/dev/null
         elif [ "$FILETYPE" = "pdf" ]; then
             echo "Content-Type: application/pdf; name=\"c$COMMID.pdf\""
             echo "Content-Description: FAX document"
             echo "Content-Transfer-Encoding: $ENCODING"
             echo "Content-Disposition: attachment; filename=\"c$COMMID.pdf\""
             echo ""
             GW=`$TIFFINFO $FILE | $GREP "Image Width" | \
                $SED 's/.*Image Width: \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'`
             GL=`$TIFFINFO $FILE | $GREP "Image Length" | \
                $SED 's/.*Image Length: \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'`
             RW=`$TIFFINFO $FILE | $GREP "Resolution" | \
                $SED 's/.*Resolution: \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'`
             RL=`$TIFFINFO $FILE | $GREP "Resolution" | \
                $SED 's/.*Resolution: [0-9]*, \([0-9]*\).*/\1/g' | sort -n | $SED -n '$p'`
             $TIFF2PS -a -O $FILE.ps $FILE 2>/dev/null # fax2ps looks bad
             $PS2PDF -g$GW\x$GL -r$RW\x$RL $FILE.ps $FILE.pdf 2>/dev/null
             base64 $FILE.pdf 2>/dev/null
             $RM -f $FILE.ps $FILE.pdf 2>/dev/null
         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>/dev/null
         fi
         echo ""
         echo "--$MIMEBOUNDARY--"
        ) | 2>&1 $SENDMAIL -ffax -oi $SENDTO
    fi
    if [ -n "$SENDTO" -a "$METHOD" = "CUPS" ]; then
        $FAX2PS -H 10.5 -S $FILE | lpr -P$SENDTO -v
    fi
else
    #
    # Generate notification mail for a failed attempt.
    #
    (echo "To: $TOADDR"
     echo "From: The HylaFAX Receive Agent <fax>"
     echo "Subject: facsimile not received"
     echo ""
     echo "An attempt to receive facsimile on $DEVICE failed 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
    ) | 2>&1 $SENDMAIL -ffax -oi $TOADDR
fi

fax/etc/users:
---------------------------------------------------------------------------------------------------------------------------------------------

#
# Sample users file for FaxDispatch on ISDN lines
# format: <email>  <MSN or extention>  <METHOD>
#
admin  5300  CUPS
fred@xxxxxxxxxxxxx        5301   SMTP

Home
Report any problems to webmaster@hylafax.org

HylaFAX is a trademark of Silicon Graphics Corporation.
Internet connectivity for hylafax.org is provided by:
VirtuALL Private Host Services