Deutsch   English   Français   Italiano  
<mailman.81.1730839621.4695.python-list@python.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.nobody.at!news.swapon.de!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>
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>
Bytes: 7174


--x3fu3allroqu7sen
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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 =3D EmailMessage()
> >>>>  mail.set_content(body, cte=3D"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:
>=20
> ######################################################################
> if args.verbose:
>     for k in mail.keys():
>         print(f"{k}: {mail.get(k)}")
>     print('')
>     print(mail.get_content())
> ######################################################################
>=20
> 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

--=20
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

--x3fu3allroqu7sen
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmcqgn4ACgkQ8g5IURL+
KF1W/hAAgjdxK0LTU1ujYIKi3RzIzJdTXx5/XZsDFyaSIcFuGwmxOx64Pg3petNd
UcI1aOcUmZhYU5YJ91Q/vYgCID/wBWqycjfQLL7N50+FMK3428KAngPeI97S5sAP
EjnfiLkM30RElveaeDBD4Savunlc93Sr74+o0+tbi/0EzuLAEB4hqPStFYUAgpLX
7f+tS26bQjAZ7EMR4oRtrerJjUV9a4c1FMakAEk8MR7A9aEvFBSR4CpDXlH3D5hB
M1iDtxh2NFLwVfiGhadfjqOww0EHGrHEDPN8nQMIs43IFIAF8tx4jood9LgGni20
x633eO9jMZ3hD/T51VqVTpv0T374Y2++SGGOsXYO/T9tFVexJH957wyXMxCwQN48
lI5XVpW8U4TKQ55n5LX5w3ZEXyCq6drR5JkRhZpl50toEz8S0QrdEv53IyANbXfJ
gaQzwfRcWEgBwSldrAaeJaeTsq3DQAOL90wY4Vk84yYWcVWxjhLM4QdzAJa4VoUh
djLSQ0qvXgJe8I6w0kFfuWpIiPc0WV7LFDQlyxyQ8YZj0xGM9AsIVOaW1KX4h9W7
xqhlusKwR7cViXoF6JixTBYRPWqxkOhmcNjuH28BklRTi7KvNFN4QVdj4hFK1yT9
27rlsW+VZXRCiEF7/pSizYhHscZhhgMsBXFMQ8lkV7SMmbqc93Q=
=mVw9
-----END PGP SIGNATURE-----

--x3fu3allroqu7sen--