More fixes
This commit is contained in:
parent
4eda39c31e
commit
41b7c39059
2 changed files with 13 additions and 11 deletions
|
@ -14,6 +14,6 @@ install:
|
|||
- pip install -e .
|
||||
# command to run tests
|
||||
script:
|
||||
- isort --skip-glob=venv
|
||||
- isort -c --skip-glob=venv
|
||||
- flake8 tests/ validate_email/
|
||||
- python -m unittest discover -v
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
import re
|
||||
import smtplib
|
||||
import socket
|
||||
from re import compile as re_compile
|
||||
from smtplib import SMTP
|
||||
from socket import gethostname
|
||||
|
||||
import dns.resolver as dns
|
||||
|
||||
DOMAIN_REGEX = re_compile(r'(?<=@)\[?([^\[\]]+)')
|
||||
|
||||
|
||||
def _get_domain_from_email_address(email_address):
|
||||
try:
|
||||
return re.search(r"(?<=@)\[?([^\[\]]+)", email_address)[1]
|
||||
return DOMAIN_REGEX.search(string=email_address)[1]
|
||||
except TypeError:
|
||||
raise ValueError("Invalid email address")
|
||||
raise ValueError('Invalid email address')
|
||||
except IndexError:
|
||||
raise ValueError("Invalid email address")
|
||||
raise ValueError('Invalid email address')
|
||||
|
||||
|
||||
def _get_mx_records(domain):
|
||||
try:
|
||||
records = dns.query(domain, 'MX')
|
||||
except dns.NXDOMAIN:
|
||||
raise ValueError("Domain {} does not seem to exist")
|
||||
raise ValueError('Domain {} does not seem to exist')
|
||||
except Exception:
|
||||
raise NotImplementedError("Feature not yet implemented")
|
||||
raise NotImplementedError('Feature not yet implemented')
|
||||
return [str(x.exchange) for x in records]
|
||||
|
||||
|
||||
def mx_check(email_address, smtp_timeout=10):
|
||||
host = socket.gethostname()
|
||||
host = gethostname()
|
||||
|
||||
smtp = smtplib.SMTP(timeout=smtp_timeout)
|
||||
smtp = SMTP(timeout=smtp_timeout)
|
||||
smtp.set_debuglevel(0)
|
||||
|
||||
domain = _get_domain_from_email_address(email_address)
|
||||
|
|
Loading…
Reference in a new issue