Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Just getting my From header field back? Date: 30 Nov 2023 16:21:54 GMT Organization: Stefan Ram Lines: 34 Expires: 1 Dec 2024 11:59:58 GMT Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de c8GqvzofQGkatyTNbM22lgGRIZ/3O/mRUDEFKMwwUVllKT Cancel-Lock: sha1:bQ+aTctAF5VPY4zHwAdqvPb7FzQ= sha256:dUdn7O4EQ3L3ecrBX+s8usO4dEvgpHRaJznjgAZnTh8= X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Accept-Language: de-DE-1901, en-US, it, fr-FR 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 \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 output (as wanted) Name name@example.com (Name)