Adding IDNA failure handling
This commit is contained in:
parent
9ab570c9af
commit
0b0e77d662
|
@ -1,3 +1,6 @@
|
||||||
|
0.1.11:
|
||||||
|
- Handling IDNA errors
|
||||||
|
|
||||||
0.1.10:
|
0.1.10:
|
||||||
- Handling the NoNameservers exception
|
- Handling the NoNameservers exception
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -26,7 +26,7 @@ class PostBuildPyCommand(build_py):
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='py3-validate-email',
|
name='py3-validate-email',
|
||||||
version='0.1.10',
|
version='0.1.11',
|
||||||
packages=find_packages(exclude=['tests']),
|
packages=find_packages(exclude=['tests']),
|
||||||
install_requires=['dnspython>=1.16.0', 'idna>=2.8'],
|
install_requires=['dnspython>=1.16.0', 'idna>=2.8'],
|
||||||
author='László Károlyi',
|
author='László Károlyi',
|
||||||
|
|
|
@ -55,6 +55,7 @@ class IdnaTestCase(TestCase):
|
||||||
second='email@address.com')
|
second='email@address.com')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GetMxRecordsTestCase(TestCase):
|
class GetMxRecordsTestCase(TestCase):
|
||||||
'Testing `_get_mx_records`.'
|
'Testing `_get_mx_records`.'
|
||||||
|
|
||||||
|
@ -100,3 +101,8 @@ class GetMxRecordsTestCase(TestCase):
|
||||||
_get_mx_records(domain='testdomain3', timeout=10)
|
_get_mx_records(domain='testdomain3', timeout=10)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
exc.exception.args[0], 'testdomain3 DNS resolve timed out')
|
exc.exception.args[0], 'testdomain3 DNS resolve timed out')
|
||||||
|
|
||||||
|
def test_returns_false_on_idna_failure(self):
|
||||||
|
'Returns `False` on IDNA failure.'
|
||||||
|
self.assertFalse(expr=mx_module.mx_check(
|
||||||
|
email_address='test@♥web.de', from_address='mail@example.com'))
|
||||||
|
|
|
@ -9,7 +9,7 @@ from dns.rdatatype import MX as rdtype_mx
|
||||||
from dns.rdtypes.ANY.MX import MX
|
from dns.rdtypes.ANY.MX import MX
|
||||||
from dns.resolver import (
|
from dns.resolver import (
|
||||||
NXDOMAIN, YXDOMAIN, Answer, NoAnswer, NoNameservers, query)
|
NXDOMAIN, YXDOMAIN, Answer, NoAnswer, NoNameservers, query)
|
||||||
from idna.core import encode
|
from idna.core import encode, IDNAError
|
||||||
|
|
||||||
from .constants import EMAIL_EXTRACT_HOST_REGEX, HOST_REGEX
|
from .constants import EMAIL_EXTRACT_HOST_REGEX, HOST_REGEX
|
||||||
|
|
||||||
|
@ -106,7 +106,10 @@ def mx_check(
|
||||||
"""
|
"""
|
||||||
host = helo_host or gethostname()
|
host = helo_host or gethostname()
|
||||||
idna_from = _get_idna_address(email_address=from_address or email_address)
|
idna_from = _get_idna_address(email_address=from_address or email_address)
|
||||||
idna_to = _get_idna_address(email_address=email_address)
|
try:
|
||||||
|
idna_to = _get_idna_address(email_address=email_address)
|
||||||
|
except IDNAError:
|
||||||
|
return False
|
||||||
_user, domain = _dissect_email(email_address=email_address)
|
_user, domain = _dissect_email(email_address=email_address)
|
||||||
try:
|
try:
|
||||||
mx_records = _get_mx_records(domain=domain, timeout=dns_timeout)
|
mx_records = _get_mx_records(domain=domain, timeout=dns_timeout)
|
||||||
|
|
Loading…
Reference in New Issue