py3: decode username and password before SMTP login
authorDenis Laxalde <denis@laxalde.org>
Thu, 10 Oct 2019 21:37:12 +0200
changeset 43172 9145abd8b96d
parent 43171 54b06bec8914
child 43173 070a38737334
py3: decode username and password before SMTP login smtplib.SMTP.login() requires str on Python 3. For 'password', we only need to decode when value comes from config as getpass() returns the correct type already.
mercurial/mail.py
--- a/mercurial/mail.py	Thu Oct 10 21:30:44 2019 +0200
+++ b/mercurial/mail.py	Thu Oct 10 21:37:12 2019 +0200
@@ -145,10 +145,14 @@
         sslutil.validatesocket(s.sock)
     username = ui.config(b'smtp', b'username')
     password = ui.config(b'smtp', b'password')
-    if username and not password:
-        password = ui.getpass()
+    if username:
+        if password:
+            password = encoding.strfromlocal(password)
+        else:
+            password = ui.getpass()
     if username and password:
         ui.note(_(b'(authenticating to mail server as %s)\n') % username)
+        username = encoding.strfromlocal(username)
         try:
             s.login(username, password)
         except smtplib.SMTPException as inst: