On 2024-11-04 13:02:21 +0100, Loris Bennett via Python-list wrote: > "Loris Bennett" <loris.benn...@fu-berlin.de> writes: > > "Loris Bennett" <loris.benn...@fu-berlin.de> writes: > >> Cameron Simpson <c...@cskk.id.au> writes: > >>> On 01Nov2024 10:10, Loris Bennett <loris.benn...@fu-berlin.de> wrote: > >>>>as expected. The non-UTF-8 text occurs when I do > >>>> > >>>> mail = EmailMessage() > >>>> mail.set_content(body, cte="quoted-printable") > >>>> ... > >>>> > >>>> if args.verbose: > >>>> print(mail) > >>>> > >>>>which is presumably also correct. > >>>> > >>>>The question is: What conversion is necessary in order to print the > >>>>EmailMessage object to the terminal, such that the quoted-printable > >>>>parts are turned (back) into UTF-8? [...] > 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.
Mails can contain lots of stuff, so there is in general no suitable human readable string representation of a whole email. You have to go through it part by part and decide what you want to do with each. For example, if you have a multipart/alternative with a text/plain and a text/html part what should the "string representation" be? For some uses the text/plain part might be sufficient. For some you might want the HTML part or some rendering of it. Or what would you do with an image? Omit it completely? Just use the filename (if any)? Try to convert it to ASCII-Art? Use an AI to describe it? hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list