Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 51 lines (40 sloc) 978 Bytes
#!/bin/bash
# Pre sendmail hook, just do attachment check now
# Set MTA
SENDMAIL=/usr/bin/msmtp
# Save msg in file for multiple tests
TMPFILE=`mktemp -t check-attach.XXXXXXXX` || exit 2
# Define test for multipart message
multipart () {
grep -q '^Content-Type: multipart' "$TMPFILE"
}
# Header to override this check
override () {
grep -i -E "^X-attached: none$" "$TMPFILE"
}
# Define test for keyword search
attach () {
grep -v '^>' "$TMPFILE" | grep -E -i -q 'attach|patch|附件'
}
# Query function to pass message
ask () {
if [ ! -z "$DISPLAY" ] && [ -x "/usr/bin/zenity" ]
then
zenity --question --title 'mutt' --text 'Attachment missed?'
else
return 0
fi
}
cat > "$TMPFILE"
if override || multipart || ! attach || ! ask
then
$SENDMAIL "$@" < "$TMPFILE"
EXIT_STATUS=$?
else
echo "Attachment missed?"
echo
echo "Add your attachment, or add a header \"X-attached: none\" to override this check."
EXIT_STATUS=1
fi
rm -f "$TMPFILE"
exit $EXIT_STATUS