Patchwork [STABLE] py3: decode Subject header in patchbomb

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 29, 2019, 5:19 p.m.
Message ID <305a12fc7cc8bed4a9dd.1572369586@marimba>
Download mbox | patch
Permalink /patch/42614/
State New
Headers show

Comments

Denis Laxalde - Oct. 29, 2019, 5:19 p.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1572369108 -3600
#      Tue Oct 29 18:11:48 2019 +0100
# Branch stable
# Node ID 305a12fc7cc8bed4a9dd95e91de3747ba6daf8ce
# Parent  17fad3f1b4742d75db23e17a04c85223bcc239a2
py3: decode Subject header in patchbomb

This fixes a crash on Python 3 when using non-ascii characters in commit
message (or subject header, e.g., in introduction message). A test was
introduced in previous changeset.

Patch

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -321,7 +321,9 @@  def makepatch(
         subj = b' '.join([prefix, opts.get(b'subject') or subj])
     else:
         subj = b' '.join([prefix, subj])
-    msg[b'Subject'] = mail.headencode(ui, subj, _charsets, opts.get(b'test'))
+    msg[b'Subject'] = encoding.strfromlocal(
+        mail.headencode(ui, subj, _charsets, opts.get(b'test'))
+    )
     msg[b'X-Mercurial-Node'] = node
     msg[b'X-Mercurial-Series-Index'] = b'%i' % idx
     msg[b'X-Mercurial-Series-Total'] = b'%i' % total
@@ -454,7 +456,9 @@  def _makeintro(repo, sender, revs, patch
 
     body = _getdescription(repo, body, sender, **opts)
     msg = mail.mimeencode(ui, body, _charsets, opts.get(r'test'))
-    msg[b'Subject'] = mail.headencode(ui, subj, _charsets, opts.get(r'test'))
+    msg[b'Subject'] = encoding.strfromlocal(
+        mail.headencode(ui, subj, _charsets, opts.get(r'test'))
+    )
     return (msg, subj, diffstat)