Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196960

Re: Printing UTF-8 mail to terminal

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Peter J. Holzer" <hjp-python@hjp.at>
Newsgroups comp.lang.python
Subject Re: Printing UTF-8 mail to terminal
Date Tue, 5 Nov 2024 21:39:32 +0100
Lines 78
Message-ID <mailman.81.1730839621.4695.python-list@python.org> (permalink)
References <875xp7nwus.fsf@zedat.fu-berlin.de> <ZyVMe3Jspc0fJrel@cskk.homeip.net> <mailman.69.1730497664.4695.python-list@python.org> <87ed3rmg7g.fsf@zedat.fu-berlin.de> <875xp3mfku.fsf@zedat.fu-berlin.de> <871pzrmcky.fsf@zedat.fu-berlin.de> <20241105203932.rclo4j5g763cfnmh@hjp.at>
Mime-Version 1.0
Content-Type multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="x3fu3allroqu7sen"
X-Trace news.uni-berlin.de Exk6+O+WaBhGUVY33AkcmwR2keULdHuYUkGjkB2vsr7Q==
Cancel-Lock sha1:DZUmMS8W0q7Ik47ddQfKO+IZkLA= sha256:dqRVgLQClB3B5Hc5FrU32IyjqN51WWFkI01kdznOmVg=
Return-Path <hjp-python@hjp.at>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
Authentication-Results mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'content- type:multipart/signed': 0.05; 'string': 0.07; 'be?': 0.09; 'content-type:application/pgp-signature': 0.09; 'describe': 0.09; 'filename:fname piece:asc': 0.09; 'filename:fname piece:signature': 0.09; 'filename:fname:signature.asc': 0.09; 'ok,': 0.09; 'prints': 0.09; 'readable': 0.09; 'rendering': 0.09; 'writes:': 0.09; '"creative': 0.16; '>>>>': 0.16; '__/': 0.16; 'bennett': 0.16; 'cameron': 0.16; 'challenge!"': 0.16; 'conversion': 0.16; 'expected.': 0.16; 'filename': 0.16; 'from:addr:hjp-python': 0.16; 'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16; 'hjp@hjp.at': 0.16; 'holzer': 0.16; 'presumably': 0.16; 'reality.': 0.16; 'simpson': 0.16; 'skip:> 10': 0.16; 'stross,': 0.16; 'sufficient.': 0.16; 'url- ip:212.17.106.129/32': 0.16; 'url-ip:212.17.106/24': 0.16; 'url- ip:212.17/16': 0.16; 'url:hjp': 0.16; 'wildly': 0.16; '|_|_)': 0.16; 'wrote:': 0.16; "can't": 0.17; 'uses': 0.19; 'it?': 0.19; 'to:addr:python-list': 0.20; 'object': 0.26; '>>>': 0.28; 'sense': 0.28; 'example,': 0.28; 'whole': 0.30; 'question': 0.32; 'mails': 0.32; 'python-list': 0.32; 'suitable': 0.32; 'but': 0.32; 'there': 0.33; 'header:In-Reply-To:1': 0.34; '...': 0.37; 'use': 0.39; 'necessary': 0.39; 'text': 0.39; 'decide': 0.39; 'want': 0.40; 'try': 0.40; 'should': 0.40; 'email.': 0.61; 'skip:m 20': 0.63; 'email': 0.63; 'received:userid': 0.66; 'order': 0.69; 'little': 0.73; 'html': 0.80; 'received:at': 0.84; 'stuff,': 0.84; 'surprised': 0.84; 'text/html': 0.84; 'subject:UTF': 0.91; 'subject:mail': 0.95; 'turned': 0.95
Mail-Followup-To python-list@python.org
Content-Disposition inline
In-Reply-To <871pzrmcky.fsf@zedat.fu-berlin.de>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.39
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <https://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <20241105203932.rclo4j5g763cfnmh@hjp.at>
X-Mailman-Original-References <875xp7nwus.fsf@zedat.fu-berlin.de> <ZyVMe3Jspc0fJrel@cskk.homeip.net> <mailman.69.1730497664.4695.python-list@python.org> <87ed3rmg7g.fsf@zedat.fu-berlin.de> <875xp3mfku.fsf@zedat.fu-berlin.de> <871pzrmcky.fsf@zedat.fu-berlin.de>
Xref csiph.com comp.lang.python:196960

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 2024-11-04 13:02:21 +0100, Loris Bennett via Python-list wrote:
> "Loris Bennett" <loris.bennett@fu-berlin.de> writes:
> > "Loris Bennett" <loris.bennett@fu-berlin.de> writes:
> >> Cameron Simpson <cs@cskk.id.au> writes:
> >>> On 01Nov2024 10:10, Loris Bennett <loris.bennett@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.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-10-31 16:33 +0100
  Re: Printing UTF-8 mail to terminal Left Right <olegsivokon@gmail.com> - 2024-10-31 17:38 +0100
    Re: Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-01 07:52 +0100
      Re: Printing UTF-8 mail to terminal Inada Naoki <songofacandy@gmail.com> - 2024-11-03 12:08 +0900
        Re: Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-04 11:48 +0100
  Re: Printing UTF-8 mail to terminal (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-10-31 19:35 +0000
  Re: Printing UTF-8 mail to terminal Cameron Simpson <cs@cskk.id.au> - 2024-11-01 07:50 +1100
    Re: Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-01 08:11 +0100
      Re: Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-01 10:10 +0100
        Re: Printing UTF-8 mail to terminal dieter.maurer@online.de - 2024-11-01 17:38 +0100
        Re: Printing UTF-8 mail to terminal Cameron Simpson <cs@cskk.id.au> - 2024-11-02 08:47 +1100
          Re: Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-04 11:44 +0100
            Re: Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-04 11:57 +0100
              Re: Printing UTF-8 mail to terminal "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-04 13:02 +0100
                Re: Printing UTF-8 mail to terminal "Peter J. Holzer" <hjp-python@hjp.at> - 2024-11-05 21:39 +0100
                Re: Printing UTF-8 mail to terminal Cameron Simpson <cs@cskk.id.au> - 2024-11-06 08:20 +1100
      Re: Printing UTF-8 mail to terminal Cameron Simpson <cs@cskk.id.au> - 2024-11-02 08:44 +1100

csiph-web