Postfix + Dovecot + Sieve + 转发 + 筛子

Postfix + Dovecot + Sieve + 转发 + 筛子

假设我的域名是 exampleserver.com。我有以下筛选规则:

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

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

[电子邮件保护]希望将邮件转发至[电子邮件保护]。它是通过 /etc/postfix/virtual 完成的,如下所示

[email protected]      [email protected]

转发非常好,但邮件发送至[电子邮件保护]现已转发至[电子邮件保护]这是完全错误的。如何修复它,以便筛选后的消息被重定向到[电子邮件保护]

答案1

Postfix 的别名通过virtual在任何进程之前执行sieve。因此,您必须完全禁用 Postfix 别名,并仅通过 dovecot 的筛选转发消息。有多种模式地址与模式进行比较:

......
# rule:[gmailfwd1]
if header :is "to" "[email protected]"
{
  redirect "[email protected]";
}

# rule:[gmailfwd2]
if header :contains "to" "user"
{
  redirect "[email protected]";
}

# rule:[gmailfwd3]
if header :regex "to" "user.*@exampleserver.com"
{
  redirect "[email protected]";
}
......

header :is表示严格匹配整个收件人地址

header :contains表示地址的任何部分与字符串匹配。

header :regex表示收件人的地址与正则表达式匹配。

无论如何,您必须记住,sieve规则是从上到下检查的,直到匹配到某个规则。因此,您可以按某种顺序重新排列规则,这样可以先捕获更具体的情况,然后再处理其他不需要的规则。

附言

dovecot正如手册中所述https://wiki.dovecot.org/Pigeonhole/Sieve/Examples#Plus_Addressed_mail_filtering都可以这样做:

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 "[email protected]";
  } else {                    /* tag is present*/
    redirect "otheruser+${tag}@exampleserver.com";
  }
}

相关内容