客户端筛选库
sievelib的Python项目详细描述
用python编写的客户端sieve和managesieve库。
安装
从pypi安装sievelib:
pip install sievelib
从git安装sievelib:
git clone git@github.com:tonioo/sievelib.git cd sievelib python ./setup.py install
筛子工具
支持的内容
目前,提供的解析器支持大多数功能 在RFC中描述。唯一的例外是 2.4.2.4。使用“编码字符”编码字符 支持。
还支持以下扩展:
扩展解析器
可以通过添加新的受支持的 命令。例如:
import sievelib class MyCommand(sievelib.commands.ActionCommand): args_definition = [ {"name": "testtag", "type": ["tag"], "write_tag": True, "values": [":testtag"], "extra_arg": {"type": "number", "required": False}, "required": False}, {"name": "recipients", "type": ["string", "stringlist"], "required": True} ] sievelib.commands.add_commands(MyCommand)
基本用法
解析器可以从命令行使用:
$ cd sievelib $ python parser.py test.sieve Syntax OK $
或者可以从python环境(或脚本/模块)中使用:
>>> from sievelib.parser import Parser >>> p = Parser() >>> p.parse('require ["fileinto"];') True >>> p.dump() require (type: control) ["fileinto"] >>> >>> p.parse('require ["fileinto"]') False >>> p.error 'line 1: parsing error: end of script reached while semicolon expected' >>>
简单过滤器创建
有些高级类提供了factory模块,它们 简化筛选规则的生成:
>>> from sievelib.factory import FiltersSet >>> fs = FiltersSet("test") >>> fs.addfilter("rule1", ... [("Sender", ":is", "toto@toto.com"),], ... [("fileinto", "Toto"),]) >>> fs.tosieve() require ["fileinto"]; # Filter: rule1 if anyof (header :is "Sender" "toto@toto.com") { fileinto "Toto"; } >>>
源代码中提供了其他文档。
管理筛选工具
支持的内容
支持所有强制命令。RENAME扩展名是 支持,对于不支持 它。
对于AUTHENTICATE命令,支持的机制是DIGEST-MD5, PLAIN和LOGIN。
基本用法
managesieve客户端打算从另一个python中使用 应用程序(没有提供任何shell):
>>> from sievelib.managesieve import Client >>> c = Client("server.example.com") >>> c.connect("user", "password", starttls=False, authmech="DIGEST-MD5") True >>> c.listscripts() ("active_script", ["script1", "script2"]) >>> c.setactive("script1") True >>> c.havespace("script3", 45) True >>>
源代码中提供了其他文档。