patchbomb: ensure all headers and values given to email mod are native strings
authorAugie Fackler <augie@google.com>
Mon, 16 Jul 2018 14:15:29 -0400
changeset 38776 65ed2fcb9032
parent 38775 e971d6eb4770
child 38777 83a505b5cf85
patchbomb: ensure all headers and values given to email mod are native strings This lets test-patch-bookmark.t only fail with some harmless header output changes on Python 3, so I think patchbomb might be basically useful on Python 3 now. Differential Revision: https://phab.mercurial-scm.org/D3952
hgext/patchbomb.py
--- a/hgext/patchbomb.py	Mon Jul 30 14:37:36 2018 -0700
+++ b/hgext/patchbomb.py	Mon Jul 16 14:15:29 2018 -0400
@@ -780,6 +780,16 @@
             m['Bcc'] = ', '.join(bcc)
         if replyto:
             m['Reply-To'] = ', '.join(replyto)
+        # Fix up all headers to be native strings.
+        # TODO(durin42): this should probably be cleaned up above in the future.
+        if pycompat.ispy3:
+            for hdr, val in list(m.items()):
+                if isinstance(hdr, bytes):
+                    del m[hdr]
+                    hdr = pycompat.strurl(hdr)
+                if isinstance(val, bytes):
+                    val = pycompat.strurl(val)
+                m[hdr] = val
         if opts.get('test'):
             ui.status(_('displaying '), subj, ' ...\n')
             ui.pager('email')