X-Git-Url: https://git.madduck.net/etc/mutt.git/blobdiff_plain/a83d50d5a64488deb3796bbd0ca0a03b0516cc77..7013dfe93a05082153f79eca6c9e5c05b54d9d50:/.config/mutt/sendmail-checks.d/check-attachments diff --git a/.config/mutt/sendmail-checks.d/check-attachments b/.config/mutt/sendmail-checks.d/check-attachments new file mode 100644 index 0000000..fe80dc0 --- /dev/null +++ b/.config/mutt/sendmail-checks.d/check-attachments @@ -0,0 +1,37 @@ +#!/bin/sh +# +# check-attachments — check that referenced attachments are actually attached +# +# This is based on the idea behind +# http://www.vim.org/scripts/download_script.php?src_id=3165: if the mail body +# matches a given regular expression, then check whether there are also +# non-PGP MIME parts in the message, or else refuse to send the message. +# +# You can override the checking by adding the X-No-Attachments header to the +# message. +# +# Copyright © 2010 martin f. krafft +# Released under the terms of the Artistic Licence 2.0 +# +set -eu + +RE_ENGLISH='attach(ing|ed|ment)?|included\W+(with|in)\W+th(is|e\W+(curr|pres)ent)\W+mail' +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)' +RE_FRENCH='attach(e|er|(é|=E9|=C3=A9)e?s?|ement|ant)' +OVERRIDE_HEADER=X-No-Attach + +if ! grep -qi "^${OVERRIDE_HEADER}:" "$1" \ + && egrep -v '^(> |Content-Disposition:)' "$1" | egrep -qzi "($RE_ENGLISH|$RE_GERMAN|$RE_FRENCH)"; then + + nr_attach=$(sed -rne 's/^Content-Type:[[:space:]]+//pi' "$1" | + egrep -civ '^(multipart/|application/pgp-signature)') + + if [ $nr_attach -lt 2 ]; then + echo >&2 "E: the mail message likely references an attachment," + echo >&2 "E: but there seems to be no non-PGP MIME part." + echo >&2 "E: (add the $OVERRIDE_HEADER header to override the check)." + exit 1 + fi +fi + +sed -i -e "/^${OVERRIDE_HEADER}:/d" "$1"