Skip to main content

Client-side SIEVE library

Project description

travis Latest version on Pypi Downloads from Pypi

Client-side Sieve and Managesieve library written in Python.

  • Sieve : An Email Filtering Language (RFC 5228)

  • ManageSieve : A Protocol for Remotely Managing Sieve Scripts (RFC 5804)

Installation

To install sievelib from PyPI:

pip install sievelib

To install sievelib from git:

git clone git@github.com:tonioo/sievelib.git
cd sievelib
python ./setup.py install

Sieve tools

What is supported

Currently, the provided parser supports most of the functionalities described in the RFC. The only exception concerns section 2.4.2.4. Encoding Characters Using “encoded-character” which is not supported.

The following extensions are also supported:

Extending the parser

It is possible to extend the parser by adding new supported commands. For example:

import sievelib

def 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)

Basic usage

The parser can either be used from the command-line:

$ cd sievelib
$ python parser.py test.sieve
Syntax OK
$

Or can be used from a python environment (or script/module):

>>> 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'
>>>

Simple filters creation

Some high-level classes are provided with the factory module, they make the generation of Sieve rules easier:

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

Additional documentation is available within source code.

ManageSieve tools

What is supported

All mandatory commands are supported. The RENAME extension is supported, with a simulated behaviour for server that do not support it.

For the AUTHENTICATE command, supported mechanisms are DIGEST-MD5, PLAIN and LOGIN.

Basic usage

The ManageSieve client is intended to be used from another python application (there isn’t any shell provided):

>>> 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
>>>

Additional documentation is available with source code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sievelib-0.9.2.tar.gz (25.7 kB view details)

Uploaded Source

File details

Details for the file sievelib-0.9.2.tar.gz.

File metadata

  • Download URL: sievelib-0.9.2.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sievelib-0.9.2.tar.gz
Algorithm Hash digest
SHA256 71abebdc069a2597f2d0354348c1afc967ec6bebe0d6e7228489d8efea56060b
MD5 535c325030ab629281cf3cde0b8c9266
BLAKE2b-256 5dd587eadeec74f04e3a86c57a7e64ac9dfc4ddae439acf9456117a7b81a2c0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page