]> git.madduck.net Git - etc/mutt.git/blob - .mutt/sendmail

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

properly remove x-bcc-spool header before sending
[etc/mutt.git] / .mutt / sendmail
1 #!/bin/sh
2 #
3 # mutt/sendmail – sendmail wrapper to enforce some checks on outgoing mails
4 #
5 # The script basically just creates a temporary file and then invokes any
6 # executable scripts in ~/.mutt/sendmail-checks.d in run-parts style. They
7 # receive the filename of a temporary file holding the message to be sent as
8 # $1, followed by all recipients as determined by mutt.
9 #
10 # Copyright © 2010 martin f. krafft <madduck@madduck.net>
11 # Released under the terms of the Artistic Licence 2.0
12 #
13 set -eu
14
15 CHECKSDIR="$HOME/.mutt/sendmail-checks.d"
16 SENDMAIL="/usr/sbin/sendmail -oem -oi"
17
18 TMPFILE=$(tempfile -p mutt-sendmail -s .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 -; }
21 settrap cleanup
22
23 argtype=s
24 recipients= sendmail_args=
25 for i in "$@"; do
26   case "$argtype/$i" in
27     (s/--) argtype=r;;
28     (s/*) sendmail_args="${sendmail_args} $i";;
29     (r/*) recipients="${recipients} $i";;
30   esac
31 done
32
33 cat > $TMPFILE
34 recipients="$recipients $(formail -czx X-Bcc-Spool: < "$TMPFILE" | tr -d ',')"
35 args=$(for i in $recipients; do echo "--arg=$i"; done)
36 run-parts --umask=0077 --arg="$TMPFILE" $args -- "$CHECKSDIR"
37 formail -I X-Bcc-Spool: < "$TMPFILE" | eval $SENDMAIL "$sendmail_args" -- "$recipients"
38
39 cleanup