Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle MX records that do not resolve to an A record #117

Merged
merged 4 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ env:
# Matrix approach here due to: https://github.com/travis-ci/travis-ci/issues/9815
matrix:
include:
- python: 3.4
dist: xenial
sudo: true
- python: 3.5
dist: xenial
sudo: true
- python: 3.6
dist: xenial
sudo: true
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def readme():
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
Expand Down
2 changes: 1 addition & 1 deletion trustymail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import unicode_literals, absolute_import, print_function

__version__ = '0.7.4'
__version__ = '0.7.5'

PublicSuffixListFilename = 'public_suffix_list.dat'
PublicSuffixListReadOnly = False
25 changes: 22 additions & 3 deletions trustymail/trustymail.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,28 @@ def starttls_scan(domain, smtp_timeout, smtp_localhost, smtp_ports, smtp_cache):
# To get around this I look up the A record and use
# that instead of the hostname in DNS when I call
# smtp_connection.connect().
addr_info = socket.getaddrinfo(
mail_server, port, socket.AF_INET, socket.SOCK_STREAM
)
try:
addr_info = socket.getaddrinfo(
mail_server, port, socket.AF_INET, socket.SOCK_STREAM
)
except socket.gaierror:
# We get this exception if there is no A record
# for the given mail server. This does happen,
# since among their MX records some domains do
# list some IPv6-only mail servers.
#
# Since we can't evaluate such cases we will
# simply log this and give them credit. One of
# the other mail servers will support IPv4.
error_str = f'The mail server {mail_server} does not have an IPv4 address.'
handle_error('[STARTTLS]', domain, error_str)
logging.warn(error_str)
domain.starttls_results[server_and_port]['is_listening'] = True
domain.starttls_results[server_and_port]['supports_smtp'] = True
domain.starttls_results[server_and_port]['starttls'] = True
continue

# Extract the IP address from the socket addrinfo
socket_address = addr_info[0][4]
mail_server_ip_address = socket_address[0]

Expand Down