More fixes

This commit is contained in:
László Károlyi 2019-03-01 23:45:29 +01:00
parent 4eda39c31e
commit 41b7c39059
Signed by: karolyi
GPG key ID: 2DCAF25E55735BFE
2 changed files with 13 additions and 11 deletions

View file

@ -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

View file

@ -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)