summaryrefslogtreecommitdiffstats
path: root/tests/unit/test-008-sievelib.py
blob: 9226ad6b32dab441d0da0d9c40a17dcf1e0ebe13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys
import unittest

sieve_scripts = [

# You're average vacation script.
"""
require [ "vacation" ];

if anyof (true) {
    vacation :days 1 :subject "Out of Office" "I'm out of the office";
}
""",

# A non-any/allof if (control) header (test) structure
"""
require ["fileinto"];

if header :contains "X-Spam-Flag" "YES" {
    fileinto "Spam";
    stop;
}
""",

# The same, all on the same line
"""
require ["fileinto"];

if header :contains "X-Spam-Flag" "YES" { fileinto "Spam"; stop; }
""",

# A little more of a complex list of tests
"""
require ["fileinto"];

if allof (header :contains "X-Mailer" "OTRS", header :contains "X-Powered-By" "OTRS", header :contains "Organization" "Example, Inc.") { fileinto "OTRS"; stop; }
""",

    ]


class TestSievelib(unittest.TestCase):

    def test_001_import_sievelib(self):
        from sievelib.parser import Parser

    def test_002_parse_tests(self):
        from sievelib.parser import Parser
        sieve_parser = Parser(debug=True)

        i = 0
        for sieve_str in sieve_scripts:
            i += 1
            result = sieve_parser.parse(sieve_str)
            if not result:
                print "Sieve line: %r" % (sieve_parser.lexer.text.split('\n')[(sieve_parser.lexer.text[:sieve_parser.lexer.pos].count('\n'))])
                raise Exception("Failed parsing Sieve script #%d: %s" % (i, sieve_parser.error))