mblaze/mcomp

115 lines
1.9 KiB
Plaintext
Raw Normal View History

2016-07-20 14:25:18 +00:00
#!/bin/sh
# mcomp [TO] - compose mail
i=0
while [ -f "snd.$i" ]; do
i=$((i+1))
done
draft="snd.$i"
{
2016-07-20 14:58:37 +00:00
case "$0" in
*mcomp*)
echo -n "To: $1"
2016-07-20 20:11:25 +00:00
[ "$#" -ge 1 ] && shift
2016-07-20 14:58:37 +00:00
for rcpt; do
echo -n ", $rcpt"
done
echo
echo "Cc: "
echo "Bcc: "
echo "Subject: "
from=$(mhdr -local-mailbox ~/.santoku/profile)
[ "$from" ] && echo "From: $from"
2016-07-20 14:58:37 +00:00
cat ~/.santoku/headers 2>/dev/null
echo
echo
;;
*mrepl*)
2016-07-22 16:35:29 +00:00
[ "$#" -eq 0 ] && set -- .
2016-07-20 14:58:37 +00:00
# XXX reply-all
echo "To: $(mhdr -from "$1")"
echo "Cc: "
echo "Bcc: "
s=$(mhdr -subject "$1")
os=
while [ "$os" != "$s" ]; do
os=$s
s=${s% }
s=${s%[Rr][Ee]:}
s=${s%[Aa][Ww]:}
s=${s%[Ff][Ww][Dd]:}
done
echo "Subject: Re: $s"
cat ~/.santoku/headers 2>/dev/null
echo -n "References:"
{
mhdr -references "$1"
mhdr -message-id "$1"
} | sed 's/^[^<]*//g;s/[^>]*$//g;s/>[^<]*</>\n</g' |
uniq | sed 's/^/ /'
echo "In-Reply-To: $(mhdr -message-id "$1")"
echo
echo "$(mhdr -from "$1") wrote:"
mshow -R "$1" |
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' |
sed 's/^/> /'
echo
esac
2016-07-20 14:25:18 +00:00
if [ -f ~/.signature ]; then
printf '%s\n' '-- '
cat ~/.signature
fi
} >$draft
c=e
while :; do
case "$c" in
s|send)
2016-07-20 21:17:38 +00:00
if [ -e $draft.mime ]; then
if [ $draft -ot $draft.mime ]; then
if sendmail -t <$draft.mime; then
rm $draft $draft.mime
exit 0
else
echo "mcomp: sendmail failed, kept draft $draft"
exit 2
fi
else
echo "mcomp: re-run mmime first."
c=
fi
else
if sendmail -t <$draft; then
rm $draft
exit 0
else
echo "mcomp: sendmail failed, kept draft $draft"
exit 2
fi
fi
2016-07-20 14:25:18 +00:00
;;
c|cancel)
echo "mcomp: cancelled draft $draft"
exit 1
;;
2016-07-20 21:17:38 +00:00
m|mime)
mmime <$draft >$draft.mime
mshow -t ./$draft.mime
c=
;;
2016-07-20 14:25:18 +00:00
e|edit)
c=
if ! ${EDITOR:-vi} $draft; then
2016-07-20 14:58:37 +00:00
c=c
2016-07-20 14:25:18 +00:00
fi
;;
*)
2016-07-20 21:17:38 +00:00
echo -n "What now? ([s]end, [c]ancel, [e]dit, [m]ime) "
2016-07-20 14:25:18 +00:00
read -r c
;;
esac
done