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 --from) 159 FROM="$2" 160 shift 161 ;; 162 --attach) 163 ATTACH="${ATTACH:-}${ATTACH:+ }--attach "`echo "file://$2" | "${URI_ENCODE}"` 164 shift 165 ;; 166 *) 167 ;; 168 esac 169 shift; 170 done 171 172 ${MAILER} --composer \ 173 ${CC:+--cc} ${CC:+"${CC}"} \ 174 ${BCC:+--bcc} ${BCC:+"${BCC}"} \ 175 ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} \ 176 ${BODY:+--body} ${BODY:+"${BODY}"} \ 177 ${FROM:+--header} ${FROM:+"From: ${FROM}"} \ 178 ${ATTACH:+${ATTACH}} \ 179 ${TO:+"${TO}"} 180 ;; 181 182 mutt) 183 184 while [ "$1" != "" ]; do 185 case $1 in 186 --from) 187 FROM="$2" 188 shift 189 ;; 190 --to) 191 TO="${TO:-}${TO:+,}$2" 192 shift 193 ;; 194 --cc) 195 CC="${CC:-}${CC:+,}$2" 196 shift 197 ;; 198 --bcc) 199 BCC="${BCC:-}${BCC:+,}$2" 200 shift 201 ;; 202 --subject) 203 SUBJECT="$2" 204 shift 205 ;; 206 --body) 207 TEMPLATE="`basename $0`.mutt.XXXXXXXX" 208 BODY=`mktemp -q -t ${TEMPLATE}` 209 echo "$2" > $BODY 210 shift 211 ;; 212 --attach) 213 ATTACH="$2" 214 shift 215 ;; 216 *) 217 ;; 218 esac 219 shift; 220 done 221 222 x-terminal-emulator -e ${MAILER} \ 223 ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \ 224 ${CC:+-c} ${CC:+"${CC}"} \ 225 ${BCC:+-b} ${BCC:+"${BCC}"} \ 226 ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \ 227 ${BODY:+-i} ${BODY:+"${BODY}"} \ 228 ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \ 229 ${TO:+"${TO}"} & 230 rm -f $BODY 231 ;; 232 233 evolution) 234 235 while [ "$1" != "" ]; do 236 case $1 in 237 --to) 238 if [ "${TO}" != "" ]; then 239 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 240 else 241 TO="$2" 242 fi 243 shift 244 ;; 245 --cc) 246 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | "${URI_ENCODE}"` 247 shift 248 ;; 249 --bcc) 250 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | "${URI_ENCODE}"` 251 shift 252 ;; 253 --subject) 254 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | "${URI_ENCODE}"` 255 shift 256 ;; 257 --body) 258 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | "${URI_ENCODE}"` 259 shift 260 ;; 261 --attach) 262 MAILTO="${MAILTO:-}${MAILTO:+&}attach="`echo "file://$2" | "${URI_ENCODE}"` 263 shift 264 ;; 265 *) 266 ;; 267 esac 268 shift; 269 done 270 271 MAILTO="mailto:${TO}?${MAILTO}" 272 ${MAILER} "${MAILTO}" & 273 ;; 274 275 groupwise) 276 277 while [ "$1" != "" ]; do 278 case $1 in 279 --to) 280 if [ "${TO}" != "" ]; then 281 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 282 else 283 TO="$2" 284 fi 285 shift 286 ;; 287 --cc) 288 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | "${URI_ENCODE}"` 289 shift 290 ;; 291 --bcc) 292 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | "${URI_ENCODE}"` 293 shift 294 ;; 295 --subject) 296 MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | "${URI_ENCODE}"` 297 shift 298 ;; 299 --body) 300 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | "${URI_ENCODE}"` 301 shift 302 ;; 303 --attach) 304 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "file://$2" | "${URI_ENCODE}"` 305 shift 306 ;; 307 *) 308 ;; 309 esac 310 shift; 311 done 312 313 MAILTO="mailto:${TO}?${MAILTO}" 314 ${MAILER} "${MAILTO}" & 315 ;; 316 317 dtmail) 318 319 while [ "$1" != "" ]; do 320 case $1 in 321 --to) 322 TO=${TO:-}${TO:+,}$2 323 shift 324 ;; 325 --attach) 326 ATTACH="$2" 327 shift 328 ;; 329 *) 330 ;; 331 esac 332 shift; 333 done 334 335 ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} 336 ;; 337 338 sylpheed | claws) 339 340 while [ "$1" != "" ]; do 341 case $1 in 342 --to) 343 TO=${TO:-}${TO:+,}$2 344 shift 345 ;; 346 --attach) 347 ATTACH="${ATTACH:-}${ATTACH:+ }$2" 348 shift 349 ;; 350 *) 351 ;; 352 esac 353 shift; 354 done 355 356 ${MAILER} ${TO:+--compose} "${TO:-}" ${ATTACH:+--attach} "${ATTACH:-}" 357 ;; 358 359 Mail | Thunderbird | *.app ) 360 361 while [ "$1" != "" ]; do 362 case $1 in 363 --attach) 364 #i95688# fix filenames containing accented chars, whatever alien 365 ATTACH="${ATTACH:-}${ATTACH:+ }"`echo "file://$2" | "${URI_ENCODE}"` 366 shift 367 ;; 368 *) 369 ;; 370 esac 371 shift; 372 done 373 /usr/bin/open -a "${MAILER}" ${ATTACH} 374 ;; 375 376 "") 377 378 # DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html 379 if [ -n "$DESKTOP_LAUNCH" ]; then 380 while [ "$1" != "" ]; do 381 case $1 in 382 --to) 383 if [ "${TO}" != "" ]; then 384 MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 385 else 386 TO="$2" 387 fi 388 shift 389 ;; 390 --cc) 391 MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | "${URI_ENCODE}"` 392 shift 393 ;; 394 --bcc) 395 MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | "${URI_ENCODE}"` 396 shift 397 ;; 398 --subject) 399 MAILTO="${MAILTO:-}${MAILTO:+&}subject="`echo "$2" | "${URI_ENCODE}"` 400 shift 401 ;; 402 --body) 403 MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | "${URI_ENCODE}"` 404 shift 405 ;; 406 --attach) 407 MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "$2" | "${URI_ENCODE}"` 408 shift 409 ;; 410 *) 411 ;; 412 esac 413 shift; 414 done 415 416 MAILTO="mailto:${TO}?${MAILTO}" 417 ${DESKTOP_LAUNCH} "${MAILTO}" & 418 else 419 echo "Could not determine a mail client to use." 420 exit 2 421 fi 422 ;; 423 424 *) 425 echo "Unsupported mail client: `basename $MAILER | sed 's/-.*^//'`" 426 exit 2 427 ;; 428esac 429 430exit 0 431