about summary refs log tree commit diff
path: root/contrib
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-04-06 22:04:32 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-04-06 22:04:32 +0200
commitb2ecbde0a37f31bf6ff4b13e81f33353b24cea9d (patch)
treedb807745e59262667f82c964b801dc7d418476d0 /contrib
parent93bfc9cf5f88727eb5d1e2a7f8fce526769fa66d (diff)
downloadmblaze-b2ecbde0a37f31bf6ff4b13e81f33353b24cea9d.tar.gz
mblaze-b2ecbde0a37f31bf6ff4b13e81f33353b24cea9d.tar.xz
mblaze-b2ecbde0a37f31bf6ff4b13e81f33353b24cea9d.zip
contrib/msendmail: add script to compose MIME mail noninteractively
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/msendmail67
1 files changed, 67 insertions, 0 deletions
diff --git a/contrib/msendmail b/contrib/msendmail
new file mode 100755
index 0000000..1a6d5ad
--- /dev/null
+++ b/contrib/msendmail
@@ -0,0 +1,67 @@
+#!/bin/sh
+# msendmail TO... < msg - compose MIME mail noninteractively
+#  -F from-name
+#  -a attach-file
+#  -b bcc
+#  -c cc
+#  -f from
+#  -s subject
+#  -m msg-paragraph
+
+IFS='
+'
+
+MBLAZE=${MBLAZE:-$HOME/.mblaze}
+from=$(mhdr -h local-mailbox "$MBLAZE/profile")
+
+subj=
+bcc=
+cc=
+msg=
+fromname=
+att=
+
+hdr() {
+	[ -z "$2" ] && return
+	printf '%s: ' "$1"
+	shift
+	printf '%s\n' "$@" | sed ':a;N;s/\n/, /;$!b a'
+}
+
+while getopts a:s:b:c:m:f:F: opt; do
+	case "$opt" in
+		s) subj=$OPTARG;;
+		b) bcc="$bcc$IFS$OPTARG";;
+		c) cc="$cc$IFS$OPTARG";;
+		m) msg="$msg$OPTARG$IFS$IFS";;
+		f) from=$OPTARG;;
+		F) fromname=$OPTARG;;
+		a) att="$att$IFS$OPTARG";;
+		[?]) exit 1;;
+	esac
+done
+shift $((OPTIND-1))
+
+[ -n "$from" ] && [ -n "$fromname" ] && from="$fromname <$from>"
+
+{
+hdr To "$@"
+hdr Cc $cc
+hdr Bcc $bcc
+hdr Subject $subj
+hdr From $from
+hdr User-Agent "mblaze/beta (msendmail)" 
+hdr Message-Id "$(mgenmid)"
+hdr Date "$(mdate)"
+
+printf '\n'
+if [ -n "$msg" ]; then
+	printf '%s' "$msg"
+else
+	cat
+fi
+
+for a in $att; do
+	printf '#%s %s\n' "$(file -b --mime-type "$a")" "$a"
+done
+} | mmime