我想在 postfix/dovecot 安装中使用 SIEVE 过滤电子邮件。
假设一封电子邮件的TO字段中有多个收件人。
如果“收件人”字段包含具有特定域名的电子邮件地址,并且同时包含域名与该特定域名不同的电子邮件地址,是否有 SIEVE 规则来匹配电子邮件?
例如,让特定域为“example.com”。
TO: [email protected], [email protected]
-> 匹配
TO: [email protected], [email protected]
-> 不匹配(因为没有 example.com 的地址)
TO: [email protected]
-> 不匹配(因为没有与 example.com 不同的地址)
TO: [email protected], [email protected]
-> 不匹配(因为没有与 example.com 不同的地址)
TO: [email protected]
-> 不匹配
require "regex";
if allof ( address :domain :is "To" "example.com",
header :regex "to" "@[^(example.com)]+"
) { ... } else { ... }
因此,您可以将“与 example.com 不同的某些域”与语句匹配 header :regex "to" "@[^(example.com)]+"
旁注
对卡斯帕建议的一些想法(对我来说不起作用)。事实证明
if address :domain :is "To" "example.com" {
如果“收件人”字段中的“任意”电子邮件包含 example.com,则匹配。
not
-语句只是否定了这个结果。即
if not address :domain :is "To" "example.com" {
如果“收件人”字段中的电子邮件中“无”包含 example.com,则匹配。因此,将 allof
内的两个语句组合起来 never
[编辑:以下规则不起作用,请参阅其他答案以了解原因。] 我不是 Sieve 邮件过滤语言的专家,但是您是否尝试过使用以下类似的方法,使用
address
、 和 allof
?
if allof (address :domain :is "To" "example.com", not address :domain :is "To" "example.com") {
…
}
您可以使用
relational
扩展来确保存在与特定域名不同的电子邮件地址。请参阅 RFC5231 的