Giter Site home page Giter Site logo

sievelib's Introduction

sievelib

workflow codecov latest-version

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 [email protected]: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:

The following extensions are partially supported:

  • Date and Index (RFC 5260)
  • Checking Mailbox Status and Accessing Mailbox Metadata (RFC 5490)

Extending the parser

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

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)

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", "[email protected]"),],
...              [("fileinto", "Toto"),])
>>> fs.tosieve()
require ["fileinto"];

# Filter: rule1
if anyof (header :is "Sender" "[email protected]") {
    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, LOGIN and OAUTHBEARER.

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.

sievelib's People

Contributors

tonioo avatar derula avatar mortal avatar bsdlp avatar ntninja avatar nomad2k avatar dveeden avatar fernand0 avatar icgood avatar cuonglm avatar luanp avatar fladi avatar encukou avatar radiac avatar sengaya avatar dhke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.