3 # mailto-mutt -- wrapper to be able to use mutt as mailto handler from firefox
5 # To use, surf to Firefox's about:config page and configure the following
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
11 # Copyright © martin f. krafft <madduck@madduck.net>
12 # Released under the terms of the Artistic Licence 2.0
14 # Revision: $Id: mailto-mutt 498 2007-05-12 12:02:10Z madduck $
26 perl -e 'use URI::Escape; while(<>) { print uri_unescape($_); }'
31 [ "$ARGS" = "$MAILTO" ] && unset ARGS
32 MAILTO="$(echo "${MAILTO#mailto:}" | url_unescape)"
43 for arg in ${ARGS:-}; do
44 value="$(echo "${arg#*=}" | url_unescape | sed -e "s,',\',")"
47 subject|Subject|SUBJECT) subject="$value";;
48 cc|Cc|CC) cc="$value";;
49 bcc|Bcc|BCC) bcc="$value";;
50 body|Body|BODY) body="$value";;
52 mutt_commands="${mutt_commands:+${mutt_commands}
53 }-e\"my_hdr ${arg%%=*}: $value\""
64 atom="${atom:+$atom }$i"
66 *,) echo "${atom%,}"; unset atom;;
69 [ -n "${atom:-}" ] && echo "${atom%,}"
76 -*) type="$1"; shift;;
80 break_at_commas "$@" | while read addr; do
81 echo -n "${type:-}\"$addr\" "
85 if [ -n "$mutt_commands" ]; then
86 mutt_args="${mutt_args:+$mutt_args }$mutt_commands"
89 if [ -n "$subject" ]; then
90 mutt_args="${mutt_args:+$mutt_args }-s\"$subject\""
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)"
99 if [ ${debug:-0} -eq 1 ]; then
101 [ -t 0 ] && [ -t 1 ] && [ -t 2 ] && $SHELL
107 if [ -n "$body" ]; then
108 TMPFILE="$(tempfile -p mailto -d /tmp)"
109 trap "rm -f $TMPFILE" 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15
110 echo "$body" > $TMPFILE
111 run x-terminal-emulator -e mutt -i $TMPFILE${mutt_args:+ $mutt_args}
114 trap - 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15
117 run exec x-terminal-emulator -e mutt${mutt_args:+ $mutt_args}