Sujet : Just getting my From header field back?
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 30. Nov 2023, 17:21:54
Autres entêtes
Organisation : Stefan Ram
Message-ID : <header-20231130172133@ram.dialup.fu-berlin.de>
I create an e-mail message, and I just want to get the From
header field back as I supplied it (as the documentation says:
"__getitem__(name) Return the value of the named header field."),
but when the header field is "
name@example.com (Name)", I just
get "
name@example.com" instead of "
name@example.com (Name)"
(see code example below).
How can I get the value of the named header field "From",
as the documentation says?
main.py
import email
import email.policy
posting = email.message_from_bytes\
( b'From: Name <
name@example.com>\r\n', policy=email.policy.default )
print( posting[ 'From' ])
posting = email.message_from_bytes\
( b'From:
name@example.com (Name)\r\n', policy=email.policy.default )
print( posting[ 'From' ])
output (as is)
Name <
name@example.com>
name@example.com output (as wanted)
Name <
name@example.com>
name@example.com (Name)