changeset 43172:9145abd8b96d

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.
author Denis Laxalde <denis@laxalde.org>
date Thu, 10 Oct 2019 21:37:12 +0200
parents 54b06bec8914
children 070a38737334
files mercurial/mail.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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: