[PATCH 4 of 4] py3: decode username and password before SMTP login

Denis Laxalde denis at laxalde.org
Thu Oct 10 15:47:31 EDT 2019


# HG changeset patch
# User Denis Laxalde <denis at laxalde.org>
# Date 1570736232 -7200
#      Thu Oct 10 21:37:12 2019 +0200
# Node ID 8844da7eb7a0aa9138f88867e737221aa8193221
# Parent  4439ff86e50d2d9c0ad63200cf22fa1c3461d3df
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.

diff --git a/mercurial/mail.py b/mercurial/mail.py
index 0d2139b..8fe752d 100644
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -145,10 +145,14 @@ def _smtp(ui):
         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:



More information about the Mercurial-devel mailing list