Re: Printing UTF-8 mail to terminal

Liste des GroupesRevenir à cl python 
Sujet : Re: Printing UTF-8 mail to terminal
De : cs (at) *nospam* cskk.id.au (Cameron Simpson)
Groupes : comp.lang.python
Date : 05. Nov 2024, 23:20:44
Autres entêtes
Message-ID : <mailman.84.1730841650.4695.python-list@python.org>
References : 1 2
User-Agent : Mutt/2.2.13 (2024-03-09)
On 04Nov2024 13:02, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
OK, so I can do:
>
######################################################################
if args.verbose:
   for k in mail.keys():
       print(f"{k}: {mail.get(k)}")
   print('')
   print(mail.get_content())
######################################################################
>
prints what I want and is not wildly clunky, but I am a little surprised
that I can't get a string representation of the whole email in one go.
A string representation of the whole message needs to be correctly encoded so that its components can be identified mechanically. So it needs to be a syntacticly valid RFC5322 message. Thus the encoding.
As an example (slightly contrived) of why this is important, multipart messages are delimited with distinct lines, and their content may not present such a line (even f it's in the "raw" original data).
So printing a whole message transcribes it in the encoded form so that it can be decoded mechanically. And conservativly, this is usually an ASCII compatibly encoding so that it can traverse various systems undamaged. This means the text requiring UTF8 encoding get further encoded as quoted printable to avoid ambiguity about the meaning of bytes/octets which have their high bit set.
BTW, doesn't this:
     for k in mail.keys():
         print(f"{k}: {mail.get(k)}")
print the quoted printable (i.e. not decoded) form of subject lines?
Cheers,
Cameron Simpson <cs@cskk.id.au>

Date Sujet#  Auteur
31 Oct 24 * Printing UTF-8 mail to terminal17Loris Bennett
31 Oct 24 +* Re: Printing UTF-8 mail to terminal4Left Right
1 Nov 24 i`* Re: Printing UTF-8 mail to terminal3Loris Bennett
3 Nov 24 i `* Re: Printing UTF-8 mail to terminal2Inada Naoki
4 Nov 24 i  `- Re: Printing UTF-8 mail to terminal1Loris Bennett
31 Oct 24 +- Re: Printing UTF-8 mail to terminal (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
31 Oct 24 `* Re: Printing UTF-8 mail to terminal11Cameron Simpson
1 Nov 24  `* Re: Printing UTF-8 mail to terminal10Loris Bennett
1 Nov 24   +* Re: Printing UTF-8 mail to terminal8Loris Bennett
1 Nov 24   i+- Re: Printing UTF-8 mail to terminal1dieter.maurer
1 Nov 24   i`* Re: Printing UTF-8 mail to terminal6Cameron Simpson
4 Nov 24   i `* Re: Printing UTF-8 mail to terminal5Loris Bennett
4 Nov 24   i  `* Re: Printing UTF-8 mail to terminal4Loris Bennett
4 Nov 24   i   `* Re: Printing UTF-8 mail to terminal3Loris Bennett
5 Nov 24   i    +- Re: Printing UTF-8 mail to terminal1Peter J. Holzer
5 Nov 24   i    `- Re: Printing UTF-8 mail to terminal1Cameron Simpson
1 Nov 24   `- Re: Printing UTF-8 mail to terminal1Cameron Simpson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal