OLD | NEW |
1 #!/bin/bash | 1 #!/bin/sh |
2 #--------------------------------------------- | 2 #--------------------------------------------- |
3 # xdg-email | 3 # xdg-email |
4 # | 4 # |
5 # Utility script to open the users favorite email program, using the | 5 # Utility script to open the users favorite email program, using the |
6 # RFC 2368 mailto: URI spec | 6 # RFC 2368 mailto: URI spec |
7 # | 7 # |
8 # Refer to the usage() function below for usage. | 8 # Refer to the usage() function below for usage. |
9 # | 9 # |
10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> | 10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
11 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> | 11 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 exit_failure_file_permission_read() | 246 exit_failure_file_permission_read() |
247 { | 247 { |
248 if [ $# -gt 0 ]; then | 248 if [ $# -gt 0 ]; then |
249 echo "xdg-email: $@" >&2 | 249 echo "xdg-email: $@" >&2 |
250 fi | 250 fi |
251 | 251 |
252 exit 5 | 252 exit 5 |
253 } | 253 } |
254 | 254 |
255 #------------------------------------------------------------ | 255 #------------------------------------------------------------ |
256 # Exit script on insufficient permission to read a specified file | 256 # Exit script on insufficient permission to write a specified file |
257 | 257 |
258 exit_failure_file_permission_write() | 258 exit_failure_file_permission_write() |
259 { | 259 { |
260 if [ $# -gt 0 ]; then | 260 if [ $# -gt 0 ]; then |
261 echo "xdg-email: $@" >&2 | 261 echo "xdg-email: $@" >&2 |
262 fi | 262 fi |
263 | 263 |
264 exit 6 | 264 exit 6 |
265 } | 265 } |
266 | 266 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 echo "Use 'man xdg-email' or 'xdg-email --manual' for additional inf
o." | 323 echo "Use 'man xdg-email' or 'xdg-email --manual' for additional inf
o." |
324 exit_success | 324 exit_success |
325 ;; | 325 ;; |
326 | 326 |
327 --manual) | 327 --manual) |
328 manualpage | 328 manualpage |
329 exit_success | 329 exit_success |
330 ;; | 330 ;; |
331 | 331 |
332 --version) | 332 --version) |
333 echo "xdg-email 1.0.1" | 333 echo "xdg-email 1.0.2" |
334 exit_success | 334 exit_success |
335 ;; | 335 ;; |
336 esac | 336 esac |
337 done | 337 done |
338 } | 338 } |
339 | 339 |
340 check_common_commands "$@" | 340 check_common_commands "$@" |
341 | 341 |
342 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; | 342 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; |
343 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then | 343 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then |
344 # Be silent | 344 # Be silent |
345 xdg_redirect_output=" > /dev/null 2> /dev/null" | 345 xdg_redirect_output=" > /dev/null 2> /dev/null" |
346 else | 346 else |
347 # All output to stderr | 347 # All output to stderr |
348 xdg_redirect_output=" >&2" | 348 xdg_redirect_output=" >&2" |
349 fi | 349 fi |
350 | 350 |
351 #-------------------------------------- | 351 #-------------------------------------- |
352 # Checks for known desktop environments | 352 # Checks for known desktop environments |
353 # set variable DE to the desktop environments name, lowercase | 353 # set variable DE to the desktop environments name, lowercase |
354 | 354 |
355 detectDE() | 355 detectDE() |
356 { | 356 { |
357 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; | 357 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
358 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; | 358 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
359 elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then
DE=xfce; | 359 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; |
| 360 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; |
360 fi | 361 fi |
361 } | 362 } |
362 | 363 |
363 #---------------------------------------------------------------------------- | 364 #---------------------------------------------------------------------------- |
364 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 | 365 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
365 # It also always returns 1 in KDE 3.4 and earlier | 366 # It also always returns 1 in KDE 3.4 and earlier |
366 # Simply return 0 in such case | 367 # Simply return 0 in such case |
367 | 368 |
368 kfmclient_fix_exit_code() | 369 kfmclient_fix_exit_code() |
369 { | 370 { |
370 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` | 371 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` |
371 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` | 372 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` |
372 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` | 373 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` |
373 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` | 374 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` |
374 test "$major" -gt 3 && return $1 | 375 test "$major" -gt 3 && return $1 |
375 test "$minor" -gt 5 && return $1 | 376 test "$minor" -gt 5 && return $1 |
376 test "$release" -gt 4 && return $1 | 377 test "$release" -gt 4 && return $1 |
377 return 0 | 378 return 0 |
378 } | 379 } |
379 | 380 |
| 381 run_thunderbird() |
| 382 { |
| 383 local THUNDERBIRD MAILTO NEWMAILTO TO CC BCC SUBJECT BODY ATTACH |
| 384 THUNDERBIRD="$1" |
| 385 MAILTO=$(echo "$2" | sed 's/^mailto://') |
| 386 echo "$MAILTO" | grep -qs "^?" |
| 387 if [ "$?" = "0" ] ; then |
| 388 MAILTO=$(echo "$MAILTO" | sed 's/^?//') |
| 389 else |
| 390 MAILTO=$(echo "$MAILTO" | sed 's/^/to=/' | sed 's/?/\&/') |
| 391 fi |
| 392 |
| 393 MAILTO=$(echo "$MAILTO" | sed 's/&/\n/g') |
| 394 TO=$(echo "$MAILTO" | grep '^to=' | sed 's/^to=//' | awk '{ printf "%s,",$0
}') |
| 395 CC=$(echo "$MAILTO" | grep '^cc=' | sed 's/^cc=//' | awk '{ printf "%s,",$0
}') |
| 396 BCC=$(echo "$MAILTO" | grep '^bcc=' | sed 's/^bcc=//' | awk '{ printf "%s,",
$0 }') |
| 397 SUBJECT=$(echo "$MAILTO" | grep '^subject=' | tail -n 1) |
| 398 BODY=$(echo "$MAILTO" | grep '^body=' | tail -n 1) |
| 399 ATTACH=$(echo "$MAILTO" | sed 's/^attach=/\n\nfile:\/\//g' | awk '/^file:/ {
printf "%s,",$0 }') |
| 400 |
| 401 if [ -z "$TO" ] ; then |
| 402 NEWMAILTO= |
| 403 else |
| 404 NEWMAILTO="to='$TO'" |
| 405 fi |
| 406 if [ -n "$CC" ] ; then |
| 407 NEWMAILTO="${NEWMAILTO},cc='$CC'" |
| 408 fi |
| 409 if [ -n "$BCC" ] ; then |
| 410 NEWMAILTO="${NEWMAILTO},bcc='$BCC'" |
| 411 fi |
| 412 if [ -n "$SUBJECT" ] ; then |
| 413 NEWMAILTO="${NEWMAILTO},$SUBJECT" |
| 414 fi |
| 415 if [ -n "$BODY" ] ; then |
| 416 NEWMAILTO="${NEWMAILTO},$BODY" |
| 417 fi |
| 418 |
| 419 if [ -n "$ATTACH" ] ; then |
| 420 NEWMAILTO="${NEWMAILTO},attachment='${ATTACH}'" |
| 421 fi |
| 422 |
| 423 NEWMAILTO=$(echo "$NEWMAILTO" | sed 's/^,//') |
| 424 DEBUG 1 "Running $THUNDERBIRD -compose \"$NEWMAILTO\"" |
| 425 "$THUNDERBIRD" -compose "$NEWMAILTO" |
| 426 if [ $? -eq 0 ]; then |
| 427 exit_success |
| 428 else |
| 429 exit_failure_operation_failed |
| 430 fi |
| 431 } |
| 432 |
380 open_kde() | 433 open_kde() |
381 { | 434 { |
382 local client | 435 local client |
| 436 client=`kreadconfig --file emaildefaults --group PROFILE_Default --key Email
Client | cut -d ' ' -f 1` |
| 437 echo $client | grep thunderbird > /dev/null 2>&1 |
| 438 if [ $? -eq 0 ] ; then |
| 439 run_thunderbird "$client" "$1" |
| 440 fi |
| 441 |
383 if [ -f /etc/SuSE-release ] ; then | 442 if [ -f /etc/SuSE-release ] ; then |
384 # Workaround for SUSE 10.0 | 443 # Workaround for SUSE 10.0 |
385 client=`kreadconfig --file emaildefaults --group PROFILE_Default --key E
mailClient| cut -d ' ' -f 1` | 444 [ -z "$client" ] && client="kmail" |
386 [ -z $client ] && client="kmail" | 445 if ! which "$client" > /dev/null 2> /dev/null; then |
387 if ! which $client > /dev/null 2> /dev/null; then | |
388 DEBUG 3 "KDE has $client configured as email client which isn't inst
alled" | 446 DEBUG 3 "KDE has $client configured as email client which isn't inst
alled" |
389 if which gnome-open > /dev/null 2> /dev/null && which evolution > /d
ev/null 2> /dev/null; then | 447 if which gnome-open > /dev/null 2> /dev/null && which evolution > /d
ev/null 2> /dev/null; then |
390 DEBUG 3 "Try gnome-open instead" | 448 DEBUG 3 "Try gnome-open instead" |
391 open_gnome "$1" | 449 open_gnome "$1" |
392 fi | 450 fi |
393 fi | 451 fi |
394 fi | 452 fi |
395 DEBUG 1 "Running kmailservice \"$1\"" | 453 DEBUG 1 "Running kmailservice \"$1\"" |
396 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then | 454 if [ x"$KDE_SESSION_VERSION" = x"4" ]; then |
397 KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null` | 455 KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null` |
398 else | 456 else |
399 KMAILSERVICE=`which kmailservice 2>/dev/null` | 457 KMAILSERVICE=`which kmailservice 2>/dev/null` |
400 fi | 458 fi |
401 # KDE uses locale's encoding when decoding the URI, so set it to UTF-8 | 459 # KDE uses locale's encoding when decoding the URI, so set it to UTF-8 |
402 LC_ALL=C.UTF-8 $KMAILSERVICE "$1" | 460 LC_ALL=C.UTF-8 $KMAILSERVICE "$1" |
403 kfmclient_fix_exit_code $? | 461 kfmclient_fix_exit_code $? |
404 | 462 |
405 if [ $? -eq 0 ]; then | 463 if [ $? -eq 0 ]; then |
406 exit_success | 464 exit_success |
407 else | 465 else |
408 exit_failure_operation_failed | 466 exit_failure_operation_failed |
409 fi | 467 fi |
410 } | 468 } |
411 | 469 |
412 open_gnome() | 470 open_gnome() |
413 { | 471 { |
414 DEBUG 1 "Running gnome-open \"$1\"" | 472 local client |
415 gnome-open "$1" | 473 client=`gconftool-2 --get /desktop/gnome/url-handlers/mailto/command | cut -
d ' ' -f 1` || "" |
| 474 echo $client | grep thunderbird > /dev/null 2>&1 |
| 475 if [ $? -eq 0 ] ; then |
| 476 run_thunderbird "$client" "$1" |
| 477 fi |
| 478 |
| 479 if gvfs-open --help 2>/dev/null 1>&2; then |
| 480 DEBUG 1 "Running gvfs-open \"$1\"" |
| 481 gvfs-open "$1" |
| 482 else |
| 483 DEBUG 1 "Running gnome-open \"$1\"" |
| 484 gnome-open "$1" |
| 485 fi |
416 | 486 |
417 if [ $? -eq 0 ]; then | 487 if [ $? -eq 0 ]; then |
418 exit_success | 488 exit_success |
419 else | 489 else |
420 exit_failure_operation_failed | 490 exit_failure_operation_failed |
421 fi | 491 fi |
422 } | 492 } |
423 | 493 |
424 | 494 |
425 open_xfce() | 495 open_xfce() |
426 { | 496 { |
427 DEBUG 1 "Running exo-open \"$1\"" | 497 DEBUG 1 "Running exo-open \"$1\"" |
428 exo-open "$1" | 498 exo-open "$1" |
429 | 499 |
430 if [ $? -eq 0 ]; then | 500 if [ $? -eq 0 ]; then |
431 exit_success | 501 exit_success |
432 else | 502 else |
433 exit_failure_operation_failed | 503 exit_failure_operation_failed |
434 fi | 504 fi |
435 } | 505 } |
436 | 506 |
437 open_generic() | 507 open_generic() |
438 { | 508 { |
439 IFS=":" | 509 IFS=":" |
440 for browser in $BROWSER; do | 510 for browser in $BROWSER; do |
441 if [ x"$browser" != x"" ]; then | 511 if [ x"$browser" != x"" ]; then |
442 | 512 |
443 IFS=' ' | 513 browser_with_arg=`printf "$browser" "$1" 2>/dev/null` |
444 browser_with_arg=${browser//'%s'/"$1"} | 514 if [ $? -ne 0 ]; then browser_with_arg=$browser; |
| 515 fi |
445 | 516 |
446 if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1"; | 517 if [ x"$browser_with_arg" = x"$browser" ]; then "$browser" "$1"; |
447 else $browser_with_arg; | 518 else $browser_with_arg; |
448 fi | 519 fi |
449 | 520 |
450 if [ $? -eq 0 ]; then exit_success; | 521 if [ $? -eq 0 ]; then exit_success; |
451 fi | 522 fi |
452 fi | 523 fi |
453 done | 524 done |
454 | 525 |
455 exit_failure_operation_impossible "no method available for opening '$1'" | 526 exit_failure_operation_impossible "no method available for opening '$1'" |
456 } | 527 } |
457 | 528 |
458 url_encode() | 529 url_encode() |
459 { | 530 { |
460 result=$(echo "$1" | $utf8 | awk ' | 531 result=$(echo "$1" | $utf8 | awk ' |
461 BEGIN { | 532 BEGIN { |
462 for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 | 533 for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 |
463 e = "" | 534 e = "" |
464 linenr = 1 | 535 linenr = 1 |
465 } | 536 } |
466 { | 537 { |
467 if ( linenr++ != 1 ) { | 538 if ( linenr++ != 1 ) { |
468 e = e "%0D%0A" | 539 e = e "%0D%0A" |
469 } | 540 } |
470 for ( i=1; i<=length ($0); ++i ) { | 541 for ( i=1; i<=length ($0); ++i ) { |
471 c = substr ($0, i, 1) | 542 c = substr ($0, i, 1) |
472 if ( ord [c] > 127 ) { | 543 if ( ord [c] > 127 ) { |
473 e = e "%" sprintf("%02X", ord [c]) | 544 e = e "%" sprintf("%02X", ord [c]) |
474 } else if ( c ~ /[@a-zA-Z0-9.-]/ ) { | 545 } else if ( c ~ /[@a-zA-Z0-9.-\\/]/ ) { |
475 e = e c | 546 e = e c |
476 } else { | 547 } else { |
477 e = e "%" sprintf("%02X", ord [c]) | 548 e = e "%" sprintf("%02X", ord [c]) |
478 } | 549 } |
479 } | 550 } |
480 } | 551 } |
481 END { | 552 END { |
482 print e | 553 print e |
483 } | 554 } |
484 ') | 555 ') |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 if [ $? -eq 0 ]; then | 680 if [ $? -eq 0 ]; then |
610 exit_success | 681 exit_success |
611 else | 682 else |
612 exit_failure_operation_failed | 683 exit_failure_operation_failed |
613 fi | 684 fi |
614 fi | 685 fi |
615 | 686 |
616 detectDE | 687 detectDE |
617 | 688 |
618 if [ x"$DE" = x"" ]; then | 689 if [ x"$DE" = x"" ]; then |
619 # if BROWSER variable is not set, check some well known browsers instead | 690 DE=generic |
620 if [ x"$BROWSER" = x"" ]; then | 691 fi |
621 BROWSER=firefox:mozilla:netscape | 692 |
| 693 # if BROWSER variable is not set, check some well known browsers instead |
| 694 if [ x"$BROWSER" = x"" ]; then |
| 695 BROWSER=links2:links:lynx:w3m |
| 696 if [ -n "$DISPLAY" ]; then |
| 697 BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrom
e:$BROWSER |
622 fi | 698 fi |
623 DE=generic | |
624 fi | 699 fi |
625 | 700 |
626 case "$DE" in | 701 case "$DE" in |
627 kde) | 702 kde) |
628 open_kde "${mailto}" | 703 open_kde "${mailto}" |
629 ;; | 704 ;; |
630 | 705 |
631 gnome) | 706 gnome) |
632 open_gnome "${mailto}" | 707 open_gnome "${mailto}" |
633 ;; | 708 ;; |
634 | 709 |
635 xfce) | 710 xfce) |
636 open_xfce "${mailto}" | 711 open_xfce "${mailto}" |
637 ;; | 712 ;; |
638 | 713 |
639 generic) | 714 generic) |
640 open_generic "${mailto}" | 715 open_generic "${mailto}" |
641 ;; | 716 ;; |
642 | 717 |
643 *) | 718 *) |
644 exit_failure_operation_impossible "no method available for opening '${mailto
}'" | 719 exit_failure_operation_impossible "no method available for opening '${mailto
}'" |
645 ;; | 720 ;; |
646 esac | 721 esac |
OLD | NEW |