Skip to content

Conversation

@AndreasLF
Copy link
Contributor

Fixes #148

As detailed in the linked issue, the ported_string utility crashes with a TypeError when it receives an email.header.Header object instead of a string or bytes. This behavior occurs in certain edge cases involving specific encodings or Python environment configurations.

Currently, ported_string assumes that any input that is not a string must be bytes, leading to a crash when it attempts to call str(raw_data, encoding) on a Header object.

Changes

  • mailparser/utils.py: Added an explicit isinstance check for email.header.Header. Since Header objects implement __str__, they are now safely converted to string using str() before processing.
  • tests/test_utils.py: Added unit test that parses a Header object to ported string, verifying that the fix works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError in ported_string when parsing headers as email.header.Header objects

1 participant