Skip to content

bpo-45706: Add imaplib.IMAP4.login_plain#29398

Merged
serhiy-storchaka merged 5 commits into
python:mainfrom
przemub:feature/imaplib/login_plain
Jul 5, 2026
Merged

bpo-45706: Add imaplib.IMAP4.login_plain#29398
serhiy-storchaka merged 5 commits into
python:mainfrom
przemub:feature/imaplib/login_plain

Conversation

@przemub

@przemub przemub commented Nov 4, 2021

Copy link
Copy Markdown
Contributor

Adds authentication using PLAIN SASL mechanism.

This is a plaintext authentication mechanism that can be used
instead of IMAP4.login() when UTF-8 support is required.

Adds authentication using PLAIN SASL mechanism.

This is a plain-text authentication mechanism which can be used
instead of :meth:`IMAP4.login()` when UTF-8 support is required.
@przemub przemub requested a review from a team as a code owner November 4, 2021 00:44
@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@przemub

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@github-actions

github-actions Bot commented Dec 5, 2021

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Dec 5, 2021

@MaxwellDupre MaxwellDupre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both tests passed.
Looks ok to me.

Comment thread Doc/library/imaplib.rst Outdated
See :RFC:`6855`, page 5.

It will only work if the server ``CAPABILITY`` response includes
the phrase ``AUTH=PLAIN``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module partially supports RFC 3501, which says that AUTH=PLAIN is mandatory. I understand that means advertising it in CAPABILITY is optional, so it might work regardless.

Comment thread Lib/imaplib.py Outdated
"""
return self.authenticate(
"PLAIN",
lambda _: "{0}\x00{0}\x00{1}".format(user, password).encode()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the authorization identity (authzid) to the user name. Wouldn’t it be better to allow omitting authzid by default, let the server derive it? https://datatracker.ietf.org/doc/html/rfc4616#section-2

f'\x00{user}\x00{password}'.encode('utf-8')

Comment thread Doc/library/imaplib.rst Outdated

This is a plain-text authentication mechanism that can be used
instead of :meth:`IMAP4.login()` when UTF-8 support is required.
See :RFC:`6855`, page 5.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that referring to RFC 6855 is that relevant. All it does is recommend against UTF-8 support with LOGIN, and say that AUTHENTICATE supports UTF-8.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Apr 10, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 11, 2026
serhiy-storchaka and others added 3 commits July 5, 2026 20:32
…in_plain

# Conflicts:
#	Lib/test/test_imaplib.py
The 'MD5 support is not available' note belongs to login_cram_md5, but
merging placed it after login_plain, which was inserted between them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Use an empty SASL authorization identity (RFC 4616): the previous
  code sent the user name as authzid, requesting proxy authorization,
  which many servers reject.
* Note that PLAIN is only base64-encoded and requires a TLS connection.
* Cite RFC 4616 for the mechanism; RFC 6855 only for UTF-8 support.
* Fix the versionadded marker and the documented parameter name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Jul 5, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33449956 | 📁 Comparing c0c2c29 against main (d733b10)

  🔍 Preview build  

3 files changed
± library/imaplib.html
± whatsnew/3.16.html
± whatsnew/changelog.html

RFC 3501 makes the PLAIN mechanism mandatory, so a server may support
it without advertising AUTH=PLAIN in its CAPABILITY response.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I synchronized the PR branch with main (it was 5 years!), addressed review comments by @vadmium, and made additional changes:

  • bytes is accepted as user and password, like in other login/authorization methods.
  • NUL is rejected in user and password. It conflicts with the delimiter.
  • Polished docs.

With all this it LGTM.

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) July 5, 2026 20:17
@serhiy-storchaka serhiy-storchaka merged commit 93b1a88 into python:main Jul 5, 2026
157 of 163 checks passed
@przemub przemub mannequin mentioned this pull request Apr 10, 2022
@przemub

przemub commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @serhiy-storchaka, @vadmium, @MaxwellDupre for fixes, reviews and support!

@serhiy-storchaka

Copy link
Copy Markdown
Member

You are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants