mail: let headencode() return a native string
authorDenis Laxalde <denis@laxalde.org>
Sat, 09 Nov 2019 12:45:14 +0100
changeset 43575 67b4439c09b2
parent 43574 02802fa87b74
child 43576 14b96072797d
mail: let headencode() return a native string This is to avoid conversion to/from str on py3.
hgext/notify.py
mercurial/mail.py
--- a/hgext/notify.py	Sat Nov 09 13:23:55 2019 +0100
+++ b/hgext/notify.py	Sat Nov 09 12:45:14 2019 +0100
@@ -421,8 +421,8 @@
         maxsubject = int(self.ui.config(b'notify', b'maxsubject'))
         if maxsubject:
             subject = stringutil.ellipsis(subject, maxsubject)
-        msg['Subject'] = encoding.strfromlocal(
-            mail.headencode(self.ui, subject, self.charsets, self.test)
+        msg['Subject'] = mail.headencode(
+            self.ui, subject, self.charsets, self.test
         )
 
         # try to make message have proper sender
--- a/mercurial/mail.py	Sat Nov 09 13:23:55 2019 +0100
+++ b/mercurial/mail.py	Sat Nov 09 12:45:14 2019 +0100
@@ -365,13 +365,13 @@
     if not display:
         # split into words?
         s, cs = _encode(ui, s, charsets)
-        return encoding.strtolocal(email.header.Header(s, cs).encode())
-    return s
+        return email.header.Header(s, cs).encode()
+    return encoding.strfromlocal(s)
 
 
 def _addressencode(ui, name, addr, charsets=None):
     assert isinstance(addr, bytes)
-    name = encoding.strfromlocal(headencode(ui, name, charsets))
+    name = headencode(ui, name, charsets)
     try:
         acc, dom = addr.split(b'@')
         acc.decode('ascii')