Update ooo320-m1
[ooovba.git] / shell / source / unix / misc / senddoc.sh
blob83724d38025416ac33b46c68a319ff899b37f1a5
1 #!/bin/sh
2 URI_ENCODE="`dirname $0`/uri-encode"
3 FOPTS=""
5 # linux file utility needs -L option to resolve symlinks
6 if [ "`uname -s`" = "Linux" ]
7 then
8 FOPTS="-L"
9 fi
11 # do not confuse the system mail clients with OOo and Java libraries
12 unset LD_LIBRARY_PATH
14 # tries to locate the executable specified
15 # as first parameter in the user's path.
16 which() {
17 if [ ! -z "$1" ]; then
18 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
19 if [ -x "$i/$1" -a ! -d "$i/$1" ]; then
20 echo "$i/$1"
21 break;
23 done
27 # checks for the original mozilla start script(s)
28 # and restrict the "-remote" semantics to those.
29 run_mozilla() {
30 # find mozilla script in PATH if necessary
31 if [ "`basename $1`" = "$1" ]; then
32 moz=`which $1`
33 else
34 moz=$1
37 if file $FOPTS "$moz" | grep "script" > /dev/null && grep "[NM]PL" "$moz" > /dev/null; then
38 "$moz" -remote 'ping()' 2>/dev/null >/dev/null
39 if [ $? -eq 2 ]; then
40 "$1" -compose "$2" &
41 else
42 "$1" -remote "xfeDoCommand(composeMessage,$2)" &
44 else
45 "$1" -compose "$2" &
49 if [ "$1" = "--mailclient" ]; then
50 shift
51 MAILER=$1
52 shift
55 # autodetect mail client from executable name
56 case `basename "$MAILER" | sed 's/-.*$//'` in
58 iceape | mozilla | netscape | seamonkey | icedove | thunderbird)
60 while [ "$1" != "" ]; do
61 case $1 in
62 --to)
63 TO=${TO:-}${TO:+,}$2
64 shift
66 --cc)
67 CC=${CC:-}${CC:+,}$2
68 shift
70 --bcc)
71 BCC=${BCC:-}${BCC:+,}$2
72 shift
74 --subject)
75 SUBJECT=$2
76 shift
78 --body)
79 BODY=$2
80 shift
82 --attach)
83 ATTACH=${ATTACH:-}${ATTACH:+,}`echo "file://$2" | ${URI_ENCODE}`
84 shift
88 esac
89 shift;
90 done
92 if [ "$TO" != "" ]; then
93 COMMAND=${COMMAND:-}${COMMAND:+,}to=${TO}
95 if [ "$CC" != "" ]; then
96 COMMAND=${COMMAND:-}${COMMAND:+,}cc=${CC}
98 if [ "$BCC" != "" ]; then
99 COMMAND=${COMMAND:-}${COMMAND:+,}bcc=${BCC}
101 if [ "$SUBJECT" != "" ]; then
102 COMMAND=${COMMAND:-}${COMMAND:+,}subject=${SUBJECT}
104 if [ "$BODY" != "" ]; then
105 COMMAND=${COMMAND:-}${COMMAND:+,}body=${BODY}
107 if [ "$ATTACH" != "" ]; then
108 COMMAND=${COMMAND:-}${COMMAND:+,}attachment=${ATTACH}
111 run_mozilla "$MAILER" "$COMMAND"
114 kmail)
116 while [ "$1" != "" ]; do
117 case $1 in
118 --to)
119 TO="${TO:-}${TO:+,}$2"
120 shift
122 --cc)
123 CC="${CC:-}${CC:+,}$2"
124 shift
126 --bcc)
127 BCC="${BCC:-}${BCC:+,}$2"
128 shift
130 --subject)
131 SUBJECT="$2"
132 shift
134 --body)
135 BODY="$2"
136 shift
138 --attach)
139 ATTACH="$2"
140 shift
144 esac
145 shift;
146 done
148 ${MAILER} --composer ${CC:+--cc} ${CC:+"${CC}"} ${BCC:+--bcc} ${BCC:+"${BCC}"} \
149 ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} ${BODY:+--body} ${BODY:+"${BODY}"} \
150 ${ATTACH:+--attach} ${ATTACH:+"${ATTACH}"} ${TO:+"${TO}"}
153 mutt)
155 while [ "$1" != "" ]; do
156 case $1 in
157 --from)
158 FROM="$2"
159 shift
161 --to)
162 TO="${TO:-}${TO:+,}$2"
163 shift
165 --cc)
166 CC="${CC:-}${CC:+,}$2"
167 shift
169 --bcc)
170 BCC="${BCC:-}${BCC:+,}$2"
171 shift
173 --subject)
174 SUBJECT="$2"
175 shift
177 --body)
178 TEMPLATE="`basename $0`.mutt.XXXXXXXX"
179 BODY=`mktemp -q -t ${TEMPLATE}`
180 echo "$2" > $BODY
181 shift
183 --attach)
184 ATTACH="$2"
185 shift
189 esac
190 shift;
191 done
193 x-terminal-emulator -e ${MAILER} \
194 ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \
195 ${CC:+-c} ${CC:+"${CC}"} \
196 ${BCC:+-b} ${BCC:+"${BCC}"} \
197 ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \
198 ${BODY:+-i} ${BODY:+"${BODY}"} \
199 ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \
200 ${TO:+"${TO}"} &
201 rm -f $BODY
204 evolution)
206 while [ "$1" != "" ]; do
207 case $1 in
208 --to)
209 if [ "${TO}" != "" ]; then
210 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
211 else
212 TO="$2"
214 shift
216 --cc)
217 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
218 shift
220 --bcc)
221 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
222 shift
224 --subject)
225 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | ${URI_ENCODE}`
226 shift
228 --body)
229 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
230 shift
232 --attach)
233 MAILTO="${MAILTO:-}${MAILTO:+&}attach="`echo "file://$2" | ${URI_ENCODE}`
234 shift
238 esac
239 shift;
240 done
242 MAILTO="mailto:${TO}?${MAILTO}"
243 ${MAILER} "${MAILTO}" &
246 groupwise)
248 while [ "$1" != "" ]; do
249 case $1 in
250 --to)
251 if [ "${TO}" != "" ]; then
252 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
253 else
254 TO="$2"
256 shift
258 --cc)
259 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
260 shift
262 --bcc)
263 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
264 shift
266 --subject)
267 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | ${URI_ENCODE}`
268 shift
270 --body)
271 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
272 shift
274 --attach)
275 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "file://$2" | ${URI_ENCODE}`
276 shift
280 esac
281 shift;
282 done
284 MAILTO="mailto:${TO}?${MAILTO}"
285 ${MAILER} "${MAILTO}" &
288 dtmail)
290 while [ "$1" != "" ]; do
291 case $1 in
292 --to)
293 TO=${TO:-}${TO:+,}$2
294 shift
296 --attach)
297 ATTACH="$2"
298 shift
302 esac
303 shift;
304 done
306 ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"}
309 sylpheed | claws)
311 while [ "$1" != "" ]; do
312 case $1 in
313 --to)
314 TO=${TO:-}${TO:+,}$2
315 shift
317 --attach)
318 ATTACH="${ATTACH:-}${ATTACH:+ }$2"
319 shift
323 esac
324 shift;
325 done
327 ${MAILER} ${TO:+--compose} "${TO:-}" ${ATTACH:+--attach} "${ATTACH:-}"
330 Mail | Thunderbird | *.app )
332 while [ "$1" != "" ]; do
333 case $1 in
334 --attach)
335 #i95688# fix filenames containing accented chars, whatever alien
336 ATTACH="${ATTACH:-}${ATTACH:+ }"`echo "file://$2" | ${URI_ENCODE}`
337 shift
341 esac
342 shift;
343 done
344 /usr/bin/open -a "${MAILER}" ${ATTACH}
349 # DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html
350 if [ -n "$DESKTOP_LAUNCH" ]; then
351 while [ "$1" != "" ]; do
352 case $1 in
353 --to)
354 if [ "${TO}" != "" ]; then
355 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
356 else
357 TO="$2"
359 shift
361 --cc)
362 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
363 shift
365 --bcc)
366 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
367 shift
369 --subject)
370 MAILTO="${MAILTO:-}${MAILTO:+&}subject="`echo "$2" | ${URI_ENCODE}`
371 shift
373 --body)
374 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
375 shift
377 --attach)
378 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "$2" | ${URI_ENCODE}`
379 shift
383 esac
384 shift;
385 done
387 MAILTO="mailto:${TO}?${MAILTO}"
388 ${DESKTOP_LAUNCH} "${MAILTO}" &
389 else
390 echo "Could not determine a mail client to use."
391 exit 2
396 echo "Unsupported mail client: `basename $MAILER | sed 's/-.*^//'`"
397 exit 2
399 esac
401 exit 0