Postfix' aliasing via virtual
is performed before any sieve
proceeding. Therefore you have to disable postfix aliasing completely and forward messages by dovecot's sieve only. There is number of modes address is compared against the pattern:
......
# rule:[gmailfwd1]
if header :is "to" "user@exampleserver.com"
{
redirect "user@gmail.com";
}
# rule:[gmailfwd2]
if header :contains "to" "user"
{
redirect "otheruser@gmail.com";
}
# rule:[gmailfwd3]
if header :regex "to" "user.*@exampleserver.com"
{
redirect "otheruser@gmail.com";
}
......
header :is
means the strict matching the whole recipient's address
header :contains
means that any part of address is matching the string.
header :regex
means that recipient's address is matching the regular expression.
Anyway you have to remember that sieve
rules are checked from the top to the bottom until some rule will be matched. So you can reorder rules in some sequence where more specific cases will be catched and proceeded before any other unwanted rules.
P.S.
As stated in the dovecot
's manual https://wiki.dovecot.org/Pigeonhole/Sieve/Examples#Plus_Addressed_mail_filtering all can be made this way:
require ["variables", "fileinto", "subaddress"];
if header :is :user "to" "someuser" {
if header :matches :detail "to" "*" {
set "tag" "${1}"; /* extract "Something" into var "tag" */
}
if string :is "${tag}" "" { /* empty/no tag */
redirect "user@gmail.com";
} else { /* tag is present*/
redirect "otheruser+${tag}@exampleserver.com";
}
}