Skip to content

Commit 759e1e7

Browse files
committed
chore: update auth method
1 parent 7c1e4d9 commit 759e1e7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Lib/poplib.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,26 @@ def auth(self, mechanism, authobject=None, initial_response=None):
237237

238238
self._putcmd(f'AUTH {mechanism}')
239239
while True:
240-
resp = self._getresp()
241-
if resp[:3] == b'+OK':
242-
return resp
240+
line, _ = self._getline()
241+
if line.startswith(b'+OK'):
242+
return line
243+
if line.startswith(b'-ERR'):
244+
while self._getline() != b'.\r\n':
245+
pass
246+
raise error_proto(line.decode('ascii', 'replace'))
247+
248+
if not line.startswith(b'+ '):
249+
raise error_proto(f'malformed challenge line: {line!r}')
250+
251+
challenge_b64 = line[2:]
252+
challenge_b64 = challenge_b64.rstrip(b'\r\n')
243253

244-
challenge_b64 = resp[1:].lstrip(b' ')
245254
if challenge_b64:
246255
try:
247256
challenge = base64.b64decode(challenge_b64)
248257
except Exception:
249258
padded = challenge_b64 + b'=' * (-len(challenge_b64) % 4)
250-
challenge = base64.b64decode(padded, validate=False)
259+
challenge = base64.b64decode(padded)
251260
else:
252261
challenge = b''
253262

@@ -259,11 +268,11 @@ def auth(self, mechanism, authobject=None, initial_response=None):
259268

260269
if response == b'*':
261270
self._putcmd('*')
262-
return self._getresp()
271+
err_line, _ = self._getline()
272+
raise error_proto(err_line.decode('ascii', 'replace'))
263273

264274
self._putcmd(base64.b64encode(response).decode('ascii'))
265275

266-
267276
def stat(self):
268277
"""Get mailbox status.
269278

0 commit comments

Comments
 (0)