예제 #1
0
def email_corrector(email):
    """
    Corrects a candidate email string, returns None if it is not valid.
    """

    is_valid = False
    corrected_email = email

    if email is not None:
        # If it is already valid coming in, then leave everything alone and go to the next one,
        # unless it has a blank in it (we want to process to remove that blank)
        if (email_validation.valid_email_address(corrected_email)) and (" " not in corrected_email):
            is_valid = True
        else:
            # First get rid of all invalid characters.
            corrected_email = "".join(c for c in corrected_email if c in _ValidEmailCharacters).strip()
            corrected_email = corrected_email.replace(" @", "@")

            # Go through each space-delimited word and check for validity
            space_separated = corrected_email.split(" ")
            for one_word in space_separated:
                one_word = one_word.strip(".").strip(",").strip("(").strip(")").strip("#").strip("[").strip("]")\
                    .strip("{").strip("}").strip("%")
                if email_validation.valid_email_address(one_word):
                    corrected_email = one_word
                    is_valid = True
                    break

            if not is_valid:
                # Try parsing it and keep if valid.
                parsed_email = parseaddr(corrected_email)
                if parsed_email[1] != "":
                    corrected_email = parsed_email[1].strip(".").strip(",").strip("(").strip(")").strip("#")\
                        .strip("[").strip("]").strip("{").strip("}").strip("%")
                is_valid = email_validation.valid_email_address(corrected_email)

    if not is_valid:
        corrected_email = None

    return corrected_email
예제 #2
0
 def match_test(self):
     self.longMessage = True
     self.assertFalse(valid_email_address(address))
예제 #3
0
파일: member.py 프로젝트: ajenta/oydiv-rpc
    "password": lambda x: _true_or_value_error(
        _is_valid_stringfield(x, max_len=64) and set(x).issubset(string.printable),
        "Passwords must be a subset of ASCII, max_len=64",
    ),
    "displayName": lambda x: _is_valid_stringfield(x, max_len=128),
    "Language": lambda x: _true_or_value_error(
        x in ("en", "de", "es", "fr", "it", "ja", "ko", "pt", "zh_CN", "fi", "pl", "zh_TW", "th", "ru"),
        "Unsupported language: %r" % x,
    ),
    "groupName": _is_valid_stringfield,
    "proxyName": _is_valid_stringfield,
    # extensions can have leading zeros but must be numeric to int
    "extension": lambda x: _true_or_value_error(
        str(x).isdigit() and len(str(x)) < 17, "Extension (%s) is out of range" % x
    ),
    "emailAddress": lambda x: _true_or_value_error(valid_email_address(x), "email address '%r' is invalid" % x),
    "RoleName": _is_valid_stringfield,
    "description": lambda x: _is_valid_stringfield(x, 0),
    "allowCallDirect": lambda x: _true_or_value_error(isinstance(x, bool)),
    "allowPersonalMeeting": lambda x: _true_or_value_error(isinstance(x, bool)),
    "locationTag": _is_valid_stringfield,
}


@six.python_2_unicode_compatible
class PortalMember(object):
    """
    PortalMember is a type-checking representation of the 'Member'
    class expected by the VidyoPortal Admin API.
    Here it is masquerading as a ``dict`` and can therefore be iterated
    upon and passed to the ``createMember()`` RPC function.
 def match_test(self):
     self.longMessage = True
     self.assertFalse(valid_email_address(address))
예제 #5
0
 def is_valid_email(email):
     if not valid_email_address(email):
         return False
     return True
예제 #6
0
 def is_valid_email(email):
     if not valid_email_address(email):
         return False
     return True