# 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: talon/signature/extraction.py
# EXTRACTOR = None
# RE_REVERSE_SIGNATURE = re.compile(r'''
# # signature should consists of blocks like this
# (?:
#    # it could end with empty line
#    e*
#    # there could be text lines but no more than 2 in a row
#    (te*){,2}
#    # every block should end with signature line
#    s
# )+
# ''', re.I | re.X | re.M | re.S)
# def is_signature_line(line, sender, classifier):
# def extract(body, sender):
# def _mark_lines(lines, sender):
# def _process_marked_lines(lines, markers):
# 
# Path: talon/signature/extraction.py
# EXTRACTOR = None
# RE_REVERSE_SIGNATURE = re.compile(r'''
# # signature should consists of blocks like this
# (?:
#    # it could end with empty line
#    e*
#    # there could be text lines but no more than 2 in a row
#    (te*){,2}
#    # every block should end with signature line
#    s
# )+
# ''', re.I | re.X | re.M | re.S)
# def is_signature_line(line, sender, classifier):
# def extract(body, sender):
# def _mark_lines(lines, sender):
# def _process_marked_lines(lines, markers):
# 
# Path: talon/signature/learning/dataset.py
# SENDER_SUFFIX = '_sender'
# BODY_SUFFIX = '_body'
# SIGNATURE_ANNOTATION = '#sig#'
# REPLY_ANNOTATION = '#reply#'
# ANNOTATIONS = [SIGNATURE_ANNOTATION, REPLY_ANNOTATION]
#             X = build_pattern(msg, features(sender))
#                 X = build_pattern(line, features(sender))
# def is_sender_filename(filename):
# def build_sender_filename(msg_filename):
# def parse_msg_sender(filename, sender_known=True):
# def build_detection_class(folder, dataset_filename,
#                           label, sender_known=True):
# def build_detection_dataset(folder, dataset_filename,
#                             sender_known=True):
# def build_extraction_dataset(folder, dataset_filename,
#                              sender_known=True):


import os
    import sys
from six.moves import range
from talon.signature import bruteforce, extraction, extract
from talon.signature import extraction as e
from talon.signature.learning import dataset
from .. import *
Do you still need a DJ for your wedding? I've included a video demo of one of our DJs available for your wedding date.

DJ Doe 
http://example.com
Password: SUPERPASSWORD

Would you like to check out more?


At your service,

John Smith
Doe Inc
555-531-7967"""

    sig = """John Smith
Doe Inc
555-531-7967"""

    eq_(sig, extract(msg_body, 'Doe')[1])


def test_over_2_text_lines_after_signature():
    body = """Blah

    Bob,
    If there are more than
    2 non signature lines in the end
    It's not signature
    """

# 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: talon/signature/extraction.py
# EXTRACTOR = None
# RE_REVERSE_SIGNATURE = re.compile(r'''
# # signature should consists of blocks like this
# (?:
#    # it could end with empty line
#    e*
#    # there could be text lines but no more than 2 in a row
#    (te*){,2}
#    # every block should end with signature line
#    s
# )+
# ''', re.I | re.X | re.M | re.S)
# def is_signature_line(line, sender, classifier):
# def extract(body, sender):
# def _mark_lines(lines, sender):
# def _process_marked_lines(lines, markers):
# 
# Path: talon/signature/extraction.py
# EXTRACTOR = None
# RE_REVERSE_SIGNATURE = re.compile(r'''
# # signature should consists of blocks like this
# (?:
#    # it could end with empty line
#    e*
#    # there could be text lines but no more than 2 in a row
#    (te*){,2}
#    # every block should end with signature line
#    s
# )+
# ''', re.I | re.X | re.M | re.S)
# def is_signature_line(line, sender, classifier):
# def extract(body, sender):
# def _mark_lines(lines, sender):
# def _process_marked_lines(lines, markers):
# 
# Path: talon/signature/learning/dataset.py
# SENDER_SUFFIX = '_sender'
# BODY_SUFFIX = '_body'
# SIGNATURE_ANNOTATION = '#sig#'
# REPLY_ANNOTATION = '#reply#'
# ANNOTATIONS = [SIGNATURE_ANNOTATION, REPLY_ANNOTATION]
#             X = build_pattern(msg, features(sender))
#                 X = build_pattern(line, features(sender))
# def is_sender_filename(filename):
# def build_sender_filename(msg_filename):
# def parse_msg_sender(filename, sender_known=True):
# def build_detection_class(folder, dataset_filename,
#                           label, sender_known=True):
# def build_detection_dataset(folder, dataset_filename,
#                             sender_known=True):
# def build_extraction_dataset(folder, dataset_filename,
#                              sender_known=True):


# Path: tests/signature/extraction_test.py
import os
    import sys
from six.moves import range
from talon.signature import bruteforce, extraction, extract
from talon.signature import extraction as e
from talon.signature.learning import dataset
from .. import *

Do you still need a DJ for your wedding? I've included a video demo of one of our DJs available for your wedding date.

DJ Doe 
http://example.com
Password: SUPERPASSWORD

Would you like to check out more?


At your service,

John Smith
Doe Inc
555-531-7967"""

    sig = """John Smith
Doe Inc
555-531-7967"""

    eq_(sig, extract(msg_body, 'Doe')[1])


def test_over_2_text_lines_after_signature():
    body = """Blah

    Bob,
    If there are more than
    2 non signature lines in the end
    It's not signature
    """

    text, extracted_signature = extract(body, "Bob")