This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maxking
Recipients andreitroiebbc, barry, maxking, r.david.murray
Date 2019-10-05.01:18:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1570238280.35.0.656906236806.issue38232@roundup.psfhosted.org>
In-reply-to
Content
It is actually parsed correctly and serialized back when you try to convert it to a string representation:

from email.parser import BytesFeedParser
import email.policy

def main():
    eml_string = 'From: Nobody <""@example.org>'
    parser = BytesFeedParser(policy = email.policy.default)
    parser.feed(eml_string.encode())
    msg = parser.close()
    print(msg.get('From').addresses[0].addr_spec)
    print(repr(msg.get('From')._parse_tree))
    print(msg.as_string())

Running this gives me:


@example.org
AddressList([Address([Mailbox([NameAddr([DisplayName([Atom([ValueTerminal('Nobody'), CFWSList([WhiteSpaceTerminal(' ')])])]), AngleAddr([ValueTerminal('<'), AddrSpec([LocalPart([QuotedString([BareQuotedString([ValueTerminal('')])])]), ValueTerminal('@'), Domain([DotAtom([DotAtomText([ValueTerminal('example'), ValueTerminal('.'), ValueTerminal('org')])])])]), ValueTerminal('>')])])])])])
From: Nobody <""@example.org>


Notice the : AddrSpec([LocalPart([QuotedString([BareQuotedString([ValueTerminal('')])])])

print() converts the addr-spec into a string, which omits the quotes. This is true for any non-none string too:


hello@example.org
AddressList([Address([Mailbox([NameAddr([DisplayName([Atom([ValueTerminal('Nobody'), CFWSList([WhiteSpaceTerminal(' ')])])]), AngleAddr([ValueTerminal('<'), AddrSpec([LocalPart([QuotedString([BareQuotedString([ValueTerminal('hello')])])]), ValueTerminal('@'), Domain([DotAtom([DotAtomText([ValueTerminal('example'), ValueTerminal('.'), ValueTerminal('org')])])])]), ValueTerminal('>')])])])])])
From: Nobody <"hello"@example.org>


If you prefer the string representation of the header's parsed value, you can try:

    print(msg.get('From').fold(policy=email.policy.default))

Which prints:

    From: Nobody <""@example.org>
History
Date User Action Args
2019-10-05 01:18:00maxkingsetrecipients: + maxking, barry, r.david.murray, andreitroiebbc
2019-10-05 01:18:00maxkingsetmessageid: <1570238280.35.0.656906236806.issue38232@roundup.psfhosted.org>
2019-10-05 01:18:00maxkinglinkissue38232 messages
2019-10-05 01:18:00maxkingcreate