summaryrefslogtreecommitdiffstats
path: root/Lib/imaplib.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-02-19 17:19:13 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-02-19 17:19:13 (GMT)
commit6cd6f015567d35be5831f0095b39a512842d31f2 (patch)
treeffedc8a64cf6e8b120ae48a27ef5d2fcbe14066c /Lib/imaplib.py
parent674a42b1141c2caa6e439a0cc47b07f620520ca4 (diff)
parent774a39f26ef2fa8ed96f3c52d3edac5e93926b4b (diff)
downloadcpython-6cd6f015567d35be5831f0095b39a512842d31f2.zip
cpython-6cd6f015567d35be5831f0095b39a512842d31f2.tar.gz
cpython-6cd6f015567d35be5831f0095b39a512842d31f2.tar.bz2
Merge: #13700: Make imap.authenticate with authobject work.
This fixes a bytes/string confusion in the API which prevented custom authobjects from working at all. Original patch by Erno Tukia.
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r--Lib/imaplib.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 3f8c65a..f8c7ffd 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -352,10 +352,10 @@ class IMAP4:
data = authobject(response)
- It will be called to process server continuation responses.
- It should return data that will be encoded and sent to server.
- It should return None if the client abort response '*' should
- be sent instead.
+ It will be called to process server continuation responses; the
+ response argument it is passed will be a bytes. It should return bytes
+ data that will be base64 encoded and sent to the server. It should
+ return None if the client abort response '*' should be sent instead.
"""
mech = mechanism.upper()
# XXX: shouldn't this code be removed, not commented out?
@@ -538,7 +538,9 @@ class IMAP4:
def _CRAM_MD5_AUTH(self, challenge):
""" Authobject to use with CRAM-MD5 authentication. """
import hmac
- return self.user + " " + hmac.HMAC(self.password, challenge).hexdigest()
+ pwd = (self.password.encode('ASCII') if isinstance(self.password, str)
+ else self.password)
+ return self.user + " " + hmac.HMAC(pwd, challenge).hexdigest()
def logout(self):
@@ -1295,14 +1297,16 @@ class _Authenticator:
# so when it gets to the end of the 8-bit input
# there's no partial 6-bit output.
#
- oup = ''
+ oup = b''
+ if isinstance(inp, str):
+ inp = inp.encode('ASCII')
while inp:
if len(inp) > 48:
t = inp[:48]
inp = inp[48:]
else:
t = inp
- inp = ''
+ inp = b''
e = binascii.b2a_base64(t)
if e:
oup = oup + e[:-1]
@@ -1310,7 +1314,7 @@ class _Authenticator:
def decode(self, inp):
if not inp:
- return ''
+ return b''
return binascii.a2b_base64(inp)
Months = ' Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ')