From aa404d71ec39623591dc19d2f98140b975fa29f1 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sun, 6 Jun 2021 20:03:44 +0100
Subject: [PATCH] Run clamav-milter as well

---
 build.sh                            | 1 +
 conf/chaperone.d/clamav-milter.conf | 4 ++++
 conf/clamav/clamav-milter.conf      | 8 ++++++++
 gen-config.sh                       | 9 ++++++---
 4 files changed, 19 insertions(+), 3 deletions(-)
 create mode 100644 conf/chaperone.d/clamav-milter.conf
 create mode 100644 conf/clamav/clamav-milter.conf

diff --git a/build.sh b/build.sh
index 118f922..0664789 100755
--- a/build.sh
+++ b/build.sh
@@ -8,6 +8,7 @@
 # chaperone (installed via pip).
 PACKAGES="
 	clamav-daemon
+	clamav-milter
 	curl
 "
 
diff --git a/conf/chaperone.d/clamav-milter.conf b/conf/chaperone.d/clamav-milter.conf
new file mode 100644
index 0000000..a6a985a
--- /dev/null
+++ b/conf/chaperone.d/clamav-milter.conf
@@ -0,0 +1,4 @@
+milter.service: {
+    command: "/usr/sbin/clamav-milter --config-file=/tmp/clamav-milter.conf",
+    exit_kills: true,
+}
diff --git a/conf/clamav/clamav-milter.conf b/conf/clamav/clamav-milter.conf
new file mode 100644
index 0000000..75c0485
--- /dev/null
+++ b/conf/clamav/clamav-milter.conf
@@ -0,0 +1,8 @@
+Foreground true
+MilterSocket inet:@MILTER_PORT@@0.0.0.0
+ClamdSocket tcp:127.0.0.1:@CLAMD_PORT@
+SupportMultipleRecipients true
+TemporaryDirectory /tmp
+OnInfected Reject
+RejectMsg Rejecting harmful email: %v found
+
diff --git a/gen-config.sh b/gen-config.sh
index 739b151..9482dd7 100755
--- a/gen-config.sh
+++ b/gen-config.sh
@@ -1,9 +1,12 @@
 #!/bin/sh
 
 # Generate the configuration by patching in environment variables.
-sed -e s,@CLAMD_PORT@,${CLAMD_PORT:-4494},g \
-    < /etc/clamav/clamd.conf \
-    > /tmp/clamd.conf
+for file in clamd.conf clamav-milter.conf ; do
+    sed -e s,@CLAMD_PORT@,${CLAMD_PORT:-4494},g \
+        -e s,@MILTER_PORT@,${MILTER_PORT:-4495},g \
+        < /etc/clamav/${file} \
+        > /tmp/${file}
+done
 
 exit 0
 
-- 
GitLab