blob: 3fe64a260ffbd16619aef7e9b3e84d1b739ce123 [file] [log] [blame]
mdm@chromium.org56df6d32010-08-31 18:16:49 +00001#!/bin/sh
dkegel@google.comf20da1f2009-06-30 19:16:32 +00002#---------------------------------------------
3# xdg-email
4#
5# Utility script to open the users favorite email program, using the
6# RFC 2368 mailto: URI spec
7#
8# Refer to the usage() function below for usage.
9#
mdm@chromium.org741e06f2011-03-30 22:51:57 +000010# Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
11# Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
dkegel@google.comf20da1f2009-06-30 19:16:32 +000012# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
13# Copyright 2006, Jeremy White <jwhite@codeweavers.com>
14#
15# LICENSE:
16#
17# Permission is hereby granted, free of charge, to any person obtaining a
18# copy of this software and associated documentation files (the "Software"),
19# to deal in the Software without restriction, including without limitation
20# the rights to use, copy, modify, merge, publish, distribute, sublicense,
21# and/or sell copies of the Software, and to permit persons to whom the
22# Software is furnished to do so, subject to the following conditions:
23#
24# The above copyright notice and this permission notice shall be included
25# in all copies or substantial portions of the Software.
26#
27# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
28# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33# OTHER DEALINGS IN THE SOFTWARE.
34#
35#---------------------------------------------
36
37manualpage()
38{
39cat << _MANUALPAGE
40Name
41
42xdg-email - command line tool for sending mail using the user's preferred
43e-mail composer
44
45Synopsis
46
47xdg-email [--utf8] [--cc address] [--bcc address] [--subject text] [--body text
48] [--attach file] [ mailto-uri | address(es) ]
49
50xdg-email { --help | --manual | --version }
51
52Description
53
54xdg-email opens the user's preferred e-mail composer in order to send a mail to
55address(es) or mailto-uri. RFC2368 defines mailto: URIs. xdg-email limits
56support to, cc, subject and body fields in mailto-uri, all other fields are
57silently ignored. address(es) must follow the syntax of RFC822. Multiple
58addresses may be provided as separate arguments.
59
60All information provided on the command line is used to prefill corresponding
61fields in the user's e-mail composer. The user will have the opportunity to
62change any of this information before actually sending the e-mail.
63
64xdg-email is for use inside a desktop session only. It is not recommended to
65use xdg-email as root.
66
67See http://portland.freedesktop.org/EmailConfig for information on how the user
68can change the e-mail composer that is used.
69
70Options
71
72--utf8
73 Indicates that all command line options that follow are in utf8. Without
74 this option, command line options are expected to be encoded according to
75 locale. If the locale already specifies utf8 this option has no effect.
76 This option does not affect mailto URIs that are passed on the command
77 line.
78--cc address
79 Specify a recipient to be copied on the e-mail.
80--bcc address
81 Specify a recipient to be blindly copied on the e-mail.
82--subject text
83 Specify a subject for the e-mail.
84--body text
85 Specify a body for the e-mail. Since the user will be able to make changes
86 before actually sending the e-mail, this can be used to provide the user
87 with a template for the e-mail. text may contain linebreaks.
88--attach file
89
90 Specify an attachment for the e-mail. file must point to an existing file.
91
92 Some e-mail applications require the file to remain present after xdg-email
93 returns.
94
95--help
96 Show command synopsis.
97--manual
98 Show this manualpage.
99--version
100 Show the xdg-utils version information.
101
102Environment Variables
103
104xdg-email honours the following environment variables:
105
106XDG_UTILS_DEBUG_LEVEL
107 Setting this environment variable to a non-zero numerical value makes
108 xdg-email do more verbose reporting on stderr. Setting a higher value
109 increases the verbosity.
110
111Exit Codes
112
113An exit code of 0 indicates success while a non-zero exit code indicates
114failure. The following failure codes can be returned:
115
1161
117 Error in command line syntax.
1182
119 One of the files passed on the command line did not exist.
1203
121 A required tool could not be found.
1224
123 The action failed.
1245
125 No permission to read one of the files passed on the command line.
126
127Configuration
128
129Visit http://portland.freedesktop.org/EmailConfig for information how to
130configure xdg-email to use the email client of your choice.
131
132Examples
133
134xdg-email 'Jeremy White <jwhite@example.com>'
135
136xdg-email --attach /tmp/logo.png \
137 --subject 'Logo contest' \
138 --body 'Attached you find the logo for the contest.' \
139 'jwhite@example.com'
140
141xdg-email --subject 'Your password is about to expire' \
142 'jwhite@example.com' 'bastian@example.com' 'whipple@example.com'
143
144_MANUALPAGE
145}
146
147usage()
148{
149cat << _USAGE
150xdg-email - command line tool for sending mail using the user's preferred
151e-mail composer
152
153Synopsis
154
155xdg-email [--utf8] [--cc address] [--bcc address] [--subject text] [--body text
156] [--attach file] [ mailto-uri | address(es) ]
157
158xdg-email { --help | --manual | --version }
159
160_USAGE
161}
162
163#@xdg-utils-common@
164
165#----------------------------------------------------------------------------
166# Common utility functions included in all XDG wrapper scripts
167#----------------------------------------------------------------------------
168
169DEBUG()
170{
171 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
172 [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
173 shift
174 echo "$@" >&2
175}
176
177#-------------------------------------------------------------
178# Exit script on successfully completing the desired operation
179
180exit_success()
181{
182 if [ $# -gt 0 ]; then
183 echo "$@"
184 echo
185 fi
186
187 exit 0
188}
189
190
191#-----------------------------------------
192# Exit script on malformed arguments, not enough arguments
193# or missing required option.
194# prints usage information
195
196exit_failure_syntax()
197{
198 if [ $# -gt 0 ]; then
199 echo "xdg-email: $@" >&2
200 echo "Try 'xdg-email --help' for more information." >&2
201 else
202 usage
203 echo "Use 'man xdg-email' or 'xdg-email --manual' for additional info."
204 fi
205
206 exit 1
207}
208
209#-------------------------------------------------------------
210# Exit script on missing file specified on command line
211
212exit_failure_file_missing()
213{
214 if [ $# -gt 0 ]; then
215 echo "xdg-email: $@" >&2
216 fi
217
218 exit 2
219}
220
221#-------------------------------------------------------------
222# Exit script on failure to locate necessary tool applications
223
224exit_failure_operation_impossible()
225{
226 if [ $# -gt 0 ]; then
227 echo "xdg-email: $@" >&2
228 fi
229
230 exit 3
231}
232
233#-------------------------------------------------------------
234# Exit script on failure returned by a tool application
235
236exit_failure_operation_failed()
237{
238 if [ $# -gt 0 ]; then
239 echo "xdg-email: $@" >&2
240 fi
241
242 exit 4
243}
244
245#------------------------------------------------------------
246# Exit script on insufficient permission to read a specified file
247
248exit_failure_file_permission_read()
249{
250 if [ $# -gt 0 ]; then
251 echo "xdg-email: $@" >&2
252 fi
253
254 exit 5
255}
256
257#------------------------------------------------------------
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000258# Exit script on insufficient permission to write a specified file
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000259
260exit_failure_file_permission_write()
261{
262 if [ $# -gt 0 ]; then
263 echo "xdg-email: $@" >&2
264 fi
265
266 exit 6
267}
268
269check_input_file()
270{
271 if [ ! -e "$1" ]; then
272 exit_failure_file_missing "file '$1' does not exist"
273 fi
274 if [ ! -r "$1" ]; then
275 exit_failure_file_permission_read "no permission to read file '$1'"
276 fi
277}
278
279check_vendor_prefix()
280{
281 file_label="$2"
282 [ -n "$file_label" ] || file_label="filename"
283 file=`basename "$1"`
284 case "$file" in
285 [a-zA-Z]*-*)
286 return
287 ;;
288 esac
289
290 echo "xdg-email: $file_label '$file' does not have a proper vendor prefix" >&2
291 echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
292 echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
293 echo "Use --novendor to override or 'xdg-email --manual' for additional info." >&2
294 exit 1
295}
296
297check_output_file()
298{
299 # if the file exists, check if it is writeable
300 # if it does not exists, check if we are allowed to write on the directory
301 if [ -e "$1" ]; then
302 if [ ! -w "$1" ]; then
303 exit_failure_file_permission_write "no permission to write to file '$1'"
304 fi
305 else
306 DIR=`dirname "$1"`
307 if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
308 exit_failure_file_permission_write "no permission to create file '$1'"
309 fi
310 fi
311}
312
313#----------------------------------------
314# Checks for shared commands, e.g. --help
315
316check_common_commands()
317{
318 while [ $# -gt 0 ] ; do
319 parm="$1"
320 shift
321
322 case "$parm" in
323 --help)
324 usage
325 echo "Use 'man xdg-email' or 'xdg-email --manual' for additional info."
326 exit_success
327 ;;
328
329 --manual)
330 manualpage
331 exit_success
332 ;;
333
334 --version)
mdm@chromium.org7bf13222011-03-30 23:20:46 +0000335 echo "xdg-email 1.1.0 rc1"
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000336 exit_success
337 ;;
338 esac
339 done
340}
341
342check_common_commands "$@"
343
344[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
345if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
346 # Be silent
347 xdg_redirect_output=" > /dev/null 2> /dev/null"
348else
349 # All output to stderr
350 xdg_redirect_output=" >&2"
351fi
352
353#--------------------------------------
354# Checks for known desktop environments
355# set variable DE to the desktop environments name, lowercase
356
357detectDE()
358{
359 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
360 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000361 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
362 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
mdm@chromium.org672539c2011-04-05 03:39:34 +0000363 fi
364
365 if [ x"$DE" = x"" ]; then
366 # fallback to checking $DESKTOP_SESSION
367 case "$DESKTOP_SESSION" in
368 LXDE)
369 DE=lxde;
370 ;;
371 xfce|xfce4)
372 DE=xfce;
373 ;;
374 esac
375 fi
376
377 if [ x"$DE" = x"" ]; then
378 # fallback to uname output for other platforms
379 case "$(uname 2>/dev/null)" in
380 Darwin)
381 DE=darwin;
382 ;;
383 esac
384 fi
385
386 if [ x"$DE" = x"gnome" ]; then
387 # gnome-default-applications-properties is only available in GNOME 2.x
388 # but not in GNOME 3.x
389 which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000390 fi
391}
392
393#----------------------------------------------------------------------------
394# kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
395# It also always returns 1 in KDE 3.4 and earlier
396# Simply return 0 in such case
397
398kfmclient_fix_exit_code()
399{
mdm@chromium.org7bf13222011-03-30 23:20:46 +0000400 [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
401 version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
402 major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
403 minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
404 release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000405 test "$major" -gt 3 && return $1
406 test "$minor" -gt 5 && return $1
407 test "$release" -gt 4 && return $1
408 return 0
409}
410
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000411run_thunderbird()
412{
413 local THUNDERBIRD MAILTO NEWMAILTO TO CC BCC SUBJECT BODY ATTACH
414 THUNDERBIRD="$1"
415 MAILTO=$(echo "$2" | sed 's/^mailto://')
416 echo "$MAILTO" | grep -qs "^?"
417 if [ "$?" = "0" ] ; then
418 MAILTO=$(echo "$MAILTO" | sed 's/^?//')
419 else
420 MAILTO=$(echo "$MAILTO" | sed 's/^/to=/' | sed 's/?/\&/')
421 fi
422
423 MAILTO=$(echo "$MAILTO" | sed 's/&/\n/g')
424 TO=$(echo "$MAILTO" | grep '^to=' | sed 's/^to=//' | awk '{ printf "%s,",$0 }')
425 CC=$(echo "$MAILTO" | grep '^cc=' | sed 's/^cc=//' | awk '{ printf "%s,",$0 }')
426 BCC=$(echo "$MAILTO" | grep '^bcc=' | sed 's/^bcc=//' | awk '{ printf "%s,",$0 }')
427 SUBJECT=$(echo "$MAILTO" | grep '^subject=' | tail -n 1)
428 BODY=$(echo "$MAILTO" | grep '^body=' | tail -n 1)
mdm@chromium.org741e06f2011-03-30 22:51:57 +0000429 ATTACH=$(echo "$MAILTO" | sed 's/^attach=/\n\nfile:\/\//g' | awk '/^file:/ { printf "%s,",$0 }' | sed 's/,$//')
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000430
431 if [ -z "$TO" ] ; then
432 NEWMAILTO=
433 else
434 NEWMAILTO="to='$TO'"
435 fi
436 if [ -n "$CC" ] ; then
437 NEWMAILTO="${NEWMAILTO},cc='$CC'"
438 fi
439 if [ -n "$BCC" ] ; then
440 NEWMAILTO="${NEWMAILTO},bcc='$BCC'"
441 fi
442 if [ -n "$SUBJECT" ] ; then
443 NEWMAILTO="${NEWMAILTO},$SUBJECT"
444 fi
445 if [ -n "$BODY" ] ; then
446 NEWMAILTO="${NEWMAILTO},$BODY"
447 fi
448
449 if [ -n "$ATTACH" ] ; then
450 NEWMAILTO="${NEWMAILTO},attachment='${ATTACH}'"
451 fi
452
453 NEWMAILTO=$(echo "$NEWMAILTO" | sed 's/^,//')
454 DEBUG 1 "Running $THUNDERBIRD -compose \"$NEWMAILTO\""
455 "$THUNDERBIRD" -compose "$NEWMAILTO"
456 if [ $? -eq 0 ]; then
457 exit_success
458 else
459 exit_failure_operation_failed
460 fi
461}
462
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000463open_kde()
464{
mdm@chromium.org7bf13222011-03-30 23:20:46 +0000465 local client kde_email_profile_name
466 kde_email_profile_name=`kreadconfig --file emaildefaults --group Defaults --key Profile`
467 client=`kreadconfig --file emaildefaults --group PROFILE_"$kde_email_profile_name" --key EmailClient | cut -d ' ' -f 1`
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000468 echo $client | grep thunderbird > /dev/null 2>&1
469 if [ $? -eq 0 ] ; then
470 run_thunderbird "$client" "$1"
471 fi
472
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000473 if [ -f /etc/SuSE-release ] ; then
474 # Workaround for SUSE 10.0
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000475 [ -z "$client" ] && client="kmail"
476 if ! which "$client" > /dev/null 2> /dev/null; then
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000477 DEBUG 3 "KDE has $client configured as email client which isn't installed"
478 if which gnome-open > /dev/null 2> /dev/null && which evolution > /dev/null 2> /dev/null; then
479 DEBUG 3 "Try gnome-open instead"
480 open_gnome "$1"
481 fi
482 fi
483 fi
484 DEBUG 1 "Running kmailservice \"$1\""
mdm@chromium.orgad856b92009-07-27 21:50:25 +0000485 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
486 KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null`
487 else
488 KMAILSERVICE=`which kmailservice 2>/dev/null`
489 fi
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000490 # KDE uses locale's encoding when decoding the URI, so set it to UTF-8
mdm@chromium.orgad856b92009-07-27 21:50:25 +0000491 LC_ALL=C.UTF-8 $KMAILSERVICE "$1"
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000492 kfmclient_fix_exit_code $?
493
494 if [ $? -eq 0 ]; then
495 exit_success
496 else
497 exit_failure_operation_failed
498 fi
499}
500
mdm@chromium.org672539c2011-04-05 03:39:34 +0000501open_gnome3()
502{
503 local client
504 local desktop
505 desktop=`xdg-mime query default "x-scheme-handler/mailto"`
506 client=`desktop_file_to_binary "$browser"`
507 echo $client | grep thunderbird > /dev/null 2>&1
508 if [ $? -eq 0 ] ; then
509 run_thunderbird "$client" "$1"
510 fi
511
512 if gvfs-open --help 2>/dev/null 1>&2; then
513 DEBUG 1 "Running gvfs-open \"$1\""
514 gvfs-open "$1"
515 else
516 DEBUG 1 "Running gnome-open \"$1\""
517 gnome-open "$1"
518 fi
519
520 if [ $? -eq 0 ]; then
521 exit_success
522 else
523 exit_failure_operation_failed
524 fi
525}
526
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000527open_gnome()
528{
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000529 local client
530 client=`gconftool-2 --get /desktop/gnome/url-handlers/mailto/command | cut -d ' ' -f 1` || ""
531 echo $client | grep thunderbird > /dev/null 2>&1
532 if [ $? -eq 0 ] ; then
533 run_thunderbird "$client" "$1"
534 fi
535
536 if gvfs-open --help 2>/dev/null 1>&2; then
537 DEBUG 1 "Running gvfs-open \"$1\""
538 gvfs-open "$1"
539 else
540 DEBUG 1 "Running gnome-open \"$1\""
541 gnome-open "$1"
542 fi
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000543
544 if [ $? -eq 0 ]; then
545 exit_success
546 else
547 exit_failure_operation_failed
548 fi
549}
550
551
552open_xfce()
553{
554 DEBUG 1 "Running exo-open \"$1\""
555 exo-open "$1"
556
557 if [ $? -eq 0 ]; then
558 exit_success
559 else
560 exit_failure_operation_failed
561 fi
562}
563
564open_generic()
565{
566 IFS=":"
567 for browser in $BROWSER; do
568 if [ x"$browser" != x"" ]; then
569
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000570 browser_with_arg=`printf "$browser" "$1" 2>/dev/null`
571 if [ $? -ne 0 ]; then browser_with_arg=$browser;
572 fi
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000573
574 if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1";
575 else $browser_with_arg;
576 fi
577
578 if [ $? -eq 0 ]; then exit_success;
579 fi
580 fi
581 done
582
583 exit_failure_operation_impossible "no method available for opening '$1'"
584}
585
586url_encode()
587{
588result=$(echo "$1" | $utf8 | awk '
589 BEGIN {
590 for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0
591 e = ""
592 linenr = 1
593 }
594 {
595 if ( linenr++ != 1 ) {
596 e = e "%0D%0A"
597 }
598 for ( i=1; i<=length ($0); ++i ) {
599 c = substr ($0, i, 1)
600 if ( ord [c] > 127 ) {
601 e = e "%" sprintf("%02X", ord [c])
mdm@chromium.org741e06f2011-03-30 22:51:57 +0000602 } else if ( c ~ /[@a-zA-Z0-9.-\\\/]/ ) {
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000603 e = e c
604 } else {
605 e = e "%" sprintf("%02X", ord [c])
606 }
607 }
608 }
609 END {
610 print e
611 }
612')
613}
614
615options=
616mailto=
617utf8="iconv -t utf8"
618while [ $# -gt 0 ] ; do
619 parm="$1"
620 shift
621
622 case "$parm" in
623 --utf8)
624 utf8="cat"
625 ;;
626
627 --to)
628 if [ -z "$1" ] ; then
629 exit_failure_syntax "email address argument missing for --to"
630 fi
631 url_encode "$1"
632 options="${options}to=${result}&"
633 shift
634 ;;
635
636 --cc)
637 if [ -z "$1" ] ; then
638 exit_failure_syntax "email address argument missing for --cc"
639 fi
640 url_encode "$1"
641 options="${options}cc=${result}&"
642 shift
643 ;;
644
645 --bcc)
646 if [ -z "$1" ] ; then
647 exit_failure_syntax "email address argument missing for --bcc"
648 fi
649 url_encode "$1"
650 options="${options}bcc=${result}&"
651 shift
652 ;;
653
654 --subject)
655 if [ -z "$1" ] ; then
656 exit_failure_syntax "text argument missing for --subject option"
657 fi
658 url_encode "$1"
659 options="${options}subject=${result}&"
660 shift
661 ;;
662
663 --body)
664 if [ -z "$1" ] ; then
665 exit_failure_syntax "text argument missing for --body option"
666 fi
667 url_encode "$1"
668 options="${options}body=${result}&"
669 shift
670 ;;
671
672 --attach)
673 if [ -z "$1" ] ; then
674 exit_failure_syntax "file argument missing for --attach option"
675 fi
676 check_input_file "$1"
677 file=`readlink -f "$1"` # Normalize path
678 if [ -z "$file" -o ! -f "$file" ] ; then
679 exit_failure_file_missing "file '$1' does not exist"
680 fi
681
682 url_encode "$file"
683 options="${options}attach=${result}&"
684 shift
685 ;;
686
687 -*)
688 exit_failure_syntax "unexpected option '$parm'"
689 ;;
690
691 mailto:*)
692 mailto="$parm"
693 ;;
694
695 *@*)
696 url_encode "$parm"
697 if [ -z "${mailto}" ] ; then
698 mailto="mailto:"${result}"?"
699 else
700 options="${options}to=${result}&"
701 fi
702 ;;
703
704 *)
705 exit_failure_syntax "unexpected argument '$parm'"
706 ;;
707 esac
708done
709
710if [ -z "${mailto}" ] ; then
711 # TO address is optional
712 mailto="mailto:?"
713fi
714
715case $mailto in
716 *\?)
717 mailto="${mailto}${options}"
718 ;;
719
720 *\?*)
721 mailto="${mailto}&${options}"
722 ;;
723
724 *)
725 mailto="${mailto}?${options}"
726 ;;
727esac
728
729# Strip trailing ? and &
730mailto=`echo "${mailto}"| sed 's/[?&]$//'`
731
732# Shouldn't happen
733[ x"${mailto}" != x"" ] || exit_failure_syntax
734
735if which xdg-email-hook.sh > /dev/null 2> /dev/null; then
736 xdg-email-hook.sh "${mailto}"
737 if [ $? -eq 0 ]; then
738 exit_success
739 else
740 exit_failure_operation_failed
741 fi
742fi
743
744detectDE
745
746if [ x"$DE" = x"" ]; then
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000747 DE=generic
748fi
749
mdm@chromium.org56df6d32010-08-31 18:16:49 +0000750# if BROWSER variable is not set, check some well known browsers instead
751if [ x"$BROWSER" = x"" ]; then
752 BROWSER=links2:links:lynx:w3m
753 if [ -n "$DISPLAY" ]; then
754 BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
755 fi
756fi
757
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000758case "$DE" in
759 kde)
760 open_kde "${mailto}"
761 ;;
762
763 gnome)
764 open_gnome "${mailto}"
765 ;;
766
mdm@chromium.org672539c2011-04-05 03:39:34 +0000767 gnome3)
768 open_gnome3 "${mailto}"
769 ;;
770
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000771 xfce)
772 open_xfce "${mailto}"
773 ;;
774
mdm@chromium.org7bf13222011-03-30 23:20:46 +0000775 generic|lxde)
dkegel@google.comf20da1f2009-06-30 19:16:32 +0000776 open_generic "${mailto}"
777 ;;
778
779 *)
780 exit_failure_operation_impossible "no method available for opening '${mailto}'"
781 ;;
782esac