From 25402ab641246fedad7be1b7f1b38731a89356ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Buczkowski?= Date: Thu, 6 Mar 2025 13:08:51 +0000 Subject: [PATCH] Use AUTHENTICATE PLAIN instead of LOGIN Makes imaplib use more modern AUTHENTICATE verb rather than LOGIN. The immediate benefit is that now the credentials can be non-ASCII. In the future, it may be used to add other authentication methods, such as OAuth. References: * https://datatracker.ietf.org/doc/html/rfc6855.html#page-5 * https://bugs.python.org/issue13700 --- radicale/auth/imap.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/radicale/auth/imap.py b/radicale/auth/imap.py index 3fdbaa70..18af91d1 100644 --- a/radicale/auth/imap.py +++ b/radicale/auth/imap.py @@ -59,7 +59,10 @@ class Auth(auth.BaseAuth): if self._security == "starttls": connection.starttls(ssl.create_default_context()) try: - connection.login(login, password) + connection.authenticate( + "PLAIN", + lambda _: "{0}\x00{0}\x00{1}".format(login, password).encode(), + ) except imaplib.IMAP4.error as e: logger.warning("IMAP authentication failed for user %r: %s", login, e, exc_info=False) return ""