How to use the pyisemail.diagnosis.RFC5321Diagnosis function in pyIsEmail

To help you get started, we’ve selected a few pyIsEmail examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github michaelherold / pyIsEmail / tests / validators / __init__.py View on Github external
tag --- the tag string to look up

    """

    if tag == "ERR":
        d_class = InvalidDiagnosis
    elif tag == "DNSWARN":
        d_class = DNSDiagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "RFC5322":
        d_class = RFC5322Diagnosis
    elif tag == "CFWS":
        d_class = CFWSDiagnosis
    elif tag == "DEPREC":
        d_class = DeprecatedDiagnosis
    else:
        d_class = ""

    return d_class
github michaelherold / pyIsEmail / tests / validators / test_dns_validator.py View on Github external
def testWithDiagnosis(self, mocked_method):
        self.assertEqual(
            self.is_valid('iana.123', diagnose=True),
            RFC5321Diagnosis('TLDNUMERIC'))
github michaelherold / pyIsEmail / tests / validators / test_dns_validator.py View on Github external
def testWithDiagnosis(self, mocked_method):
        self.assertEqual(
            self.is_valid('com', diagnose=True),
            RFC5321Diagnosis('TLD'))
github michaelherold / pyIsEmail / tests / validators / __init__.py View on Github external
"""Get class of the Diagnosis to use for a given tag.

    Keyword arguments:
    tag --- the tag string to look up

    """

    if tag == "ERR":
        d_class = InvalidDiagnosis
    elif tag == "DNSWARN":
        d_class = DNSDiagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "RFC5322":
        d_class = RFC5322Diagnosis
    elif tag == "CFWS":
        d_class = CFWSDiagnosis
    elif tag == "DEPREC":
        d_class = DeprecatedDiagnosis
    else:
        d_class = ""

    return d_class
github michaelherold / pyIsEmail / pyisemail / validators / dns_validator.py View on Github external
# anywhere, except as a general component of a DNS host name (a label).
        # However, this could potentially lead to 123.123.123.123 being a
        # valid DNS name (rather than an IP address) and thereby creating
        # an ambiguity. The most authoritative statement on TLD formats that
        # the author can find is in a (rejected!) erratum to RFC 1123
        # submitted by John Klensin, the author of RFC 5321:
        #
        # http://www.rfc-editor.org/errata_search.php?rfc=1123&eid=1353
        #   However, a valid host name can never have the dotted-decimal
        #   form #.#.#.#, since this change does not permit the highest-level
        #   component label to start with a digit even if it is not
        #   all-numeric.
        if not dns_checked:
            atom_list = domain.split(".")
            if len(atom_list) == 1:
                return_status.append(RFC5321Diagnosis('TLD'))

            try:
                float(atom_list[len(atom_list)-1][0])
                return_status.append(RFC5321Diagnosis('TLDNUMERIC'))
            except ValueError:
                pass

        final_status = max(return_status)

        return final_status if diagnose else final_status == ValidDiagnosis()
github michaelherold / pyIsEmail / pyisemail / validators / dns_validator.py View on Github external
# the author can find is in a (rejected!) erratum to RFC 1123
        # submitted by John Klensin, the author of RFC 5321:
        #
        # http://www.rfc-editor.org/errata_search.php?rfc=1123&eid=1353
        #   However, a valid host name can never have the dotted-decimal
        #   form #.#.#.#, since this change does not permit the highest-level
        #   component label to start with a digit even if it is not
        #   all-numeric.
        if not dns_checked:
            atom_list = domain.split(".")
            if len(atom_list) == 1:
                return_status.append(RFC5321Diagnosis('TLD'))

            try:
                float(atom_list[len(atom_list)-1][0])
                return_status.append(RFC5321Diagnosis('TLDNUMERIC'))
            except ValueError:
                pass

        final_status = max(return_status)

        return final_status if diagnose else final_status == ValidDiagnosis()
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
# CFWS & quoted strings are OK again now we're at
                            # the beginning of an element (although they are
                            # obsolete forms)
                            end_or_die = False
                            element_len = 0
                            element_count += 1
                            parse_data[Context.LOCALPART] += token
                            atom_list[Context.LOCALPART].append('')
                    elif token == Char.DQUOTE:
                        if element_len == 0:
                            # The entire local-part can be a quoted string for
                            # RFC 5321. If it's just one atom that is quoted
                            # then it's an RFC 5322 obsolete form
                            if element_count == 0:
                                return_status.append(
                                    RFC5321Diagnosis('QUOTEDSTRING'))
                            else:
                                return_status.append(
                                    DeprecatedDiagnosis('LOCALPART'))

                            parse_data[Context.LOCALPART] += token
                            atom_list[Context.LOCALPART][element_count] += token
                            element_len += 1
                            end_or_die = True
                            context_stack.append(context)
                            context = Context.QUOTEDSTRING
                        else:
                            # Fatal error
                            return_status.append(
                                InvalidDiagnosis('EXPECTING_ATEXT'))
                    # Folding White Space (FWS)
                    elif token in [Char.CR, Char.SP, Char.HTAB]:
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
# Address starts with a single colon
                                    return_status.append(
                                        RFC5322Diagnosis('IPV6_COLONSTRT'))
                                elif (ipv6[-1] == Char.COLON and
                                        ipv6[-2] != Char.COLON):
                                    # Address ends with a single colon
                                    return_status.append(
                                        RFC5322Diagnosis('IPV6_COLONEND'))
                                elif ([re.match(r"^[0-9A-Fa-f]{0,4}$", i)
                                       for i in match_ip].count(None) != 0):
                                    # Check for unmatched characters
                                    return_status.append(
                                        RFC5322Diagnosis('IPV6_BADCHAR'))
                                else:
                                    return_status.append(
                                        RFC5321Diagnosis('ADDRESSLITERAL'))
                        else:
                            return_status.append(
                                RFC5322Diagnosis('DOMAINLITERAL'))

                        parse_data[Context.DOMAIN] += token
                        atom_list[Context.DOMAIN][element_count] += token
                        element_len += 1
                        context_prior = context
                        context = context_stack.pop()
                    elif token == Char.BACKSLASH:
                        return_status.append(
                            RFC5322Diagnosis('DOMLIT_OBSDTEXT'))
                        context_stack.append(context)
                        context = Context.QUOTEDPAIR
                    # Folding White Space (FWS)
                    elif token in [Char.CR, Char.SP, Char.HTAB]:
github michaelherold / pyIsEmail / pyisemail / validators / parser_validator.py View on Github external
RFC5322Diagnosis('IPV6_2X2XCOLON'))
                                    else:
                                        if index in [0, len(ipv6) - 2]:
                                            # RFC 4291 allows :: at the start
                                            # or end of an address with 7 other
                                            # groups in addition
                                            max_groups += 1

                                        if grp_count > max_groups:
                                            return_status.append(
                                                RFC5322Diagnosis(
                                                    'IPV6_MAXGRPS'))
                                        elif grp_count == max_groups:
                                            # Eliding a single "::"
                                            return_status.append(
                                                RFC5321Diagnosis(
                                                    'IPV6DEPRECATED'))

                                # Revision 2.7: Daniel Marschall's new IPv6
                                # testing strategy
                                if (ipv6[0] == Char.COLON and
                                        ipv6[1] != Char.COLON):
                                    # Address starts with a single colon
                                    return_status.append(
                                        RFC5322Diagnosis('IPV6_COLONSTRT'))
                                elif (ipv6[-1] == Char.COLON and
                                        ipv6[-2] != Char.COLON):
                                    # Address ends with a single colon
                                    return_status.append(
                                        RFC5322Diagnosis('IPV6_COLONEND'))
                                elif ([re.match(r"^[0-9A-Fa-f]{0,4}$", i)
                                       for i in match_ip].count(None) != 0):