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