git » chasquid » commit 5782a77

hooks: Add rspamd integration to the example hook

author Alberto Bertogli
2019-10-21 12:48:35 UTC
committer Alberto Bertogli
2019-10-21 12:51:58 UTC
parent 27227986ab23ae377f52f07bae2c8e838ee7fc86

hooks: Add rspamd integration to the example hook

Rspamd (https://rspamd.com/) is a popular open-source spam filtering
system.

This patch adds integration with it in the example hook, which uses the
rspamc client to get a veredict, similar to what it does for
Spamassassin.

docs/install.md +1 -1
etc/chasquid/hooks/post-data +17 -0

diff --git a/docs/install.md b/docs/install.md
index 71f7c2b..5e088a9 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -93,7 +93,7 @@ The hook should be at `/etc/chasquid/hooks/post-data`.
 The one installed by default is a bash script supporting:
 
 * greylisting using greylistd.
-* anti-spam using spamassassin.
+* anti-spam using spamassassin or rspamd.
 * anti-virus using clamav.
 
 To use them, they just need to be available in your system.
diff --git a/etc/chasquid/hooks/post-data b/etc/chasquid/hooks/post-data
index 6f2ea6e..aa0ccc9 100755
--- a/etc/chasquid/hooks/post-data
+++ b/etc/chasquid/hooks/post-data
@@ -5,6 +5,7 @@
 #
 #  - greylist (from greylistd) to do greylisting.
 #  - spamc (from Spamassassin) to filter spam.
+#  - rspamc (from rspamd) to filter spam.
 #  - clamdscan (from ClamAV) to filter virus.
 #  - dkimsign (from driusan/dkim) to do DKIM signing.
 #
@@ -46,6 +47,22 @@ if command -v spamc >/dev/null; then
 fi
 
 
+if command -v rspamc >/dev/null; then
+	ACTION=$( rspamc < "$TF" 2>/dev/null | grep Action: | cut -d " " -f 2- )
+	case "$ACTION" in
+		greylist)
+			echo "greylisted, please try again"
+			exit 75  # temporary error
+			;;
+		reject)
+			echo "spam detected"
+			exit 20  # permanent error
+			;;
+	esac
+	echo "X-Spam-Action:" "$ACTION"
+fi
+
+
 if command -v clamdscan >/dev/null; then
         if ! clamdscan --no-summary --infected - < "$TF" 1>&2 ; then
                 echo "virus detected"