import re

from .base import RegexDetector
from ..filth import EmailFilth


class EmailDetector(RegexDetector):
    """Use regular expression magic to remove email addresses from dirty
    dirty ``text``. This method also catches email addresses like ``john at
    gmail.com``.
    """
    filth_cls = EmailFilth
    name = 'email'

    # there may be better solutions than this out there and this certainly
    # doesn't do that great of a job with people that spell out the
    # hyphenation of their email address, but its a pretty solid start.
    #
    # adapted from https://gist.github.com/dideler/5219706
    regex = re.compile((
        r"[a-z0-9!#$%&'*+\/=?^_`{|}~-]+"           # start with this character
        r"(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*"    # valid next characters
        r"(@|\sat\s)"                              # @ or at fanciness
        r"(?:"
        r"[a-z0-9]"                                # domain starts like this
        r"(?:[a-z0-9-]*[a-z0-9])?"                 # might have this
        r"(\.|\sdot\s)"                            # . or dot fanciness
        r")+"                                      # repeat as necessary
        r"[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"         # end of domain
    ), re.VERBOSE | re.IGNORECASE)


# class NewEmailDetector(RegexDetector):
#     """Detects email addresses with a wider regex"""
#     filth_cls = EmailFilth
#     name = 'email_v2'
#     regex = re.compile(r'''
#         \w[a-zA-Z0-9!#$%&\'*+‐‑‒–—―/=?^_`{|}~\.]+
#         @
#         \w[a-zA-Z0-9!#$%&\'*+‐‑‒–—―/=?^_`{|}~]+
#         (\.\w[a-zA-Z0-9!#$%&\'*+‐‑‒–—―/=?^_`{|}~]*\w)+
#     ''', re.VERBOSE)

@@ -1268,379 +1268,4 @@
 SE)%0A
-%0A%0A# class NewEmailDetector(RegexDetector):%0A#     %22%22%22Detects email addresses with a wider regex%22%22%22%0A#     filth_cls = EmailFilth%0A#     name = 'email_v2'%0A#     regex = re.compile(r'''%0A#         %5Cw%5Ba-zA-Z0-9!#$%25&%5C'*+%E2%80%90%E2%80%91%E2%80%92%E2%80%93%E2%80%94%E2%80%95/=?%5E_%60%7B%7C%7D~%5C.%5D+%0A#         @%0A#         %5Cw%5Ba-zA-Z0-9!#$%25&%5C'*+%E2%80%90%E2%80%91%E2%80%92%E2%80%93%E2%80%94%E2%80%95/=?%5E_%60%7B%7C%7D~%5D+%0A#         (%5C.%5Cw%5Ba-zA-Z0-9!#$%25&%5C'*+%E2%80%90%E2%80%91%E2%80%92%E2%80%93%E2%80%94%E2%80%95/=?%5E_%60%7B%7C%7D~%5D*%5Cw)+%0A#     ''', re.VERBOSE)%0A

remove new email detector