Update git submodules
[LibreOffice.git] / shell / source / unix / misc / senddoc.sh
blobd4bc20176b5b2363ad9c6d861a552557ca5adc3f
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 # checks for the original mozilla start script(s)
33 # and restrict the "-remote" semantics to those.
34 run_mozilla() {
35 # find mozilla script in PATH if necessary
36 if [ "$(basename "$1")" = "$1" ]; then
37 moz=$(command -v "$1")
38 else
39 moz=$1
42 if file $FOPTS "$moz" | grep "script" > /dev/null && grep "[NM]PL" "$moz" > /dev/null; then
43 "$moz" -remote 'ping()' 2>/dev/null >/dev/null
44 if [ $? -eq 2 ]; then
45 "$1" -compose "$2" &
46 else
47 "$1" -remote "xfeDoCommand(composeMessage,$2)" &
49 else
50 "$1" -compose "$2" &
54 if [ "$1" = "--mailclient" ]; then
55 shift
56 MAILER=$1
57 shift
60 # autodetect mail client from executable name
61 case $(basename "$MAILER" | sed 's/-.*$//') in
63 iceape | mozilla | netscape | seamonkey | icedove | thunderbird | betterbird)
65 while [ "$1" != "" ]; do
66 case $1 in
67 --to)
68 TO=${TO:-}${TO:+,}$2
69 shift
71 --cc)
72 CC=${CC:-}${CC:+,}$2
73 shift
75 --bcc)
76 BCC=${BCC:-}${BCC:+,}$2
77 shift
79 --subject)
80 SUBJECT=$2
81 shift
83 --body)
84 BODY=$2
85 shift
87 --attach)
88 ATTACH=${ATTACH:-}${ATTACH:+,}$(echo "file://$2" | "${URI_ENCODE}")
89 shift
93 esac
94 shift;
95 done
97 if [ "$TO" != "" ]; then
98 COMMAND=${COMMAND:-}${COMMAND:+,}to=\'${TO}\'
100 if [ "$CC" != "" ]; then
101 COMMAND=${COMMAND:-}${COMMAND:+,}cc=\'${CC}\'
103 if [ "$BCC" != "" ]; then
104 COMMAND=${COMMAND:-}${COMMAND:+,}bcc=\'${BCC}\'
106 if [ "$SUBJECT" != "" ]; then
107 COMMAND=${COMMAND:-}${COMMAND:+,}subject=\'${SUBJECT}\'
109 if [ "$BODY" != "" ]; then
110 COMMAND=${COMMAND:-}${COMMAND:+,}body=\'${BODY}\'
112 if [ "$ATTACH" != "" ]; then
113 COMMAND=${COMMAND:-}${COMMAND:+,}attachment=\'${ATTACH}\'
116 run_mozilla "$MAILER" "$COMMAND"
119 kmail)
121 while [ "$1" != "" ]; do
122 case $1 in
123 --to)
124 TO="${TO:-}${TO:+,}$2"
125 shift
127 --cc)
128 CC="${CC:-}${CC:+,}$2"
129 shift
131 --bcc)
132 BCC="${BCC:-}${BCC:+,}$2"
133 shift
135 --subject)
136 SUBJECT="$2"
137 shift
139 --body)
140 BODY="$2"
141 shift
143 --from)
144 FROM="$2"
145 shift
147 --attach)
148 ATTACH="${ATTACH:-}${ATTACH:+ }--attach "$(echo "file://$2" | "${URI_ENCODE}")
149 shift
153 esac
154 shift;
155 done
157 ${MAILER} --composer \
158 ${CC:+--cc} ${CC:+"${CC}"} \
159 ${BCC:+--bcc} ${BCC:+"${BCC}"} \
160 ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} \
161 ${BODY:+--body} ${BODY:+"${BODY}"} \
162 ${FROM:+--header} ${FROM:+"From: ${FROM}"} \
163 ${ATTACH:+${ATTACH}} \
164 ${TO:+"${TO}"}
167 mutt)
169 while [ "$1" != "" ]; do
170 case $1 in
171 --from)
172 FROM="$2"
173 shift
175 --to)
176 TO="${TO:-}${TO:+,}$2"
177 shift
179 --cc)
180 CC="${CC:-}${CC:+,}$2"
181 shift
183 --bcc)
184 BCC="${BCC:-}${BCC:+,}$2"
185 shift
187 --subject)
188 SUBJECT="$2"
189 shift
191 --body)
192 TEMPLATE="$(basename "$0").mutt.XXXXXXXX"
193 BODY=$(mktemp -q -t "${TEMPLATE}")
194 echo "$2" > "$BODY"
195 shift
197 --attach)
198 ATTACH="$2"
199 shift
203 esac
204 shift;
205 done
207 x-terminal-emulator -e ${MAILER} \
208 ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \
209 ${CC:+-c} ${CC:+"${CC}"} \
210 ${BCC:+-b} ${BCC:+"${BCC}"} \
211 ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \
212 ${BODY:+-i} ${BODY:+"${BODY}"} \
213 ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \
214 ${TO:+"${TO}"} &
215 rm -f "$BODY"
218 evolution | gnome | xdg) # NB. shortened from the dash on
220 while [ "$1" != "" ]; do
221 case $1 in
222 --to)
223 if [ "${TO}" != "" ]; then
224 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
225 else
226 TO="$2"
228 shift
230 --cc)
231 MAILTO="${MAILTO:-}${MAILTO:+&}cc="$(echo "$2" | "${URI_ENCODE}")
232 shift
234 --bcc)
235 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="$(echo "$2" | "${URI_ENCODE}")
236 shift
238 --subject)
239 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=$(echo "$2" | "${URI_ENCODE}")
240 shift
242 --body)
243 MAILTO="${MAILTO:-}${MAILTO:+&}body="$(echo "$2" | "${URI_ENCODE}")
244 shift
246 --attach)
247 MAILTO="${MAILTO:-}${MAILTO:+&}attach="$(echo "file://$2" | "${URI_ENCODE}")
248 shift
252 esac
253 shift;
254 done
256 MAILTO="mailto:${TO}?${MAILTO}"
257 ${MAILER} "${MAILTO}" &
260 groupwise)
262 while [ "$1" != "" ]; do
263 case $1 in
264 --to)
265 if [ "${TO}" != "" ]; then
266 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
267 else
268 TO="$2"
270 shift
272 --cc)
273 MAILTO="${MAILTO:-}${MAILTO:+&}cc="$(echo "$2" | "${URI_ENCODE}")
274 shift
276 --bcc)
277 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="$(echo "$2" | "${URI_ENCODE}")
278 shift
280 --subject)
281 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=$(echo "$2" | "${URI_ENCODE}")
282 shift
284 --body)
285 MAILTO="${MAILTO:-}${MAILTO:+&}body="$(echo "$2" | "${URI_ENCODE}")
286 shift
288 --attach)
289 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="$(echo "file://$2" | "${URI_ENCODE}")
290 shift
294 esac
295 shift;
296 done
298 MAILTO="mailto:${TO}?${MAILTO}"
299 ${MAILER} "${MAILTO}" &
302 dtmail)
304 while [ "$1" != "" ]; do
305 case $1 in
306 --to)
307 TO=${TO:-}${TO:+,}$2
308 shift
310 --attach)
311 ATTACH="$2"
312 shift
316 esac
317 shift;
318 done
320 ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"}
323 sylpheed | claws)
325 while [ "$1" != "" ]; do
326 case $1 in
327 --to)
328 TO=${TO:-}${TO:+,}$2
329 shift
331 --attach)
332 ATTACH=${ATTACH:-}${ATTACH:+,}$(echo "file://$2" | "${URI_ENCODE}")
333 shift
337 esac
338 shift;
339 done
341 ${MAILER} ${TO:+--compose} ${TO:-} ${ATTACH:+--attach} ${ATTACH:-}
344 Mail | Thunderbird | Betterbird | *.app )
346 while [ "$1" != "" ]; do
347 case $1 in
348 --attach)
349 #i95688# fix filenames containing accented chars, whatever alien
350 ATTACH="${ATTACH:-}${ATTACH:+ }"$(echo "file://$2" | "${URI_ENCODE}")
351 shift
355 esac
356 shift;
357 done
358 /usr/bin/open -a "${MAILER}" ${ATTACH}
363 # LO is configured to use something we do not recognize, or is not configured.
364 # Try to be smart, and send the mail anyway, if we have the
365 # possibility to do so.
367 if [ -x /usr/bin/xdg-email ] ; then
368 MAILER=/usr/bin/xdg-email
369 elif [ -n "$DESKTOP_LAUNCH" ]; then
370 # http://lists.freedesktop.org/pipermail/xdg/2004-August/002873.html
371 MAILER=${DESKTOP_LAUNCH}
372 elif [ -n "$KDE_FULL_SESSION" -a -x /usr/bin/kde-open ] ; then
373 MAILER=/usr/bin/kde-open
374 elif [ -x /usr/bin/xdg-open ] ; then
375 MAILER=/usr/bin/xdg-open
376 elif command -v xdg-open >/dev/null 2>&1 ; then
377 MAILER=$(command -v xdg-open)
378 else
379 echo "Unsupported mail client: $(basename $MAILER | sed 's/-.*^//')"
380 exit 2
383 while [ "$1" != "" ]; do
384 case $1 in
385 --to)
386 if [ "${TO}" != "" ]; then
387 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
388 else
389 TO="$2"
391 shift
393 --cc)
394 MAILTO="${MAILTO:-}${MAILTO:+&}cc="$(echo "$2" | "${URI_ENCODE}")
395 shift
397 --bcc)
398 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="$(echo "$2" | "${URI_ENCODE}")
399 shift
401 --subject)
402 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=$(echo "$2" | "${URI_ENCODE}")
403 shift
405 --body)
406 MAILTO="${MAILTO:-}${MAILTO:+&}body="$(echo "$2" | "${URI_ENCODE}")
407 shift
409 --attach)
410 if [ "$MAILER" = "/usr/bin/xdg-email" ]; then
411 MAILTO="${MAILTO:-}${MAILTO:+&}attach="$(echo "file://$2" | "${URI_ENCODE}")
412 else
413 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="$(echo "file://$2" | "${URI_ENCODE}")
415 shift
419 esac
420 shift;
421 done
423 MAILTO="mailto:${TO}?${MAILTO}"
424 ${MAILER} "${MAILTO}" &
426 esac