# Path: talon/utils.py
# def get_delimiter(msg_body):
#     delimiter = RE_DELIMITER.search(msg_body)
#     if delimiter:
#         delimiter = delimiter.group()
#     else:
#         delimiter = '\n'
# 
#     return delimiter
# 
# def html_tree_to_text(tree):
#     for style in CSSSelector('style')(tree):
#         style.getparent().remove(style)
# 
#     for c in tree.xpath('//comment()'):
#         parent = c.getparent()
# 
#         # comment with no parent does not impact produced text
#         if parent is None:
#             continue
# 
#         parent.remove(c)
# 
#     text = ""
#     for el in tree.iter():
#         el_text = (el.text or '') + (el.tail or '')
#         if len(el_text) > 1:
#             if el.tag in _BLOCKTAGS + _HARDBREAKS:
#                 text += "\n"
#             if el.tag == 'li':
#                 text += "  * "
#             text += el_text.strip() + " "
# 
#             # add href to the output
#             href = el.attrib.get('href')
#             if href:
#                 text += "(%s) " % href
# 
#         if (el.tag in _HARDBREAKS and text and
#             not text.endswith("\n") and not el_text):
#             text += "\n"
# 
#     retval = _rm_excessive_newlines(text)
#     return _encode_utf8(retval)
# 
# def html_document_fromstring(s):
#     """Parse html tree from string. Return None if the string can't be parsed.
#     """
#     if isinstance(s, six.text_type):
#         s = s.encode('utf8')
#     try:
#         return html5parser.document_fromstring(s, parser=_html5lib_parser())
#     except Exception:
#         pass
# 
# Path: talon/html_quotations.py
# CHECKPOINT_PREFIX = '#!%!'
# CHECKPOINT_SUFFIX = '!%!#'
# CHECKPOINT_PATTERN = re.compile(CHECKPOINT_PREFIX + '\d+' + CHECKPOINT_SUFFIX)
# QUOTE_IDS = ['OLK_SRC_BODY_SECTION']
# RE_FWD = re.compile("^[-]+[ ]*Forwarded message[ ]*[-]+$", re.I | re.M)
# def add_checkpoint(html_note, counter):
# def delete_quotation_tags(html_note, counter, quotation_checkpoints):
# def cut_gmail_quote(html_message):
# def cut_microsoft_quote(html_message):
# def cut_by_id(html_message):
# def cut_blockquote(html_message):
# def cut_from_block(html_message):
# def cut_zimbra_quote(html_message):


import regex as re
import logging
import six
from copy import deepcopy
from lxml import html, etree
from talon.utils import (get_delimiter, html_tree_to_text,
                         html_document_fromstring)
from talon import html_quotations
from six.moves import range
        return msg_body

    return result


def extract_from_html_tree(html_tree):
    """
    Extract not quoted message from provided parsed html tree using tags and
    plain text algorithm.

    Cut out the 'blockquote', 'gmail_quote' tags.
    Cut Microsoft quotations.

    Then use plain text algorithm to cut out splitter or
    leftover quotation.
    This works by adding checkpoint text to all html tags,
    then converting html to text,
    then extracting quotations from text,
    then checking deleted checkpoints,
    then deleting necessary tags.
    """
    cut_quotations = (html_quotations.cut_gmail_quote(html_tree) or
                      html_quotations.cut_zimbra_quote(html_tree) or
                      html_quotations.cut_blockquote(html_tree) or
                      html_quotations.cut_microsoft_quote(html_tree) or
                      html_quotations.cut_by_id(html_tree) or
                      html_quotations.cut_from_block(html_tree)
                      )
    html_tree_copy = deepcopy(html_tree)


# Path: talon/utils.py
# def get_delimiter(msg_body):
#     delimiter = RE_DELIMITER.search(msg_body)
#     if delimiter:
#         delimiter = delimiter.group()
#     else:
#         delimiter = '\n'
# 
#     return delimiter
# 
# def html_tree_to_text(tree):
#     for style in CSSSelector('style')(tree):
#         style.getparent().remove(style)
# 
#     for c in tree.xpath('//comment()'):
#         parent = c.getparent()
# 
#         # comment with no parent does not impact produced text
#         if parent is None:
#             continue
# 
#         parent.remove(c)
# 
#     text = ""
#     for el in tree.iter():
#         el_text = (el.text or '') + (el.tail or '')
#         if len(el_text) > 1:
#             if el.tag in _BLOCKTAGS + _HARDBREAKS:
#                 text += "\n"
#             if el.tag == 'li':
#                 text += "  * "
#             text += el_text.strip() + " "
# 
#             # add href to the output
#             href = el.attrib.get('href')
#             if href:
#                 text += "(%s) " % href
# 
#         if (el.tag in _HARDBREAKS and text and
#             not text.endswith("\n") and not el_text):
#             text += "\n"
# 
#     retval = _rm_excessive_newlines(text)
#     return _encode_utf8(retval)
# 
# def html_document_fromstring(s):
#     """Parse html tree from string. Return None if the string can't be parsed.
#     """
#     if isinstance(s, six.text_type):
#         s = s.encode('utf8')
#     try:
#         return html5parser.document_fromstring(s, parser=_html5lib_parser())
#     except Exception:
#         pass
# 
# Path: talon/html_quotations.py
# CHECKPOINT_PREFIX = '#!%!'
# CHECKPOINT_SUFFIX = '!%!#'
# CHECKPOINT_PATTERN = re.compile(CHECKPOINT_PREFIX + '\d+' + CHECKPOINT_SUFFIX)
# QUOTE_IDS = ['OLK_SRC_BODY_SECTION']
# RE_FWD = re.compile("^[-]+[ ]*Forwarded message[ ]*[-]+$", re.I | re.M)
# def add_checkpoint(html_note, counter):
# def delete_quotation_tags(html_note, counter, quotation_checkpoints):
# def cut_gmail_quote(html_message):
# def cut_microsoft_quote(html_message):
# def cut_by_id(html_message):
# def cut_blockquote(html_message):
# def cut_from_block(html_message):
# def cut_zimbra_quote(html_message):


# Path: talon/quotations.py
import regex as re
import logging
import six
from copy import deepcopy
from lxml import html, etree
from talon.utils import (get_delimiter, html_tree_to_text,
                         html_document_fromstring)
from talon import html_quotations
from six.moves import range

        return msg_body

    return result


def extract_from_html_tree(html_tree):
    """
    Extract not quoted message from provided parsed html tree using tags and
    plain text algorithm.

    Cut out the 'blockquote', 'gmail_quote' tags.
    Cut Microsoft quotations.

    Then use plain text algorithm to cut out splitter or
    leftover quotation.
    This works by adding checkpoint text to all html tags,
    then converting html to text,
    then extracting quotations from text,
    then checking deleted checkpoints,
    then deleting necessary tags.
    """
    cut_quotations = (html_quotations.cut_gmail_quote(html_tree) or
                      html_quotations.cut_zimbra_quote(html_tree) or
                      html_quotations.cut_blockquote(html_tree) or
                      html_quotations.cut_microsoft_quote(html_tree) or
                      html_quotations.cut_by_id(html_tree) or
                      html_quotations.cut_from_block(html_tree)
                      )
    html_tree_copy = deepcopy(html_tree)


    number_of_checkpoints = html_quotations.add_checkpoint(html_tree, 0)