Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: third_party/xdg-utils/scripts/xdg-email.in

Issue 151098: Patch from mdm@google.com... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/xdg-utils/scripts/xdg-email ('k') | third_party/xdg-utils/scripts/xdg-file-dialog » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
2 #---------------------------------------------
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 #
10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
11 # Copyright 2006, Jeremy White <jwhite@codeweavers.com>
12 #
13 # LICENSE:
14 #
15 #---------------------------------------------
16
17 manualpage()
18 {
19 cat << _MANUALPAGE
20 _MANUALPAGE
21 }
22
23 usage()
24 {
25 cat << _USAGE
26 _USAGE
27 }
28
29 #@xdg-utils-common@
30
31 open_kde()
32 {
33 local client
34 if [ -f /etc/SuSE-release ] ; then
35 # Workaround for SUSE 10.0
36 client=`kreadconfig --file emaildefaults --group PROFILE_Default --key E mailClient| cut -d ' ' -f 1`
37 [ -z $client ] && client="kmail"
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"
40 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"
42 open_gnome "$1"
43 fi
44 fi
45 fi
46 DEBUG 1 "Running kmailservice \"$1\""
47 # KDE uses locale's encoding when decoding the URI, so set it to UTF-8
48 LC_ALL=C.UTF-8 kmailservice "$1"
49 kfmclient_fix_exit_code $?
50
51 if [ $? -eq 0 ]; then
52 exit_success
53 else
54 exit_failure_operation_failed
55 fi
56 }
57
58 open_gnome()
59 {
60 DEBUG 1 "Running gnome-open \"$1\""
61 gnome-open "$1"
62
63 if [ $? -eq 0 ]; then
64 exit_success
65 else
66 exit_failure_operation_failed
67 fi
68 }
69
70
71 open_xfce()
72 {
73 DEBUG 1 "Running exo-open \"$1\""
74 exo-open "$1"
75
76 if [ $? -eq 0 ]; then
77 exit_success
78 else
79 exit_failure_operation_failed
80 fi
81 }
82
83 open_generic()
84 {
85 IFS=":"
86 for browser in $BROWSER; do
87 if [ x"$browser" != x"" ]; then
88
89 IFS=' '
90 browser_with_arg=${browser//'%s'/"$1"}
91
92 if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1";
93 else $browser_with_arg;
94 fi
95
96 if [ $? -eq 0 ]; then exit_success;
97 fi
98 fi
99 done
100
101 exit_failure_operation_impossible "no method available for opening '$1'"
102 }
103
104 url_encode()
105 {
106 result=$(echo "$1" | $utf8 | awk '
107 BEGIN {
108 for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0
109 e = ""
110 linenr = 1
111 }
112 {
113 if ( linenr++ != 1 ) {
114 e = e "%0D%0A"
115 }
116 for ( i=1; i<=length ($0); ++i ) {
117 c = substr ($0, i, 1)
118 if ( ord [c] > 127 ) {
119 e = e "%" sprintf("%02X", ord [c])
120 } else if ( c ~ /[@a-zA-Z0-9.-]/ ) {
121 e = e c
122 } else {
123 e = e "%" sprintf("%02X", ord [c])
124 }
125 }
126 }
127 END {
128 print e
129 }
130 ')
131 }
132
133 options=
134 mailto=
135 utf8="iconv -t utf8"
136 while [ $# -gt 0 ] ; do
137 parm="$1"
138 shift
139
140 case "$parm" in
141 --utf8)
142 utf8="cat"
143 ;;
144
145 --to)
146 if [ -z "$1" ] ; then
147 exit_failure_syntax "email address argument missing for --to"
148 fi
149 url_encode "$1"
150 options="${options}to=${result}&"
151 shift
152 ;;
153
154 --cc)
155 if [ -z "$1" ] ; then
156 exit_failure_syntax "email address argument missing for --cc"
157 fi
158 url_encode "$1"
159 options="${options}cc=${result}&"
160 shift
161 ;;
162
163 --bcc)
164 if [ -z "$1" ] ; then
165 exit_failure_syntax "email address argument missing for --bcc"
166 fi
167 url_encode "$1"
168 options="${options}bcc=${result}&"
169 shift
170 ;;
171
172 --subject)
173 if [ -z "$1" ] ; then
174 exit_failure_syntax "text argument missing for --subject option"
175 fi
176 url_encode "$1"
177 options="${options}subject=${result}&"
178 shift
179 ;;
180
181 --body)
182 if [ -z "$1" ] ; then
183 exit_failure_syntax "text argument missing for --body option"
184 fi
185 url_encode "$1"
186 options="${options}body=${result}&"
187 shift
188 ;;
189
190 --attach)
191 if [ -z "$1" ] ; then
192 exit_failure_syntax "file argument missing for --attach option"
193 fi
194 check_input_file "$1"
195 file=`readlink -f "$1"` # Normalize path
196 if [ -z "$file" -o ! -f "$file" ] ; then
197 exit_failure_file_missing "file '$1' does not exist"
198 fi
199
200 url_encode "$file"
201 options="${options}attach=${result}&"
202 shift
203 ;;
204
205 -*)
206 exit_failure_syntax "unexpected option '$parm'"
207 ;;
208
209 mailto:*)
210 mailto="$parm"
211 ;;
212
213 *@*)
214 url_encode "$parm"
215 if [ -z "${mailto}" ] ; then
216 mailto="mailto:"${result}"?"
217 else
218 options="${options}to=${result}&"
219 fi
220 ;;
221
222 *)
223 exit_failure_syntax "unexpected argument '$parm'"
224 ;;
225 esac
226 done
227
228 if [ -z "${mailto}" ] ; then
229 # TO address is optional
230 mailto="mailto:?"
231 fi
232
233 case $mailto in
234 *\?)
235 mailto="${mailto}${options}"
236 ;;
237
238 *\?*)
239 mailto="${mailto}&${options}"
240 ;;
241
242 *)
243 mailto="${mailto}?${options}"
244 ;;
245 esac
246
247 # Strip trailing ? and &
248 mailto=`echo "${mailto}"| sed 's/[?&]$//'`
249
250 # Shouldn't happen
251 [ x"${mailto}" != x"" ] || exit_failure_syntax
252
253 if which @NAME@-hook.sh > /dev/null 2> /dev/null; then
254 @NAME@-hook.sh "${mailto}"
255 if [ $? -eq 0 ]; then
256 exit_success
257 else
258 exit_failure_operation_failed
259 fi
260 fi
261
262 detectDE
263
264 if [ x"$DE" = x"" ]; then
265 # if BROWSER variable is not set, check some well known browsers instead
266 if [ x"$BROWSER" = x"" ]; then
267 BROWSER=firefox:mozilla:netscape
268 fi
269 DE=generic
270 fi
271
272 case "$DE" in
273 kde)
274 open_kde "${mailto}"
275 ;;
276
277 gnome)
278 open_gnome "${mailto}"
279 ;;
280
281 xfce)
282 open_xfce "${mailto}"
283 ;;
284
285 generic)
286 open_generic "${mailto}"
287 ;;
288
289 *)
290 exit_failure_operation_impossible "no method available for opening '${mailto }'"
291 ;;
292 esac
OLDNEW
« no previous file with comments | « third_party/xdg-utils/scripts/xdg-email ('k') | third_party/xdg-utils/scripts/xdg-file-dialog » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698