~ubuntu-branches/ubuntu/precise/mutt/precise

« back to all changes in this revision

Viewing changes to debian/extra/lib/mailto-mutt

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-06-27 23:52:24 UTC
  • mfrom: (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090627235224-z52j0hm6cpknxrk1
Tags: 1.5.20-2ubuntu1
Merge from debian unstable (LP: #392997), remaining changes:
debian/control: Recommend default-mta instead of exim4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# mailto-mutt -- wrapper to be able to use mutt as mailto handler from firefox
 
4
#
 
5
# To use, surf to Firefox's about:config page and configure the following
 
6
# three values:
 
7
#   network.protocol-handler.external.mailto boolean true
 
8
#   network.protocol-handler.app.mailto string '/path/to/handler'
 
9
#   network.protocol-handler.warn-external.mailto boolean false
 
10
#
 
11
# Copyright � martin f. krafft <madduck@madduck.net>
 
12
# Released under the terms of the Artistic Licence 2.0
 
13
 
14
# Revision: $Id: mailto-mutt 498 2007-05-12 12:02:10Z madduck $
 
15
 
16
set -eu
 
17
 
 
18
case "${1:-}" in
 
19
  -d) debug=1; shift;;
 
20
  '') exit 0;;
 
21
  *) :;;
 
22
esac
 
23
 
 
24
url_unescape()
 
25
{
 
26
  perl -e 'use URI::Escape; while(<>) { print uri_unescape($_); }'
 
27
}
 
28
 
 
29
MAILTO="${@%%\?*}"
 
30
ARGS="${@#*\?}"
 
31
[ "$ARGS" = "$MAILTO" ] && unset ARGS
 
32
MAILTO="$(echo "${MAILTO#mailto:}" | url_unescape)"
 
33
 
 
34
subject=
 
35
cc=
 
36
bcc=
 
37
body=
 
38
mutt_commands=
 
39
 
 
40
IFS_store="$IFS"
 
41
IFS='&'
 
42
 
 
43
for arg in ${ARGS:-}; do
 
44
  value="$(echo "${arg#*=}" | url_unescape | sed -e "s,',\',")"
 
45
 
 
46
  case "${arg%%=*}" in
 
47
    subject|Subject|SUBJECT) subject="$value";;
 
48
    cc|Cc|CC) cc="$value";;
 
49
    bcc|Bcc|BCC) bcc="$value";;
 
50
    body|Body|BODY) body="$value";;
 
51
    *)
 
52
      mutt_commands="${mutt_commands:+${mutt_commands}
 
53
        }-e\"my_hdr ${arg%%=*}: $value\""
 
54
      ;;
 
55
  esac
 
56
done
 
57
 
 
58
IFS="$IFS_store"
 
59
 
 
60
break_at_commas()
 
61
{
 
62
  local atom
 
63
  for i; do
 
64
    atom="${atom:+$atom }$i"
 
65
    case "${atom:-}" in
 
66
      *,) echo "${atom%,}"; unset atom;;
 
67
    esac
 
68
  done
 
69
  [ -n "${atom:-}" ] && echo "${atom%,}"
 
70
}
 
71
 
 
72
get_addr_args()
 
73
{
 
74
  local type
 
75
  case "$1" in
 
76
    -*) type="$1"; shift;;
 
77
    *) unset type;;
 
78
  esac
 
79
 
 
80
  break_at_commas "$@" | while read addr; do
 
81
    echo -n "${type:-}\"$addr\" "
 
82
  done
 
83
}
 
84
 
 
85
if [ -n "$mutt_commands" ]; then
 
86
  mutt_args="${mutt_args:+$mutt_args }$mutt_commands"
 
87
fi
 
88
 
 
89
if [ -n "$subject" ]; then
 
90
  mutt_args="${mutt_args:+$mutt_args }-s\"$subject\""
 
91
fi
 
92
 
 
93
mutt_args="${mutt_args:+$mutt_args }$(get_addr_args -c $cc)"
 
94
mutt_args="${mutt_args:+$mutt_args }$(get_addr_args -b $bcc)"
 
95
mutt_args="${mutt_args:+$mutt_args }$(get_addr_args $MAILTO)"
 
96
 
 
97
run()
 
98
{
 
99
  if [ ${debug:-0} -eq 1 ]; then
 
100
    echo "$@"
 
101
  else
 
102
    eval "$@"
 
103
  fi
 
104
}
 
105
 
 
106
if [ -n "$body" ]; then
 
107
  TMPFILE="$(tempfile -p mailto -d /tmp)"
 
108
  echo "$body" > $TMPFILE
 
109
  trap "rm -f $TMPFILE" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
110
  run x-terminal-emulator -e mutt${mutt_args:+ $mutt_args} -i $TMPFILE
 
111
  ret=$?
 
112
  rm -f $TMPFILE
 
113
  trap - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
114
  exit $ret
 
115
else
 
116
  run exec x-terminal-emulator -e mutt${mutt_args:+ $mutt_args}
 
117
fi