[PATCH 5 of 6] mail: mime-encode patches that are utf-8

Christian Ebert blacktrash at gmx.net
Sat Jul 12 14:32:52 CDT 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1215891079 -3600
# Node ID 6448dca3a747274dd2fa4465fa4369c73d6a19cf
# Parent  22d79713a3e99299da562a244c6afacaaa29a771
mail: mime-encode patches that are utf-8

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

Try other utf charsets besides utf-8?
Prefer quoted-printable over base64 for quasi-readability
of raw mail?
TODO: "hg email --test"

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -86,6 +86,18 @@
             raise util.Abort(_('%r specified as email transport, '
                                'but not in PATH') % method)
 
+def mimetextpatch(s, subtype='plain'):
+    '''if patch in utf-8 mime-encode it.'''
+    # what about further utf charsets?
+    for cs in ('us-ascii', 'utf-8'):
+        try:
+            s.decode(cs)
+            return email.MIMEText.MIMEText(s, subtype, cs)
+        except UnicodeDecodeError:
+            pass
+    # no guessing of 8bit charsets; send as binary attachment instead?
+    return email.MIMEText.MIMEText(s, subtype)
+
 def _charsets(ui):
     '''obtain charsets to send mail parts not containing patches.'''
     charsets = [cs for cs in ui.configlist('email', 'charsets')


More information about the Mercurial-devel mailing list