Skip to content

Fix parsing from address with special chars#61

Merged
polsala merged 3 commits intomasterfrom
fix-parsing-encoded-from
Jul 31, 2025
Merged

Fix parsing from address with special chars#61
polsala merged 3 commits intomasterfrom
fix-parsing-encoded-from

Conversation

@ecarreras
Copy link
Member

This pull request introduces a new utility function, normalize_display_address, to handle email address normalization, ensuring display names are properly quoted when necessary. It also updates the from_ method in the Email class to use this normalization function, adds corresponding test cases, and includes new fixtures for testing. Below are the key changes:

New functionality for email address normalization:

  • Added the normalize_display_address function in qreu/address.py to ensure display names in email addresses are quoted if they contain special characters, such as commas or semicolons.
  • Updated the from_ method in qreu/email.py to apply the normalize_display_address function to the "From" header before parsing.

Unit tests for normalization:

  • Added test cases in spec/address_spec.py to validate the behavior of normalize_display_address, covering scenarios like unquoted display names, already quoted names, and addresses without display names or angle brackets.
  • Updated spec/qreu_spec.py to include tests for parsing emails with normalized display names and accented characters.

Test fixtures:

  • Added new email fixtures (spec/fixtures/7.txt and spec/fixtures/8.txt) to test parsing of display names with accents and encoded characters. [1] [2]
  • Adjusted the test suite in spec/qreu_spec.py to load the new fixtures.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes email address parsing when display names contain special characters like commas or semicolons by introducing proper quoting normalization before parsing.

  • Adds a new normalize_display_address utility function to handle proper quoting of display names containing special characters
  • Updates the Email.from_ property to use the normalization function before parsing addresses
  • Includes comprehensive test coverage for the new functionality with various edge cases and character encodings

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
qreu/address.py Adds the normalize_display_address function with proper UTF-8 handling and quoting logic
qreu/email.py Updates from_ property to apply address normalization before parsing
spec/address_spec.py Adds comprehensive unit tests for the new normalization function
spec/qreu_spec.py Updates test suite to include new fixtures and adds integration tests
spec/fixtures/7.txt New test fixture with quoted display name containing accents and comma
spec/fixtures/8.txt New test fixture with encoded display name containing special characters

ecarreras and others added 2 commits July 30, 2025 14:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@polsala polsala merged commit a1c7004 into master Jul 31, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants