Пример #1
0
def test_ok_ham34():
    tmp = maketemp()
    mockqsf = os.path.join(tmp, 'mock-qsf')
    writeFile(
        mockqsf,
        """\
#!/bin/sh
test "$#" = "2"
test "$1" = "--test"
test "$2" = "--rating"
test "$(cat)" = "fake-email"
echo 34
exit 0
""")
    os.chmod(mockqsf, 0755)
    message = os.path.join(tmp, 'fake-email')
    writeFile(
        message,
        'fake email',
        )
    got = spamminess.spamminess(
        path=message,
        _qsf=mockqsf,
        )
    eq(got, 34)
Пример #2
0
def test_process_newline():
    # line wrapping in the config file can cause extra whitespace in
    # the value; this affects all rules but testing with this one
    tmp = maketemp()
    depot = os.path.join(tmp, 'depot')
    os.mkdir(depot)
    incoming_path = os.path.join(depot, 'incoming')
    maildir.create(incoming_path)
    MAILBODY = """\
From: bar
To: foo
List-ID: Users of FOO <FOO-users.lists.example.COM>
Subject: foo

foo
"""
    writeFile(
        os.path.join(
            incoming_path,
            'new',
            '1202936960.V801I880d5M358047.foo',
            ),
        MAILBODY,
        )
    cfg = ConfigParser.RawConfigParser()
    cfg.add_section('depot %s' % depot)
    cfg.add_section('rules incoming')
    cfg.set(
        'rules incoming',
        'angle-bracket-header liST-id foo-USERS.lists.EXAMPLE.com',
        '\nlist.foo\n',
        )
    incoming.process(cfg)
    folder = 'list.foo'
    eq(
        sorted(os.listdir(depot)),
        sorted(['incoming', folder]),
        )
    eq(
        list(maildir.walk(os.path.join(depot, 'incoming'))),
        [],
        )
    path = os.path.join(depot, folder)
    eq(
        list(maildir.walk(path)),
        [
            'new/1202936960.V801I880d5M358047.foo',
            ],
        )
    eq(
        readFile(os.path.join(
                path,
                'new',
                '1202936960.V801I880d5M358047.foo',
                )),
        MAILBODY,
        )
Пример #3
0
def test_process_post_colon():
    # bah ConfigParser won't let the config keys contain either ":" or "="
    tmp = maketemp()
    depot = os.path.join(tmp, 'depot')
    os.mkdir(depot)
    incoming_path = os.path.join(depot, 'incoming')
    maildir.create(incoming_path)
    MAILBODY = """\
From: bar
To: foo
List-Post: <mailto:[email protected]>
Subject: foo

foo
"""
    writeFile(
        os.path.join(
            incoming_path,
            'new',
            '1202936960.V801I880d5M358047.foo',
            ),
        MAILBODY,
        )
    cfg = ConfigParser.RawConfigParser()
    cfg.add_section('depot %s' % depot)
    cfg.add_section('rules incoming')
    cfg.set(
        'rules incoming',
        'angle-bracket-header liST-post mailto%(colon)[email protected]',
        'list.foo',
        )
    incoming.process(cfg)
    folder = 'list.foo'
    eq(
        sorted(os.listdir(depot)),
        sorted(['incoming', folder]),
        )
    eq(
        list(maildir.walk(os.path.join(depot, 'incoming'))),
        [],
        )
    path = os.path.join(depot, folder)
    eq(
        list(maildir.walk(path)),
        [
            'new/1202936960.V801I880d5M358047.foo',
            ],
        )
    eq(
        readFile(os.path.join(
                path,
                'new',
                '1202936960.V801I880d5M358047.foo',
                )),
        MAILBODY,
        )
Пример #4
0
def test_walk_simple_cur():
    tmp = maketemp()
    os.mkdir(os.path.join(tmp, 'new'))
    os.mkdir(os.path.join(tmp, 'cur'))
    writeFile(
        os.path.join(tmp, 'cur', '1202936960.V801I880d5M358047.foo:2,'),
        'fake email',
        )
    g = maildir.walk(tmp)
    eq(g.next(), os.path.join('cur', '1202936960.V801I880d5M358047.foo:2,'))
    assert_raises(StopIteration, g.next)
Пример #5
0
def test_fail():
    tmp = maketemp()
    mockqsf = os.path.join(tmp, 'mock-qsf')
    writeFile(
        mockqsf,
        """\
#!/bin/sh
exit 42
""")
    os.chmod(mockqsf, 0755)
    message = os.path.join(tmp, 'fake-email')
    writeFile(
        message,
        'fake email',
        )
    e = assert_raises(
        RuntimeError,
        spamminess.spamminess,
        path=message,
        _qsf=mockqsf,
        )
    eq(str(e), 'qsf failed: 42')
Пример #6
0
def test_process_spam():
    tmp = maketemp()
    depot = os.path.join(tmp, 'depot')
    os.mkdir(depot)
    incoming_path = os.path.join(depot, 'incoming')
    maildir.create(incoming_path)
    writeFile(
        os.path.join(
            incoming_path,
            'new',
            '1202936960.V801I880d5M358047.foo',
            ),
        'fake email',
        )
    mockqsf = os.path.join(tmp, 'mock-qsf')
    writeFile(
        mockqsf,
        """\
#!/bin/sh
test "$#" = "2"
test "$1" = "--test"
test "$2" = "--rating"
test "$(cat)" = "fake email"
echo 97
exit 1
""")
    os.chmod(mockqsf, 0755)
    cfg = ConfigParser.RawConfigParser()
    cfg.add_section('qsf')
    cfg.set('qsf', 'path',  mockqsf)
    cfg.add_section('depot %s' % depot)
    cfg.add_section('rules incoming')
    cfg.set(
        'rules incoming',
        'spam all',
        'INBOX.spam.%(spamminess_percentage_rounded_5)d',
        )
    incoming.process(cfg)
    folder = 'INBOX.spam.95'
    eq(
        sorted(os.listdir(depot)),
        sorted(['incoming', folder]),
        )
    eq(
        list(maildir.walk(os.path.join(depot, 'incoming'))),
        [],
        )
    path = os.path.join(depot, folder)
    eq(
        list(maildir.walk(path)),
        [
            'new/1202936960.V801I880d5M358047.foo',
            ],
        )
    eq(
        readFile(os.path.join(
                path,
                'new',
                '1202936960.V801I880d5M358047.foo',
                )),
        'fake email',
        )