All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 # mutt/sendmail – sendmail wrapper to enforce some checks on outgoing mails
5 # The script basically just creates a temporary file and then invokes any
6 # executable scripts in ~/.config/mutt/sendmail-checks.d in run-parts style.
7 # They receive the filename of a temporary file holding the message to be sent
8 # as $1, followed by all recipients as determined by mutt.
10 # Copyright © 2010 martin f. krafft <madduck@madduck.net> Released under the
11 # terms of the Artistic Licence 2.0
15 CHECKSDIR="$HOME/.config/mutt/sendmail-checks.d"
16 SENDMAIL="/usr/sbin/sendmail -oem -oi"
18 TMPFILE=$(mktemp --tmpdir mutt-sendmail.XXXXXXXXXX.msg)
19 settrap () { trap "$@" 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15; }
20 cleanup () { rm -f "$TMPFILE"; settrap -; }
24 recipients= sendmail_args=
28 (s/*) sendmail_args="${sendmail_args} $i";;
29 (r/*) recipients="${recipients} $i";;
36 if ! formail -czx "Resent-" < "$TMPFILE" | grep -q .; then
37 # only do this for original mails, not bounces
38 recipients="$recipients $(formail -czx "X-Bcc" < "$TMPFILE" | tr -d ',')"
39 remove_headers="$remove_headers -IX-Bcc"
41 args=$(for i in $recipients; do echo "--arg=$i"; done)
42 run-parts --exit-on-error --umask=0077 --arg="$TMPFILE" $args -- "$CHECKSDIR"
44 recipients=$(echo "$recipients" | xargs)
46 formail $remove_headers < "$TMPFILE" \
47 | eval $SENDMAIL "$sendmail_args" -- "$recipients"