This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: imaplib authenticate raises TypeError if authenticator tries to abort
Type: behavior Stage: resolved
Components: email, Library (Lib) Versions: Python 3.4, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, berker.peksag, craigh, eric.smith, python-dev, r.david.murray, rbcollins
Priority: normal Keywords: patch

Created on 2015-03-25 22:21 by craigh, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
imap_auth.patch craigh, 2015-03-25 22:21 patch review
imap_auth2.patch craigh, 2015-03-31 02:51 review
imap_auth3.patch craigh, 2015-03-31 21:46 review
Messages (8)
msg239283 - (view) Author: Craig Holmquist (craigh) Date: 2015-03-25 22:21
If the authenticator object passed to the IMAP authenticate method tries to abort the handshake by returning None, TypeError is raised instead of sending the * line to the server.

>>> import imaplib
>>> imap = imaplib.IMAP4_SSL('')
>>> imap.authenticate(b'PLAIN', lambda x: None)
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    imap.authenticate(b'PLAIN', lambda x: None)
  File "C:\Python34\lib\", line 380, in authenticate
    typ, dat = self._simple_command('AUTHENTICATE', mech)
  File "C:\Python34\lib\", line 1133, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "C:\Python34\lib\", line 940, in _command
  File "C:\Python34\lib\", line 276, in send
  File "C:\Python34\lib\", line 723, in sendall
    v = self.send(data[count:])
  File "C:\Python34\lib\", line 684, in send
    v = self._sslobj.write(data)
TypeError: 'str' does not support the buffer interface

The problem is that _Authenticator.process returns a string instead of bytes in this case.
msg239656 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-03-31 02:25
Thanks for the report and the patch, Craig. Could you convert your reproducer to a test case? imaplib tests are located in Lib/test/
msg239658 - (view) Author: Craig Holmquist (craigh) Date: 2015-03-31 02:51
New patch is attached.
msg239701 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-03-31 13:12
The patch looks good to me, except that I think it would be better if the test verified that the '*' response is received by the server (perhaps return OK if we don't get it?)
msg239752 - (view) Author: Craig Holmquist (craigh) Date: 2015-03-31 21:46
Okay, I attached another patch.  The new version of the test returns success if the client's response is anything other than the abort line (*\r\n).

It fails with the current version of imaplib, fails if I change _Authenticator.process to output a byte-string besides *, and succeeds with the change in the patch.
msg239803 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-04-01 13:20
Looks good to me, thanks.
msg247698 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-30 21:03
New changeset fe55a36a335b by Robert Collins in branch '3.4':
Issue #23779: imaplib raises TypeError if authenticator tries to abort.

New changeset b6f04b9d8c12 by Robert Collins in branch '3.5':
Issue #23779: imaplib raises TypeError if authenticator tries to abort.

New changeset 0879f2c53289 by Robert Collins in branch 'default':
Issue #23779: imaplib raises TypeError if authenticator tries to abort.
msg247699 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-07-30 21:04
Thanks for the patch. Applied to 3.4 through 3.6.
Date User Action Args
2022-04-11 14:58:14adminsetgithub: 67967
2015-07-30 21:04:24rbcollinssetstatus: open -> closed

nosy: + rbcollins
messages: + msg247699

resolution: fixed
stage: commit review -> resolved
2015-07-30 21:03:42python-devsetnosy: + python-dev
messages: + msg247698
2015-04-01 13:20:55r.david.murraysetmessages: + msg239803
stage: patch review -> commit review
2015-03-31 21:46:30craighsetfiles: + imap_auth3.patch

messages: + msg239752
2015-03-31 13:12:28r.david.murraysetnosy: + barry, r.david.murray
messages: + msg239701

components: + email
stage: test needed -> patch review
2015-03-31 02:51:15craighsetfiles: + imap_auth2.patch

messages: + msg239658
2015-03-31 02:25:43berker.peksagsetnosy: + berker.peksag

messages: + msg239656
versions: + Python 3.5
2015-03-25 23:17:21eric.smithsetnosy: + eric.smith
2015-03-25 23:16:22eric.smithsetstage: test needed
2015-03-25 22:21:23craighcreate