Sifter3 is a Python 3 implementation of the Sieve email filter language (RFC 5228)
pip install sifter3
import email
import sifter.parser
rules = sifter.parser.parse_file(open('my_rules.sieve'))
msg = email.message_from_file(open('an_email_to_me.eml'))
msg_actions = rules.evaluate(msg)
In the above example, msg_actions
is a list of actions to apply to the
email message. Each action is a tuple consisting of the action name and
action-specific arguments. It is up to the caller to manipulate the
message and message store based on the actions returned.
The output of the command line tool can be parsed as json.
$ sifter tests/evaluation_1.rules tests/evaluation_1.msg
[['redirect', 'acm@example.com']]
email.message
implements header comparisons
the same way as the sieve spec