# Path: talon/signature/bruteforce.py
# RE_SIGNATURE = re.compile(r'''
#                (
#                    (?:
#                        ^[\s]*--*[\s]*[a-z \.]*$
#                        |
#                        ^thanks[\s,!]*$
#                        |
#                        ^regards[\s,!]*$
#                        |
#                        ^cheers[\s,!]*$
#                        |
#                        ^best[ a-z]*[\s,!]*$
#                    )
#                    .*
#                )
#                ''', re.I | re.X | re.M | re.S)
# RE_PHONE_SIGNATURE = re.compile(r'''
#                (
#                    (?:
#                        ^sent[ ]{1}from[ ]{1}my[\s,!\w]*$
#                        |
#                        ^sent[ ]from[ ]Mailbox[ ]for[ ]iPhone.*$
#                        |
#                        ^sent[ ]([\S]*[ ])?from[ ]my[ ]BlackBerry.*$
#                        |
#                        ^Enviado[ ]desde[ ]mi[ ]([\S]+[ ]){0,2}BlackBerry.*$
#                    )
#                    .*
#                )
#                ''', re.I | re.X | re.M | re.S)
# RE_SIGNATURE_CANDIDATE = re.compile(r'''
#     (?P<candidate>c+d)[^d]
#     |
#     (?P<candidate>c+d)$
#     |
#     (?P<candidate>c+)
#     |
#     (?P<candidate>d)[^d]
#     |
#     (?P<candidate>d)$
# ''', re.I | re.X | re.M | re.S)
# def extract_signature(msg_body):
# def get_signature_candidate(lines):
# def _mark_candidate_indexes(lines, candidate):
# def _process_marked_candidate_indexes(candidate, markers):


from .. import *
from talon.signature import bruteforce

    msg_body = u"""Blah
Enviado desde mi oficina mÃ³vil BlackBerryÂ® de Telcel"""

    eq_(('Blah', u'Enviado desde mi oficina mÃ³vil BlackBerryÂ® de Telcel'),
        bruteforce.extract_signature(msg_body))


@patch.object(bruteforce, 'get_delimiter', Mock(side_effect=Exception()))
def test_crash_in_extract_signature():
    msg_body = '''Hey!
-roman'''
    eq_((msg_body, None), bruteforce.extract_signature(msg_body))


def test_signature_cant_start_from_first_line():
    msg_body = """Thanks,

Blah

regards

John Doe"""
    eq_(('Thanks,\n\nBlah', 'regards\n\nJohn Doe'),
        bruteforce.extract_signature(msg_body))


@patch.object(bruteforce, 'SIGNATURE_MAX_LINES', 2)
def test_signature_max_lines_ignores_empty_lines():
    msg_body = """Thanks,

# Path: talon/signature/bruteforce.py
# RE_SIGNATURE = re.compile(r'''
#                (
#                    (?:
#                        ^[\s]*--*[\s]*[a-z \.]*$
#                        |
#                        ^thanks[\s,!]*$
#                        |
#                        ^regards[\s,!]*$
#                        |
#                        ^cheers[\s,!]*$
#                        |
#                        ^best[ a-z]*[\s,!]*$
#                    )
#                    .*
#                )
#                ''', re.I | re.X | re.M | re.S)
# RE_PHONE_SIGNATURE = re.compile(r'''
#                (
#                    (?:
#                        ^sent[ ]{1}from[ ]{1}my[\s,!\w]*$
#                        |
#                        ^sent[ ]from[ ]Mailbox[ ]for[ ]iPhone.*$
#                        |
#                        ^sent[ ]([\S]*[ ])?from[ ]my[ ]BlackBerry.*$
#                        |
#                        ^Enviado[ ]desde[ ]mi[ ]([\S]+[ ]){0,2}BlackBerry.*$
#                    )
#                    .*
#                )
#                ''', re.I | re.X | re.M | re.S)
# RE_SIGNATURE_CANDIDATE = re.compile(r'''
#     (?P<candidate>c+d)[^d]
#     |
#     (?P<candidate>c+d)$
#     |
#     (?P<candidate>c+)
#     |
#     (?P<candidate>d)[^d]
#     |
#     (?P<candidate>d)$
# ''', re.I | re.X | re.M | re.S)
# def extract_signature(msg_body):
# def get_signature_candidate(lines):
# def _mark_candidate_indexes(lines, candidate):
# def _process_marked_candidate_indexes(candidate, markers):


# Path: tests/signature/bruteforce_test.py
from .. import *
from talon.signature import bruteforce


    msg_body = u"""Blah
Enviado desde mi oficina mÃ³vil BlackBerryÂ® de Telcel"""

    eq_(('Blah', u'Enviado desde mi oficina mÃ³vil BlackBerryÂ® de Telcel'),
        bruteforce.extract_signature(msg_body))


@patch.object(bruteforce, 'get_delimiter', Mock(side_effect=Exception()))
def test_crash_in_extract_signature():
    msg_body = '''Hey!
-roman'''
    eq_((msg_body, None), bruteforce.extract_signature(msg_body))


def test_signature_cant_start_from_first_line():
    msg_body = """Thanks,

Blah

regards

John Doe"""
    eq_(('Thanks,\n\nBlah', 'regards\n\nJohn Doe'),
        bruteforce.extract_signature(msg_body))


@patch.object(bruteforce, 'SIGNATURE_MAX_LINES', 2)
def test_signature_max_lines_ignores_empty_lines():
    msg_body = """Thanks,

Blah