Patchwork [1,of,2,v2] mail: convert addr to str early in addrlistencode()

login
register
mail settings
Submitter Denis Laxalde
Date Nov. 10, 2019, 9:05 a.m.
Message ID <9a59fd5811220d3d2742.1573376715@marimba>
Download mbox | patch
Permalink /patch/43102/
State Accepted
Headers show

Comments

Denis Laxalde - Nov. 10, 2019, 9:05 a.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1573314873 -3600
#      Sat Nov 09 16:54:33 2019 +0100
# Node ID 9a59fd5811220d3d2742b041dbdc9a0d0f5f2992
# Parent  b8e4d65733c52d2425e571a6148dbfbafe9ebab3
mail: convert addr to str early in addrlistencode()
Yuya Nishihara - Nov. 10, 2019, 1:17 p.m.
On Sun, 10 Nov 2019 10:05:15 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis@laxalde.org>
> # Date 1573314873 -3600
> #      Sat Nov 09 16:54:33 2019 +0100
> # Node ID 9a59fd5811220d3d2742b041dbdc9a0d0f5f2992
> # Parent  b8e4d65733c52d2425e571a6148dbfbafe9ebab3
> mail: convert addr to str early in addrlistencode()

Queued, thanks.

Patch

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -400,15 +400,15 @@  def addrlistencode(ui, addrs, charsets=N
     '''Turns a list of addresses into a list of RFC-2047 compliant headers.
     A single element of input list may contain multiple addresses, but output
     always has one address per item'''
+    straddrs = []
     for a in addrs:
         assert isinstance(a, bytes), '%r unexpectedly not a bytestr' % a
+        straddrs.append(encoding.strfromlocal(a))
     if display:
-        return [encoding.strfromlocal(a.strip()) for a in addrs if a.strip()]
+        return [a.strip() for a in straddrs if a.strip()]
 
     result = []
-    for name, addr in email.utils.getaddresses(
-        [encoding.strfromlocal(a) for a in addrs]
-    ):
+    for name, addr in email.utils.getaddresses(straddrs):
         if name or addr:
             r = _addressencode(ui, name, encoding.strtolocal(addr), charsets)
             result.append(r)