File: sample_faxrcvd

package info (click to toggle)
capi4hylafax 1:01.03.00.99.svn.300-16
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,044 kB
  • ctags: 3,085
  • sloc: cpp: 20,823; sh: 9,412; makefile: 226; perl: 36
file content (130 lines) | stat: -rwxr-xr-x 3,165 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
#
#   This is a sample of a receive script for c2faxrecv if runing in
#   stand alone mode.
#   For scripts for the hylafax mode take a look at
#   /var/spool/fax/bin/faxrcvd or www.hylafax.org.
#
#   This script converts a TIFF-File to a PDF and sends a mail to different
#   mail addresses (depending on the MSN) with the PDF file attached.
#   This sample needs GenerateFileMail.pl to send mails with attachement and
#   GenerateFileMail.pl needs perl and mimencode from the metamail packet.
#

#
#   "stand alone" calling parameters are:
#   [Result Code] [CAPI Disconnect Reason] [Sender ID or Number]
#   [Called Number (MSN) or DDI] [Num of Pages] [Filename(s) without path]
#
#   For your information: "hylafax" calling parameters are:
#   [TIFF-File] [ModemDeviceID] [CommID] [Reason Text] [Calling Number] [ReceiveID] [MSN]
#

#
# Check command line
#
if [ $# -lt 6 ] ; then
    echo "ERROR - Missing parameters!"
    echo ""
    echo "Call: $0 ResultCode CAPIReason SenderID MSN NumPages Filename [Filename2 [...]]"
fi

#
# Get current time and set sender mail address
#
CurrentDate="`date`"
SenderAddr="uucp"

#
# Remember Filename
# [ Normally there is only one file specified (Exception: The "G3" format)
#   and this sample handles mostly only one file. ]
#
SendFile="$6"
# If someone needs an absolute path uncomment the following line:
#SendFile=`pwd`"/$SendFile"

#
# Transform "Result Code" to text.
#
ResultString="Okay"
case "$1" in
6)
    ResultString="Can't build up B-Channel for incoming call."
    ;;
7)
    ResultString="Connection established, but no fax transfer occured."
    ;;
12)
    ResultString="Error during fax receiving. Fax was only be received partially."
    ;;
esac


#
# Convert TIFF File to PDF
#
#FileMimeType="image/tiff"
FileMimeType="application/octet-stream"
if [ -n "`echo "$SendFile" | grep "\.tif$"`" ] ; then
    OrgSendFile=$SendFile
    SendFile="`echo "$OrgSendFile" | sed -e 's/\.tif//'`.pdf"
    FileMimeType="application/pdf"
    tiff2ps -a "$OrgSendFile" | ps2pdf13 - - > "$SendFile"
    # ps2pdf-workaround, because ps2pdf can't handle file names with spaces
fi


#
# Get a mail address from the MSN
#
MailAddr=unresolvedfax@test.de
case "$4" in
123400)
    MailAddr=mueller@test.de
    ;;
123401)
    MailAddr=meier@test.de
    ;;
esac


#
# Generates mail text
#
SubjectText="Fax from \"$3\""

MailText="Received a new fax with
result:         $ResultString (CAPI: $2)
from:           $3
to:             $4
pages:          $5
at:             $CurrentDate
file:           $SendFile"

# if c2faxrecv was started with -f G3 then you can get more than one file
shift 6
while [ -n "$1" ] ; do
    MailText="$MailText
                $1"
    shift
done


#
# Send Mail
#
if [ "$MailAddr" = "root" ] ; then
    #
    # only a notification for root
    #
    echo "$MailText" | mail -s "$SubjectText" "$MailAddr"

else
    #
    # attach fax file
    #
    perl GenerateFileMail.pl "$SenderAddr" "$MailAddr" "$SubjectText" "$MailText" "Fax Information"   \
                             "$SendFile" "$FileMimeType" "`basename \"$SendFile\"`" "$SubjectText"   | \
    /usr/sbin/sendmail "$MailAddr"
fi