Move spam messages to folder with \Junk special-use attribute (#3918)

This commit is contained in:
Kirill Kirilenko 2024-03-04 18:02:48 +03:00
parent b5b193ca4c
commit 4be3948ed9
6 changed files with 14 additions and 8 deletions

View File

@ -36,6 +36,8 @@ The most noteworthy change of this release is the update of the container's base
- DMS `main.cf` has renamed `postscreen_dnsbl_whitelist_threshold` to `postscreen_dnsbl_allowlist_threshold` as part of this change.
- `smtpd_relay_restrictions` (relay policy) is now evaluated after `smtpd_recipient_restrictions` (spam policy). Previously it was evaluated before `smtpd_recipient_restrictions`. Mail to be relayed via DMS must now pass through the spam policy first.
- The TLS fingerprint policy has changed the default from MD5 to SHA256 (_DMS does not modify this Postfix parameter, but may affect any user customizations that do_).
- **Dovecot**
- If `MOVE_SPAM_TO_JUNK=1`, spam messages now will be moved to one mailbox with `\Junk` special-use attribute. If there is no such mailbox, messages will be moved to 'Junk' mailbox, as earlier. This change may break configurations with the file `spam_to_junk.sieve` patched via `user-patches.sh`.
- **rsyslog:**
- Debian 12 adjusted the `rsyslog` configuration for the default file template from `RSYSLOG_TraditionalFileFormat` to `RSYSLOG_FileFormat` (_upstream default since 2012_). This change may affect you if you have any monitoring / analysis of log output (_eg: `mail.log` / `docker logs`_).
- The two formats are roughly equivalent to [RFC 3164](https://www.rfc-editor.org/rfc/rfc3164)) and [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424#section-1) respectively.

View File

@ -329,9 +329,9 @@ Note: More information at <https://dovecot.org/doc/dovecot-example.conf>
##### MOVE_SPAM_TO_JUNK
- 0 => Spam messages will be delivered in the mailbox.
- **1** => Spam messages will be delivered in the `Junk` folder.
- **1** => Spam messages will be delivered in a folder with '\Junk' special-use attribute.
Routes mail identified as spam into the recipient(s) Junk folder (_via a Dovecot Sieve script_).
Routes mail identified as spam into the recipient(s) folder with '\Junk' special-use attribute set (_via a Dovecot Sieve script_).
!!! info

View File

@ -51,7 +51,7 @@ plugin {
# deprecated imapflags extension in addition to all extensions were already
# enabled by default.
#sieve_extensions = +notify +imapflags
sieve_extensions = +notify +imapflags +vnd.dovecot.pipe +vnd.dovecot.filter
sieve_extensions = +notify +imapflags +special-use +vnd.dovecot.pipe +vnd.dovecot.filter
# Which Sieve language extensions are ONLY available in global scripts. This
# can be used to restrict the use of certain Sieve extensions to administrator

View File

@ -304,11 +304,11 @@ function _setup_spam_to_junk() {
_log 'debug' 'Spam emails will be moved to the Junk folder'
mkdir -p /usr/lib/dovecot/sieve-global/after/
cat >/usr/lib/dovecot/sieve-global/after/spam_to_junk.sieve << EOF
require ["fileinto","mailbox"];
require ["fileinto","special-use"];
if anyof (header :contains "X-Spam-Flag" "YES",
header :contains "X-Spam" "Yes") {
fileinto "Junk";
fileinto :specialuse "\\\\Junk" "Junk";
}
EOF
sievec /usr/lib/dovecot/sieve-global/after/spam_to_junk.sieve

View File

@ -232,7 +232,7 @@ function teardown_file() { _default_teardown ; }
_service_log_should_contain_string 'rspamd' 'add header "Gtube pattern"'
_print_mail_log_for_msgid 'rspamd-test-email-header'
assert_output --partial "fileinto action: stored mail into mailbox 'Junk'"
assert_output --partial "fileinto action: stored mail into mailbox [SPECIAL-USE \\Junk]"
_count_files_in_directory_in_container /var/mail/localhost.localdomain/user1/new/ 2
_count_files_in_directory_in_container /var/mail/localhost.localdomain/user1/.Junk/new/ 1

View File

@ -49,7 +49,7 @@ function teardown() { _default_teardown ; }
_should_receive_spam_at '/var/mail/localhost.localdomain/user1/new/'
}
@test "(enabled + MOVE_SPAM_TO_JUNK=1) should deliver spam message into Junk folder" {
@test "(enabled + MOVE_SPAM_TO_JUNK=1) should deliver spam message into folder with \Junk attribute" {
export CONTAINER_NAME=${CONTAINER3_NAME}
local CUSTOM_SETUP_ARGUMENTS=(
@ -62,12 +62,16 @@ function teardown() { _default_teardown ; }
)
_init_with_defaults
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
_run_in_container sed -i -e 's/mailbox Junk/mailbox Spam/' /etc/dovecot/conf.d/15-mailboxes.conf
assert_success
_run_in_container dovecot reload
assert_success
_should_send_spam_message
_should_be_received_by_amavis 'Passed SPAM {RelayedTaggedInbound,Quarantined}'
# Should move delivered spam to Junk folder
_should_receive_spam_at '/var/mail/localhost.localdomain/user1/.Junk/new/'
_should_receive_spam_at '/var/mail/localhost.localdomain/user1/.Spam/new/'
}
# NOTE: Same as test for `CONTAINER3_NAME`, only differing by ENV `MARK_SPAM_AS_READ=1` + `_should_receive_spam_at` location