#!/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=$(tempfile -p reuse) 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" if [ -n "$editor" ]; then eval exec "$editor" "$mailfile" elif [ -n "$VISUAL" ]; then eval exec "$VISUAL" "$mailfile" elif [ -n "$EDITOR" ]; then eval exec "$EDITOR" "$mailfile" fi exec /usr/bin/editor "$mailfile"