无法直接从消息主体中直接提取内容以进一步处理。 Sieve不会从身体匹配中填充变量,如${1}
。
RFC明确指出,这不可能。
然而,通过提供(过滤)消息抛出一个单独的应用程序来解决这个问题是可能的,如下所示,将所需的信息放入标题中。
想象的原始消息是:
To: [email protected]
Subject: Test
From: [email protected]
Date: Wed, 25 Oct 2017 16:22:05 +0200
Hi guy, here starts the body
This mail contains a important dynamic address
From: [email protected]
wich has to be matched und processed by sieve
然后你筛看起来是这样的:
require ["copy","variables","vnd.dovecot.filter"];
if header :contains "Subject" "Returned mail" {
filter "bleed_from.py";
if header :matches "Bleeded-From" "*" {
redirect :copy "${1}";
}
}
过滤脚本 “bleed_from.py”:
#!/usr/bin/python
import re
import email
# Read the mail from stdin
parser = email.FeedParser.FeedParser()
mail = None
for line in sys.stdin.readlines():
parser.feed(line)
mail = parser.close()
# Grep the From out of the body and add it to the header
ret = re.findall("From: (.*)", mail.get_payload())
mail.add_header("Bleeded-From", ret[0])
# Return the message
print(mail.as_string())
这是一个非常简单的概念证明,仅适用于没有特殊字符的非多部分消息。否则这个应用程序将崩溃。处理这些字符集会打破这个例子的边界。
可悲这必须是不可能由RFC 5173块腹肌。 6.也让我烦恼。也许构建一个愚蠢的解决办法,通过管道整个消息到一个python脚本专用于单匹配极其比通过返回变量返回结果? Procmail ftw。 – Sprinterfreak