Mercurial > public > mercurial-scm > hg
comparison mercurial/mail.py @ 39037:ede768cfe83e
mail: always fall back to iso-8859-1 if us-ascii won't work (BC)
It looks like this was a well-intentioned backwards compat hack for
previewing the output of `hg email` in a stable way. Unfortunately I
think this hack's time has come, because Python 3 does a much better
job of ensuring it actually emits *valid* email messages. In
particular, Python 2 would blindly trust us that the bytes we handed
it were valid for the encoding we claimed, but Python 3 has some more
sniff-tests that we end up failing.
As a result, if we're going to print an email to the terminal, try
us-ascii first, but if that fails go straight to iso-8859-1 which
should be reasonably readable for ascii-compatible patch bodies. This
*will* be a breaking change for ascii-incompatible textual patch
content, but I don't think that's avoidable if we want to continue
using the email library from the stdlib.
.. bc::
Emails from the patchbomb extension will always be printed as though
they are iso-8859-1 if they're not valid us-ascii. Previously,
previewed emails were always claimed to be us-ascii and might
contain invalid byte sequences.
Differential Revision: https://phab.mercurial-scm.org/D4231
author | Augie Fackler <augie@google.com> |
---|---|
date | Thu, 09 Aug 2018 21:04:15 -0400 |
parents | 2cf3bd4ae55e |
children | 952bf3c948f0 |
comparison
equal
deleted
inserted
replaced
39036:598467614c15 | 39037:ede768cfe83e |
---|---|
218 ISO-8859-1, an encoding with that allows all byte sequences. | 218 ISO-8859-1, an encoding with that allows all byte sequences. |
219 Transfer encodings will be used if necessary.''' | 219 Transfer encodings will be used if necessary.''' |
220 | 220 |
221 cs = ['us-ascii', 'utf-8', encoding.encoding, encoding.fallbackencoding] | 221 cs = ['us-ascii', 'utf-8', encoding.encoding, encoding.fallbackencoding] |
222 if display: | 222 if display: |
223 return mimetextqp(s, subtype, 'us-ascii') | 223 cs = ['us-ascii'] |
224 for charset in cs: | 224 for charset in cs: |
225 try: | 225 try: |
226 s.decode(pycompat.sysstr(charset)) | 226 s.decode(pycompat.sysstr(charset)) |
227 return mimetextqp(s, subtype, codec2iana(charset)) | 227 return mimetextqp(s, subtype, codec2iana(charset)) |
228 except UnicodeDecodeError: | 228 except UnicodeDecodeError: |