diff --git a/Makefile b/Makefile index 02d2aedd..eab04cc6 100644 --- a/Makefile +++ b/Makefile @@ -249,6 +249,7 @@ fixtures: docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt" docker exec mail_disabled_clamav_spamassassin /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" + docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt" # postfix virtual transport lmtp docker exec mail_lmtp_ip /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" docker exec mail_privacy /bin/sh -c "openssl s_client -quiet -starttls smtp -connect 0.0.0.0:587 < /tmp/docker-mailserver-test/email-templates/send-privacy-email.txt" diff --git a/target/postfix/main.cf b/target/postfix/main.cf index e1c094c7..0e74b38c 100644 --- a/target/postfix/main.cf +++ b/target/postfix/main.cf @@ -7,9 +7,9 @@ readme_directory = no # Basic configuration # myhostname = -alias_maps = texthash:/etc/aliases -alias_database = texthash:/etc/aliases -mydestination = +alias_maps = hash:/etc/aliases +alias_database = hash:/etc/aliases +mydestination = $myhostname, localhost.$mydomain, localhost relayhost = mynetworks = 127.0.0.0/8 [::1]/128 [fe80::]/64 mailbox_size_limit = 0 diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index abd22b18..c6e79e55 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -656,7 +656,7 @@ function _setup_spoof_protection () { sed -i 's|smtpd_sender_restrictions =|smtpd_sender_restrictions = reject_authenticated_sender_login_mismatch,|' /etc/postfix/main.cf [ "$ENABLE_LDAP" = 1 ] \ && postconf -e "smtpd_sender_login_maps=ldap:/etc/postfix/ldap-users.cf ldap:/etc/postfix/ldap-aliases.cf ldap:/etc/postfix/ldap-groups.cf" \ - || postconf -e "smtpd_sender_login_maps=texthash:/etc/postfix/virtual, texthash:/etc/aliases, pcre:/etc/postfix/maps/sender_login_maps.pcre" + || postconf -e "smtpd_sender_login_maps=texthash:/etc/postfix/virtual, hash:/etc/aliases, pcre:/etc/postfix/maps/sender_login_maps.pcre" } function _setup_postfix_access_control() { @@ -754,6 +754,10 @@ function _setup_postfix_aliases() { s/$/ pcre:\/etc\/postfix\/regexp/ }' /etc/postfix/main.cf fi + + notify 'inf' "Configuring root alias" + echo "root: ${POSTMASTER_ADDRESS}" > /etc/aliases + postalias /etc/aliases } function _setup_SRS() { diff --git a/test/config/postfix-regexp.cf b/test/config/postfix-regexp.cf index ac8e5e73..27954d6f 100644 --- a/test/config/postfix-regexp.cf +++ b/test/config/postfix-regexp.cf @@ -1,2 +1,4 @@ /^test[0-9][0-9]*@localhost.localdomain/ user1@localhost.localdomain /^bounce.*@.*/ external1@otherdomain.tld +/^postmaster@/ user1@localhost.localdomain + diff --git a/test/email-templates/root-email.txt b/test/email-templates/root-email.txt new file mode 100644 index 00000000..b778e86d --- /dev/null +++ b/test/email-templates/root-email.txt @@ -0,0 +1,3 @@ +Subject: Root Test Message + +This is a test mail. diff --git a/test/tests.bats b/test/tests.bats index 4bc6db65..54457e21 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -296,7 +296,7 @@ load 'test_helper/bats-assert/load' @test "checking smtp: delivers mail to existing account" { run docker exec mail /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)' | wc -l" assert_success - assert_output 10 + assert_output 12 } @test "checking smtp: delivers mail to existing alias" { @@ -326,10 +326,10 @@ load 'test_helper/bats-assert/load' assert_output 1 } -@test "checking smtp: user1 should have received 6 mails" { +@test "checking smtp: user1 should have received 9 mails" { run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l" assert_success - assert_output 7 + assert_output 9 } @test "checking smtp: rejects mail to unknown user" { @@ -1708,3 +1708,12 @@ load 'test_helper/bats-assert/load' run docker exec mail_with_relays /bin/sh -c 'cat /etc/postfix/sasl_passwd | grep -e "^\[default.relay.com\]:2525\s\+smtp_user:smtp_password" | wc -l | grep 1' assert_success } + +# +# root mail delivery +# + +@test "checking that mail for root was delivered" { + run docker exec mail grep "Subject: Root Test Message" /var/mail/localhost.localdomain/user1/new/ -R + assert_success +}