From 30d113e4bf401ecd0dc3a1e5847fafb70ab4d8e0 Mon Sep 17 00:00:00 2001 From: Julien CHATY-CAPELLE Date: Mon, 6 Jun 2022 18:57:19 +0200 Subject: [PATCH 1/8] allow ENABLE command in NONAUTH state for UTF8 passwords --- Lib/imaplib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 577b4b9b03a88de..751a7233834e071 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -66,7 +66,7 @@ 'CREATE': ('AUTH', 'SELECTED'), 'DELETE': ('AUTH', 'SELECTED'), 'DELETEACL': ('AUTH', 'SELECTED'), - 'ENABLE': ('AUTH', ), + 'ENABLE': ('NONAUTH', 'AUTH', ), 'EXAMINE': ('AUTH', 'SELECTED'), 'EXPUNGE': ('SELECTED',), 'FETCH': ('SELECTED',), From 6216e0d14d303d78e4ee0a08b382e3ba1356aa0e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 17:15:13 +0000 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst diff --git a/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst b/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst new file mode 100644 index 000000000000000..aa019e41d622615 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst @@ -0,0 +1 @@ +imaplib allows early UTF8 enabling to handle UTF8 passwords From d877abedd9a8b599e1ed8aacaa8ba915f488be03 Mon Sep 17 00:00:00 2001 From: Julien CHATY-CAPELLE Date: Tue, 7 Jun 2022 00:50:54 +0200 Subject: [PATCH 3/8] add sasl plain auth example --- Doc/library/imaplib.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst index f1344ae9bb0a493..be703ec8d620d89 100644 --- a/Doc/library/imaplib.rst +++ b/Doc/library/imaplib.rst @@ -639,3 +639,29 @@ retrieves and prints all messages:: M.close() M.logout() +.. _imap4-plain-sasl-auth-example: + +IMAP4 Plain SASL Auth Example +------------- + +The :meth:`login` method is limited to ASCII characters by specification. +If you need to handle UTF-8 credentials you can use a simple +authentication object:: + + import getpass, imaplib + + def plain_auth(data): + user = input('User: ') + password = getpass.getpass() + response = f'{user}\x00{user}\x00{password}' + return response + + M = imaplib.IMAP4() + M.authenticate('PLAIN', plain_auth) + M.select() + typ, data = M.search(None, 'ALL') + for num in data[0].split(): + typ, data = M.fetch(num, '(RFC822)') + print('Message %s\n%s\n' % (num, data[0][1])) + M.close() + M.logout() From bde920790116af461fd914d96b84a6bc0c35d04e Mon Sep 17 00:00:00 2001 From: Julien CHATY-CAPELLE Date: Tue, 7 Jun 2022 00:51:56 +0200 Subject: [PATCH 4/8] Revert "allow ENABLE command in NONAUTH state for UTF8 passwords" This reverts commit e7be8ece2b018de7a86f1e58064009313922f8fa. --- Lib/imaplib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 751a7233834e071..577b4b9b03a88de 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -66,7 +66,7 @@ 'CREATE': ('AUTH', 'SELECTED'), 'DELETE': ('AUTH', 'SELECTED'), 'DELETEACL': ('AUTH', 'SELECTED'), - 'ENABLE': ('NONAUTH', 'AUTH', ), + 'ENABLE': ('AUTH', ), 'EXAMINE': ('AUTH', 'SELECTED'), 'EXPUNGE': ('SELECTED',), 'FETCH': ('SELECTED',), From 12e5a3e2302503ab35855198ef9a0819ad48666f Mon Sep 17 00:00:00 2001 From: Julien CHATY-CAPELLE Date: Tue, 7 Jun 2022 00:56:30 +0200 Subject: [PATCH 5/8] update news --- .../next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst b/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst index aa019e41d622615..21a6215a6809323 100644 --- a/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst +++ b/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst @@ -1 +1 @@ -imaplib allows early UTF8 enabling to handle UTF8 passwords +new example for UTF-8 credentials in the documentation of imaplib (SASL PLAIN authentication) From 46c9d1e4b106863f285db3d897e0f45fc89f3cde Mon Sep 17 00:00:00 2001 From: Julien CHATY-CAPELLE Date: Tue, 7 Jun 2022 01:04:44 +0200 Subject: [PATCH 6/8] move the example to the authenticate section --- Doc/library/imaplib.rst | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst index be703ec8d620d89..561fe65582b82ff 100644 --- a/Doc/library/imaplib.rst +++ b/Doc/library/imaplib.rst @@ -230,9 +230,20 @@ An :class:`IMAP4` instance has the following methods: that will be base64 encoded and sent to the server. It should return ``None`` if the client abort response ``*`` should be sent instead. + Example of a SASL PLAIN *authobject*:: + + def plain_auth(data): + user = input('User: ') + password = getpass.getpass() + response = f'{user}\x00{user}\x00{password}' + return response + + M.authenticate('PLAIN', plain_auth) + .. versionchanged:: 3.5 string usernames and passwords are now encoded to ``utf-8`` instead of - being limited to ASCII. + being limited to ASCII. :meth:`authenticate` is the only standard way + to use ``utf-8`` credentials on an ``IMAP4rev1`` server. .. method:: IMAP4.check() @@ -638,30 +649,3 @@ retrieves and prints all messages:: print('Message %s\n%s\n' % (num, data[0][1])) M.close() M.logout() - -.. _imap4-plain-sasl-auth-example: - -IMAP4 Plain SASL Auth Example -------------- - -The :meth:`login` method is limited to ASCII characters by specification. -If you need to handle UTF-8 credentials you can use a simple -authentication object:: - - import getpass, imaplib - - def plain_auth(data): - user = input('User: ') - password = getpass.getpass() - response = f'{user}\x00{user}\x00{password}' - return response - - M = imaplib.IMAP4() - M.authenticate('PLAIN', plain_auth) - M.select() - typ, data = M.search(None, 'ALL') - for num in data[0].split(): - typ, data = M.fetch(num, '(RFC822)') - print('Message %s\n%s\n' % (num, data[0][1])) - M.close() - M.logout() From 11f7124522f01688dab9ac09ab8083b14380adda Mon Sep 17 00:00:00 2001 From: Julien CHATY-CAPELLE Date: Tue, 7 Jun 2022 01:06:35 +0200 Subject: [PATCH 7/8] smarter syntax --- Doc/library/imaplib.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst index 561fe65582b82ff..0a3754ae5c9adc4 100644 --- a/Doc/library/imaplib.rst +++ b/Doc/library/imaplib.rst @@ -235,8 +235,7 @@ An :class:`IMAP4` instance has the following methods: def plain_auth(data): user = input('User: ') password = getpass.getpass() - response = f'{user}\x00{user}\x00{password}' - return response + return f'{user}\x00{user}\x00{password}' M.authenticate('PLAIN', plain_auth) From 224d63d4347ae0960f6eb4d9d954138ca6204ed8 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 16 Feb 2023 13:31:20 +0400 Subject: [PATCH 8/8] We do not add news for documentation changes --- .../next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst diff --git a/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst b/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst deleted file mode 100644 index 21a6215a6809323..000000000000000 --- a/Misc/NEWS.d/next/Library/2022-06-06-17-15-13.gh-issue-93548.tEXixP.rst +++ /dev/null @@ -1 +0,0 @@ -new example for UTF-8 credentials in the documentation of imaplib (SASL PLAIN authentication)