mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-23 15:37:01 +00:00
smtpsrv: Implement a post-DATA hook
This patch implements a post-DATA hook, which is run after receiving the data but before sending a reply. It can be used to implement content filtering when receiving email, for example for passing the email through an anti-spam or an anti-virus.
This commit is contained in:
35
hooks/post-data
Executable file
35
hooks/post-data
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# This file is an example post-data hook that will run standard filtering
|
||||
# utilities if they are available.
|
||||
#
|
||||
# - spamc (from Spamassassin) to filter spam.
|
||||
# - clamdscan (from ClamAV) to filter virus.
|
||||
|
||||
set -e
|
||||
|
||||
TF="$(mktemp --tmpdir "post-data-XXXXXXXXXX")"
|
||||
trap 'rm "$TF"' EXIT
|
||||
|
||||
# Save the message to the temporary file, so we can pass it on to the various
|
||||
# filters.
|
||||
cat > "$TF"
|
||||
|
||||
|
||||
if command -v spamc >/dev/null; then
|
||||
if ! SL=$(spamc -c - < "$TF") ; then
|
||||
echo "spam detected"
|
||||
exit 1
|
||||
fi
|
||||
echo "X-Spam-Score: $SL"
|
||||
fi
|
||||
|
||||
|
||||
if command -v clamdscan >/dev/null; then
|
||||
if ! clamdscan --no-summary --infected - < "$TF" 1>&2 ; then
|
||||
echo "virus detected"
|
||||
exit 1
|
||||
fi
|
||||
echo "X-Virus-Scanned: pass"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user