Patchwork [5,of,6] mail: move strtolocal call in _addressencode()

login
register
mail settings
Submitter Denis Laxalde
Date Nov. 13, 2019, 9:59 p.m.
Message ID <11d514fd71855ace61c5.1573682398@marimba>
Download mbox | patch
Permalink /patch/43162/
State Accepted
Headers show

Comments

Denis Laxalde - Nov. 13, 2019, 9:59 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1573659988 -3600
#      Wed Nov 13 16:46:28 2019 +0100
# Node ID 11d514fd71855ace61c549d3154f52569cea9264
# Parent  6f035c6bb911f36cd2459272843388a218be120d
mail: move strtolocal call in _addressencode()

Patch

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -395,8 +395,8 @@  def headencode(ui, s, charsets=None, dis
 
 
 def _addressencode(ui, name, addr, charsets=None):
-    # type: (Any, str, bytes, List[str]) -> str
-    assert isinstance(addr, bytes)
+    # type: (Any, str, str, List[str]) -> str
+    addr = encoding.strtolocal(addr)
     name = headencode(ui, name, charsets)
     try:
         acc, dom = addr.split(b'@')
@@ -420,7 +420,7 @@  def addressencode(ui, address, charsets=
     if display or not address:
         return encoding.strfromlocal(address or b'')
     name, addr = email.utils.parseaddr(encoding.strfromlocal(address))
-    return _addressencode(ui, name, encoding.strtolocal(addr), charsets)
+    return _addressencode(ui, name, addr, charsets)
 
 
 def addrlistencode(ui, addrs, charsets=None, display=False):
@@ -438,7 +438,7 @@  def addrlistencode(ui, addrs, charsets=N
     result = []
     for name, addr in email.utils.getaddresses(straddrs):
         if name or addr:
-            r = _addressencode(ui, name, encoding.strtolocal(addr), charsets)
+            r = _addressencode(ui, name, addr, charsets)
             result.append(r)
     return result