Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consistently make 1 the default value for SPAMASSASSIN_SPAM_TO_INBOX #2361

Merged
merged 14 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/content/config/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,10 @@ Finally the logrotate interval **may** affect the period for generated reports.
- **0** => SpamAssassin is disabled
- 1 => SpamAssassin is enabled

**/!\\ Spam delivery:** when SpamAssassin is enabled, messages marked as spam WILL NOT BE DELIVERED.
Use `SPAMASSASSIN_SPAM_TO_INBOX=1` for receiving spam messages.

##### SPAMASSASSIN_SPAM_TO_INBOX

- **0** => Spam messages will be bounced (_rejected_) without any notification (_dangerous_).
- 1 => Spam messages will be delivered to the inbox and tagged as spam using `SA_SPAM_SUBJECT`.
- **1** => Spam messages will be delivered to the inbox and tagged as spam using `SA_SPAM_SUBJECT`.
- 0 => Spam messages will be bounced (_rejected_) without any notification (_dangerous_).

##### MOVE_SPAM_TO_JUNK

Expand Down
3 changes: 1 addition & 2 deletions target/scripts/start-mailserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ VARS[SA_SPAM_SUBJECT]=${SA_SPAM_SUBJECT:="***SPAM*** "}
VARS[SA_TAG]=${SA_TAG:="2.0"}
VARS[SA_TAG2]=${SA_TAG2:="6.31"}
VARS[SMTP_ONLY]="${SMTP_ONLY:=0}"
VARS[SPAMASSASSIN_SPAM_TO_INBOX_SET]="${SPAMASSASSIN_SPAM_TO_INBOX:-not set}"
VARS[SPAMASSASSIN_SPAM_TO_INBOX]="${SPAMASSASSIN_SPAM_TO_INBOX:=0}"
VARS[SPAMASSASSIN_SPAM_TO_INBOX]="${SPAMASSASSIN_SPAM_TO_INBOX:=1}"
VARS[SPOOF_PROTECTION]="${SPOOF_PROTECTION:=0}"
VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}"
VARS[SSL_TYPE]="${SSL_TYPE:=}"
Expand Down
5 changes: 0 additions & 5 deletions target/scripts/startup/setup-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,6 @@ function _setup_security_stack

sed -i "s|\$final_spam_destiny.*=.*$|\$final_spam_destiny = D_BOUNCE;|g" /etc/amavis/conf.d/49-docker-mailserver
sed -i "s|\$final_bad_header_destiny.*=.*$|\$final_bad_header_destiny = D_BOUNCE;|g" /etc/amavis/conf.d/49-docker-mailserver

if [[ ${VARS[SPAMASSASSIN_SPAM_TO_INBOX_SET]} == 'not set' ]]
then
_notify 'warn' 'Spam messages WILL NOT BE DELIVERED, you will NOT be notified of ANY message bounced. Please define SPAMASSASSIN_SPAM_TO_INBOX explicitly.'
fi
fi
fi

Expand Down
25 changes: 1 addition & 24 deletions test/mail_spam_bounced.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,21 @@ function setup_file() {
}

@test "checking amavis: spam message is bounced (rejected)" {
local TEST_DOCKER_ARGS=(
--env ENABLE_SPAMASSASSIN=1
--env SPAMASSASSIN_SPAM_TO_INBOX=0
)

common_container_setup 'TEST_DOCKER_ARGS'

run _should_emit_warning
assert_failure

_should_bounce_spam
}

@test "checking amavis: spam message is bounced (rejected), undefined SPAMASSASSIN_SPAM_TO_INBOX should raise a warning" {
# SPAMASSASSIN_SPAM_TO_INBOX=0 is the default. If no explicit ENV value is set, it should log a warning at startup.

# shellcheck disable=SC2034
local TEST_DOCKER_ARGS=(
--env ENABLE_SPAMASSASSIN=1
--env SPAMASSASSIN_SPAM_TO_INBOX=0
)

common_container_setup 'TEST_DOCKER_ARGS'

run _should_emit_warning
assert_success

_should_bounce_spam
}

@test "last" {
skip 'this test is only there to reliably mark the end for the teardown_file'
}

# This warning should only be raised when the env SPAMASSASSIN_SPAM_TO_INBOX has no explicit value set
function _should_emit_warning() {
sh -c "docker logs ${TEST_NAME} | grep 'Spam messages WILL NOT BE DELIVERED'"
}

function _should_bounce_spam() {
wait_for_smtp_port_in_container_to_respond "${TEST_NAME}"

Expand Down
11 changes: 8 additions & 3 deletions test/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ setup_file() {
-e ENABLE_QUOTAS=1 \
-e ENABLE_SPAMASSASSIN=1 \
-e ENABLE_SRS=1 \
-e ENABLE_UPDATE_CHECK=0 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is necessary, because there will never be a new version, hence no e-mail notification about an update. But it doesn't hurt, so leave it as it is if you like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added by @craue, and you're right, probably not necessary. I will note this and remove this with an upcoming PR of mine. Remind me if I forget about it :)

-e PERMIT_DOCKER=host \
-e REPORT_RECIPIENT=user1@localhost.localdomain \
-e REPORT_SENDER=report1@mail.my-domain.com \
Expand Down Expand Up @@ -244,12 +245,13 @@ teardown_file() {
assert_success
}

# TODO add a test covering case SPAMASSASSIN_SPAM_TO_INBOX=0
@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)' | sed 's/.* to=</</g' | sed 's/, relay.*//g' | sort | uniq -c | tr -s \" \""
assert_success
assert_output <<'EOF'
1 <added@localhost.localdomain>
6 <user1@localhost.localdomain>
7 <user1@localhost.localdomain>
1 <user1@localhost.localdomain>, orig_to=<postmaster@my-domain.com>
1 <user1@localhost.localdomain>, orig_to=<root>
1 <user1~test@localhost.localdomain>
Expand Down Expand Up @@ -316,10 +318,11 @@ EOF
assert_output 2
}

# TODO add a test covering case SPAMASSASSIN_SPAM_TO_INBOX=0
@test "checking smtp: rejects spam" {
run docker exec mail /bin/sh -c "grep 'Blocked SPAM' /var/log/mail/mail.log | grep external.tld=spam@my-domain.com | wc -l"
assert_success
assert_output 1
assert_output 0
}

@test "checking smtp: rejects virus" {
Expand Down Expand Up @@ -670,7 +673,9 @@ EOF
@test "checking accounts: listmailuser (quotas enabled)" {
run docker exec mail /bin/sh -c "sed -i '/ENABLE_QUOTAS=0/d' /etc/dms-settings; listmailuser | head -n 1"
assert_success
assert_output '* user1@localhost.localdomain ( 12K / ~ ) [0%]'
assert_output --regexp '\* user1@localhost\.localdomain \( 1[3,4]{1}K \/ ~ \) \[0%\]'
# TODO find out why, during CI, sometimes it's 13K, and sometimes 14K
# assert_output '* user1@localhost.localdomain ( 14K / ~ ) [0%]'
}

@test "checking accounts: no error is generated when deleting a user if /tmp/docker-mailserver/postfix-accounts.cf is missing" {
Expand Down