Error parsing email headers: AttributeError: 'ValueTerminal' object has no attribute 'fold' #118643
Copy link
Copy link
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
The following code breaks with an attribute error:
import email.parser
import email.policy
a = 't'*46
h = f'''\
To: =?utf-8?B?dGVzdC50ZXN0LnRlc3QudGVzdEB0ZXN0LmNvbeKAiw=?= <test@test.com>,\r\n\t"tttest&{a}.t.t.t.t.t.t.t@yahoo.ES" <test@test.tj>,\r\n\t"tttest&{a}.t.t.t.t.t.t@yahoo.ES" <info@test.tj>'''
m = email.parser.HeaderParser(policy=email.policy.default).parsestr(h)
m.as_string()The problem was introduced on #100885, setting ListSeparator.as_ew_allowed = False to True fixes the problem. Changing any character in the header in the example above also fixes the problem (which makes it harder to understand exactly why it's broken).
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
serhiy-storchaka commentedon May 10, 2024
From RFC 822, section 3.11:
I think it means that we should also set
ListSeparator.syntactic_breaktoFalse.serhiy-storchaka commentedon May 10, 2024
But this does not help. It just returns the bug reported in #100884.
mgmacias95 commentedon May 11, 2024
I don't understand this comment, I just tested the code mentioned in that issue setting ListSeparator.syntactic_break to
False and it works. What bug is returned then?
serhiy-storchaka commentedon May 16, 2024
It no longer raises an exception, but it encodes the comma as
=?utf-8?q?=2C?=. #100885 was not only incorrect, even after fixing the error it is not enough to fix the original issue #100884. I am trying to find a solution which fixes both the original issue and the new error.pythongh-118643: Fix AttributeError in the email module
pythongh-118643: Fix AttributeError in the email module
gh-118643: Fix AttributeError in the email module (GH-119099)
pythongh-118643: Fix AttributeError in the email module (pythonGH-119099
pythongh-118643: Fix AttributeError in the email module (pythonGH-119099
[3.11] pythongh-118643: Fix AttributeError in the email module (pytho…
[3.13] gh-118643: Fix AttributeError in the email module (GH-119099) (G…
[3.12] gh-118643: Fix AttributeError in the email module (GH-119099) (G…
[3.11] gh-118643: Fix AttributeError in the email module (GH-119099) (#…
pythongh-118643: Fix AttributeError in the email module (pythonGH-119099