筛滤规则

问题描述 投票:0回答:3

我想在 postfix/dovecot 安装中使用 SIEVE 过滤电子邮件。

假设一封电子邮件的TO字段中有多个收件人。

如果“收件人”字段包含具有特定域名的电子邮件地址,并且同时包含域名与该特定域名不同的电子邮件地址,是否有 SIEVE 规则来匹配电子邮件?

例如,让特定域为“example.com”。

postfix-mta sieve-language
3个回答
1
投票
对我有用的结果如下:

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 邮件过滤语言的专家,但是您是否尝试过使用以下类似的方法,使用

0
投票
address

not

allof
if allof (address :domain :is "To" "example.com", not address :domain :is "To" "example.com") { … }
    

您可以使用
relational
扩展来确保存在与特定域名不同的电子邮件地址。请参阅 RFC5231 的

0
投票

require "relational";

if allof (
    address :domain :is "To" "example.com",
    address :value "ne" :domain "To" "example.com"
) {
    # match
} else {
    # no match
}

© www.soinside.com 2019 - 2024. All rights reserved.