# HG changeset patch # User Christian Ebert # Date 1224517229 -7200 # Node ID d1421221858228cf1b17d260c9293b75c629df39 # Parent 099b4f9be5ab353fd76497eefdfe454a7a7586ed 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 -r 099b4f9be5ab -r d14212218582 mercurial/mail.py --- 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')]