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