How to use the pyisemail.is_email 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 / test_is_email.py View on Github external
def test_without_diagnosis(self):
        result = is_email(self.address)
        expected = create_diagnosis(self.diagnosis) < self.threshold

        self.assertEqual(
            result,
            expected,
            ("%s (%s): Got %s, but expected %s."
             % (self.id, self.address, result, expected))
        )
github radiasoft / sirepo / sirepo / pkcli / service.py View on Github external
def _cfg_emails(value):
    """Parse a list of emails separated by comma, colons, semicolons or spaces.

    Args:
        value (object): if list or tuple, use verbatim; else split
    Returns:
        list: validated emails
    """
    import pyisemail
    try:
        if not isinstance(value, (list, tuple)):
            value = re.split(r'[,;:\s]+', value)
    except Exception:
        pkcli.command_error('{}: invalid email list', value)
    for v in value:
        if not pyisemail.is_email(value):
            pkcli.command_error('{}: invalid email', v)
github CCExtractor / sample-platform / mod_auth / controllers.py View on Github external
def signup() -> Dict[str, SignupForm]:
    """Route for handling the signup page."""
    from run import app
    form = SignupForm(request.form)
    if form.validate_on_submit():
        if is_email(form.email.data):
            # Check if user exists
            user = User.query.filter_by(email=form.email.data).first()
            if user is None:
                expires = int(time.time()) + 86400
                content_to_hash = "{email}|{expiry}".format(email=form.email.data, expiry=expires)
                hmac_hash = generate_hmac_hash(app.config.get('HMAC_KEY', ''), content_to_hash)
                # New user
                template = app.jinja_env.get_or_select_template('email/registration_email.txt')
                message = template.render(url=url_for(
                    '.complete_signup', email=form.email.data, expires=expires, mac=hmac_hash, _external=True)
                )
            else:
                # Existing user
                template = app.jinja_env.get_or_select_template('email/registration_existing.txt')
                message = template.render(url=url_for('.reset', _external=True), name=user.name)
            if g.mailer.send_simple_message({
github radiasoft / sirepo / sirepo / auth / email.py View on Github external
def _parse_email(data):
    res = data.email.strip().lower()
    assert pyisemail.is_email(res), \
        'invalid post data: email={}'.format(data.email)
    return res
github assembl / assembl / assembl / auth / util.py View on Github external
request, csv_file, discussion_id, with_role,
        send_password_change=False, message_subject=None,
        text_message=None, html_message=None, sender_name=None,
        resend_if_not_logged_in=False):
    r = reader(csv_file, skipinitialspace=True)
    localizer = request.localizer
    for i, row in enumerate(r):
        if not len(row):
            # tolerate empty lines
            continue
        row = [x.decode('utf-8').strip() for x in row]
        if len(row) != 2:
            raise RuntimeError(localizer.translate(_(
                "The CSV file must have two columns")))
        (name, email) = row
        if not is_email(email):
            if i == 0:
                # Header
                continue
            raise RuntimeError(localizer.translate(_(
                "Not an email: <%s> at line %d")) % (email, i))
        if len(name) < 5:
            raise RuntimeError(localizer.translate(_(
                "Name too short: <%s> at line %d")) % (name, i))
        (user, created_user, created_localrole) = add_user(
            name, email, None, None, True, localrole=with_role,
            discussion=discussion_id, change_old_password=False)
        status_in_discussion = None
        if send_password_change and not (created_user or created_localrole):
            status_in_discussion = user.get_status_in_discussion(discussion_id)
        if send_password_change and (
                created_user or created_localrole or (
github assembl / assembl / assembl / views / auth / views.py View on Github external
and asbool(config.get("accept_secure_connection")):
            return HTTPFound(get_global_base_url(True) + request.path_qs)
        response = get_login_context(request)
        return response
    forget(request)
    session = AgentProfile.default_db
    localizer = request.localizer
    name = request.params.get('name', '').strip()
    if not name or len(name) < 3:
        return dict(get_default_context(request),
            error=localizer.translate(_(
                "Please use a name of at least 3 characters")))
    password = request.params.get('password', '').strip()
    password2 = request.params.get('password2', '').strip()
    email = request.params.get('email', '').strip()
    if not is_email(email):
        return dict(get_default_context(request),
                    error=localizer.translate(_(
                        "This is not a valid email")))
    email = EmailString.normalize_email_case(email)
    # Find agent account to avoid duplicates!
    if session.query(AbstractAgentAccount).filter_by(
            email_ci=email, verified=True).count():
        return dict(get_default_context(request),
                    error=localizer.translate(_(
                        "We already have a user with this email.")))
    if password != password2:
        return dict(get_default_context(request),
                    error=localizer.translate(_(
                        "The passwords should be identical")))

    # TODO: Validate password quality
github assembl / assembl / assembl / models / preferences.py View on Github external
# No empty strings allowed
                        break
                    elif is_valid_ipv4_address(val):
                        condition = True
                        break
                    elif is_valid_ipv6_address(val):
                        condition = True
                        break
                    else:
                        # Must be a regular URL then. TODO: Check that the location has a DNS record
                        condition = True
                        break
                assert condition, "Not a valid URL. Must follow the specification of a URI."
            elif data_type == "email":
                from pyisemail import is_email
                assert is_email(value), "Not an email"
            elif data_type == "locale":
                pass  # TODO
            elif data_type == "permission":
                assert value in ASSEMBL_PERMISSIONS
            elif data_type == "role":
                if value not in SYSTEM_ROLES:
                    from .auth import Role
                    assert self.db.query(Role).filter_by(
                        name=value).count() == 1, "Unknown role"
            elif data_type == "domain":
                from pyisemail.validators.dns_validator import DNSValidator
                v = DNSValidator()
                assert v.is_valid(value), "Not a valid domain"
                value = value.lower()
            else:
                raise RuntimeError("Invalid data_type: " + data_type)
github assembl / assembl / assembl / alembic / versions / 250035d23e83_recalc_message_id.py View on Github external
op.execute("""UPDATE post
            SET message_id = concat(
                substring(message_id, 10, length(message_id)), '_assembl@%s')
            WHERE message_id LIKE 'urn:uuid:%%'""" % (
                config.get('public_hostname'),))

    # Do stuff with the app's models here.
    from assembl import models as m
    db = m.get_session_maker()()
    accepted = (
        pyisemail.diagnosis.valid_diagnosis.ValidDiagnosis(),
        pyisemail.diagnosis.rfc5322_diagnosis.RFC5322Diagnosis('LOCAL_TOOLONG'))

    with transaction.manager:
        for id, email in db.execute("SELECT id, message_id FROM post"):
            if pyisemail.is_email(email, diagnose=True) in accepted:
                continue
            c = m.Content.get(id)
            if isinstance(c, m.ImportedPost):
                c.message_id = c.source.generate_message_id(c.source_post_id)
            elif isinstance(c, m.AssemblPost):
                c.message_id = c.generate_message_id()
            else:
                print "ERROR: Pure post", id