X-Git-Url: https://git.madduck.net/etc/neomutt.git/blobdiff_plain/a6ac44586209b9b0be5add1bef270451f3dcb677..4d1afcd5cc3e282554877a10d6be81931ef0cc03:/.config/neomutt/reuse-message diff --git a/.config/neomutt/reuse-message b/.config/neomutt/reuse-message new file mode 100755 index 0000000..0d8ed23 --- /dev/null +++ b/.config/neomutt/reuse-message @@ -0,0 +1,35 @@ +#!/bin/sh +set -eu + +eval mailfile="\${$#}" +editor= +for i in "$@"; do + # strip last argument from editor, yuk + case "$i" in + ("$mailfile") break;; + (*) editor="${editor:+$editor }$i";; + esac +done + +tmpfile=$(mktemp --tmpdir reuse.XXXXXXXXXX) +cleanup() { rm -f "$tmpfile"; trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15; } +trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15 + +formail -I Subject: < "$mailfile" | \ + formail -I In-Reply-To: | \ + sed -e '/^$/,/^-- /d' | \ + sed -e '/^Bcc:/aSubject: ' > "$tmpfile" +cat "$tmpfile" > "$mailfile" + +cleanup + +if [ -n "$editor" ]; then + eval exec "$editor" "$mailfile" + +# the last three replicate mutt's default (cf. manual) +elif [ -n "$VISUAL" ]; then + eval exec "$VISUAL" "$mailfile" +elif [ -n "$EDITOR" ]; then + eval exec "$EDITOR" "$mailfile" +fi +exec /usr/bin/editor "$mailfile"