Sfoglia il codice sorgente

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
Przemysław Buczkowski 11 mesi fa
parent
commit
25402ab641
1 ha cambiato i file con 4 aggiunte e 1 eliminazioni
  1. 4 1
      radicale/auth/imap.py

+ 4 - 1
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 ""