changeset 7191:d14212218582

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).
author Christian Ebert <blacktrash@gmx.net>
date Mon, 20 Oct 2008 17:40:29 +0200
parents 099b4f9be5ab
children f31ba106fc19
files mercurial/mail.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mail.py	Mon Oct 20 14:13:37 2008 +0200
+++ b/mercurial/mail.py	Mon Oct 20 17:40:29 2008 +0200
@@ -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')]