Printing UTF-8 mail to terminal

Cameron Simpson cs at cskk.id.au
Fri Nov 1 17:44:18 EDT 2024


On 01Nov2024 08:11, Loris Bennett <loris.bennett at fu-berlin.de> wrote:
>Cameron Simpson <cs at cskk.id.au> writes:
>> If you're using the Python email module to parse (or construct) the
>> message as a `Message` object I'd expect that to happen automatically.
>
>I am using
>  email.message.EmailMessage

Noted. That seems like the correct approach to me.

>And you are right that encoding for the actual mail which is received 
>is
>automatically sorted out.  If I display the raw email in my client I get
>the following:
>
>  Content-Type: text/plain; charset="utf-8"
>  Content-Transfer-Encoding: quoted-printable
>  ...
>  Subject: =?utf-8?q?=C3=9Cbungsbetreff?=
>  ...
>  Dies ist eine =C3=9Cbung.

Right. Quoted-printable encoding for the transport.

>I would interpret that as meaning that the subject and body are encoded
>in the same way.

Yes.

>The problem just occurs with the unsent string representation printed to
>the terminal.

Yes, and I was thinking abut this yesterday. I suspect that 
`print(some_message_object)` is intended to transcribe it for transport.  
For example, one could write to an mbox file and just print() the 
message into it and get correct transport/storage formatting, which 
includes the qp encoding.

Can you should the code (or example code) which leads to the qp output?  
I suspect there's a straight forward way to get the decoded Unicode, but 
I'd need to see how what you've got was obtained.


More information about the Python-list mailing list