Debian Codegraph @

util/faxrcvd.sh.in

raw ◀ ▶
Source reconstructed at patch state 1 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 DESTINATION="$CALLID3"
120
121 FILENAME=`echo $FILE | $SED -e 's/\.tif//' -e 's/recvq\///'`
122
123 SetupPrivateTmp
124
125 parseFaxInfo $FILE
126
127 MIMEBOUNDARY="NextPart$$"
128
129 export FILE
130 export COMMID
131 export DEVICE
132 export MSG
133 export FROMADDR
134 export HOSTNAME
135 export PORT
136 export SENDTO
137 export TOADDR
138
139 #
140 # Apply customizations. All customizable variables should
141 # be set to their non-customized defaults prior to this.
142 #
143 if [ -f etc/FaxDispatch ]; then
144 . etc/FaxDispatch # NB: FaxDispatch sets SENDTO
145 fi
146
147 #
148 # Our man page says to set SENDTO1...x if they want additional
149 # receipients. We reserve $SENDTO0 for our initial SENDTO
150 if [ -z "$SENDTO0" ]
151 then
152 SENDTO0="$SENDTO"
153 fi
154
155 if [ -f etc/templates/$TEMPLATE/hook.sh ]
156 then
157 # Any hooks that the templates need
158 . etc/templates/$TEMPLATE/hook.sh
159 fi
160
161
162 ## MailWithFAX <type>
163 ## Email the <type> template,adding the attachments according
164 ## to $FILETYPE to $SENDTO for each of $SENDTOx recipients
165 ##
166 ## We use the common CreateMailMessage <template> <f1> <t1> <n1> <d1>
167 ## function, creating the file to mail as we go.
168 MailWithFAX ()
169 {
170 template="etc/templates/$TEMPLATE/faxrcvd-$1.txt"
171 files_1=$FILE;
172 filetype_1=TIFF;
173 nfiles=1;
174 for ft in $FILETYPE
175 do
176 ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
177 done
178
179 i=0
180 SENDTO="$SENDTO0"
181 while [ -n "$SENDTO" ]
182 do
183 eval CreateMailMessage $template $ATTACH_ARGS \
184 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$SENDTO"
185
186 i=`expr $i + 1`
187 eval SENDTO='"$SENDTO'$i'"'
188 done
189 }
190
191 if [ -f $FILE ]; then
192 #
193 # Don't send FaxMaster duplicates, and FaxMaster may not even
194 # want a message at all, depending on NOTIFY_FAXMASTER.
195 #
196 case $NOTIFY_FAXMASTER$MSG in
197 never*) NOTIFY_FAXMASTER=no;;
198 errors) NOTIFY_FAXMASTER=no;;
199 *) NOTIFY_FAXMASTER=yes;;
200 esac
201 if [ "$TOADDR" != "$SENDTO" ] && [ "$NOTIFY_FAXMASTER" != "no" ]; then
202 if [ -z "$MSG" ]; then
203 CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-notify-success.txt \
204 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
205 else
206 CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-notify-error.txt \
207 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
208 fi
209 fi
210 if [ -n "$SENDTO0" ]; then
211 # Create the document to attach
212 if [ -z "$MSG" ]; then
213 MailWithFAX success
214 else
215 MailWithFAX error
216 fi
217
218 fi
219 else
220 #
221 # Generate notification mail for a failed attempt.
222 # There is no file to send...
223 #
224 CreateMailMessage etc/templates/$TEMPLATE/faxrcvd-failure.txt \
225 2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$TOADDR"
226 fi
227
228 CleanupPrivateTmp