diff --git a/Dockerfile b/Dockerfile index 315d095d..29e2da6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -75,6 +75,8 @@ RUN sed -i -r 's/^(CRON)=0/\1=1/g' /etc/default/spamassassin COPY target/postgrey/postgrey /etc/default/postgrey COPY target/postgrey/postgrey.init /etc/init.d/postgrey RUN chmod 755 /etc/init.d/postgrey +RUN mkdir /var/run/postgrey +RUN chown postgrey:postgrey /var/run/postgrey # Enables Amavis RUN sed -i -r 's/#(@| \\%)bypass/\1bypass/g' /etc/amavis/conf.d/15-content_filter_mode diff --git a/Makefile b/Makefile index 7043e14d..c77d2067 100644 --- a/Makefile +++ b/Makefile @@ -123,8 +123,11 @@ run: -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test":/tmp/docker-mailserver-test \ -e ENABLE_POSTGREY=1 \ + -e POSTGREY_DELAY=15 \ + -e POSTGREY_MAX_AGE=35 \ + -e POSTGREY_TEXT="Delayed by postgrey" \ -h mail.my-domain.com -t $(NAME) - sleep 15 + sleep 20 fixtures: diff --git a/target/postgrey/postgrey b/target/postgrey/postgrey index a5cc1bc9..b95d67dd 100644 --- a/target/postgrey/postgrey +++ b/target/postgrey/postgrey @@ -3,5 +3,3 @@ # --max-age=N delete old entries after N days (default: 35) POSTGREY_OPTS="--inet=10023" - -#POSTGREY_TEXT="Your customized rejection message here" \ No newline at end of file diff --git a/target/postgrey/postgrey.init b/target/postgrey/postgrey.init index 1ace4f0a..59f036d1 100644 --- a/target/postgrey/postgrey.init +++ b/target/postgrey/postgrey.init @@ -26,7 +26,7 @@ DAEMON_NAME=postgrey DESC="postfix greylisting daemon" DAEMON_USER=postgrey -PIDFILE=/var/run/$DAEMON_NAME.pid +PIDFILE=/var/run/$DAEMON_NAME/$DAEMON_NAME.pid SCRIPTNAME=/etc/init.d/$DAEMON_NAME # Gracefully exit if the package has been removed. @@ -138,4 +138,4 @@ case "$1" in ;; esac -exit $ret \ No newline at end of file +exit $ret diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 0da7706e..d6fcd273 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -15,6 +15,9 @@ DEFAULT_VARS["ENABLE_MANAGESIEVE"]="${ENABLE_MANAGESIEVE:="0"}" DEFAULT_VARS["ENABLE_FETCHMAIL"]="${ENABLE_FETCHMAIL:="0"}" DEFAULT_VARS["ENABLE_LDAP"]="${ENABLE_LDAP:="0"}" DEFAULT_VARS["ENABLE_POSTGREY"]="${ENABLE_POSTGREY:="0"}" +DEFAULT_VARS["POSTGREY_DELAY"]="${POSTGREY_DELAY:="300"}" +DEFAULT_VARS["POSTGREY_MAX_AGE"]="${POSTGREY_MAX_AGE:="35"}" +DEFAULT_VARS["POSTGREY_TEXT"]="${POSTGREY_TEXT:="Delayed by postgrey"}" DEFAULT_VARS["ENABLE_SASLAUTHD"]="${ENABLE_SASLAUTHD:="0"}" DEFAULT_VARS["SMTP_ONLY"]="${SMTP_ONLY:="0"}" DEFAULT_VARS["VIRUSMAILS_DELETE_DELAY"]="${VIRUSMAILS_DELETE_DELAY:="7"}" @@ -147,7 +150,7 @@ function register_functions() { _register_start_daemon "_start_daemons_opendkim" _register_start_daemon "_start_daemons_opendmarc" - #postfix uses postgray, needs to be started before postfix + #postfix uses postgrey, needs to be started before postfix if [ "$ENABLE_POSTGREY" = 1 ]; then _register_start_daemon "_start_daemons_postgrey" fi @@ -501,9 +504,16 @@ function _setup_ldap() { function _setup_postgrey() { notify 'inf' "Configuring postgrey" - sed -i -e 's/bl.spamcop.net/bl.spamcop.net, check_policy_service inet:127.0.0.1:10023/' /etc/postfix/main.cf + sed -i -e 's/bl.spamcop.net$/bl.spamcop.net, check_policy_service inet:127.0.0.1:10023/' /etc/postfix/main.cf + sed -i -e "s/\"--inet=10023\"/\"--inet=10023 --delay=$POSTGREY_DELAY --max-age=$POSTGREY_MAX_AGE\"/" /etc/default/postgrey + TEXT_FOUND=`grep -i "POSTGREY_TEXT" /etc/default/postgrey | wc -l` + + if [ $TEXT_FOUND -eq 0 ]; then + printf "POSTGREY_TEXT=\"$POSTGREY_TEXT\"\n\n" >> /etc/default/postgrey + fi } + function _setup_postfix_sasl() { [ ! -f /etc/postfix/sasl/smtpd.conf ] && cat > /etc/postfix/sasl/smtpd.conf << EOF pwcheck_method: saslauthd diff --git a/test/email-templates/postgrey.txt b/test/email-templates/postgrey.txt new file mode 100644 index 00000000..69cd2e72 --- /dev/null +++ b/test/email-templates/postgrey.txt @@ -0,0 +1,12 @@ +HELO mail.external.tld +MAIL FROM: user@external.tld +RCPT TO: user1@localhost.localdomain +DATA +From: Docker Mail Server +To: Existing Local User +Date: Sat, 22 May 2010 07:43:25 -0400 +Subject: Postgrey Test Message +This is a test mail. + +. +QUIT \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index 6a433665..2706da59 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -88,8 +88,18 @@ load 'test_helper/bats-assert/load' } @test "checking postgrey: /etc/postfix/main.cf correctly edited" { - run docker exec mail_with_postgrey /bin/bash -c "grep 'bl.spamcop.net, check_policy_service' /etc/postfix/main.cf" + run docker exec mail_with_postgrey /bin/bash -c "grep 'bl.spamcop.net, check_policy_service inet:127.0.0.1:10023' /etc/postfix/main.cf | wc -l" assert_success + assert_output 1 +} + +@test "checking postgrey: /etc/default/postgrey correctly edited and has the default values" { + run docker exec mail_with_postgrey /bin/bash -c "grep '^POSTGREY_OPTS=\"--inet=10023 --delay=15 --max-age=35\"$' /etc/default/postgrey | wc -l" + assert_success + assert_output 1 + run docker exec mail_with_postgrey /bin/bash -c "grep '^POSTGREY_TEXT=\"Delayed by postgrey\"$' /etc/default/postgrey | wc -l" + assert_success + assert_output 1 } @test "checking process: postgrey (postgrey server enabled)" { @@ -97,6 +107,30 @@ load 'test_helper/bats-assert/load' assert_success } +@test "checking postgrey: there should be a log entry about a new greylisted e-mail user@external.tld in /var/log/mail/mail.log" { + #editing the postfix config in order to ensure that postgrey handles the test e-mail. The other spam checks at smtpd_recipient_restrictionswould interfere with it. + run docker exec mail_with_postgrey /bin/sh -c "sed -ie 's/permit_sasl_authenticated.*reject_unauth_destination,$//g' /etc/postfix/main.cf" + run docker exec mail_with_postgrey /bin/sh -c "sed -ie 's/reject_unauth_pipelining.*reject_unknown_recipient_domain,$//g' /etc/postfix/main.cf" + run docker exec mail_with_postgrey /bin/sh -c "sed -ie 's/reject_rbl_client.*inet:127\.0\.0\.1:10023$//g' /etc/postfix/main.cf" + run docker exec mail_with_postgrey /bin/sh -c "sed -ie 's/smtpd_recipient_restrictions = /smtpd_recipient_restrictions = check_policy_service inet:127.0.0.1:10023/g' /etc/postfix/main.cf" + + run docker exec mail_with_postgrey /bin/sh -c "/etc/init.d/postfix reload" + run docker exec mail_with_postgrey /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/postgrey.txt" + sleep 5 #ensure that the information has been written into the log + run docker exec mail_with_postgrey /bin/bash -c "grep -i 'action=greylist.*user@external\.tld' /var/log/mail/mail.log | wc -l" + assert_success + assert_output 1 +} + +@test "checking postgrey: there should be a log entry about the retried and passed e-mail user@external.tld in /var/log/mail/mail.log" { + sleep 20 #wait 20 seconds so that postgrey would accept the message + run docker exec mail_with_postgrey /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/postgrey.txt" + sleep 8 + run docker exec mail_with_postgrey /bin/sh -c "grep -i 'action=pass, reason=triplet found.*user@external\.tld' /var/log/mail/mail.log | wc -l" + assert_success + assert_output 1 +} + # # imap #