0

Let's suppose my domain at exampleserver.com. I have following sieve rule:

require ["fileinto", "subaddress", "mailbox", "variables"];

if address :detail :matches "to" "*" {
set "folder" "${1}"; 
fileinto :create "INBOX.${folder}";
}

user@exampleserver.com wants mail forwarded to xxxxx@gmail.com. It is done via /etc/postfix/virtual as

user@exampleserver.com      xxxxx@gmail.com

The forwarding is perfectly good, but mail sent to user+Something@exampleserver.com is now forwarded to user+Something@gmail.com which is utterly wrong. How to fix it so sieved messages get redirected to xxxxx+Something@exampleserver.com?

0

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";
  }
}
  • That yields invalid regular expression 'user(+.*)@exampleserver.com' for regex match: invalid preceding regular expression. – Flat Spaztech Jun 14 '18 at 14:32
  • Have you added the plugin? require ["fileinto","regex"....]; – Kondybas Jun 14 '18 at 14:39
  • Yes:require ["regex", "fileinto", "subaddress", "mailbox", "variables"]; – Flat Spaztech Jun 14 '18 at 14:41
  • I can't test it right now but it look like special meaning of + sign. Try to escape it by backslash (\+.*) – Kondybas Jun 14 '18 at 14:43
  • Didn't work. I tried to escape the parentheses as well but the result is still the same. If I use user(\\+.*)exampleserver.com (double backslashes) the sievec doesn't give errors. – Flat Spaztech Jun 14 '18 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.