From e465e659ad573de48d29bbf08df226ecf0cba2b3 Mon Sep 17 00:00:00 2001 From: Germain Masse Date: Thu, 17 Oct 2019 07:04:14 +0000 Subject: [PATCH 1/3] Remove unnecessary maildir folders creation --- Makefile | 2 -- target/check-for-changes.sh | 10 +--------- target/start-mailserver.sh | 10 +--------- test/tests.bats | 15 ++++++--------- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 6140ce73..fcec16b3 100644 --- a/Makefile +++ b/Makefile @@ -104,8 +104,6 @@ generate-accounts-after-run: fixtures: # Setup sieve & create filtering folder (INBOX/spam) docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve - docker exec mail /bin/sh -c "maildirmake.dovecot /var/mail/localhost.localdomain/user1/.INBOX.spam" - docker exec mail /bin/sh -c "chown 5000:5000 -R /var/mail/localhost.localdomain/user1/.INBOX.spam" sleep 30 # Sending test mails docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" diff --git a/target/check-for-changes.sh b/target/check-for-changes.sh index afcb059b..2109e1d9 100755 --- a/target/check-for-changes.sh +++ b/target/check-for-changes.sh @@ -126,15 +126,7 @@ if [[ $chksum == *"FAIL"* ]]; then # Example : # ${login}:${pass}:5000:5000::/var/mail/${domain}/${user}::userdb_mail=maildir:/var/mail/${domain}/${user} echo "${login}:${pass}:5000:5000::/var/mail/${domain}/${user}::" >> /etc/dovecot/userdb - mkdir -p /var/mail/${domain} - if [ ! -d "/var/mail/${domain}/${user}" ]; then - maildirmake.dovecot "/var/mail/${domain}/${user}" - maildirmake.dovecot "/var/mail/${domain}/${user}/.Sent" - maildirmake.dovecot "/var/mail/${domain}/${user}/.Trash" - maildirmake.dovecot "/var/mail/${domain}/${user}/.Drafts" - echo -e "INBOX\nSent\nTrash\nDrafts" >> "/var/mail/${domain}/${user}/subscriptions" - touch "/var/mail/${domain}/${user}/.Sent/maildirfolder" - fi + mkdir -p /var/mail/${domain}/${user} # Copy user provided sieve file, if present test -e /tmp/docker-mailserver/${login}.dovecot.sieve && cp /tmp/docker-mailserver/${login}.dovecot.sieve /var/mail/${domain}/${user}/.dovecot.sieve echo ${domain} >> /tmp/vhost.tmp diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 26e98e56..c9e575a6 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -652,15 +652,7 @@ function _setup_dovecot_local_user() { # Example : # ${login}:${pass}:5000:5000::/var/mail/${domain}/${user}::userdb_mail=maildir:/var/mail/${domain}/${user} echo "${login}:${pass}:5000:5000::/var/mail/${domain}/${user}::" >> /etc/dovecot/userdb - mkdir -p /var/mail/${domain} - if [ ! -d "/var/mail/${domain}/${user}" ]; then - maildirmake.dovecot "/var/mail/${domain}/${user}" - maildirmake.dovecot "/var/mail/${domain}/${user}/.Sent" - maildirmake.dovecot "/var/mail/${domain}/${user}/.Trash" - maildirmake.dovecot "/var/mail/${domain}/${user}/.Drafts" - echo -e "INBOX\nSent\nTrash\nDrafts" >> "/var/mail/${domain}/${user}/subscriptions" - touch "/var/mail/${domain}/${user}/.Sent/maildirfolder" - fi + mkdir -p /var/mail/${domain}/${user} # Copy user provided sieve file, if present test -e /tmp/docker-mailserver/${login}.dovecot.sieve && cp /tmp/docker-mailserver/${login}.dovecot.sieve /var/mail/${domain}/${user}/.dovecot.sieve echo ${domain} >> /tmp/vhost.tmp diff --git a/test/tests.bats b/test/tests.bats index c130c46f..4dd2241f 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -294,22 +294,19 @@ function count_processed_changes() { [ "${lines[2]}" = "added@localhost.localdomain" ] } -@test "checking accounts: user mail folders for user1" { - run docker exec mail /bin/bash -c "ls -A /var/mail/localhost.localdomain/user1 | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" +@test "checking accounts: user mail folder for user1" { + run docker exec mail /bin/bash -c "ls -d /var/mail/localhost.localdomain/user1" assert_success - assert_output 7 } -@test "checking accounts: user mail folders for user2" { - run docker exec mail /bin/bash -c "ls -A /var/mail/otherdomain.tld/user2 | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" +@test "checking accounts: user mail folder for user2" { + run docker exec mail /bin/bash -c "ls -d /var/mail/otherdomain.tld/user2" assert_success - assert_output 7 } -@test "checking accounts: user mail folders for added user" { - run docker exec mail /bin/bash -c "ls -A /var/mail/localhost.localdomain/added | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" +@test "checking accounts: user mail folder for added user" { + run docker exec mail /bin/bash -c "ls -d /var/mail/localhost.localdomain/added" assert_success - assert_output 7 } @test "checking accounts: comments are not parsed" { From fa167a9e515d720fc644e5bc9f955f5d6ce405b4 Mon Sep 17 00:00:00 2001 From: Germain Masse Date: Fri, 1 Nov 2019 18:49:58 +0000 Subject: [PATCH 2/3] Test special-use folders are available in IMAP --- test/mail_special_use_folders.bats | 56 +++++++++++++++++++ .../nc_templates/imap_special_use_folders.txt | 3 + 2 files changed, 59 insertions(+) create mode 100644 test/mail_special_use_folders.bats create mode 100644 test/test-files/nc_templates/imap_special_use_folders.txt diff --git a/test/mail_special_use_folders.bats b/test/mail_special_use_folders.bats new file mode 100644 index 00000000..bbd2cc79 --- /dev/null +++ b/test/mail_special_use_folders.bats @@ -0,0 +1,56 @@ +load 'test_helper/common' + +setup() { + run_setup_file_if_necessary +} + +teardown() { + run_teardown_file_if_necessary +} + +setup_file() { + docker run -d --name mail_special_use_folders \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -e SASL_PASSWD="external-domain.com username:password" \ + -e ENABLE_CLAMAV=0 \ + -e ENABLE_SPAMASSASSIN=0 \ + --cap-add=SYS_PTRACE \ + -e PERMIT_DOCKER=host \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME} + wait_for_smtp_port_in_container mail_special_use_folders +} + +teardown_file() { + docker rm -f mail_special_use_folders +} + +@test "first" { + skip 'only used to call setup_file from setup' +} + + +@test "checking normal delivery" { + run docker exec mail_special_use_folders /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" + assert_success + + repeat_until_success_or_timeout 30 docker exec mail_special_use_folders /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/new | wc -l) -eq 1 ]' +} + +@test "checking special-use folders not yet created" { + run docker exec mail_special_use_folders /bin/bash -c "ls -A /var/mail/localhost.localdomain/user1 | grep -E '.Drafts|.Sent|.Trash' | wc -l" + assert_success + assert_output 0 +} + +@test "checking special-use folders available in IMAP" { + run docker exec mail_special_use_folders /bin/sh -c "nc -w 8 0.0.0.0 143 < /tmp/docker-mailserver-test/nc_templates/imap_special_use_folders.txt | grep -E 'Drafts|Junk|Trash|Sent' | wc -l" + assert_success + assert_output 4 +} + + +@test "last" { + skip 'only used to call teardown_file from teardown' +} diff --git a/test/test-files/nc_templates/imap_special_use_folders.txt b/test/test-files/nc_templates/imap_special_use_folders.txt new file mode 100644 index 00000000..12e7b6d5 --- /dev/null +++ b/test/test-files/nc_templates/imap_special_use_folders.txt @@ -0,0 +1,3 @@ +a1 LOGIN user1@localhost.localdomain mypassword +a2 LIST "" "*" +a3 LOGOUT From be907b2d916d4b0db42d610e158f89cbe9eb2578 Mon Sep 17 00:00:00 2001 From: Germain Masse Date: Fri, 1 Nov 2019 20:07:45 +0000 Subject: [PATCH 3/3] Minor comment fix --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fcec16b3..53ee92e1 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ generate-accounts-after-run: sleep 10 fixtures: - # Setup sieve & create filtering folder (INBOX/spam) + # Setup sieve docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve sleep 30 # Sending test mails