]> git.madduck.net Git - etc/neomutt.git/blob - .config/neomutt/sendmail-checks.d/check-attachments

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:

import of config from mutt
[etc/neomutt.git] / .config / neomutt / sendmail-checks.d / check-attachments
1 #!/bin/sh
2 #
3 # check-attachments — check that referenced attachments are actually attached
4 #
5 # This is based on the idea behind
6 # http://www.vim.org/scripts/download_script.php?src_id=3165: if the mail body
7 # matches a given regular expression, then check whether there are also
8 # non-PGP MIME parts in the message, or else refuse to send the message.
9 #
10 # You can override the checking by adding the X-No-Attachments header to the
11 # message.
12 #
13 # Copyright © 2010 martin f. krafft <madduck@madduck.net>
14 # Released under the terms of the Artistic Licence 2.0
15 #
16 set -eu
17
18 RE_ENGLISH='attach(ing|ed|ment)?|included\W+(with|in)\W+th(is|e\W+(curr|pres)ent)\W+mail'
19 RE_GERMAN='an(geh(ä|=E4|=C3=A4)ngt|h(ä|=E4|=C3=A4)ngsel|bei)|bei(gef(ü|=FC|=C3=BC)gt|lage)|(im|siehe)\W+(anhang|beilage)'
20 RE_FRENCH='attach(e|er|(é|=E9|=C3=A9)e?s?|ement|ant)'
21 OVERRIDE_HEADER=X-No-Attach
22
23 if ! grep -qi "^${OVERRIDE_HEADER}:" "$1" \
24     && egrep -v '^(> |Content-Disposition:)' "$1" | egrep -qzi "($RE_ENGLISH|$RE_GERMAN|$RE_FRENCH)"; then
25
26   nr_attach=$(sed -rne 's/^Content-Type:[[:space:]]+//pi' "$1" |
27               egrep -civ '^(multipart/|application/pgp-signature)')
28
29   if [ $nr_attach -lt 2 ]; then
30     echo >&2 "E: the mail message likely references an attachment,"
31     echo >&2 "E: but there seems to be no non-PGP MIME part."
32     echo >&2 "E: (add the $OVERRIDE_HEADER header to override the check)."
33     exit 1
34   fi
35 fi
36
37 sed -i -e "/^${OVERRIDE_HEADER}:/d" "$1"