예제 #1
0
def extract(body, sender):
    """Strips signature from the body of the message.

    Returns stripped body and signature as a tuple.
    If no signature is found the corresponding returned value is None.
    """
    try:
        delimiter = get_delimiter(body)

        body = body.strip()

        if has_signature(body, sender):
            lines = body.splitlines()

            markers = _mark_lines(lines, sender)
            text, signature = _process_marked_lines(lines, markers)

            if signature:
                text = delimiter.join(text)
                if text.strip():
                    return (text, delimiter.join(signature))
    except Exception:
        log.exception('ERROR when extracting signature with classifiers')

    return (body, None)
예제 #2
0
def extract(body, sender):
    """Strips signature from the body of the message.

    Returns stripped body and signature as a tuple.
    If no signature is found the corresponding returned value is None.
    """
    try:
        delimiter = get_delimiter(body)

        body = body.strip()

        if has_signature(body, sender):
            lines = body.splitlines()

            markers = _mark_lines(lines, sender)
            text, signature = _process_marked_lines(lines, markers)

            if signature:
                text = delimiter.join(text)
                if text.strip():
                    return (text, delimiter.join(signature))
    except Exception:
        log.exception('ERROR when extracting signature with classifiers')

    return (body, None)
예제 #3
0
def test_has_signature():
    ok_(h.has_signature("sender", "*****@*****.**"))
    ok_(h.has_signature("http://www.example.com\n555 555 5555", "*****@*****.**"))
    ok_(h.has_signature("http://www.example.com\[email protected]", "*****@*****.**"))
    assert_false(h.has_signature("http://www.example.com/555-555-5555", "*****@*****.**"))
    long_line = "".join(["q" for e in range(28)])
    assert_false(h.has_signature(long_line + " sender", "*****@*****.**"))
    # wont crash on an empty string
    assert_false(h.has_signature("", ""))
    # dont consider empty strings when analysing signature
    with patch.object(h, "SIGNATURE_MAX_LINES", 1):
        ok_("sender\n\n", "*****@*****.**")
예제 #4
0
def test_has_signature():
    ok_(h.has_signature('sender', '*****@*****.**'))
    ok_(h.has_signature('http://www.example.com\n555 555 5555',
                        '*****@*****.**'))
    ok_(h.has_signature('http://www.example.com\[email protected]',
                        '*****@*****.**'))
    assert_false(h.has_signature('http://www.example.com/555-555-5555',
                                 '*****@*****.**'))
    long_line = ''.join(['q' for e in range(28)])
    assert_false(h.has_signature(long_line + ' sender', '*****@*****.**'))
    # wont crash on an empty string
    assert_false(h.has_signature('', ''))
    # dont consider empty strings when analysing signature
    with patch.object(h, 'SIGNATURE_MAX_LINES', 1):
        ok_('sender\n\n', '*****@*****.**')
예제 #5
0
def test_has_signature():
    ok_(h.has_signature('sender', '*****@*****.**'))
    ok_(h.has_signature('http://www.example.com\n555 555 5555',
                        '*****@*****.**'))
    ok_(h.has_signature('http://www.example.com\[email protected]',
                        '*****@*****.**'))
    assert_false(h.has_signature('http://www.example.com/555-555-5555',
                                 '*****@*****.**'))
    long_line = ''.join(['q' for e in xrange(28)])
    assert_false(h.has_signature(long_line + ' sender', '*****@*****.**'))
    # wont crash on an empty string
    assert_false(h.has_signature('', ''))
    # dont consider empty strings when analysing signature
    with patch.object(h, 'SIGNATURE_MAX_LINES', 1):
        ok_('sender\n\n', '*****@*****.**')