Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1436f1

Browse files
committed
Fix IMAP.login() to work properly.
Also, add remote tests for imaplib (part of #4471).
1 parent adffced commit b1436f1

3 files changed

Lines changed: 48 additions & 6 deletions

File tree

Lib/imaplib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,10 @@ def _new_tag(self):
10541054

10551055
def _quote(self, arg):
10561056

1057-
arg = arg.replace(b'\\', b'\\\\')
1058-
arg = arg.replace(b'"', b'\\"')
1057+
arg = arg.replace('\\', '\\\\')
1058+
arg = arg.replace('"', '\\"')
10591059

1060-
return b'"' + arg + b'"'
1060+
return '"' + arg + '"'
10611061

10621062

10631063
def _simple_command(self, name, *args):

Lib/test/test_imaplib.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import socketserver
1111
import time
1212

13-
from test.support import reap_threads, verbose
13+
from test.support import reap_threads, verbose, transient_internet
1414
import unittest
1515

1616
try:
@@ -192,8 +192,45 @@ class ThreadedNetworkedTestsSSL(BaseThreadedNetworkedTests):
192192
imap_class = IMAP4_SSL
193193

194194

195-
def test_main():
195+
class RemoteIMAPTest(unittest.TestCase):
196+
host = 'cyrus.andrew.cmu.edu'
197+
port = 143
198+
username = 'anonymous'
199+
password = 'pass'
200+
imap_class = imaplib.IMAP4
201+
202+
def setUp(self):
203+
with transient_internet(self.host):
204+
self.server = self.imap_class(self.host, self.port)
205+
206+
def tearDown(self):
207+
if self.server is not None:
208+
self.server.logout()
209+
210+
def test_logincapa(self):
211+
self.assertTrue('LOGINDISABLED' in self.server.capabilities)
212+
213+
def test_anonlogin(self):
214+
self.assertTrue('AUTH=ANONYMOUS' in self.server.capabilities)
215+
rs = self.server.login(self.username, self.password)
216+
self.assertEqual(rs[0], 'OK')
217+
218+
def test_logout(self):
219+
rs = self.server.logout()
220+
self.assertEqual(rs[0], 'BYE')
196221

222+
223+
@unittest.skipUnless(ssl, "SSL not available")
224+
class RemoteIMAP_SSLTest(RemoteIMAPTest):
225+
port = 993
226+
imap_class = IMAP4_SSL
227+
228+
def test_logincapa(self):
229+
self.assertFalse('LOGINDISABLED' in self.server.capabilities)
230+
self.assertTrue('AUTH=PLAIN' in self.server.capabilities)
231+
232+
233+
def test_main():
197234
tests = [TestImaplib]
198235

199236
if support.is_resource_enabled('network'):
@@ -203,7 +240,10 @@ def test_main():
203240
"keycert.pem")
204241
if not os.path.exists(CERTFILE):
205242
raise support.TestFailed("Can't read certificate files!")
206-
tests.extend([ThreadedNetworkedTests, ThreadedNetworkedTestsSSL])
243+
tests.extend([
244+
ThreadedNetworkedTests, ThreadedNetworkedTestsSSL,
245+
RemoteIMAPTest, RemoteIMAP_SSLTest,
246+
])
207247

208248
support.run_unittest(*tests)
209249

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Core and Builtins
6060
Library
6161
-------
6262

63+
- Fix IMAP.login() to work properly.
64+
6365
- Issue #9244: multiprocessing pool worker processes could terminate
6466
unexpectedly if the return value of a task could not be pickled. Only
6567
the ``repr`` of such errors are now sent back, wrapped in an

0 commit comments

Comments
 (0)