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

.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";
    }

转载于:https://my.oschina.net/hxily/blog/807277

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值