]> granicus.if.org Git - python/commitdiff
Fix IMAP.login() to work properly.
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 9 Nov 2010 22:55:55 +0000 (22:55 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 9 Nov 2010 22:55:55 +0000 (22:55 +0000)
Also, add remote tests for imaplib (part of #4471).

Lib/imaplib.py
Lib/test/test_imaplib.py
Misc/NEWS

index 9b0fd3b98f57775c74d27d176646fbfd77bd79b2..1b375465af68f42334038be2083493215fe0fc29 100644 (file)
@@ -1054,10 +1054,10 @@ class IMAP4:
 
     def _quote(self, arg):
 
-        arg = arg.replace(b'\\', b'\\\\')
-        arg = arg.replace(b'"', b'\\"')
+        arg = arg.replace('\\', '\\\\')
+        arg = arg.replace('"', '\\"')
 
-        return b'"' + arg + b'"'
+        return '"' + arg + '"'
 
 
     def _simple_command(self, name, *args):
index e3d51a9bfd42916b5c9e479b93130cc894b36af2..8d86ce6f4b050e6f20241abe9647fb5b0b54b547 100644 (file)
@@ -10,7 +10,7 @@ import os.path
 import socketserver
 import time
 
-from test.support import reap_threads, verbose
+from test.support import reap_threads, verbose, transient_internet
 import unittest
 
 try:
@@ -192,8 +192,45 @@ class ThreadedNetworkedTestsSSL(BaseThreadedNetworkedTests):
     imap_class = IMAP4_SSL
 
 
-def test_main():
+class RemoteIMAPTest(unittest.TestCase):
+    host = 'cyrus.andrew.cmu.edu'
+    port = 143
+    username = 'anonymous'
+    password = 'pass'
+    imap_class = imaplib.IMAP4
+
+    def setUp(self):
+        with transient_internet(self.host):
+            self.server = self.imap_class(self.host, self.port)
+
+    def tearDown(self):
+        if self.server is not None:
+            self.server.logout()
+
+    def test_logincapa(self):
+        self.assertTrue('LOGINDISABLED' in self.server.capabilities)
+
+    def test_anonlogin(self):
+        self.assertTrue('AUTH=ANONYMOUS' in self.server.capabilities)
+        rs = self.server.login(self.username, self.password)
+        self.assertEqual(rs[0], 'OK')
+
+    def test_logout(self):
+        rs = self.server.logout()
+        self.assertEqual(rs[0], 'BYE')
 
+
+@unittest.skipUnless(ssl, "SSL not available")
+class RemoteIMAP_SSLTest(RemoteIMAPTest):
+    port = 993
+    imap_class = IMAP4_SSL
+
+    def test_logincapa(self):
+        self.assertFalse('LOGINDISABLED' in self.server.capabilities)
+        self.assertTrue('AUTH=PLAIN' in self.server.capabilities)
+
+
+def test_main():
     tests = [TestImaplib]
 
     if support.is_resource_enabled('network'):
@@ -203,7 +240,10 @@ def test_main():
                                     "keycert.pem")
             if not os.path.exists(CERTFILE):
                 raise support.TestFailed("Can't read certificate files!")
-        tests.extend([ThreadedNetworkedTests, ThreadedNetworkedTestsSSL])
+        tests.extend([
+            ThreadedNetworkedTests, ThreadedNetworkedTestsSSL,
+            RemoteIMAPTest, RemoteIMAP_SSLTest,
+        ])
 
     support.run_unittest(*tests)
 
index 3e0de21c36af729d23decc887977219dbab9431a..19e653cb3209eac9a09f0fbe37453ebbfdf601bf 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,8 @@ Core and Builtins
 Library
 -------
 
+- Fix IMAP.login() to work properly.
+
 - Issue #9244: multiprocessing pool worker processes could terminate
   unexpectedly if the return value of a task could not be pickled.  Only
   the ``repr`` of such errors are now sent back, wrapped in an