diff options
author | Leah Neukirchen <leah@vuxu.org> | 2019-02-01 15:08:20 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2019-02-01 15:08:20 +0100 |
commit | 5a2c6747b69a312e350b658b4446f845f70b671d (patch) | |
tree | 5dbda1e7507c0ca2e7d0025290575963b707214d /mcom | |
parent | 79434e45dbd988a03d193aa1944ecdbe35b08fb9 (diff) | |
download | mblaze-5a2c6747b69a312e350b658b4446f845f70b671d.tar.gz mblaze-5a2c6747b69a312e350b658b4446f845f70b671d.tar.xz mblaze-5a2c6747b69a312e350b658b4446f845f70b671d.zip |
mcom: check if mail is formatted sensibly
Diffstat (limited to 'mcom')
-rwxr-xr-x | mcom | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/mcom b/mcom index 69bf1ee..c2f55c0 100755 --- a/mcom +++ b/mcom @@ -40,6 +40,27 @@ stampdate() { fi } +checksensible() { + awk ' + /^$/ { + seenheader=1 + exit + } + !(/^[^ \t][^ \t]*[ \t]*:/ || /^[ \t]/) { + bad=1 + print "invalid header line: "$0 >"/dev/stderr" + } + END { + if (!seenheader) { + print "warning: message does not contain an empty line between headers and body." >"/dev/stderr" + exit 1 + } + if (bad) + exit 1 + } +' "$1" +} + stripempty() { tmp=$(mktemp -t mcom.XXXXXX) msed 's/^[ \t]*$//d' "$1" >"$tmp" @@ -441,13 +462,18 @@ while :; do c= if ! ${EDITOR:-vi} $draft; then c=d - fi - stripempty $draft - if mmime -c <$draft && ! needs_multipart $draft; then - automime= else - automime=1 - do_mime + if checksensible $draft; then + stripempty $draft + if mmime -c <$draft && ! needs_multipart $draft; then + automime= + else + automime=1 + do_mime + fi + else + printf '\n' + fi fi ;; justsend) |