Python3.6 , email.message.Message.get_content() . get_payload(), get_payload() .
, s ( ):
Subject: Ayons asperges pour le =?utf-8?q?d=C3=A9jeuner?=
From: =?utf-8?q?Pep=C3=A9?= Le Pew <pepe@example.com>
To: Penelope Pussycat <penelope@example.com>,
Fabrette Pussycat <fabrette@example.com>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Salut!
Cela ressemble =C3=A0 un excellent recipie[1] d=C3=A9jeuner.
[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718
--Pep=C3=A9
=20
-ascii quoted-printable quoted-printable, Content-Transfer-Encoding.
:
import email
from email import policy
msg = email.message_from_string(s, policy=policy.default)
; policy.compat32, , get_content. policy.default , Python3.7 policy.compat32.
The method get_content()handles decoding automatically:
print(msg.get_content())
Salut!
Cela ressemble Γ un excellent recipie[1] dΓ©jeuner.
[1] http:
--PepΓ©
If you have a get_content()message, get_content()you must call for individual parts, for example like this:
for part in message.iter_parts():
print(part.get_content())
source
share