email.message_from_file & quoted printable
Cameron Simpson
cs at cskk.id.au
Thu Dec 23 17:55:14 EST 2021
On 23Dec2021 14:50, Skip Montanaro <skip.montanaro at gmail.com> wrote:
>I have a bunch of old email archives I'm messing around with, for example,
>rendering them on-demand in HTML. Some of the files use quoted printable
>content transfer encoding. Here's one (with a number of headers elided):
[...]
>This message is stored in a file. I read it using
>email.message_from_file.
>In the example above, the payload still retains the quoted printable bits.
>Maybe it's not correctly encoded (no "=20" at the end of the second
>paragraph, for example)
That seems legit, as it is a space in the message text.
>, but I would have thought the email package would
>do what it could to decode things, but nope:
>
>>>> print(msg.get_payload())
From the docs:
get_payload(i=None, decode=False)
Return the current payload, which will be a list of Message
objects when is_multipart() is True, or a string when is_multipart()
is False. [...]
Optional decode is a flag indicating whether the payload should
be decoded or not, according to the Content-Transfer-Encoding
header. When True and the message is not a multipart, the payload
will be decoded if this header’s value is quoted-printable or
base64.
Try decode=True.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list