[PATCH 5 of 6] mailutil: utf patches with appropriate charset
Christian Ebert
blacktrash at gmx.net
Sat Mar 8 16:01:53 UTC 2008
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1204991685 -3600
# Node ID 6dc138f7bb0debcd50ebd156ac5880f2facc3cda
# Parent 0ebd7f655fdc1fef161a10d0786ceac33b6c5b03
mailutil: utf patches with appropriate charset
diff --git a/hgext/mailutil.py b/hgext/mailutil.py
--- a/hgext/mailutil.py
+++ b/hgext/mailutil.py
@@ -86,3 +86,15 @@
charset and transfer-encoding accordingly.'''
s, cs = self.encode(s)
return email.MIMEText.MIMEText(s, 'plain', cs)
+
+ def mimetextpatch(self, s, subtype='plain'):
+ '''If patch in ascii or utf-8 we can set correct charset.'''
+ # try out utf-16 etc.?
+ for cs in ('us-ascii', 'utf-8'):
+ try:
+ s.decode(cs)
+ return email.MIMEText.MIMEText(s, subtype, cs)
+ except UnicodeDecodeError:
+ pass
+ # pseudo us-ascii; send as binary attachment instead?
+ return email.MIMEText.MIMEText(s, subtype)
More information about the Mercurial-devel
mailing list