Re: getmail failing for messages with invalid uncode
Charles Cazabon <[email protected]> Sun, 17 Oct 2021 16:48:46 -0600
| Newsgroups | gmane.mail.getmail.user |
|---|---|
| Message-ID | <[email protected]> |
Geert Stappers <[email protected]> wrote: > > another good reason to name "getmail6" without 'getmail'. Indeed. I'm hoping Roland does the right thing here. > Who learnt from this thread that Python3 is NOT so good at unicode as > advertised ... Actually, Python 3 is a huge improvement. Python 2 would implicitly and silently convert between str and unicode (equivalent of bytes and str in Python 3) in some cases, which would cause your code to work fine until you happened to pass an encoded string containing characters with the high bit set, which would then cause your application to explode. Python 3 refuses to convert them implicitly. You have to handle them separately in your code, and explicitly encode and decode them when converting between them (and specifying the correct encoding!). It's much easier to make sure your text/bytes ASCII/unicode handling are correct. The problem is a lot of programmers - at least Western-world ones, and particularly those working in English, where ASCII is a useful approximation of "possible text" - don't really understand text, unicode, code points, and encodings. They tend to deal with it cargo-cult programming style, randomly inserting `.encode(...)` and `.decode(...)` until they get something that works. It took me a few years to really "get" unicode handling. Charles -- ----------------------------------------------------------------------- Charles Cazabon GPL'ed software available at: http://pyropus.ca/software/ -----------------------------------------------------------------------