The Issue:
Mailcow’s default tagging rule checks for header :contains “X-Moo-Tag” “YES”. When an email is routed through a Mailcow alias to a tagged address, Postfix expands the alias after Rspamd processes the message. As a result, the X-Moo-Tag header is never added, and the default Sieve rule skips folder sorting—dropping the email directly into the main INBOX.
The Solution:
Add a fallback elsif condition in your global Sieve postfilter (data/conf/dovecot/sieve_after or Sieve UI). It detects if an email passed through an alias by comparing X-Original-To with Delivered-To. If they differ and Delivered-To contains a +tag, it extracts the tag and auto-sorts the email into its respective subfolder.
if allof (
envelope :detail :matches "to" "*",
header :contains "X-Moo-Tag" "YES"
) {
set :lower :upperfirst "tag" "${1}";
if mailboxexists "INBOX/${1}" {
fileinto "INBOX/${1}";
} else {
fileinto :create "INBOX/${tag}";
}
}
elsif allof (
not header :is "X-Original-To" "${Delivered-To}",
header :matches "Delivered-To" "*+*@*"
) {
# ${1} = localpart (e.g. alice)
# ${2} = tag (e.g. sometag)
# ${3} = domain (e.g. example.com)
set :lower "tag" "${2}";
if mailboxexists "INBOX/${tag}" {
fileinto "INBOX/${tag}";
} else {
fileinto :create "INBOX/${tag}";
}
}