mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit 75ba2ab9a5b3df6c1d3071667094fa050a6d32bb
parent d4cbac0aa5a58e0ea9e8522300bdc24b4d98980f
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Fri, 22 Sep 2017 14:53:30 +0200

mcom: automatically run mmime when deemed necessary

Diffstat:
mcom | 43+++++++++++++++++++++++++++----------------
1 file changed, 27 insertions(+), 16 deletions(-)

diff --git 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