OLD | NEW |
1 #!/bin/bash | 1 #!/bin/sh |
2 #--------------------------------------------- | 2 #--------------------------------------------- |
3 # xdg-email | 3 # xdg-email |
4 # | 4 # |
5 # Utility script to open the users favorite email program, using the | 5 # Utility script to open the users favorite email program, using the |
6 # RFC 2368 mailto: URI spec | 6 # RFC 2368 mailto: URI spec |
7 # | 7 # |
8 # Refer to the usage() function below for usage. | 8 # Refer to the usage() function below for usage. |
9 # | 9 # |
10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> | 10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
11 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> | 11 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> |
12 # | 12 # |
13 # LICENSE: | 13 # LICENSE: |
14 # | 14 # |
15 #--------------------------------------------- | 15 #--------------------------------------------- |
16 | 16 |
17 manualpage() | 17 manualpage() |
18 { | 18 { |
19 cat << _MANUALPAGE | 19 cat << _MANUALPAGE |
20 _MANUALPAGE | 20 _MANUALPAGE |
21 } | 21 } |
22 | 22 |
23 usage() | 23 usage() |
24 { | 24 { |
25 cat << _USAGE | 25 cat << _USAGE |
26 _USAGE | 26 _USAGE |
27 } | 27 } |
28 | 28 |
29 #@xdg-utils-common@ | 29 #@xdg-utils-common@ |
30 | 30 |
| 31 run_thunderbird() |
| 32 { |
| 33 local THUNDERBIRD MAILTO NEWMAILTO TO CC BCC SUBJECT BODY ATTACH |
| 34 THUNDERBIRD="$1" |
| 35 MAILTO=$(echo "$2" | sed 's/^mailto://') |
| 36 echo "$MAILTO" | grep -qs "^?" |
| 37 if [ "$?" = "0" ] ; then |
| 38 MAILTO=$(echo "$MAILTO" | sed 's/^?//') |
| 39 else |
| 40 MAILTO=$(echo "$MAILTO" | sed 's/^/to=/' | sed 's/?/\&/') |
| 41 fi |
| 42 |
| 43 MAILTO=$(echo "$MAILTO" | sed 's/&/\n/g') |
| 44 TO=$(echo "$MAILTO" | grep '^to=' | sed 's/^to=//' | awk '{ printf "%s,",$0
}') |
| 45 CC=$(echo "$MAILTO" | grep '^cc=' | sed 's/^cc=//' | awk '{ printf "%s,",$0
}') |
| 46 BCC=$(echo "$MAILTO" | grep '^bcc=' | sed 's/^bcc=//' | awk '{ printf "%s,",
$0 }') |
| 47 SUBJECT=$(echo "$MAILTO" | grep '^subject=' | tail -n 1) |
| 48 BODY=$(echo "$MAILTO" | grep '^body=' | tail -n 1) |
| 49 ATTACH=$(echo "$MAILTO" | sed 's/^attach=/\n\nfile:\/\//g' | awk '/^file:/ {
printf "%s,",$0 }') |
| 50 |
| 51 if [ -z "$TO" ] ; then |
| 52 NEWMAILTO= |
| 53 else |
| 54 NEWMAILTO="to='$TO'" |
| 55 fi |
| 56 if [ -n "$CC" ] ; then |
| 57 NEWMAILTO="${NEWMAILTO},cc='$CC'" |
| 58 fi |
| 59 if [ -n "$BCC" ] ; then |
| 60 NEWMAILTO="${NEWMAILTO},bcc='$BCC'" |
| 61 fi |
| 62 if [ -n "$SUBJECT" ] ; then |
| 63 NEWMAILTO="${NEWMAILTO},$SUBJECT" |
| 64 fi |
| 65 if [ -n "$BODY" ] ; then |
| 66 NEWMAILTO="${NEWMAILTO},$BODY" |
| 67 fi |
| 68 |
| 69 if [ -n "$ATTACH" ] ; then |
| 70 NEWMAILTO="${NEWMAILTO},attachment='${ATTACH}'" |
| 71 fi |
| 72 |
| 73 NEWMAILTO=$(echo "$NEWMAILTO" | sed 's/^,//') |
| 74 DEBUG 1 "Running $THUNDERBIRD -compose \"$NEWMAILTO\"" |
| 75 "$THUNDERBIRD" -compose "$NEWMAILTO" |
| 76 if [ $? -eq 0 ]; then |
| 77 exit_success |
| 78 else |
| 79 exit_failure_operation_failed |
| 80 fi |
| 81 } |
| 82 |
31 open_kde() | 83 open_kde() |
32 { | 84 { |
33 local client | 85 local client |
| 86 client=`kreadconfig --file emaildefaults --group PROFILE_Default --key Email
Client | cut -d ' ' -f 1` |
| 87 echo $client | grep thunderbird > /dev/null 2>&1 |
| 88 if [ $? -eq 0 ] ; then |
| 89 run_thunderbird "$client" "$1" |
| 90 fi |
| 91 |
34 if [ -f /etc/SuSE-release ] ; then | 92 if [ -f /etc/SuSE-release ] ; then |
35 # Workaround for SUSE 10.0 | 93 # Workaround for SUSE 10.0 |
36 client=`kreadconfig --file emaildefaults --group PROFILE_Default --key E
mailClient| cut -d ' ' -f 1` | 94 [ -z "$client" ] && client="kmail" |
37 [ -z $client ] && client="kmail" | 95 if ! which "$client" > /dev/null 2> /dev/null; then |
38 if ! which $client > /dev/null 2> /dev/null; then | |
39 DEBUG 3 "KDE has $client configured as email client which isn't inst
alled" | 96 DEBUG 3 "KDE has $client configured as email client which isn't inst
alled" |
40 if which gnome-open > /dev/null 2> /dev/null && which evolution > /d
ev/null 2> /dev/null; then | 97 if which gnome-open > /dev/null 2> /dev/null && which evolution > /d
ev/null 2> /dev/null; then |
41 DEBUG 3 "Try gnome-open instead" | 98 DEBUG 3 "Try gnome-open instead" |
42 open_gnome "$1" | 99 open_gnome "$1" |
43 fi | 100 fi |
44 fi | 101 fi |
45 fi | 102 fi |
46 DEBUG 1 "Running kmailservice \"$1\"" | 103 DEBUG 1 "Running kmailservice \"$1\"" |
47 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then | 104 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
48 KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null` | 105 KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null` |
49 else | 106 else |
50 KMAILSERVICE=`which kmailservice 2>/dev/null` | 107 KMAILSERVICE=`which kmailservice 2>/dev/null` |
51 fi | 108 fi |
52 # KDE uses locale's encoding when decoding the URI, so set it to UTF-8 | 109 # KDE uses locale's encoding when decoding the URI, so set it to UTF-8 |
53 LC_ALL=C.UTF-8 $KMAILSERVICE "$1" | 110 LC_ALL=C.UTF-8 $KMAILSERVICE "$1" |
54 kfmclient_fix_exit_code $? | 111 kfmclient_fix_exit_code $? |
55 | 112 |
56 if [ $? -eq 0 ]; then | 113 if [ $? -eq 0 ]; then |
57 exit_success | 114 exit_success |
58 else | 115 else |
59 exit_failure_operation_failed | 116 exit_failure_operation_failed |
60 fi | 117 fi |
61 } | 118 } |
62 | 119 |
63 open_gnome() | 120 open_gnome() |
64 { | 121 { |
65 DEBUG 1 "Running gnome-open \"$1\"" | 122 local client |
66 gnome-open "$1" | 123 client=`gconftool-2 --get /desktop/gnome/url-handlers/mailto/command | cut -
d ' ' -f 1` || "" |
| 124 echo $client | grep thunderbird > /dev/null 2>&1 |
| 125 if [ $? -eq 0 ] ; then |
| 126 run_thunderbird "$client" "$1" |
| 127 fi |
| 128 |
| 129 if gvfs-open --help 2>/dev/null 1>&2; then |
| 130 DEBUG 1 "Running gvfs-open \"$1\"" |
| 131 gvfs-open "$1" |
| 132 else |
| 133 DEBUG 1 "Running gnome-open \"$1\"" |
| 134 gnome-open "$1" |
| 135 fi |
67 | 136 |
68 if [ $? -eq 0 ]; then | 137 if [ $? -eq 0 ]; then |
69 exit_success | 138 exit_success |
70 else | 139 else |
71 exit_failure_operation_failed | 140 exit_failure_operation_failed |
72 fi | 141 fi |
73 } | 142 } |
74 | 143 |
75 | 144 |
76 open_xfce() | 145 open_xfce() |
77 { | 146 { |
78 DEBUG 1 "Running exo-open \"$1\"" | 147 DEBUG 1 "Running exo-open \"$1\"" |
79 exo-open "$1" | 148 exo-open "$1" |
80 | 149 |
81 if [ $? -eq 0 ]; then | 150 if [ $? -eq 0 ]; then |
82 exit_success | 151 exit_success |
83 else | 152 else |
84 exit_failure_operation_failed | 153 exit_failure_operation_failed |
85 fi | 154 fi |
86 } | 155 } |
87 | 156 |
88 open_generic() | 157 open_generic() |
89 { | 158 { |
90 IFS=":" | 159 IFS=":" |
91 for browser in $BROWSER; do | 160 for browser in $BROWSER; do |
92 if [ x"$browser" != x"" ]; then | 161 if [ x"$browser" != x"" ]; then |
93 | 162 |
94 IFS=' ' | 163 browser_with_arg=`printf "$browser" "$1" 2>/dev/null` |
95 browser_with_arg=${browser//'%s'/"$1"} | 164 if [ $? -ne 0 ]; then browser_with_arg=$browser; |
| 165 fi |
96 | 166 |
97 if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1"; | 167 if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1"; |
98 else $browser_with_arg; | 168 else $browser_with_arg; |
99 fi | 169 fi |
100 | 170 |
101 if [ $? -eq 0 ]; then exit_success; | 171 if [ $? -eq 0 ]; then exit_success; |
102 fi | 172 fi |
103 fi | 173 fi |
104 done | 174 done |
105 | 175 |
106 exit_failure_operation_impossible "no method available for opening '$1'" | 176 exit_failure_operation_impossible "no method available for opening '$1'" |
107 } | 177 } |
108 | 178 |
109 url_encode() | 179 url_encode() |
110 { | 180 { |
111 result=$(echo "$1" | $utf8 | awk ' | 181 result=$(echo "$1" | $utf8 | awk ' |
112 BEGIN { | 182 BEGIN { |
113 for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 | 183 for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 |
114 e = "" | 184 e = "" |
115 linenr = 1 | 185 linenr = 1 |
116 } | 186 } |
117 { | 187 { |
118 if ( linenr++ != 1 ) { | 188 if ( linenr++ != 1 ) { |
119 e = e "%0D%0A" | 189 e = e "%0D%0A" |
120 } | 190 } |
121 for ( i=1; i<=length ($0); ++i ) { | 191 for ( i=1; i<=length ($0); ++i ) { |
122 c = substr ($0, i, 1) | 192 c = substr ($0, i, 1) |
123 if ( ord [c] > 127 ) { | 193 if ( ord [c] > 127 ) { |
124 e = e "%" sprintf("%02X", ord [c]) | 194 e = e "%" sprintf("%02X", ord [c]) |
125 } else if ( c ~ /[@a-zA-Z0-9.-]/ ) { | 195 } else if ( c ~ /[@a-zA-Z0-9.-\\/]/ ) { |
126 e = e c | 196 e = e c |
127 } else { | 197 } else { |
128 e = e "%" sprintf("%02X", ord [c]) | 198 e = e "%" sprintf("%02X", ord [c]) |
129 } | 199 } |
130 } | 200 } |
131 } | 201 } |
132 END { | 202 END { |
133 print e | 203 print e |
134 } | 204 } |
135 ') | 205 ') |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 if [ $? -eq 0 ]; then | 330 if [ $? -eq 0 ]; then |
261 exit_success | 331 exit_success |
262 else | 332 else |
263 exit_failure_operation_failed | 333 exit_failure_operation_failed |
264 fi | 334 fi |
265 fi | 335 fi |
266 | 336 |
267 detectDE | 337 detectDE |
268 | 338 |
269 if [ x"$DE" = x"" ]; then | 339 if [ x"$DE" = x"" ]; then |
270 # if BROWSER variable is not set, check some well known browsers instead | 340 DE=generic |
271 if [ x"$BROWSER" = x"" ]; then | 341 fi |
272 BROWSER=firefox:mozilla:netscape | 342 |
| 343 # if BROWSER variable is not set, check some well known browsers instead |
| 344 if [ x"$BROWSER" = x"" ]; then |
| 345 BROWSER=links2:links:lynx:w3m |
| 346 if [ -n "$DISPLAY" ]; then |
| 347 BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrom
e:$BROWSER |
273 fi | 348 fi |
274 DE=generic | |
275 fi | 349 fi |
276 | 350 |
277 case "$DE" in | 351 case "$DE" in |
278 kde) | 352 kde) |
279 open_kde "${mailto}" | 353 open_kde "${mailto}" |
280 ;; | 354 ;; |
281 | 355 |
282 gnome) | 356 gnome) |
283 open_gnome "${mailto}" | 357 open_gnome "${mailto}" |
284 ;; | 358 ;; |
285 | 359 |
286 xfce) | 360 xfce) |
287 open_xfce "${mailto}" | 361 open_xfce "${mailto}" |
288 ;; | 362 ;; |
289 | 363 |
290 generic) | 364 generic) |
291 open_generic "${mailto}" | 365 open_generic "${mailto}" |
292 ;; | 366 ;; |
293 | 367 |
294 *) | 368 *) |
295 exit_failure_operation_impossible "no method available for opening '${mailto
}'" | 369 exit_failure_operation_impossible "no method available for opening '${mailto
}'" |
296 ;; | 370 ;; |
297 esac | 371 esac |
OLD | NEW |