From 8023afe9bef4fcfb5870d6ac00bc3547b0afa482 Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Fri, 10 Sep 2021 16:38:59 +0200 Subject: [PATCH] use email_validator instead of validate_email which isn't updated for a while --- app/email_utils.py | 22 ++++++++++++++-------- poetry.lock | 20 ++------------------ pyproject.toml | 1 - 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/app/email_utils.py b/app/email_utils.py index 2f49b728..a4e8af5c 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -6,22 +6,22 @@ import quopri import random import re import time +from copy import deepcopy from email.errors import HeaderParseError -from email.header import decode_header +from email.header import decode_header, Header from email.message import Message from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import make_msgid, formatdate, parseaddr from smtplib import SMTP, SMTPServerDisconnected -from typing import Tuple, List, Optional -from copy import deepcopy +from typing import Tuple, List, Optional, Union import arrow import dkim import spf +from email_validator import validate_email, EmailNotValidError from jinja2 import Environment, FileSystemLoader from sqlalchemy import func -from validate_email import validate_email from app.config import ( SUPPORT_EMAIL, @@ -769,10 +769,16 @@ def should_add_dkim_signature(domain: str) -> bool: 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 - ) + """ + Used to check whether an email address is valid + NOT run MX check. + NOT allow unicode. + """ + try: + validate_email(email_address, check_deliverability=False, allow_smtputf8=False) + return True + except EmailNotValidError: + return False class EmailEncoding(enum.Enum): diff --git a/poetry.lock b/poetry.lock index 81b099cd..199d9e32 100644 --- a/poetry.lock +++ b/poetry.lock @@ -423,7 +423,7 @@ requests = "*" name = "filelock" version = "3.0.12" description = "A platform independent file lock." -category = "main" +category = "dev" optional = false python-versions = "*" @@ -1166,19 +1166,6 @@ category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -[[package]] -name = "py3-validate-email" -version = "0.2.10" -description = "Email validator with regex, blacklisted domains and SMTP checking." -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -dnspython = ">=2.0,<3.0" -filelock = ">=3.0,<4.0" -idna = ">=2.10,<3.0" - [[package]] name = "pyasn1" version = "0.4.8" @@ -1805,7 +1792,7 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "a80a9f350a39e926d74ea73a7b9d5b04ec8b515bcc2e9bc31bd2537989763aa5" +content-hash = "a2f1de1d4ecbe4b1e36d965bb9ba52d10d16b344b6c7e4509a53245b67fdcec5" [metadata.files] aiohttp = [ @@ -2440,9 +2427,6 @@ py = [ {file = "py-1.9.0-py2.py3-none-any.whl", hash = "sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2"}, {file = "py-1.9.0.tar.gz", hash = "sha256:9ca6883ce56b4e8da7e79ac18787889fa5206c79dcc67fb065376cd2fe03f342"}, ] -py3-validate-email = [ - {file = "py3-validate-email-0.2.10.tar.gz", hash = "sha256:3bbb264b49c0ae09afdb2738956f00b0e8dd7e079e2d079b2e9b6688de474d28"}, -] pyasn1 = [ {file = "pyasn1-0.4.8-py2.4.egg", hash = "sha256:fec3e9d8e36808a28efb59b489e4528c10ad0f480e57dcc32b4de5c9d8c9fdf3"}, {file = "pyasn1-0.4.8-py2.5.egg", hash = "sha256:0458773cfe65b153891ac249bcf1b5f8f320b7c2ce462151f8fa74de8934becf"}, diff --git a/pyproject.toml b/pyproject.toml index 6c38e8d3..9c3e46c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,6 @@ gevent = "^20.9.0" aiospamc = "^0.6.1" email_validator = "^1.1.1" PGPy = "^0.5.3" -py3-validate-email = "^0.2.10" coinbase-commerce = "^1.0.1" requests = "^2.25.1" newrelic = "^6.4.4"