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

[3.6] bpo-18540: Fix EAI_NONAME in imaplib.IMAP4*() (GH-8634) #8698

Merged
merged 1 commit into from
Aug 7, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Lib/imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ def __exit__(self, *args):


def _create_socket(self):
return socket.create_connection((self.host, self.port))
# Default value of IMAP4.host is '', but socket.getaddrinfo()
# (which is used by socket.create_connection()) expects None
# as a default value for host.
host = None if not self.host else self.host
return socket.create_connection((host, self.port))

def open(self, host = '', port = IMAP4_PORT):
"""Setup connection to remote server on "host:port"
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
threading = support.import_module('threading')

from contextlib import contextmanager
import errno
import imaplib
import os.path
import socketserver
Expand Down Expand Up @@ -73,6 +74,19 @@ def test_that_Time2Internaldate_returns_a_result(self):
for t in self.timevalues():
imaplib.Time2Internaldate(t)

def test_imap4_host_default_value(self):
expected_errnos = [
# This is the exception that should be raised.
errno.ECONNREFUSED,
]
if hasattr(errno, 'EADDRNOTAVAIL'):
# socket.create_connection() fails randomly with
# EADDRNOTAVAIL on Travis CI.
expected_errnos.append(errno.EADDRNOTAVAIL)
with self.assertRaises(OSError) as cm:
imaplib.IMAP4()
self.assertIn(cm.exception.errno, expected_errnos)


if ssl:
class SecureTCPServer(socketserver.TCPServer):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The :class:`imaplib.IMAP4` and :class:`imaplib.IMAP4_SSL` classes now
resolve to the local host IP correctly when the default value of *host*
parameter (``''``) is used.