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

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 10, 2019, 7:47 p.m.
Message ID <8844da7eb7a0aa9138f8.1570736851@marimba>
Download mbox | patch
Permalink /patch/42195/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 10, 2019, 7:47 p.m.
# HG changeset patch
# User Denis Laxalde <denis@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.

Patch

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: