[PATCH 5 of 6] mailcharset: utf patches with appropriate charset

Christian Ebert blacktrash at gmx.net
Wed Jul 9 11:33:46 CDT 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1215604078 -3600
# Node ID 7d5f9b4b460243b468797cf78079e8b82d61f428
# Parent  ab8923afb48b25c55f313fa57fa234ade51cb2b9
mailcharset: utf patches with appropriate charset

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

Try other utf charsets besides utf-8?

diff --git a/mercurial/mailcharset.py b/mercurial/mailcharset.py
--- a/mercurial/mailcharset.py
+++ b/mercurial/mailcharset.py
@@ -4,6 +4,19 @@
 import util
 from i18n import _
 import email.Header, email.MIMEText, email.Utils
+
+def mimetextpatch(s, subtype='plain', **opts):
+    '''If patch in utf-8 encode it.'''
+    if not opts.get('test'):
+        # 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)
 
 class converter(object):
     '''


More information about the Mercurial-devel mailing list