diff -r c43362d35d8d Lib/imaplib.py --- a/Lib/imaplib.py Fri Jul 04 17:00:25 2014 -0700 +++ b/Lib/imaplib.py Tue Jul 08 20:58:47 2014 +0200 @@ -244,7 +244,9 @@ def _create_socket(self): - return socket.create_connection((self.host, self.port)) + # Workaround for issue 18540: + host = None if str(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" diff -r c43362d35d8d Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py Fri Jul 04 17:00:25 2014 -0700 +++ b/Lib/test/test_imaplib.py Tue Jul 08 20:58:47 2014 +0200 @@ -228,6 +228,12 @@ client.shutdown() @reap_threads + def test_issue18540(self): + # Test that the socket.connect method gets arguments plausible + # enough to attempt an connection. + self.assertRaises(ConnectionRefusedError, self.imap_class) + + @reap_threads def test_issue5949(self): class EOFHandler(socketserver.StreamRequestHandler):