提问人:Janumar 提问时间:5/23/2023 更新时间:6/9/2023 访问量:209
在Dovecot Sieve中从邮件中删除附件需要什么配置?
What configuration is needed to remove attachments from mails in Dovecot Sieve?
问:
如何从dovecot sieve邮件服务器中的邮件中删除特定附件? 我尝试了几种配置,但附件没有被删除。 但它不知道关键字“替换”,我不知道它需要什么。 我正在使用 https://github.com/docker-mailserver/docker-mailserver。 我需要插件或扩展来做到这一点吗? 或者最简单的配置是什么?
我试过了replace :mime :contenttype "text/plain" "This email originally contained an attachment, which has been removed.";
答:
1赞
ernix
6/9/2023
#1
正如我在这里提到的,您必须使用 sieve 插件来过滤传入的消息。Vanilla dovecot 没有特定的 sieve 插件来修改部分多部分 MIME 消息。extprograms
首先,您需要编辑 dovecot 以启用:90-sieve.conf
+vnd.dovecot.filter
...
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.filter
...
sieve_plugins = sieve_extprograms
...
在以下位置指定程序位置:90-sieve-extprograms.conf
sieve_pipe_bin_dir = /etc/dovecot/sieve-pipe
sieve_filter_bin_dir = /etc/dovecot/sieve-filter
sieve_execute_bin_dir = /etc/dovecot/sieve-execute
创建以下目录:
mkdir -p /etc/dovecot/sieve-{pipe,filter,execute}
然后,编写一些过滤器程序来剥离附件,如下所示:
#!/usr/bin/python3
import sys
from email.parser import Parser
from email.policy import default
from email.errors import MessageError
def main():
parser = Parser(policy=default)
stdin = sys.stdin
try:
msg = parser.parse(stdin)
for part in msg.walk():
if part.is_attachment():
part.clear()
part.set_content(
"This email originally contained an attachment, "
"which has been removed."
)
except (TypeError, MessageError):
print(stdin.read()) # fallback
else:
print(msg.as_string())
if __name__ == "__main__":
main()
将此脚本另存为并使其可执行:/etc/dovecot/sieve-filter/strip_attachments.py
chmod +x /etc/dovecot/sieve-filter/strip_attachments.py
筛子脚本应如下所示:
require "mime";
require "vnd.dovecot.filter";
# Executing external programs is SLOW, should be avoided as much as possible.
if header :mime :anychild :param "filename" :matches "Content-Disposition" "*" {
filter "strip_attachments.py";
}
评论