[PATCH 1 of 2] mail: mime-encode patches that are utf-8

Christian Ebert blacktrash at gmx.net
Mon Oct 20 03:39:02 CDT 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1224491726 -7200
# Node ID 951bef46c3fc972e35c169c22bb19c840d93a1a5
# Parent  3d080733a339fbfc4fc6e4dadbbcc6e8acfa254b
mail: mime-encode patches that are utf-8

utf-8 can be safely detected without making assumptions on the
encoding/locale used by the recipient.

Content-Transfer-Encoding for utf-8 patches is base64 (default of
python's email module).

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -86,6 +86,17 @@
             raise util.Abort(_('%r specified as email transport, '
                                'but not in PATH') % method)
 
+def mimetextpatch(s, subtype='plain', display=False):
+    '''If patch in utf-8 transfer-encode it.'''
+    if not display:
+        for cs in ('us-ascii', 'utf-8'):
+            try:
+                s.decode(cs)
+                return email.MIMEText.MIMEText(s, subtype, cs)
+            except UnicodeDecodeError:
+                pass
+    return email.MIMEText.MIMEText(s, subtype)
+
 def _charsets(ui):
     '''Obtains charsets to send mail parts not containing patches.'''
     charsets = [cs.lower() for cs in ui.configlist('email', 'charsets')]


More information about the Mercurial-devel mailing list