From dd1780fe8b204abc03e70254b5e0797758891379 Mon Sep 17 00:00:00 2001 From: John L Date: Sun, 13 Jun 2021 13:27:56 -0400 Subject: [PATCH] smtplib make AUTH work with non-ASCII user/pw EAI mail systems can have UTF-8 usernames and passwords. This makes AUTH use the same encoding as the rest of smtplib --- Lib/smtplib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py index 4a5ca669f6926f8..5a7d993a8177da1 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -633,7 +633,7 @@ def auth(self, mechanism, authobject, *, initial_response_ok=True): mechanism = mechanism.upper() initial_response = (authobject() if initial_response_ok else None) if initial_response is not None: - response = encode_base64(initial_response.encode('ascii'), eol='') + response = encode_base64(initial_response.encode(self.command_encoding), eol='') (code, resp) = self.docmd("AUTH", mechanism + " " + response) self._auth_challenge_count = 1 else: @@ -644,7 +644,7 @@ def auth(self, mechanism, authobject, *, initial_response_ok=True): self._auth_challenge_count += 1 challenge = base64.decodebytes(resp) response = encode_base64( - authobject(challenge).encode('ascii'), eol='') + authobject(challenge).encode(self.command_encoding), eol='') (code, resp) = self.docmd(response) # If server keeps sending challenges, something is wrong. if self._auth_challenge_count > _MAXCHALLENGE: @@ -663,7 +663,7 @@ def auth_cram_md5(self, challenge=None): if challenge is None: return None return self.user + " " + hmac.HMAC( - self.password.encode('ascii'), challenge, 'md5').hexdigest() + self.password.encode(self.command_encoding), challenge, 'md5').hexdigest() def auth_plain(self, challenge=None): """ Authobject to use with PLAIN authentication. Requires self.user and