summary refs log tree commit diff
path: root/mcomp
blob: f4ce30c97c20d8407e31d484348fb2e5702b58d8 (plain) (blame)
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
#!/bin/sh
# mcomp [TO] - compose mail

i=0
while [ -f "snd.$i" ]; do
	i=$((i+1))
done
draft="snd.$i"

{
	echo -n "To: $1"
	[ "$#" -gt 1 ] && shift
	for rcpt; do
		echo -n ", $rcpt"
	done
	echo
	echo "Cc: "
	echo "Bcc: "
	echo "Subject: "
	cat ~/.santoku/headers 2>/dev/null
        echo
        echo
	if [ -f ~/.signature ]; then
		printf '%s\n' '-- '
		cat ~/.signature
	fi
} >$draft

c=e
while :; do
	case "$c" in
	s|send)
		sendmail -t <$draft && rm $draft
		exit $?
		;;
	c|cancel)
		echo "mcomp: cancelled draft $draft"
		exit 1
		;;
	e|edit)
		c=
		if ! ${EDITOR:-vi} $draft; then
			c=q
		fi
		;;
	*)
		echo -n "What now? ([s]end, [c]ancel, [e]dit) "
		read -r c
		;;
	esac
done