1#!/bin/sh 2# ************************************************************* 3# 4# Licensed to the Apache Software Foundation (ASF) under one 5# or more contributor license agreements. See the NOTICE file 6# distributed with this work for additional information 7# regarding copyright ownership. The ASF licenses this file 8# to you under the Apache License, Version 2.0 (the 9# "License"); you may not use this file except in compliance 10# with the License. You may obtain a copy of the License at 11# 12# http://www.apache.org/licenses/LICENSE-2.0 13# 14# Unless required by applicable law or agreed to in writing, 15# software distributed under the License is distributed on an 16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17# KIND, either express or implied. See the License for the 18# specific language governing permissions and limitations 19# under the License. 20# 21# ************************************************************* 22URI_ENCODE="`dirname $0`/uri-encode" 23FOPTS="" 24 25# linux file utility needs -L option to resolve symlinks 26if [ "`uname -s`" = "Linux" ] 27then 28 FOPTS="-L" 29fi 30 31# do not confuse the system mail clients with OOo and Java libraries 32unset LD_LIBRARY_PATH 33 34# tries to locate the executable specified 35# as first parameter in the user's path. 36which() { 37 if [ ! -z "$1" ]; then 38 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do 39 if [ -x "$i/$1" -a ! -d "$i/$1" ]; then 40 echo "$i/$1" 41 break; 42 fi 43 done 44 fi 45} 46 47# checks for the original mozilla start script(s) 48# and restrict the "-remote" semantics to those. 49run_mozilla() { 50 # find mozilla script in PATH if necessary 51 if [ "`basename $1`" = "$1" ]; then 52 moz=`which $1` 53 else 54 moz=$1 55 fi 56 57 if file $FOPTS "$moz" | grep "script" > /dev/null && grep "[NM]PL" "$moz" > /dev/null; then 58 "$moz" -remote 'ping()' 2>/dev/null >/dev/null 59 if [ $? -eq 2 ]; then 60 "$1" -compose "$2" & 61 else 62 "$1" -remote "xfeDoCommand(composeMessage,$2)" & 63 fi 64 else 65 "$1" -compose "$2" & 66 fi 67} 68 69if [ "$1" = "--mailclient" ]; then 70 shift 71 MAILER=$1 72 shift 73fi 74 75# autodetect mail client from executable name 76case `basename "$MAILER" | sed 's/-.*$//'` in 77 78 iceape | mozilla | netscape | seamonkey | icedove | thunderbird) 79 80 while [ "$1" != "" ]; do 81 case $1 in 82 --to) 83 TO=${TO:-}${TO:+,}$2 84 shift 85 ;; 86 --cc) 87 CC=${CC:-}${CC:+,}$2 88 shift 89 ;; 90 --bcc) 91 BCC=${BCC:-}${BCC:+,}$2 92 shift 93 ;; 94 --subject) 95 SUBJECT=$2 96 shift 97 ;; 98 --body) 99 BODY=$2 100 shift 101 ;; 102 --attach) 103 ATTACH=${ATTACH:-}${ATTACH:+,}`echo "file://$2" | ${URI_ENCODE}` 104 shift 105 ;; 106 *) 107 ;; 108 esac 109 shift; 110 done 111 112 if [ "$TO" != "" ]; then 113 COMMAND=${COMMAND:-}${COMMAND:+,}to=${TO} 114 fi 115 if [ "$CC" != "" ]; then 116 COMMAND=${COMMAND:-}${COMMAND:+,}cc=${CC} 117 fi 118 if [ "$BCC" != "" ]; then 119 COMMAND=${COMMAND:-}${COMMAND:+,}bcc=${BCC} 120 fi 121 if [ "$SUBJECT" != "" ]; then 122 COMMAND=${COMMAND:-}${COMMAND:+,}subject=${SUBJECT} 123 fi 124 if [ "$BODY" != "" ]; then 125 COMMAND=${COMMAND:-}${COMMAND:+,}body=${BODY} 126 fi 127 if [ "$ATTACH" != "" ]; then 128 COMMAND=${COMMAND:-}${COMMAND:+,}attachment=${ATTACH} 129 fi 130 131 run_mozilla "$MAILER" "$COMMAND" 132 ;; 133 134 kmail) 135 136 while [ "$1" != "" ]; do 137 case $1 in 138 --to) 139 TO="${TO:-}${TO:+,}$2" 140 shift 141 ;; 142 --cc) 143 CC="${CC:-}${CC:+,}$2" 144 shift 145 ;; 146 --bcc) 147 BCC="${BCC:-}${BCC:+,}$2" 148 shift 149 ;; 150 --subject) 151 SUBJECT="$2" 152 shift 153 ;; 154 --body) 155 BODY="$2" 156 shift 157 ;; 158 --attach) 159 ATTACH="$2" 160 shift 161 ;; 162 *) 163 ;; 164 esac 165 shift; 166 done 167 168 ${MAILER} --composer ${CC:+--cc} ${CC:+"${CC}"} ${BCC:+--bcc} ${BCC:+"${BCC}"} \ 169 ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} ${BODY:+--body} ${BODY:+"${BODY}"} \ 170 ${ATTACH:+--attach} ${ATTACH:+"${ATTACH}"} ${TO:+"${TO}"} 171 ;; 172 173 mutt) 174 175 while [ "$1" != "" ]; do 176 case $1 in 177 --from) 178 FROM="$2" 179 shift 180 ;; 181 --to) 182 TO="${TO:-}${TO:+,}$2" 183 shift 184 ;; 185 --cc) 186 CC="${CC:-}${CC:+,}$2" 187 shift 188 ;; 189 --bcc) 190 BCC="${BCC:-}${BCC:+,}$2" 191 shift 192 ;; 193 --subject) 194 SUBJECT="$2" 195 shift 196 ;; 197 --body) 198 TEMPLATE="`basename $0`.mutt.XXXXXXXX" 199 BODY=`mktemp -q -t ${TEMPLATE}` 200 echo "$2" > $BODY 201 shift 202 ;; 203 --attach) 204 ATTACH="$2" 205 shift 206 ;; 207 *) 208 ;; 209 esac 210 shift; 211 done 212 213 x-terminal-emulator -e ${MAILER} \ 214 ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \ 215 ${CC:+-c} ${CC:+"${CC}"} \ 216 ${BCC:+-b} ${BCC:+"${BCC}"} \ 217 ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \ 218 ${BODY:+-i} ${BODY:+"${BODY}"} \ 219 ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \ 220 ${TO:+"${TO}"} & 221 rm -f $BODY 222 ;; 223 224 evolution) 225 226 while [ "$1" != "" ]; do 227 case $1 in 228 --to) 229 if [ "${TO}" != "" ]; then 230 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 231 else 232 TO="$2" 233 fi 234 shift 235 ;; 236 --cc) 237 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}` 238 shift 239 ;; 240 --bcc) 241 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}` 242 shift 243 ;; 244 --subject) 245 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | ${URI_ENCODE}` 246 shift 247 ;; 248 --body) 249 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}` 250 shift 251 ;; 252 --attach) 253 MAILTO="${MAILTO:-}${MAILTO:+&}attach="`echo "file://$2" | ${URI_ENCODE}` 254 shift 255 ;; 256 *) 257 ;; 258 esac 259 shift; 260 done 261 262 MAILTO="mailto:${TO}?${MAILTO}" 263 ${MAILER} "${MAILTO}" & 264 ;; 265 266 groupwise) 267 268 while [ "$1" != "" ]; do 269 case $1 in 270 --to) 271 if [ "${TO}" != "" ]; then 272 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 273 else 274 TO="$2" 275 fi 276 shift 277 ;; 278 --cc) 279 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}` 280 shift 281 ;; 282 --bcc) 283 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}` 284 shift 285 ;; 286 --subject) 287 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | ${URI_ENCODE}` 288 shift 289 ;; 290 --body) 291 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}` 292 shift 293 ;; 294 --attach) 295 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "file://$2" | ${URI_ENCODE}` 296 shift 297 ;; 298 *) 299 ;; 300 esac 301 shift; 302 done 303 304 MAILTO="mailto:${TO}?${MAILTO}" 305 ${MAILER} "${MAILTO}" & 306 ;; 307 308 dtmail) 309 310 while [ "$1" != "" ]; do 311 case $1 in 312 --to) 313 TO=${TO:-}${TO:+,}$2 314 shift 315 ;; 316 --attach) 317 ATTACH="$2" 318 shift 319 ;; 320 *) 321 ;; 322 esac 323 shift; 324 done 325 326 ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} 327 ;; 328 329 sylpheed | claws) 330 331 while [ "$1" != "" ]; do 332 case $1 in 333 --to) 334 TO=${TO:-}${TO:+,}$2 335 shift 336 ;; 337 --attach) 338 ATTACH="${ATTACH:-}${ATTACH:+ }$2" 339 shift 340 ;; 341 *) 342 ;; 343 esac 344 shift; 345 done 346 347 ${MAILER} ${TO:+--compose} "${TO:-}" ${ATTACH:+--attach} "${ATTACH:-}" 348 ;; 349 350 Mail | Thunderbird | *.app ) 351 352 while [ "$1" != "" ]; do 353 case $1 in 354 --attach) 355 #i95688# fix filenames containing accented chars, whatever alien 356 ATTACH="${ATTACH:-}${ATTACH:+ }"`echo "file://$2" | ${URI_ENCODE}` 357 shift 358 ;; 359 *) 360 ;; 361 esac 362 shift; 363 done 364 /usr/bin/open -a "${MAILER}" ${ATTACH} 365 ;; 366 367 "") 368 369 # DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html 370 if [ -n "$DESKTOP_LAUNCH" ]; then 371 while [ "$1" != "" ]; do 372 case $1 in 373 --to) 374 if [ "${TO}" != "" ]; then 375 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 376 else 377 TO="$2" 378 fi 379 shift 380 ;; 381 --cc) 382 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}` 383 shift 384 ;; 385 --bcc) 386 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}` 387 shift 388 ;; 389 --subject) 390 MAILTO="${MAILTO:-}${MAILTO:+&}subject="`echo "$2" | ${URI_ENCODE}` 391 shift 392 ;; 393 --body) 394 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}` 395 shift 396 ;; 397 --attach) 398 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "$2" | ${URI_ENCODE}` 399 shift 400 ;; 401 *) 402 ;; 403 esac 404 shift; 405 done 406 407 MAILTO="mailto:${TO}?${MAILTO}" 408 ${DESKTOP_LAUNCH} "${MAILTO}" & 409 else 410 echo "Could not determine a mail client to use." 411 exit 2 412 fi 413 ;; 414 415 *) 416 echo "Unsupported mail client: `basename $MAILER | sed 's/-.*^//'`" 417 exit 2 418 ;; 419esac 420 421exit 0 422