.dovecot 规则 相应的扩展 参考 http://wiki2.dovecot.org/Pigeonhole/Sieve
里面有说明 editheader 默认没有启用
首先 90-sieve.conf 里面要启用editheader
sieve_extensions = +editheader
# 邮件内容包含 Content-Disposition: attachment 时增加X-Has-Attach: yes否则no
# 需要考虑的是邮件内容为明文则包含该内容时会命中该规则,如已有X-Has-Attach 也会再添加一次,可以判断修改规则
require ["body","editheader"];
if body :raw :contains "Content-Disposition: attachment"
{
addheader "X-Has-Attach" "yes";
}
else
{
addheader "X-Has-Attach" "no";
}
另一个稍完整一点的,通过mime来判断
# 会先判断是否有X-Has-Attach,有则先删除再增加
require [ "mime","editheader"];
if header :mime :param "filename" :matches ["Content-Type", "Content-Disposition"] ["*.*"]
{
if header :contains "X-Has-Attach" "yes"
{
deleteheader :index 1 "X-Has-Attach";
addheader "X-Has-Attach" "yes";
}
else
{
addheader "X-Has-Attach" "yes";
}
}
else
{
if header :contains "X-Has-Attach" "no"
{
deleteheader :index 1 "X-Has-Attach";
addheader "X-Has-Attach" "no";
}
else
{
addheader "X-Has-Attach" "no";
}
}
测试了下,通过不同的客户端的,会有误判的情况,根据上面文档改成下面的准确性要高一些,目前测试还未出现误判
require ["editheader", "mime"];
#if allof (
# header :mime :anychild :contenttype "Content-Type" "application/octet-stream",
# header :mime :anychild :contenttype "Content-Disposition" "attachment")
if header :mime :anychild :contenttype "Content-Disposition" "attachment"
{
addheader "X-Has-Attach" "yes";
}
else
{
addheader "X-Has-Attach" "no";
}