Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / shell / source / unix / misc / senddoc.sh
blobf70251ecf310ebbfde5ffb2d230632135d4ed4b7
1 #!/bin/sh
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 URI_ENCODE=$(dirname "$0")/uri-encode
21 FOPTS=""
22 sd_platform=$(uname -s)
24 # linux file utility needs -L option to resolve symlinks
25 if [ "$sd_platform" = "Linux" ] ; then
26 FOPTS="-L"
29 # do not confuse the system mail clients with OOo and Java libraries
30 unset LD_LIBRARY_PATH
32 # tries to locate the executable specified
33 # as first parameter in the user's path.
34 which() {
35 if [ ! -z "$1" ]; then
36 for i in $(echo "$PATH" | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'); do
37 if [ -x "$i/$1" -a ! -d "$i/$1" ]; then
38 echo "$i/$1"
39 break;
41 done
45 # checks for the original mozilla start script(s)
46 # and restrict the "-remote" semantics to those.
47 run_mozilla() {
48 # find mozilla script in PATH if necessary
49 if [ "$(basename "$1")" = "$1" ]; then
50 moz=$(which "$1")
51 else
52 moz=$1
55 if file $FOPTS "$moz" | grep "script" > /dev/null && grep "[NM]PL" "$moz" > /dev/null; then
56 "$moz" -remote 'ping()' 2>/dev/null >/dev/null
57 if [ $? -eq 2 ]; then
58 "$1" -compose "$2" &
59 else
60 "$1" -remote "xfeDoCommand(composeMessage,$2)" &
62 else
63 "$1" -compose "$2" &
67 if [ "$1" = "--mailclient" ]; then
68 shift
69 MAILER=$1
70 shift
73 # autodetect mail client from executable name
74 case $(basename "$MAILER" | sed 's/-.*$//') in
76 iceape | mozilla | netscape | seamonkey | icedove | thunderbird | betterbird)
78 while [ "$1" != "" ]; do
79 case $1 in
80 --to)
81 TO=${TO:-}${TO:+,}$2
82 shift
84 --cc)
85 CC=${CC:-}${CC:+,}$2
86 shift
88 --bcc)
89 BCC=${BCC:-}${BCC:+,}$2
90 shift
92 --subject)
93 SUBJECT=$2
94 shift
96 --body)
97 BODY=$2
98 shift
100 --attach)
101 ATTACH=${ATTACH:-}${ATTACH:+,}$(echo "file://$2" | "${URI_ENCODE}")
102 shift
106 esac
107 shift;
108 done
110 if [ "$TO" != "" ]; then
111 COMMAND=${COMMAND:-}${COMMAND:+,}to=\'${TO}\'
113 if [ "$CC" != "" ]; then
114 COMMAND=${COMMAND:-}${COMMAND:+,}cc=\'${CC}\'
116 if [ "$BCC" != "" ]; then
117 COMMAND=${COMMAND:-}${COMMAND:+,}bcc=\'${BCC}\'
119 if [ "$SUBJECT" != "" ]; then
120 COMMAND=${COMMAND:-}${COMMAND:+,}subject=\'${SUBJECT}\'
122 if [ "$BODY" != "" ]; then
123 COMMAND=${COMMAND:-}${COMMAND:+,}body=\'${BODY}\'
125 if [ "$ATTACH" != "" ]; then
126 COMMAND=${COMMAND:-}${COMMAND:+,}attachment=\'${ATTACH}\'
129 run_mozilla "$MAILER" "$COMMAND"
132 kmail)
134 while [ "$1" != "" ]; do
135 case $1 in
136 --to)
137 TO="${TO:-}${TO:+,}$2"
138 shift
140 --cc)
141 CC="${CC:-}${CC:+,}$2"
142 shift
144 --bcc)
145 BCC="${BCC:-}${BCC:+,}$2"
146 shift
148 --subject)
149 SUBJECT="$2"
150 shift
152 --body)
153 BODY="$2"
154 shift
156 --from)
157 FROM="$2"
158 shift
160 --attach)
161 ATTACH="${ATTACH:-}${ATTACH:+ }--attach "$(echo "file://$2" | "${URI_ENCODE}")
162 shift
166 esac
167 shift;
168 done
170 ${MAILER} --composer \
171 ${CC:+--cc} ${CC:+"${CC}"} \
172 ${BCC:+--bcc} ${BCC:+"${BCC}"} \
173 ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} \
174 ${BODY:+--body} ${BODY:+"${BODY}"} \
175 ${FROM:+--header} ${FROM:+"From: ${FROM}"} \
176 ${ATTACH:+${ATTACH}} \
177 ${TO:+"${TO}"}
180 mutt)
182 while [ "$1" != "" ]; do
183 case $1 in
184 --from)
185 FROM="$2"
186 shift
188 --to)
189 TO="${TO:-}${TO:+,}$2"
190 shift
192 --cc)
193 CC="${CC:-}${CC:+,}$2"
194 shift
196 --bcc)
197 BCC="${BCC:-}${BCC:+,}$2"
198 shift
200 --subject)
201 SUBJECT="$2"
202 shift
204 --body)
205 TEMPLATE="$(basename "$0").mutt.XXXXXXXX"
206 BODY=$(mktemp -q -t "${TEMPLATE}")
207 echo "$2" > "$BODY"
208 shift
210 --attach)
211 ATTACH="$2"
212 shift
216 esac
217 shift;
218 done
220 x-terminal-emulator -e ${MAILER} \
221 ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \
222 ${CC:+-c} ${CC:+"${CC}"} \
223 ${BCC:+-b} ${BCC:+"${BCC}"} \
224 ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \
225 ${BODY:+-i} ${BODY:+"${BODY}"} \
226 ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \
227 ${TO:+"${TO}"} &
228 rm -f "$BODY"
231 evolution | gnome | xdg) # NB. shortened from the dash on
233 while [ "$1" != "" ]; do
234 case $1 in
235 --to)
236 if [ "${TO}" != "" ]; then
237 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
238 else
239 TO="$2"
241 shift
243 --cc)
244 MAILTO="${MAILTO:-}${MAILTO:+&}cc="$(echo "$2" | "${URI_ENCODE}")
245 shift
247 --bcc)
248 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="$(echo "$2" | "${URI_ENCODE}")
249 shift
251 --subject)
252 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=$(echo "$2" | "${URI_ENCODE}")
253 shift
255 --body)
256 MAILTO="${MAILTO:-}${MAILTO:+&}body="$(echo "$2" | "${URI_ENCODE}")
257 shift
259 --attach)
260 MAILTO="${MAILTO:-}${MAILTO:+&}attach="$(echo "file://$2" | "${URI_ENCODE}")
261 shift
265 esac
266 shift;
267 done
269 MAILTO="mailto:${TO}?${MAILTO}"
270 ${MAILER} "${MAILTO}" &
273 groupwise)
275 while [ "$1" != "" ]; do
276 case $1 in
277 --to)
278 if [ "${TO}" != "" ]; then
279 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
280 else
281 TO="$2"
283 shift
285 --cc)
286 MAILTO="${MAILTO:-}${MAILTO:+&}cc="$(echo "$2" | "${URI_ENCODE}")
287 shift
289 --bcc)
290 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="$(echo "$2" | "${URI_ENCODE}")
291 shift
293 --subject)
294 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=$(echo "$2" | "${URI_ENCODE}")
295 shift
297 --body)
298 MAILTO="${MAILTO:-}${MAILTO:+&}body="$(echo "$2" | "${URI_ENCODE}")
299 shift
301 --attach)
302 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="$(echo "file://$2" | "${URI_ENCODE}")
303 shift
307 esac
308 shift;
309 done
311 MAILTO="mailto:${TO}?${MAILTO}"
312 ${MAILER} "${MAILTO}" &
315 dtmail)
317 while [ "$1" != "" ]; do
318 case $1 in
319 --to)
320 TO=${TO:-}${TO:+,}$2
321 shift
323 --attach)
324 ATTACH="$2"
325 shift
329 esac
330 shift;
331 done
333 ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"}
336 sylpheed | claws)
338 while [ "$1" != "" ]; do
339 case $1 in
340 --to)
341 TO=${TO:-}${TO:+,}$2
342 shift
344 --attach)
345 ATTACH=${ATTACH:-}${ATTACH:+,}$(echo "file://$2" | "${URI_ENCODE}")
346 shift
350 esac
351 shift;
352 done
354 ${MAILER} ${TO:+--compose} ${TO:-} ${ATTACH:+--attach} ${ATTACH:-}
357 Mail | Thunderbird | Betterbird | *.app )
359 while [ "$1" != "" ]; do
360 case $1 in
361 --attach)
362 #i95688# fix filenames containing accented chars, whatever alien
363 ATTACH="${ATTACH:-}${ATTACH:+ }"$(echo "file://$2" | "${URI_ENCODE}")
364 shift
368 esac
369 shift;
370 done
371 /usr/bin/open -a "${MAILER}" ${ATTACH}
376 # LO is configured to use something we do not recognize, or is not configured.
377 # Try to be smart, and send the mail anyway, if we have the
378 # possibility to do so.
380 if [ -x /usr/bin/xdg-email ] ; then
381 MAILER=/usr/bin/xdg-email
382 elif [ -n "$DESKTOP_LAUNCH" ]; then
383 # http://lists.freedesktop.org/pipermail/xdg/2004-August/002873.html
384 MAILER=${DESKTOP_LAUNCH}
385 elif [ -n "$KDE_FULL_SESSION" -a -x /usr/bin/kde-open ] ; then
386 MAILER=/usr/bin/kde-open
387 elif [ -x /usr/bin/xdg-open ] ; then
388 MAILER=/usr/bin/xdg-open
389 elif command -v xdg-open >/dev/null 2>&1 ; then
390 MAILER=$(command -v xdg-open)
391 else
392 echo "Unsupported mail client: $(basename $MAILER | sed 's/-.*^//')"
393 exit 2
396 while [ "$1" != "" ]; do
397 case $1 in
398 --to)
399 if [ "${TO}" != "" ]; then
400 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
401 else
402 TO="$2"
404 shift
406 --cc)
407 MAILTO="${MAILTO:-}${MAILTO:+&}cc="$(echo "$2" | "${URI_ENCODE}")
408 shift
410 --bcc)
411 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="$(echo "$2" | "${URI_ENCODE}")
412 shift
414 --subject)
415 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=$(echo "$2" | "${URI_ENCODE}")
416 shift
418 --body)
419 MAILTO="${MAILTO:-}${MAILTO:+&}body="$(echo "$2" | "${URI_ENCODE}")
420 shift
422 --attach)
423 if [ "$MAILER" = "/usr/bin/xdg-email" ]; then
424 MAILTO="${MAILTO:-}${MAILTO:+&}attach="$(echo "file://$2" | "${URI_ENCODE}")
425 else
426 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="$(echo "file://$2" | "${URI_ENCODE}")
428 shift
432 esac
433 shift;
434 done
436 MAILTO="mailto:${TO}?${MAILTO}"
437 ${MAILER} "${MAILTO}" &
439 esac