From 59a6649f0e297f4113a4fa9e03f917aa71c146c6 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Thu, 18 Feb 2016 22:11:24 +0100 Subject: [PATCH] Fixes #79 and add spamassassin configuration variables (see README.md) --- Makefile | 19 +++++++++++++++---- README.md | 6 ++++++ start-mailserver.sh | 7 +++---- test/test.sh | 8 ++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index f96bc3c9..c83e9fad 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,30 @@ NAME = tvial/docker-mailserver -VERSION = $(TRAVIS_BUILD_ID) all: build run fixtures tests clean all-no-build: run fixtures tests clean build: - docker build --no-cache -t $(NAME):$(VERSION) . + docker build --no-cache -t $(NAME) . run: # Copy test files cp test/accounts.cf postfix/ cp test/virtual postfix/ # Run containers - docker run -d --name mail -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -h mail.my-domain.com -t $(NAME):$(VERSION) - docker run -d --name mail_pop3 -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -e ENABLE_POP3=1 -h mail.my-domain.com -t $(NAME):$(VERSION) + docker run -d --name mail \ + -v "`pwd`/postfix":/tmp/postfix \ + -v "`pwd`/spamassassin":/tmp/spamassassin \ + -v "`pwd`/test":/tmp/test \ + -e SA_TAG=1.0 \ + -e SA_TAG2=2.0 \ + -e SA_KILL=3.0 \ + -h mail.my-domain.com -t $(NAME) + docker run -d --name mail_pop3 \ + -v "`pwd`/postfix":/tmp/postfix \ + -v "`pwd`/spamassassin":/tmp/spamassassin \ + -v "`pwd`/test":/tmp/test \ + -e ENABLE_POP3=1 \ + -h mail.my-domain.com -t $(NAME) # Wait for containers to fully start sleep 60 diff --git a/README.md b/README.md index 5d8b767d..66337e5a 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,12 @@ Example: * ENABLE_POP3 * *empty* (default) => POP3 service disabled * 1 => Enables POP3 service +* SA_TAG + * *2.0* (default) => add spam info headers if at, or above that level +* SA_TAG2 + * *6.31* (default) => add 'spam detected' headers at that level +* SA_KILL + * *6.31* (default) => triggers spam evasive actions) Please read [how the container starts](https://github.com/tomav/docker-mailserver/blob/master/start-mailserver.sh) to understand what's expected. diff --git a/start-mailserver.sh b/start-mailserver.sh index 359ef8b5..2e640822 100644 --- a/start-mailserver.sh +++ b/start-mailserver.sh @@ -182,12 +182,11 @@ echo "Creating /etc/mailname" echo $(hostname -d) > /etc/mailname echo "Configuring Spamassassin" -echo "required_score 5" >> /etc/spamassassin/local.cf -echo "report_safe 0" >> /etc/spamassassin/local.cf -echo "rewrite_header Subject ***SPAM***" >> /etc/spamassassin/local.cf +SA_TAG=${SA_TAG:="2.0"} && sed -i -r 's/^\$sa_tag_level_deflt (.*);/\$sa_tag_level_deflt = '$SA_TAG';/g' /etc/amavis/conf.d/20-debian_defaults +SA_TAG2=${SA_TAG2:="6.31"} && sed -i -r 's/^\$sa_tag2_level_deflt (.*);/\$sa_tag2_level_deflt = '$SA_TAG2';/g' /etc/amavis/conf.d/20-debian_defaults +SA_KILL=${SA_KILL:="6.31"} && sed -i -r 's/^\$sa_kill_level_deflt (.*);/\$sa_kill_level_deflt = '$SA_KILL';/g' /etc/amavis/conf.d/20-debian_defaults cp /tmp/spamassassin/rules.cf /etc/spamassassin/ - echo "Configuring fail2ban" # enable filters perl -i -0pe 's/(\[postfix\]\n\n).*\n/\1enabled = true\n/' /etc/fail2ban/jail.conf diff --git a/test/test.sh b/test/test.sh index d855fc00..b6530b9d 100644 --- a/test/test.sh +++ b/test/test.sh @@ -68,6 +68,14 @@ assert_raises "docker exec mail grep ': error:' /var/log/mail.log" 1 assert_raises "docker exec mail_pop3 grep 'non-null host address bits in' /var/log/mail.log" 1 assert_raises "docker exec mail_pop3 grep ': error:' /var/log/mail.log" 1 +# Testing Spamssassin config in Amavis +assert_raises "docker exec mail_pop3 grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" 0 +assert_raises "docker exec mail_pop3 grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" 0 +assert_raises "docker exec mail_pop3 grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" 0 +assert_raises "docker exec mail grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 1.0'" 0 +assert_raises "docker exec mail grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" 0 +assert_raises "docker exec mail grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 3.0'" 0 + # Testing OpenDKIM assert "docker exec mail cat /etc/opendkim/KeyTable | wc -l" "2" assert "docker exec mail ls -l /etc/opendkim/keys/ | grep '^d' | wc -l" "2"