about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-09-22 14:53:30 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-09-22 14:53:30 +0200
commit75ba2ab9a5b3df6c1d3071667094fa050a6d32bb (patch)
treeff7ae6c694caa9b5b360b9f045cd1fdf30382996
parentd4cbac0aa5a58e0ea9e8522300bdc24b4d98980f (diff)
downloadmblaze-75ba2ab9a5b3df6c1d3071667094fa050a6d32bb.tar.gz
mblaze-75ba2ab9a5b3df6c1d3071667094fa050a6d32bb.tar.xz
mblaze-75ba2ab9a5b3df6c1d3071667094fa050a6d32bb.zip
mcom: automatically run mmime when deemed necessary
-rwxr-xr-xmcom43
1 files changed, 27 insertions, 16 deletions
diff --git a/mcom b/mcom
index 6fe2b84..fb7ec8d 100755
--- a/mcom
+++ b/mcom
@@ -38,6 +38,23 @@ needs_multipart() {
 		grep -q '^#[^ ]*/[^ ]* ' "$1"
 }
 
+do_mime() {
+	if needs_multipart "$draft"; then
+		(
+			IFS='
+'
+			msed '/attach/d' $draft
+			for f in $(mhdr -M -h attach $draft); do
+				printf '#%s %s\n' \
+				       "$(file -Lbi $f | sed 's/ //g')" \
+				       "$f"
+			done
+		) | mmime >$draftmime
+	else
+		mmime -r <"$draft" >"$draftmime"
+	fi
+}
+
 MBLAZE=${MBLAZE:-$HOME/.mblaze}
 
 sendmail=$(mhdr -h sendmail "$MBLAZE/profile")
@@ -173,6 +190,7 @@ fi
 	fi
 } >$draft
 
+automime=
 c=e
 while :; do
 	case "$c" in
@@ -183,7 +201,7 @@ while :; do
 		esac
 
 		if [ -e $draftmime ]; then
-			if [ $draft -ot $draftmime ]; then
+			if [ $draft -ot $draftmime ] || [ "$automime" -eq 1 ]; then
 				stampdate $draftmime
 				if $sendmail <$draftmime; then
 					if [ "$outbox" ]; then
@@ -227,20 +245,7 @@ while :; do
 		exit 1
 		;;
 	m|mime)
-		if needs_multipart "$draft"; then
-			(
-				IFS='
-'
-				msed '/attach/d' $draft
-				for f in $(mhdr -M -h attach $draft); do
-					printf '#%s %s\n' \
-					       "$(file -Lbi $f | sed 's/ //g')" \
-					       "$f"
-				done
-			) | mmime >$draftmime
-		else
-			mmime -r <"$draft" >"$draftmime"
-		fi
+		do_mime
 		mshow -t $draftmime
 		c=
 		;;
@@ -249,6 +254,12 @@ while :; do
 		if ! ${EDITOR:-vi} $draft; then
 			c=c
 		fi
+		if mmime -c <$draft; then
+			automime=
+		else
+			automime=1
+			do_mime
+		fi
 		;;
 	d|delete)
 		rm -i $draft
@@ -278,7 +289,7 @@ while :; do
 		c=
 		;;
 	*)
-		printf 'What now? ([s]end, [c]ancel, [d]elete, [e]dit, [m]ime, sign, encrypt) '
+		printf 'What now? (%s[s]end, [c]ancel, [d]elete, [e]dit, [m]ime, sign, encrypt) ' "${automime:+mime and }"
 		read -r c
 		;;
 	esac