Skip to content

Commit b1a50f0

Browse files
authored
Merge pull request #117 from cisagov/bugfix/ipv6_only_mail_servers_not_handled_gracefully
Gracefully handle MX records that do not resolve to an A record
2 parents 469e440 + d663c15 commit b1a50f0

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ env:
1212
# Matrix approach here due to: https://github.com/travis-ci/travis-ci/issues/9815
1313
matrix:
1414
include:
15-
- python: 3.4
16-
dist: xenial
17-
sudo: true
18-
- python: 3.5
19-
dist: xenial
20-
sudo: true
2115
- python: 3.6
2216
dist: xenial
2317
sudo: true

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def readme():
5858
# Specify the Python versions you support here. In particular, ensure
5959
# that you indicate whether you support Python 2, Python 3 or both.
6060
'Programming Language :: Python :: 3',
61-
'Programming Language :: Python :: 3.4',
62-
'Programming Language :: Python :: 3.5',
6361
'Programming Language :: Python :: 3.6',
6462
'Programming Language :: Python :: 3.7',
6563
],

trustymail/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals, absolute_import, print_function
22

3-
__version__ = '0.7.4'
3+
__version__ = '0.7.5'
44

55
PublicSuffixListFilename = 'public_suffix_list.dat'
66
PublicSuffixListReadOnly = False

trustymail/trustymail.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,28 @@ def starttls_scan(domain, smtp_timeout, smtp_localhost, smtp_ports, smtp_cache):
173173
# To get around this I look up the A record and use
174174
# that instead of the hostname in DNS when I call
175175
# smtp_connection.connect().
176-
addr_info = socket.getaddrinfo(
177-
mail_server, port, socket.AF_INET, socket.SOCK_STREAM
178-
)
176+
try:
177+
addr_info = socket.getaddrinfo(
178+
mail_server, port, socket.AF_INET, socket.SOCK_STREAM
179+
)
180+
except socket.gaierror:
181+
# We get this exception if there is no A record
182+
# for the given mail server. This does happen,
183+
# since among their MX records some domains do
184+
# list some IPv6-only mail servers.
185+
#
186+
# Since we can't evaluate such cases we will
187+
# simply log this and give them credit. One of
188+
# the other mail servers will support IPv4.
189+
error_str = f'The mail server {mail_server} does not have an IPv4 address.'
190+
handle_error('[STARTTLS]', domain, error_str)
191+
logging.warn(error_str)
192+
domain.starttls_results[server_and_port]['is_listening'] = True
193+
domain.starttls_results[server_and_port]['supports_smtp'] = True
194+
domain.starttls_results[server_and_port]['starttls'] = True
195+
continue
196+
197+
# Extract the IP address from the socket addrinfo
179198
socket_address = addr_info[0][4]
180199
mail_server_ip_address = socket_address[0]
181200

0 commit comments

Comments
 (0)