patchbomb: work around email module really wanting to write unicode data
authorAugie Fackler <augie@google.com>
Mon, 16 Jul 2018 14:14:27 -0400
changeset 39022 b95538a21613
parent 39020 0b5f534df82a
child 39023 858fe9625dab
patchbomb: work around email module really wanting to write unicode data Differential Revision: https://phab.mercurial-scm.org/D3951
hgext/patchbomb.py
--- a/hgext/patchbomb.py	Thu Aug 09 12:25:06 2018 -0700
+++ b/hgext/patchbomb.py	Mon Jul 16 14:14:27 2018 -0400
@@ -139,6 +139,11 @@
     default=None,
 )
 
+if pycompat.ispy3:
+    _bytesgenerator = emailgen.BytesGenerator
+else:
+    _bytesgenerator = lambda f: f
+
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
@@ -793,7 +798,8 @@
         if opts.get('test'):
             ui.status(_('displaying '), subj, ' ...\n')
             ui.pager('email')
-            generator = emailgen.Generator(ui, mangle_from_=False)
+            generator = emailgen.Generator(_bytesgenerator(ui),
+                                           mangle_from_=False)
             try:
                 generator.flatten(m, 0)
                 ui.write('\n')
@@ -809,7 +815,8 @@
                 # Exim does not remove the Bcc field
                 del m['Bcc']
             fp = stringio()
-            generator = emailgen.Generator(fp, mangle_from_=False)
+            generator = emailgen.Generator(_bytesgenerator(fp),
+                                           mangle_from_=False)
             generator.flatten(m, 0)
             sendmail(sender_addr, to + bcc + cc, fp.getvalue())