mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 15:05:59 +08:00
add is_valid_email()
This commit is contained in:
parent
fe6e9fa435
commit
72a34e28be
|
@ -11,6 +11,7 @@ from smtplib import SMTP
|
|||
import arrow
|
||||
import dkim
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from validate_email import validate_email
|
||||
|
||||
from app.config import (
|
||||
SUPPORT_EMAIL,
|
||||
|
@ -645,3 +646,10 @@ def should_add_dkim_signature(domain: str) -> bool:
|
|||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def is_valid_email(email_address: str) -> bool:
|
||||
"""Used to check whether an email address is valid"""
|
||||
return validate_email(
|
||||
email_address=email_address, check_mx=False, use_blacklist=False
|
||||
)
|
||||
|
|
|
@ -13,6 +13,7 @@ from app.email_utils import (
|
|||
copy,
|
||||
get_spam_from_header,
|
||||
get_header_from_bounce,
|
||||
is_valid_email,
|
||||
)
|
||||
from app.extensions import db
|
||||
from app.models import User, CustomDomain
|
||||
|
@ -286,3 +287,10 @@ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simplelogin.co;
|
|||
assert (
|
||||
get_header_from_bounce(email.message_from_string(msg_str), "Not-exist") is None
|
||||
)
|
||||
|
||||
|
||||
def test_is_valid_email():
|
||||
assert is_valid_email("abcd@gmail.com")
|
||||
assert not is_valid_email("with space@gmail.com")
|
||||
assert not is_valid_email("strange char !ç@gmail.com")
|
||||
assert not is_valid_email("emoji👌@gmail.com")
|
||||
|
|
Loading…
Reference in a new issue