Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing email headers: AttributeError: 'ValueTerminal' object has no attribute 'fold' #118643

Closed
mgmacias95 opened this issue May 6, 2024 · 4 comments
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@mgmacias95
Copy link
Contributor

mgmacias95 commented May 6, 2024

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

@mgmacias95 mgmacias95 added the type-bug An unexpected behavior, bug, or error label May 6, 2024
@Eclips4 Eclips4 added stdlib Python modules in the Lib dir topic-email labels May 6, 2024
@serhiy-storchaka
Copy link
Member

From RFC 822, section 3.11:

        Note:  While the standard  permits  folding  wherever  linear-
               white-space is permitted, it is recommended that struc-
               tured fields, such as those containing addresses, limit
               folding  to higher-level syntactic breaks.  For address
               fields, it  is  recommended  that  such  folding  occur
               between addresses, after the separating comma.

I think it means that we should also set ListSeparator.syntactic_break to False.

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented May 10, 2024

But this does not help. It just returns the bug reported in #100884.

@serhiy-storchaka serhiy-storchaka self-assigned this May 10, 2024
@serhiy-storchaka serhiy-storchaka added 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels May 10, 2024
@mgmacias95
Copy link
Contributor Author

But this does not help. It just returns the bug reported in #100884.

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
Copy link
Member

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.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 16, 2024
Fix regression introduced in pythongh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in pythongh-100884.
serhiy-storchaka added a commit that referenced this issue May 22, 2024
Fix regression introduced in gh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in gh-100884.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 22, 2024
)

Fix regression introduced in pythongh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in pythongh-100884.
(cherry picked from commit 858b9e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 22, 2024
)

Fix regression introduced in pythongh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in pythongh-100884.
(cherry picked from commit 858b9e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 22, 2024
…nGH-119099)

Fix regression introduced in pythongh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in pythongh-100884.
(cherry picked from commit 858b9e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue May 22, 2024
…H-119389)

Fix regression introduced in gh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in gh-100884.
(cherry picked from commit 858b9e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue May 22, 2024
…H-119390)

Fix regression introduced in gh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in gh-100884.
(cherry picked from commit 858b9e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchaka serhiy-storchaka added the 3.11 only security fixes label May 22, 2024
pablogsal pushed a commit that referenced this issue May 23, 2024
…119393)

Fix regression introduced in gh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in gh-100884.
(cherry picked from commit 858b9e8)
@hugovk hugovk closed this as completed Jun 15, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
)

Fix regression introduced in pythongh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in pythongh-100884.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants