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

Skip to content

Commit dbe7519

Browse files
committed
Issue #10429: IMAP.starttls() stored the capabilities as bytes objects,
rather than strings.
1 parent 36c0dbc commit dbe7519

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

Lib/imaplib.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,7 @@ def __init__(self, host = '', port = IMAP4_PORT):
196196
else:
197197
raise self.error(self.welcome)
198198

199-
typ, dat = self.capability()
200-
if dat == [None]:
201-
raise self.error('no CAPABILITY response from server')
202-
dat = str(dat[-1], "ASCII")
203-
dat = dat.upper()
204-
self.capabilities = tuple(dat.split())
205-
199+
self._get_capabilities()
206200
if __debug__:
207201
if self.debug >= 3:
208202
self._mesg('CAPABILITIES: %r' % (self.capabilities,))
@@ -737,10 +731,7 @@ def starttls(self, ssl_context=None):
737731
self.sock = ssl_context.wrap_socket(self.sock)
738732
self.file = self.sock.makefile('rb')
739733
self._tls_established = True
740-
typ, dat = self.capability()
741-
if dat == [None]:
742-
raise self.error('no CAPABILITY response from server')
743-
self.capabilities = tuple(dat[-1].upper().split())
734+
self._get_capabilities()
744735
else:
745736
raise self.error("Couldn't establish TLS session")
746737
return self._untagged_response(typ, dat, name)
@@ -956,6 +947,15 @@ def _command_complete(self, name, tag):
956947
return typ, data
957948

958949

950+
def _get_capabilities(self):
951+
typ, dat = self.capability()
952+
if dat == [None]:
953+
raise self.error('no CAPABILITY response from server')
954+
dat = str(dat[-1], "ASCII")
955+
dat = dat.upper()
956+
self.capabilities = tuple(dat.split())
957+
958+
959959
def _get_response(self):
960960

961961
# Read response and store.

Lib/test/test_imaplib.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def tearDown(self):
208208
self.server.logout()
209209

210210
def test_logincapa(self):
211+
for cap in self.server.capabilities:
212+
self.assertIsInstance(cap, str)
211213
self.assertTrue('LOGINDISABLED' in self.server.capabilities)
212214
self.assertTrue('AUTH=ANONYMOUS' in self.server.capabilities)
213215
rs = self.server.login(self.username, self.password)
@@ -228,6 +230,8 @@ def setUp(self):
228230
self.assertEqual(rs[0], 'OK')
229231

230232
def test_logincapa(self):
233+
for cap in self.server.capabilities:
234+
self.assertIsInstance(cap, str)
231235
self.assertFalse('LOGINDISABLED' in self.server.capabilities)
232236

233237

@@ -237,6 +241,8 @@ class RemoteIMAP_SSLTest(RemoteIMAPTest):
237241
imap_class = IMAP4_SSL
238242

239243
def test_logincapa(self):
244+
for cap in self.server.capabilities:
245+
self.assertIsInstance(cap, str)
240246
self.assertFalse('LOGINDISABLED' in self.server.capabilities)
241247
self.assertTrue('AUTH=PLAIN' in self.server.capabilities)
242248

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #10429: IMAP.starttls() stored the capabilities as bytes objects,
17+
rather than strings.
18+
1619

1720
What's New in Python 3.2 Alpha 4?
1821
=================================

0 commit comments

Comments
 (0)