1cdf0e10cSrcweir#!/bin/sh 29f22d7c2SAndrew Rist# ************************************************************* 3*1748116dSmseidel# 49f22d7c2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 59f22d7c2SAndrew Rist# or more contributor license agreements. See the NOTICE file 69f22d7c2SAndrew Rist# distributed with this work for additional information 79f22d7c2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 89f22d7c2SAndrew Rist# to you under the Apache License, Version 2.0 (the 99f22d7c2SAndrew Rist# "License"); you may not use this file except in compliance 109f22d7c2SAndrew Rist# with the License. You may obtain a copy of the License at 11*1748116dSmseidel# 129f22d7c2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 13*1748116dSmseidel# 149f22d7c2SAndrew Rist# Unless required by applicable law or agreed to in writing, 159f22d7c2SAndrew Rist# software distributed under the License is distributed on an 169f22d7c2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 179f22d7c2SAndrew Rist# KIND, either express or implied. See the License for the 189f22d7c2SAndrew Rist# specific language governing permissions and limitations 199f22d7c2SAndrew Rist# under the License. 20*1748116dSmseidel# 219f22d7c2SAndrew Rist# ************************************************************* 2227513102SJuergen SchmidtURI_ENCODE="`dirname "$0"`/uri-encode" 23cdf0e10cSrcweirFOPTS="" 24cdf0e10cSrcweir 25*1748116dSmseidel# Linux file utility needs -L option to resolve symlinks 26cdf0e10cSrcweirif [ "`uname -s`" = "Linux" ] 27cdf0e10cSrcweirthen 28cdf0e10cSrcweir FOPTS="-L" 29cdf0e10cSrcweirfi 30cdf0e10cSrcweir 31*1748116dSmseidel# do not confuse the system mail clients with AOO and Java libraries 32cdf0e10cSrcweirunset LD_LIBRARY_PATH 33cdf0e10cSrcweir 34*1748116dSmseidel# 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 47*1748116dSmseidel# 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) 79*1748116dSmseidel 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) 10327513102SJuergen Schmidt ATTACH=${ATTACH:-}${ATTACH:+,}`echo "file://$2" | "${URI_ENCODE}"` 104cdf0e10cSrcweir shift 105cdf0e10cSrcweir ;; 106cdf0e10cSrcweir *) 107cdf0e10cSrcweir ;; 108cdf0e10cSrcweir esac 109cdf0e10cSrcweir shift; 110cdf0e10cSrcweir done 111cdf0e10cSrcweir 112cdf0e10cSrcweir if [ "$TO" != "" ]; then 1137aca818aSAriel Constenla-Haile COMMAND=${COMMAND:-}${COMMAND:+,}to=\'${TO}\' 114cdf0e10cSrcweir fi 115cdf0e10cSrcweir if [ "$CC" != "" ]; then 1167aca818aSAriel Constenla-Haile COMMAND=${COMMAND:-}${COMMAND:+,}cc=\'${CC}\' 117cdf0e10cSrcweir fi 118cdf0e10cSrcweir if [ "$BCC" != "" ]; then 1197aca818aSAriel Constenla-Haile COMMAND=${COMMAND:-}${COMMAND:+,}bcc=\'${BCC}\' 120cdf0e10cSrcweir fi 121cdf0e10cSrcweir if [ "$SUBJECT" != "" ]; then 1227aca818aSAriel Constenla-Haile COMMAND=${COMMAND:-}${COMMAND:+,}subject=\'${SUBJECT}\' 123cdf0e10cSrcweir fi 124cdf0e10cSrcweir if [ "$BODY" != "" ]; then 1257aca818aSAriel Constenla-Haile COMMAND=${COMMAND:-}${COMMAND:+,}body=\'${BODY}\' 126cdf0e10cSrcweir fi 127cdf0e10cSrcweir if [ "$ATTACH" != "" ]; then 1287aca818aSAriel Constenla-Haile COMMAND=${COMMAND:-}${COMMAND:+,}attachment=\'${ATTACH}\' 129cdf0e10cSrcweir fi 130*1748116dSmseidel 131cdf0e10cSrcweir run_mozilla "$MAILER" "$COMMAND" 132cdf0e10cSrcweir ;; 133*1748116dSmseidel 134*1748116dSmseidel kmail) 135*1748116dSmseidel 136*1748116dSmseidel while [ "$1" != "" ]; do 137*1748116dSmseidel case $1 in 138*1748116dSmseidel --to) 139*1748116dSmseidel TO="${TO:-}${TO:+,}$2" 140*1748116dSmseidel shift 141*1748116dSmseidel ;; 142*1748116dSmseidel --cc) 143*1748116dSmseidel CC="${CC:-}${CC:+,}$2" 144*1748116dSmseidel shift 145*1748116dSmseidel ;; 146*1748116dSmseidel --bcc) 147*1748116dSmseidel BCC="${BCC:-}${BCC:+,}$2" 148*1748116dSmseidel shift 149*1748116dSmseidel ;; 150*1748116dSmseidel --subject) 151*1748116dSmseidel SUBJECT="$2" 152*1748116dSmseidel shift 153*1748116dSmseidel ;; 154*1748116dSmseidel --body) 155*1748116dSmseidel BODY="$2" 156*1748116dSmseidel shift 157*1748116dSmseidel ;; 158*1748116dSmseidel --from) 159*1748116dSmseidel FROM="$2" 160*1748116dSmseidel shift 161*1748116dSmseidel ;; 162*1748116dSmseidel --attach) 163*1748116dSmseidel ATTACH="${ATTACH:-}${ATTACH:+ }--attach "`echo "file://$2" | "${URI_ENCODE}"` 164*1748116dSmseidel shift 165*1748116dSmseidel ;; 166*1748116dSmseidel *) 167*1748116dSmseidel ;; 168*1748116dSmseidel esac 169*1748116dSmseidel shift; 170*1748116dSmseidel done 171*1748116dSmseidel 172*1748116dSmseidel ${MAILER} --composer \ 173*1748116dSmseidel ${CC:+--cc} ${CC:+"${CC}"} \ 174*1748116dSmseidel ${BCC:+--bcc} ${BCC:+"${BCC}"} \ 175*1748116dSmseidel ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} \ 176*1748116dSmseidel ${BODY:+--body} ${BODY:+"${BODY}"} \ 177*1748116dSmseidel ${FROM:+--header} ${FROM:+"From: ${FROM}"} \ 178*1748116dSmseidel ${ATTACH:+${ATTACH}} \ 179*1748116dSmseidel ${TO:+"${TO}"} 180*1748116dSmseidel ;; 181*1748116dSmseidel 182cdf0e10cSrcweir mutt) 183*1748116dSmseidel 184cdf0e10cSrcweir while [ "$1" != "" ]; do 185cdf0e10cSrcweir case $1 in 186cdf0e10cSrcweir --from) 187cdf0e10cSrcweir FROM="$2" 188cdf0e10cSrcweir shift 189cdf0e10cSrcweir ;; 190cdf0e10cSrcweir --to) 191cdf0e10cSrcweir TO="${TO:-}${TO:+,}$2" 192cdf0e10cSrcweir shift 193cdf0e10cSrcweir ;; 194cdf0e10cSrcweir --cc) 195cdf0e10cSrcweir CC="${CC:-}${CC:+,}$2" 196cdf0e10cSrcweir shift 197cdf0e10cSrcweir ;; 198cdf0e10cSrcweir --bcc) 199cdf0e10cSrcweir BCC="${BCC:-}${BCC:+,}$2" 200cdf0e10cSrcweir shift 201cdf0e10cSrcweir ;; 202cdf0e10cSrcweir --subject) 203cdf0e10cSrcweir SUBJECT="$2" 204cdf0e10cSrcweir shift 205cdf0e10cSrcweir ;; 206cdf0e10cSrcweir --body) 207cdf0e10cSrcweir TEMPLATE="`basename $0`.mutt.XXXXXXXX" 208cdf0e10cSrcweir BODY=`mktemp -q -t ${TEMPLATE}` 209cdf0e10cSrcweir echo "$2" > $BODY 210cdf0e10cSrcweir shift 211cdf0e10cSrcweir ;; 212cdf0e10cSrcweir --attach) 213cdf0e10cSrcweir ATTACH="$2" 214cdf0e10cSrcweir shift 215cdf0e10cSrcweir ;; 216cdf0e10cSrcweir *) 217cdf0e10cSrcweir ;; 218cdf0e10cSrcweir esac 219cdf0e10cSrcweir shift; 220cdf0e10cSrcweir done 221*1748116dSmseidel 222cdf0e10cSrcweir x-terminal-emulator -e ${MAILER} \ 223cdf0e10cSrcweir ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \ 224cdf0e10cSrcweir ${CC:+-c} ${CC:+"${CC}"} \ 225cdf0e10cSrcweir ${BCC:+-b} ${BCC:+"${BCC}"} \ 226cdf0e10cSrcweir ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \ 227cdf0e10cSrcweir ${BODY:+-i} ${BODY:+"${BODY}"} \ 228cdf0e10cSrcweir ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \ 229cdf0e10cSrcweir ${TO:+"${TO}"} & 230cdf0e10cSrcweir rm -f $BODY 231cdf0e10cSrcweir ;; 232*1748116dSmseidel 233cdf0e10cSrcweir evolution) 234*1748116dSmseidel 235cdf0e10cSrcweir while [ "$1" != "" ]; do 236cdf0e10cSrcweir case $1 in 237cdf0e10cSrcweir --to) 238cdf0e10cSrcweir if [ "${TO}" != "" ]; then 239cdf0e10cSrcweir MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 240cdf0e10cSrcweir else 241cdf0e10cSrcweir TO="$2" 242cdf0e10cSrcweir fi 243cdf0e10cSrcweir shift 244cdf0e10cSrcweir ;; 245cdf0e10cSrcweir --cc) 24627513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | "${URI_ENCODE}"` 247cdf0e10cSrcweir shift 248cdf0e10cSrcweir ;; 249cdf0e10cSrcweir --bcc) 25027513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | "${URI_ENCODE}"` 251cdf0e10cSrcweir shift 252cdf0e10cSrcweir ;; 253cdf0e10cSrcweir --subject) 25427513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | "${URI_ENCODE}"` 255cdf0e10cSrcweir shift 256cdf0e10cSrcweir ;; 257cdf0e10cSrcweir --body) 25827513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | "${URI_ENCODE}"` 259cdf0e10cSrcweir shift 260cdf0e10cSrcweir ;; 261cdf0e10cSrcweir --attach) 26227513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}attach="`echo "file://$2" | "${URI_ENCODE}"` 263cdf0e10cSrcweir shift 264cdf0e10cSrcweir ;; 265cdf0e10cSrcweir *) 266cdf0e10cSrcweir ;; 267cdf0e10cSrcweir esac 268cdf0e10cSrcweir shift; 269cdf0e10cSrcweir done 270*1748116dSmseidel 271cdf0e10cSrcweir MAILTO="mailto:${TO}?${MAILTO}" 272cdf0e10cSrcweir ${MAILER} "${MAILTO}" & 273cdf0e10cSrcweir ;; 274*1748116dSmseidel 275cdf0e10cSrcweir groupwise) 276*1748116dSmseidel 277cdf0e10cSrcweir while [ "$1" != "" ]; do 278cdf0e10cSrcweir case $1 in 279cdf0e10cSrcweir --to) 280cdf0e10cSrcweir if [ "${TO}" != "" ]; then 281cdf0e10cSrcweir MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 282cdf0e10cSrcweir else 283cdf0e10cSrcweir TO="$2" 284cdf0e10cSrcweir fi 285cdf0e10cSrcweir shift 286cdf0e10cSrcweir ;; 287cdf0e10cSrcweir --cc) 28827513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | "${URI_ENCODE}"` 289cdf0e10cSrcweir shift 290cdf0e10cSrcweir ;; 291cdf0e10cSrcweir --bcc) 29227513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | "${URI_ENCODE}"` 293cdf0e10cSrcweir shift 294cdf0e10cSrcweir ;; 295cdf0e10cSrcweir --subject) 29627513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | "${URI_ENCODE}"` 297cdf0e10cSrcweir shift 298cdf0e10cSrcweir ;; 299cdf0e10cSrcweir --body) 30027513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | "${URI_ENCODE}"` 301cdf0e10cSrcweir shift 302cdf0e10cSrcweir ;; 303cdf0e10cSrcweir --attach) 30427513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "file://$2" | "${URI_ENCODE}"` 305cdf0e10cSrcweir shift 306cdf0e10cSrcweir ;; 307cdf0e10cSrcweir *) 308cdf0e10cSrcweir ;; 309cdf0e10cSrcweir esac 310cdf0e10cSrcweir shift; 311cdf0e10cSrcweir done 312*1748116dSmseidel 313cdf0e10cSrcweir MAILTO="mailto:${TO}?${MAILTO}" 314cdf0e10cSrcweir ${MAILER} "${MAILTO}" & 315cdf0e10cSrcweir ;; 316cdf0e10cSrcweir 317cdf0e10cSrcweir dtmail) 318*1748116dSmseidel 319cdf0e10cSrcweir while [ "$1" != "" ]; do 320cdf0e10cSrcweir case $1 in 321cdf0e10cSrcweir --to) 322cdf0e10cSrcweir TO=${TO:-}${TO:+,}$2 323cdf0e10cSrcweir shift 324cdf0e10cSrcweir ;; 325cdf0e10cSrcweir --attach) 326cdf0e10cSrcweir ATTACH="$2" 327cdf0e10cSrcweir shift 328cdf0e10cSrcweir ;; 329cdf0e10cSrcweir *) 330cdf0e10cSrcweir ;; 331cdf0e10cSrcweir esac 332cdf0e10cSrcweir shift; 333cdf0e10cSrcweir done 334*1748116dSmseidel 335cdf0e10cSrcweir ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} 336cdf0e10cSrcweir ;; 337cdf0e10cSrcweir 338*1748116dSmseidel sylpheed | claws | claws-mail) 339*1748116dSmseidel 340cdf0e10cSrcweir while [ "$1" != "" ]; do 341cdf0e10cSrcweir case $1 in 342cdf0e10cSrcweir --to) 343cdf0e10cSrcweir TO=${TO:-}${TO:+,}$2 344cdf0e10cSrcweir shift 345cdf0e10cSrcweir ;; 346cdf0e10cSrcweir --attach) 347cdf0e10cSrcweir ATTACH="${ATTACH:-}${ATTACH:+ }$2" 348cdf0e10cSrcweir shift 349cdf0e10cSrcweir ;; 350cdf0e10cSrcweir *) 351cdf0e10cSrcweir ;; 352cdf0e10cSrcweir esac 353cdf0e10cSrcweir shift; 354cdf0e10cSrcweir done 355*1748116dSmseidel 356cdf0e10cSrcweir ${MAILER} ${TO:+--compose} "${TO:-}" ${ATTACH:+--attach} "${ATTACH:-}" 357cdf0e10cSrcweir ;; 358cdf0e10cSrcweir 359cdf0e10cSrcweir Mail | Thunderbird | *.app ) 360cdf0e10cSrcweir 361cdf0e10cSrcweir while [ "$1" != "" ]; do 362cdf0e10cSrcweir case $1 in 363cdf0e10cSrcweir --attach) 364cdf0e10cSrcweir #i95688# fix filenames containing accented chars, whatever alien 36527513102SJuergen Schmidt ATTACH="${ATTACH:-}${ATTACH:+ }"`echo "file://$2" | "${URI_ENCODE}"` 366cdf0e10cSrcweir shift 367cdf0e10cSrcweir ;; 368cdf0e10cSrcweir *) 369cdf0e10cSrcweir ;; 370cdf0e10cSrcweir esac 371cdf0e10cSrcweir shift; 372cdf0e10cSrcweir done 373cdf0e10cSrcweir /usr/bin/open -a "${MAILER}" ${ATTACH} 374cdf0e10cSrcweir ;; 375cdf0e10cSrcweir 376cdf0e10cSrcweir "") 377*1748116dSmseidel 378cdf0e10cSrcweir # DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html 379cdf0e10cSrcweir if [ -n "$DESKTOP_LAUNCH" ]; then 380cdf0e10cSrcweir while [ "$1" != "" ]; do 381cdf0e10cSrcweir case $1 in 382cdf0e10cSrcweir --to) 383cdf0e10cSrcweir if [ "${TO}" != "" ]; then 384cdf0e10cSrcweir MAILTO="${MAILTO:-}${MAILTO:+&}to=$2" 385cdf0e10cSrcweir else 386cdf0e10cSrcweir TO="$2" 387cdf0e10cSrcweir fi 388cdf0e10cSrcweir shift 389cdf0e10cSrcweir ;; 390cdf0e10cSrcweir --cc) 39127513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | "${URI_ENCODE}"` 392cdf0e10cSrcweir shift 393cdf0e10cSrcweir ;; 394cdf0e10cSrcweir --bcc) 39527513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | "${URI_ENCODE}"` 396cdf0e10cSrcweir shift 397cdf0e10cSrcweir ;; 398cdf0e10cSrcweir --subject) 39927513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}subject="`echo "$2" | "${URI_ENCODE}"` 400cdf0e10cSrcweir shift 401cdf0e10cSrcweir ;; 402cdf0e10cSrcweir --body) 40327513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | "${URI_ENCODE}"` 404cdf0e10cSrcweir shift 405cdf0e10cSrcweir ;; 406cdf0e10cSrcweir --attach) 40727513102SJuergen Schmidt MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "$2" | "${URI_ENCODE}"` 408cdf0e10cSrcweir shift 409cdf0e10cSrcweir ;; 410cdf0e10cSrcweir *) 411cdf0e10cSrcweir ;; 412cdf0e10cSrcweir esac 413cdf0e10cSrcweir shift; 414cdf0e10cSrcweir done 415*1748116dSmseidel 416cdf0e10cSrcweir MAILTO="mailto:${TO}?${MAILTO}" 417cdf0e10cSrcweir ${DESKTOP_LAUNCH} "${MAILTO}" & 418cdf0e10cSrcweir else 419cdf0e10cSrcweir echo "Could not determine a mail client to use." 420cdf0e10cSrcweir exit 2 421cdf0e10cSrcweir fi 422cdf0e10cSrcweir ;; 423*1748116dSmseidel 424cdf0e10cSrcweir *) 425cdf0e10cSrcweir echo "Unsupported mail client: `basename $MAILER | sed 's/-.*^//'`" 426cdf0e10cSrcweir exit 2 427cdf0e10cSrcweir ;; 428*1748116dSmseidelesac 429*1748116dSmseidel 430cdf0e10cSrcweirexit 0 431