Skip to content

Fix double quoted email address validation#43

Open
chris-adam wants to merge 1 commit intomasterfrom
DMS-1195
Open

Fix double quoted email address validation#43
chris-adam wants to merge 1 commit intomasterfrom
DMS-1195

Conversation

@chris-adam
Copy link
Copy Markdown
Contributor

@chris-adam chris-adam commented Apr 17, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of complex email formats with embedded quotes so real names and addresses are normalized and validated correctly.
  • Tests
    • Added a test asserting correct parsing of quoted/escaped real-name values in email addresses.
  • Chores
    • Updated unreleased changelog entry to note the email validation fix.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 76506d8a-793e-4752-8ae8-7e3704351ebf

📥 Commits

Reviewing files that changed from the base of the PR and between abc6481 and ba62a71.

📒 Files selected for processing (3)
  • CHANGES.rst
  • src/imio/helpers/emailer.py
  • src/imio/helpers/tests/test_email.py
✅ Files skipped from review due to trivial changes (2)
  • CHANGES.rst
  • src/imio/helpers/tests/test_email.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/imio/helpers/emailer.py

📝 Walkthrough

Walkthrough

The double-quote handling in validate_email_address was changed to anchored, start-focused regex normalization: it now detects a leading "" prefix, extracts a quoted real-name and address with anchored matches, strips extra " from the name, reconstructs "<name>" <addr>, then proceeds with existing parsing and validation.

Changes

Cohort / File(s) Summary
Email parsing logic
src/imio/helpers/emailer.py
Replaced substring-based un-doubling with start-anchored regex checks. Now guards with eml.startswith('""'), captures quoted name and address using anchored patterns, removes remaining " from the name, rebuilds "<name>" <addr> and continues with parseaddr and validation.
Tests
src/imio/helpers/tests/test_email.py
Added an assertion verifying parsing of a real name containing embedded/escaped quotes ("\"\"Real name\", Long real name\" <name@domain.org>") into Real name, Long real name and name@domain.org.
Changelog
CHANGES.rst
Replaced placeholder with entry "Fix double quoted email address validation" under 1.3.15 (unreleased), credited to [chris-adam].

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibbled at quotes, untwined the knot,
Pulled stray marks out, left names tidy in spot,
I stitched the string — a cleaner mail song,
Now names and addresses hop along,
— a rabbit's little fix for parsing gone wrong

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix double quoted email address validation' directly and clearly describes the main change: fixing email validation for double-quoted email addresses, as evidenced by changes to the emailer validation logic and corresponding test.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DMS-1195

Comment @coderabbitai help to get the list of available commands and usage tips.

@chris-adam chris-adam requested a review from sgeulette April 17, 2026 12:35
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/imio/helpers/emailer.py`:
- Around line 252-257: The current normalization in the email formatter removes
every double-quote via name_part.replace('"', ''), which corrupts
intended/escaped quotes; instead only collapse doubled quotes into a single
quote. Update the logic in the block handling parts = re.match(...) so that
clean_name collapses double-quotes (e.g. replace occurrences of '""' with '"' or
use a regex to substitute r'""' -> '"') rather than removing all '"' characters,
then continue to reformat eml as before with u'"{}" <{}>'. Ensure this change is
applied where name_part and addr_part are extracted so escaped single quotes are
preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a1d0c96d-fa44-4dce-965d-91e4a93b8841

📥 Commits

Reviewing files that changed from the base of the PR and between 5b387a7 and 1aae039.

📒 Files selected for processing (1)
  • src/imio/helpers/emailer.py

Comment thread src/imio/helpers/emailer.py Outdated
Comment on lines +252 to +257
# '"\\"' ends with '""' and must be corrected. We choose to un-double the doublequotes
parts = re.match(r'^["\s]*(.*?)["\s]*<(.*)>', eml)
if parts:
name_part, addr_part = parts.groups()
clean_name = name_part.replace('"', '')
eml = u'"{}" <{}>'.format(clean_name, addr_part)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Quote normalization is over-aggressive and can corrupt valid real names.

On Line 256, name_part.replace('"', '') strips all quotes, including intentional/escaped ones. That conflicts with existing expected behavior (see src/imio/helpers/tests/test_email.py:163-193, escaped-quote case). Please normalize only doubled quotes, not every quote character.

Proposed targeted fix
-        parts = re.match(r'^["\s]*(.*?)["\s]*<(.*)>', eml)
+        parts = re.match(r'^\s*(.*?)\s*<([^<>]+)>\s*$', eml)
         if parts:
             name_part, addr_part = parts.groups()
-            clean_name = name_part.replace('"', '')
-            eml = u'"{}" <{}>'.format(clean_name, addr_part)
+            # Only undouble raw double-quotes; preserve intentional/escaped quotes.
+            clean_name = re.sub(r'(?<!\\)""', '"', name_part)
+            eml = u'{} <{}>'.format(clean_name.strip(), addr_part)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/imio/helpers/emailer.py` around lines 252 - 257, The current
normalization in the email formatter removes every double-quote via
name_part.replace('"', ''), which corrupts intended/escaped quotes; instead only
collapse doubled quotes into a single quote. Update the logic in the block
handling parts = re.match(...) so that clean_name collapses double-quotes (e.g.
replace occurrences of '""' with '"' or use a regex to substitute r'""' -> '"')
rather than removing all '"' characters, then continue to reformat eml as before
with u'"{}" <{}>'. Ensure this change is applied where name_part and addr_part
are extracted so escaped single quotes are preserved.

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 17, 2026

Coverage Status

coverage: 80.868% (+0.04%) from 80.83% — DMS-1195 into master

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.

2 participants