Fix parsing from address with special chars#61
Merged
Conversation
Contributor
There was a problem hiding this comment.
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_addressutility 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 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
polsala
approved these changes
Jul 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thefrom_method in theEmailclass 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:
normalize_display_addressfunction inqreu/address.pyto ensure display names in email addresses are quoted if they contain special characters, such as commas or semicolons.from_method inqreu/email.pyto apply thenormalize_display_addressfunction to the "From" header before parsing.Unit tests for normalization:
spec/address_spec.pyto validate the behavior ofnormalize_display_address, covering scenarios like unquoted display names, already quoted names, and addresses without display names or angle brackets.spec/qreu_spec.pyto include tests for parsing emails with normalized display names and accented characters.Test fixtures:
spec/fixtures/7.txtandspec/fixtures/8.txt) to test parsing of display names with accents and encoded characters. [1] [2]spec/qreu_spec.pyto load the new fixtures.