Debian Codegraph @

util/faxrcvd.sh.in

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 #! @SCRIPT_SH@
2 # $Id$
3 #
4 # HylaFAX Facsimile Software
5 #
6 # Copyright (c) 1990-1996 Sam Leffler
7 # Copyright (c) 1991-1996 Silicon Graphics, Inc.
8 # HylaFAX is a trademark of Silicon Graphics
9 #
10 # Permission to use, copy, modify, distribute, and sell this software and
11 # its documentation for any purpose is hereby granted without fee, provided
12 # that (i) the above copyright notices and this permission notice appear in
13 # all copies of the software and related documentation, and (ii) the names of
14 # Sam Leffler and Silicon Graphics may not be used in any advertising or
15 # publicity relating to the software without the specific, prior written
16 # permission of Sam Leffler and Silicon Graphics.
17 #
18 # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
19 # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
20 # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
21 #
22 # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
23 # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
24 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
25 # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
26 # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 # OF THIS SOFTWARE.
28 #
29
30 . bin/common-functions
31
32 #
33 # faxrcvd file devID commID error-msg
34 #
35 if [ $# -lt 4 ]; then
36 echo "Usage: $0 file devID commID error-msg [ callID-1 [ callID-2 [ ... [ callID-n ] ] ] ]"
37 hfExit 1
38 fi
39
40 test -f etc/setup.cache || {
41 SPOOL=`pwd`
42 cat<<EOF
43
44 FATAL ERROR: $SPOOL/etc/setup.cache is missing!
45
46 The file $SPOOL/etc/setup.cache is not present. This
47 probably means the machine has not been setup using the faxsetup(@MANNUM1_8@)
48 command. Read the documentation on setting up HylaFAX before you
49 startup a server system.
50
51 EOF
52 hfExit 1
53 }
54
55 # These settings may not be present in setup.cache if user upgraded and
56 # didn't re-run faxsetup; we set them before calling setup.cache for
57 # backward compatibility.
58 ENCODING=base64
59 TIFF2PDF=bin/tiff2pdf
60 TTYCMD=tty
61
62 . etc/setup.cache
63
64 INFO=$SBIN/faxinfo
65 FAX2PS=$TIFFBIN/fax2ps
66 TIFF2PS=tiff2ps
67 TOADDR=FaxMaster
68 FROMADDR=fax
69 TIFFINFO=tiffinfo
70 NOTIFY_FAXMASTER=always
71
72 #
73 # Redirect errors to a tty, if possible, rather than
74 # dev-nulling them or allowing them to creep into
75 # the mail.
76 #
77 if $TTYCMD >/dev/null 2>&1; then
78 ERRORSTO=`$TTYCMD`
79 else
80 ERRORSTO=/dev/null
81 fi
82
83 #
84 # Permit various types of attachment types: ps, tif, pdf
85 # Note that non-ASCII filetypes require an encoder.
86 # pdf requires tiff2ps and tiff2pdf
87 # Multiple file types may be specified by separating them with
88 # whitespace; in that case a separate attachment for each filetype
89 # will be created.
90 #
91 FILETYPE=ps
92 SENDTO=
93
94 #
95 # There is no good portable way to find out the fully qualified
96 # domain name (FQDN) of the host or the TCP port for the hylafax
97 # service so we fudge here. Folks may want to tailor this to
98 # their needs; e.g. add a domain or use localhost so the loopback
99 # interface is used.
100 #
101 HOSTNAME=`hostname` # XXX no good way to find FQDN
102 PORT=4559 # XXX no good way to lookup service
103
104 FILE="$1"; shift;
105 DEVICE="$1"; shift;
106 COMMID="$1"; shift;
107 MSG="$1"; shift;
108 COUNT=1
109 while [ $# -ge 1 ]; do
110 # The eval has $1 set yet, and this forces a variable-to-variable
111 # assignment, allowing us to not need to do escaping
112 eval CALLID$COUNT='$1'
113 export CALLID$COUNT
114 shift
115 COUNT=`expr $COUNT + 1`
116 done
117 CIDNUMBER="$CALLID1"
118 CIDNAME="$CALLID2"
119
120 FILENAME=`echo $FILE | $SED -e 's/\.tif//' -e 's/recvq\///'`
121
122 SetupPrivateTmp
123
124 parseFaxInfo $FILE
125
126 MIMEBOUNDARY="NextPart$$"
127
128 export FILE
129 export COMMID
130 export DEVICE
131 export MSG
132 export FROMADDR
133 export HOSTNAME
134 export PORT
135 export SENDTO
136 export TOADDR
137
138 #
139 # Apply customizations. All customizable variables should
140 # be set to their non-customized defaults prior to this.
141 #
142 if [ -f etc/FaxDispatch ]; then
143 . etc/FaxDispatch # NB: FaxDispatch sets SENDTO
144 fi
145
146 #
147 # Our man page says to set SENDTO1...x if they want additional
148 # receipients. We reserve $SENDTO0 for our initial SENDTO
149 if [ -z "$SENDTO0" ]
150 then
151 SENDTO0="$SENDTO"
152 fi
153
154 if [ -f etc/templates/$TEMPLATE/hook.sh ]
155 then
156 # Any hooks that the templates need
157 . etc/templates/$TEMPLATE/hook.sh
158 fi
159
160
161 ## MailWithFAX <type>
162 ## Email the <type> template,adding the attachments according
163 ## to $FILETYPE to $SENDTO for each of $SENDTOx recipients
164 ##
165 ## We use the common CreateMailMessage <template> <f1> <t1> <n1> <d1>
166 ## function, creating the file to mail as we go.
167 MailWithFAX ()
168 {
169 template="etc/templates/$TEMPLATE/faxrcvd-$1.txt"
170 files_1=$FILE;
171 filetype_1=TIFF;
172 nfiles=1;
173 for ft in $FILETYPE
174 do
175 ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
176 done
177
178 i=0
179 SENDTO="$SENDTO0"
180 while [ -n "$SENDTO" ]
181 do
182 eval CreateMailMessage $template $ATTACH_ARGS \
183 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$SENDTO"
184
185 i=`expr $i + 1`
186 eval SENDTO='"$SENDTO'$i'"'
187 done
188 }
189
190 if [ -f $FILE ]; then
191 #
192 # Don't send FaxMaster duplicates, and FaxMaster may not even
193 # want a message at all, depending on NOTIFY_FAXMASTER.
194 #
195 case $NOTIFY_FAXMASTER$MSG in
196 never*) NOTIFY_FAXMASTER=no;;
197 errors) NOTIFY_FAXMASTER=no;;
198 *) NOTIFY_FAXMASTER=yes;;
199 esac
200 if [ "$TOADDR" != "$SENDTO" ] && [ "$NOTIFY_FAXMASTER" != "no" ]; then
201 if [ -z "$MSG" ]; then
202 CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-notify-success.txt \
203 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
204 else
205 CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-notify-error.txt \
206 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
207 fi
208 fi
209 if [ -n "$SENDTO0" ]; then
210 # Create the document to attach
211 if [ -z "$MSG" ]; then
212 MailWithFAX success
213 else
214 MailWithFAX error
215 fi
216
217 fi
218 else
219 #
220 # Generate notification mail for a failed attempt.
221 # There is no file to send...
222 #
223 CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-failure.txt \
224 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
225 fi
226
227 CleanupPrivateTmp