From 0b2b1ba738450df29728f28849ae48fdeeb777b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Mon, 8 Feb 2021 14:19:59 +0100 Subject: [PATCH] Fix #45, bump version --- CHANGELOG.txt | 4 ++++ setup.py | 2 +- validate_email/mx_check.py | 15 +++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index daecd05..c74144c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,7 @@ +0.2.13: +- Fix 5xx errors not getting through in the exception parameters on the RCPT TO + handling. (#45) + 0.2.12: - Fixed a TLS error where the MX hostname mismatched the actual hostname due to MX records resolving to hostnames with dots at the end. Yahoo lookups diff --git a/setup.py b/setup.py index 4164b79..e78a10a 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,7 @@ class BuildPyCommand(build_py): setup( name='py3-validate-email', - version='0.2.12', + version='0.2.13', packages=find_packages(exclude=['tests']), install_requires=['dnspython~=2.0', 'idna~=2.10', 'filelock~=3.0'], author='László Károlyi', diff --git a/validate_email/mx_check.py b/validate_email/mx_check.py index 55bb870..2010f79 100644 --- a/validate_email/mx_check.py +++ b/validate_email/mx_check.py @@ -78,7 +78,7 @@ def _smtp_mail(smtp: SMTP, from_address: EmailAddress): if code >= 300: # MAIL FROM bails out, no further SMTP commands are acceptable message = message.decode(errors='ignore') - raise ProtocolError(f'RCPT TO failed: {message}') + raise ProtocolError(f'MAIL FROM failed: {message}') def _smtp_converse( @@ -89,7 +89,8 @@ def _smtp_converse( Do the `SMTP` conversation, handle errors in the caller. Return a `tuple(code, message)` when ambigious, or raise - `StopIteration` if the conversation points out an existing email. + `ProtocolError` on error, and `StopIteration` if the conversation + points out an existing email. """ if debug: LOGGER.debug(msg=f'Trying {mx_record} ...') @@ -101,10 +102,12 @@ def _smtp_converse( smtp.quit() if code == 250: raise StopIteration - elif 400 <= code <= 499: - # Ambigious return code, can be graylist, temporary problems, - # quota or mailsystem error - return code, message.decode(errors='ignore') + elif code >= 500: + message = message.decode(errors='ignore') + raise ProtocolError(f'RCPT TO failed: {message}') + # Ambigious return code, can be graylist, temporary problems, + # quota or mailsystem error + return code, message.decode(errors='ignore') def _check_one_mx(