Skip to content

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

Description

@mgmacias95

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

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 6, 2024
  2. serhiy-storchaka commented on May 10, 2024

    @serhiy-storchaka
    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.

  3. serhiy-storchaka commented on May 10, 2024

    @serhiy-storchaka
    Member

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

  4. added
    3.12only security fixes
    3.13only security fixes
    3.14bugs and security fixes
    on May 10, 2024
  5. mgmacias95 commented on May 11, 2024

    @mgmacias95
    ContributorAuthor

    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?

  6. serhiy-storchaka commented on May 16, 2024

    @serhiy-storchaka
    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.

  7. added 3 commits that reference this issue on May 16, 2024
  8. added 2 commits that reference this issue on May 22, 2024
  9. added 3 commits that reference this issue on May 22, 2024
  10. added a commit that references this issue on May 23, 2024
  11. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixes3.13only security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions