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