diff --git a/Dockerfile b/Dockerfile index af736af2..4357eb4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -117,10 +117,8 @@ RUN sed -i -e 's/include_try \/usr\/share\/dovecot\/protocols\.d/include_try \/e chmod 755 /etc/dovecot/ssl && \ cd /usr/share/dovecot && \ ./mkcert.sh && \ - mkdir /usr/lib/dovecot/sieve-pipe && \ - chmod 755 /usr/lib/dovecot/sieve-pipe && \ - mkdir /usr/lib/dovecot/sieve-filter && \ - chmod 755 /usr/lib/dovecot/sieve-filter + mkdir -p /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global && \ + chmod 755 -R /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global # Configures LDAP COPY target/dovecot/dovecot-ldap.conf.ext /etc/dovecot diff --git a/target/dovecot/90-sieve.conf b/target/dovecot/90-sieve.conf index 5e53df72..8fb7649e 100644 --- a/target/dovecot/90-sieve.conf +++ b/target/dovecot/90-sieve.conf @@ -31,14 +31,14 @@ plugin { # executed. The order of execution within a directory is determined by the # file names, using a normal 8bit per-character comparison. Multiple script # file or directory paths can be specified by appending an increasing number. - #sieve_before = + #sieve_before = /usr/lib/dovecot/sieve-global/before.dovecot.sieve #sieve_before2 = #sieve_before3 = (etc...) # Identical to sieve_before, only the specified scripts are executed after the # user's script (only when keep is still in effect!). Multiple script file or # directory paths can be specified by appending an increasing number. - #sieve_after = + #sieve_after = /usr/lib/dovecot/sieve-global/after.dovecot.sieve #sieve_after2 = #sieve_after2 = (etc...) diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 879dbd29..f3ad1eff 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -483,16 +483,25 @@ function _setup_dovecot() { # Copy pipe and filter programs, if any rm -f /usr/lib/dovecot/sieve-filter/* rm -f /usr/lib/dovecot/sieve-pipe/* - if [ -d /tmp/docker-mailserver/sieve-filter ]; then - cp /tmp/docker-mailserver/sieve-filter/* /usr/lib/dovecot/sieve-filter/ - chown docker:docker /usr/lib/dovecot/sieve-filter/* - chmod 550 /usr/lib/dovecot/sieve-filter/* + [ -d /tmp/docker-mailserver/sieve-filter ] && cp /tmp/docker-mailserver/sieve-filter/* /usr/lib/dovecot/sieve-filter/ + [ -d /tmp/docker-mailserver/sieve-pipe ] && cp /tmp/docker-mailserver/sieve-pipe/* /usr/lib/dovecot/sieve-pipe/ + if [ -f /tmp/docker-mailserver/before.dovecot.sieve ]; then + sed -i "s/#sieve_before =/sieve_before =/" /etc/dovecot/conf.d/90-sieve.conf + cp /tmp/docker-mailserver/before.dovecot.sieve /usr/lib/dovecot/sieve-global/ + sievec /usr/lib/dovecot/sieve-global/before.dovecot.sieve + else + sed -i "s/ sieve_before =/ #sieve_before =/" /etc/dovecot/conf.d/90-sieve.conf fi - if [ -d /tmp/docker-mailserver/sieve-pipe ]; then - cp /tmp/docker-mailserver/sieve-pipe/* /usr/lib/dovecot/sieve-pipe/ - chown docker:docker /usr/lib/dovecot/sieve-pipe/* - chmod 550 /usr/lib/dovecot/sieve-pipe/* + + if [ -f /tmp/docker-mailserver/after.dovecot.sieve ]; then + sed -i "s/#sieve_after =/sieve_after =/" /etc/dovecot/conf.d/90-sieve.conf + cp /tmp/docker-mailserver/after.dovecot.sieve /usr/lib/dovecot/sieve-global/ + sievec /usr/lib/dovecot/sieve-global/after.dovecot.sieve + else + sed -i "s/ sieve_after =/ #sieve_after =/" /etc/dovecot/conf.d/90-sieve.conf fi + chown docker:docker -R /usr/lib/dovecot/sieve* + chmod 550 -R /usr/lib/dovecot/sieve* } function _setup_dovecot_local_user() { diff --git a/test/config/before.dovecot.sieve b/test/config/before.dovecot.sieve new file mode 100644 index 00000000..188412ba --- /dev/null +++ b/test/config/before.dovecot.sieve @@ -0,0 +1,6 @@ +require ["fileinto", "copy"]; + +if address :contains ["From"] "spam@spam.com" { + fileinto :copy "INBOX"; +} + diff --git a/test/tests.bats b/test/tests.bats index 47127846..b02e0802 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -329,7 +329,7 @@ load 'test_helper/bats-assert/load' @test "checking smtp: user1 should have received 6 mails" { run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l" assert_success - assert_output 6 + assert_output 7 } @test "checking smtp: rejects mail to unknown user" { @@ -1047,6 +1047,10 @@ load 'test_helper/bats-assert/load' assert_output 1 } +@test "checking sieve global: user1 should have gotten a copy of his spam mail" { + run docker exec mail /bin/sh -c "grep 'Spambot ' -R /var/mail/localhost.localdomain/user1/new/" + assert_success +} # # accounts #