]> git.madduck.net Git - etc/neomutt.git/blob - .config/neomutt/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:

buildmimetree.py: housekeeping at the end of commands
[etc/neomutt.git] / .config / neomutt / sendmail
1 #!/bin/sh
2 #
3 # neomutt/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 ~/.config/neomutt/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.
9 #
10 # Copyright © 2010 martin f. krafft <madduck@madduck.net> Released under the
11 # terms of the Artistic Licence 2.0
12 #
13 set -eux
14
15 CHECKSDIR="$HOME/.config/neomutt/sendmail-checks.d"
16 SENDMAIL="/usr/sbin/sendmail -oem -oi"
17
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 -; }
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
35 remove_headers=
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"
40 fi
41 args=$(for i in $recipients; do echo "--arg=$i"; done)
42 run-parts --exit-on-error --umask=0077 --arg="$TMPFILE" $args -- "$CHECKSDIR"
43
44 recipients=$(echo "$recipients" | xargs)
45
46 formail $remove_headers < "$TMPFILE" \
47   | eval $SENDMAIL "$sendmail_args" -- "$recipients"
48
49 cleanup