Repository navigation
imaplib - bug/regression on login command with 3.14.7 #155775
Description
Bug report
Bug description:
Hello!
I notice a change of behavior with imaplib login command starting with 3.14.7. It was working fine with 3.14.6 and previous version.
However, I'm not sure if what happens with 3.14.7 is the right way and a correction or not.
Problem
In imap, after a successful login command like this, the response also has the capabilities
$ telnet 127.0.0.1 143
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ STARTTLS AUTH=PLAIN AUTH=LOGIN AUTH=XOAUTH2] Dovecot ready.
1 LOGIN username password
1 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW STATUS=SIZE SAVEDATE LITERAL+ NOTIFY QUOTA ACL RIGHTS=texk] Logged in.The way to get those capabilities with imaplib has changed in 3.14.7
Prior 3.14.7, (works in 3.14.6 and prior)
To get those capabilities, I have to do that:
# Assume conn is a proper imaplib.IMAP4 object
conn.login(user, password)
cap_ret = conn.response('CAPABILITY')
# cap_ret = ('CAPABILITY', [b'bla blou bli']) with bla blou bli the capabilitiesWith imaplib.Debug = 4, notice the answer in two parts
20:46.30 > b'NDMB1 LOGIN [username](mailto:username) "password"'
20:46.32 < b'* CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW STATUS=SIZE SAVEDATE LITERAL+ NOTIFY QUOTA ACL RIGHTS=texk'
20:46.32 < b'NDMB1 OK Logged in'
With 3.14.7
With imaplib.Debug = 4, notice that the answer is is one part
22:31.17 > b'EHKG0 LOGIN LOGIN [username](mailto:username) "password"'
22:31.19 < b'EHKG0 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW STATUS=SIZE SAVEDATE LITERAL+ NOTIFY QUOTA ACL RIGHTS=texk] Logged in'
And in python:
# Assume conn is a proper imaplib.IMAP4 object
conn.login(user, password)
cap_ret = conn.response('CAPABILITY')
# cap_ret is now = ('CAPABILITY', [None]) because there is no response "* CAPABILITY"Now I have to parse the response of conn.login() to get the capabilities.
Conclusion
I'm not sure which of 3.14.7 or previous version is the expected way for that. However, I would have to implement the two methods if I want my app to work whatever the 3.14.x.
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-155775: Do not consume the CAPABILITY response in imaplib #155789
- [3.15] gh-155775: Do not consume the CAPABILITY response in imaplib (GH-155789) #156585
- [3.14] gh-155775: Do not consume the CAPABILITY response in imaplib (GH-155789) #156586
- [3.13] gh-155775: Do not consume the CAPABILITY response in imaplib (GH-155789) #156587
Activity
picnixz commentedon Aug 14, 2026
Likely #152752. cc @serhiy-storchaka
serhiy-storchaka commentedon Aug 14, 2026
Thank you for the report. This is a regression from gh-63121 (#152752), which refreshes the capability list after a successful
LOGINorAUTHENTICATE.Refreshing was intentional; consuming the response was not —
_refresh_capabilities()doesself.untagged_responses.pop('CAPABILITY'), soresponse('CAPABILITY')right afterlogin()now returns[None].Use the
capabilitiesattribute instead, which now reflects the post-login capabilities.#155789 restores the old behaviour.
QHivert commentedon Aug 14, 2026
Thanks for the quick response and fix !
gh-155775: Do not consume the CAPABILITY response in imaplib (GH-155789)
[3.14] gh-155775: Do not consume the CAPABILITY response in imaplib (G…
[3.13] gh-155775: Do not consume the CAPABILITY response in imaplib (G…
pythongh-155775: Do not consume the CAPABILITY response in imaplib (p…
[3.15] gh-155775: Do not consume the CAPABILITY response in imaplib (G…