您的位置:首页 > 其它

dovecot editheader 扩展增加自己的邮件头

2016-12-16 00:00 281 查看
.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";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dovecot Sieve