Introducing global filters. (#934)

* Introducing global filters
* added optional after.dovecot.sieve/before.dovecot.sieve files
* added global filter test
This commit is contained in:
17Halbe 2018-04-05 18:54:01 +02:00 committed by Johan Smits
parent 137d623171
commit cc7c1f8804
5 changed files with 32 additions and 15 deletions

View file

@ -117,10 +117,8 @@ RUN sed -i -e 's/include_try \/usr\/share\/dovecot\/protocols\.d/include_try \/e
chmod 755 /etc/dovecot/ssl && \ chmod 755 /etc/dovecot/ssl && \
cd /usr/share/dovecot && \ cd /usr/share/dovecot && \
./mkcert.sh && \ ./mkcert.sh && \
mkdir /usr/lib/dovecot/sieve-pipe && \ mkdir -p /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global && \
chmod 755 /usr/lib/dovecot/sieve-pipe && \ chmod 755 -R /usr/lib/dovecot/sieve-pipe /usr/lib/dovecot/sieve-filter /usr/lib/dovecot/sieve-global
mkdir /usr/lib/dovecot/sieve-filter && \
chmod 755 /usr/lib/dovecot/sieve-filter
# Configures LDAP # Configures LDAP
COPY target/dovecot/dovecot-ldap.conf.ext /etc/dovecot COPY target/dovecot/dovecot-ldap.conf.ext /etc/dovecot

View file

@ -31,14 +31,14 @@ plugin {
# executed. The order of execution within a directory is determined by the # executed. The order of execution within a directory is determined by the
# file names, using a normal 8bit per-character comparison. Multiple script # file names, using a normal 8bit per-character comparison. Multiple script
# file or directory paths can be specified by appending an increasing number. # 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_before2 =
#sieve_before3 = (etc...) #sieve_before3 = (etc...)
# Identical to sieve_before, only the specified scripts are executed after the # 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 # user's script (only when keep is still in effect!). Multiple script file or
# directory paths can be specified by appending an increasing number. # 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 =
#sieve_after2 = (etc...) #sieve_after2 = (etc...)

View file

@ -483,16 +483,25 @@ function _setup_dovecot() {
# Copy pipe and filter programs, if any # Copy pipe and filter programs, if any
rm -f /usr/lib/dovecot/sieve-filter/* rm -f /usr/lib/dovecot/sieve-filter/*
rm -f /usr/lib/dovecot/sieve-pipe/* rm -f /usr/lib/dovecot/sieve-pipe/*
if [ -d /tmp/docker-mailserver/sieve-filter ]; then [ -d /tmp/docker-mailserver/sieve-filter ] && cp /tmp/docker-mailserver/sieve-filter/* /usr/lib/dovecot/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/
chown docker:docker /usr/lib/dovecot/sieve-filter/* if [ -f /tmp/docker-mailserver/before.dovecot.sieve ]; then
chmod 550 /usr/lib/dovecot/sieve-filter/* 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 fi
if [ -d /tmp/docker-mailserver/sieve-pipe ]; then
cp /tmp/docker-mailserver/sieve-pipe/* /usr/lib/dovecot/sieve-pipe/ if [ -f /tmp/docker-mailserver/after.dovecot.sieve ]; then
chown docker:docker /usr/lib/dovecot/sieve-pipe/* sed -i "s/#sieve_after =/sieve_after =/" /etc/dovecot/conf.d/90-sieve.conf
chmod 550 /usr/lib/dovecot/sieve-pipe/* 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 fi
chown docker:docker -R /usr/lib/dovecot/sieve*
chmod 550 -R /usr/lib/dovecot/sieve*
} }
function _setup_dovecot_local_user() { function _setup_dovecot_local_user() {

View file

@ -0,0 +1,6 @@
require ["fileinto", "copy"];
if address :contains ["From"] "spam@spam.com" {
fileinto :copy "INBOX";
}

View file

@ -329,7 +329,7 @@ load 'test_helper/bats-assert/load'
@test "checking smtp: user1 should have received 6 mails" { @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" run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l"
assert_success assert_success
assert_output 6 assert_output 7
} }
@test "checking smtp: rejects mail to unknown user" { @test "checking smtp: rejects mail to unknown user" {
@ -1047,6 +1047,10 @@ load 'test_helper/bats-assert/load'
assert_output 1 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 <spam@spam.com>' -R /var/mail/localhost.localdomain/user1/new/"
assert_success
}
# #
# accounts # accounts
# #