Skip to content

fix(conversations): fix email preview mangling newsletter content#823

Merged
Israeltheminer merged 2 commits into
mainfrom
fix/email-preview-quoted-content-detection
Mar 20, 2026
Merged

fix(conversations): fix email preview mangling newsletter content#823
Israeltheminer merged 2 commits into
mainfrom
fix/email-preview-quoted-content-detection

Conversation

@Israeltheminer
Copy link
Copy Markdown
Collaborator

@Israeltheminer Israeltheminer commented Mar 20, 2026

Summary

  • Fixed overly greedy quoted-content detection in EmailPreview that was incorrectly splitting newsletter emails (e.g. text containing "wrote about" was triggering the reply-header detector)
  • Tightened splitQuotedContent regex patterns to require a colon after "wrote", a digit (date) in the "On...wrote:" pattern, and proper line boundaries
  • Removed aggressive > / > stripping from sanitizePreviewHtml that was corrupting HTML content

Test plan

  • Added unit tests for splitQuotedContent covering false-positives (newsletter prose) and legitimate reply headers
  • Verify newsletter emails render fully in Conversations without "Show quoted text" toggle
  • Verify actual reply emails still correctly detect and collapse quoted content

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved accuracy of quoted and forwarded content detection in email previews by refining pattern matching to reduce false positives.
    • Enhanced handling of various email reply and forward formats (Apple Mail, Outlook, and standard email conventions).
  • Tests

    • Added comprehensive test coverage for quoted content splitting logic.

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

The changes refactor the email preview component's quoted content detection by exporting the previously internal splitQuotedContent function and narrowing its detection patterns. The sanitizePreviewHtml function is simplified by removing broad HTML quote marker stripping logic. The splitQuotedContent function detection patterns are refined to target specific reply/forward markers: Apple Mail "Begin forwarded message:", a stricter date-based "On ... wrote:" pattern, Outlook-style "From:" headers ending at "Subject:", and the "-----Original Message-----" separator. Comprehensive test coverage is added for the exported function with multiple edge cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 accurately summarizes the main change: fixing email preview content handling for newsletters. It directly addresses the core issue (overly greedy quoted-content detection mangling newsletter content) and is concise and specific.

✏️ 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 fix/email-preview-quoted-content-detection

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

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 `@services/platform/app/components/ui/data-display/email-preview.tsx`:
- Around line 322-328: splitQuotedContent's reply-header regexes fail on
HTML-wrapped headers; update the patterns used in splitQuotedContent to anchor
to HTML/text/block boundaries by allowing optional HTML tags or block-level
breaks (e.g., <br>, </p>, other tags or end-of-string) after the header
delimiter and by requiring a boundary before the header start (start of string
or block/tag boundary) so the "/On\s+(?=.*\d).*\swrote:\s*$/im" and
"/From:\s[\s\S]*?Subject:/i" matches also when headers are wrapped in markup;
adjust the two regexes to accept trailing HTML tags/line-break elements and
preceding block boundaries and add a regression test that passes an
HTML-formatted reply header like "<div>On ... wrote:<br>" and an HTML-formatted
"From: ... Subject:" block to ensure splitting still occurs.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5fe5aca7-3a70-4ba6-8754-6b9750b3df77

📥 Commits

Reviewing files that changed from the base of the PR and between 80c7a53 and b482771.

📒 Files selected for processing (2)
  • services/platform/app/components/ui/data-display/email-preview.test.tsx
  • services/platform/app/components/ui/data-display/email-preview.tsx

Comment on lines +322 to +328
// "On <date/time>, <name> wrote:" — standard reply header.
// Requires a colon after "wrote" and a date-like token (digit) between On and wrote.
/On\s+(?=.*\d).*\swrote:\s*$/im,
// "From: ... Subject: ..." — Outlook-style forwarding header
/From:\s[\s\S]*?Subject:/i,
// "-----Original Message-----" — Outlook reply separator
/-----\s*Original Message\s*-----/i,
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

Anchor the reply-header regexes to HTML/text boundaries.

splitQuotedContent operates on raw HTML. Line 324 only matches On … wrote: when the colon is followed by plain-text whitespace/end-of-line, so common client output like <div>On … wrote:<br> or <p>On … wrote:</p> will no longer collapse. Line 326 has the same boundary problem and can still split normal body prose containing From:Subject:. Please make these matchers aware of HTML/block boundaries and add a regression case for an HTML-formatted reply header.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@services/platform/app/components/ui/data-display/email-preview.tsx` around
lines 322 - 328, splitQuotedContent's reply-header regexes fail on HTML-wrapped
headers; update the patterns used in splitQuotedContent to anchor to
HTML/text/block boundaries by allowing optional HTML tags or block-level breaks
(e.g., <br>, </p>, other tags or end-of-string) after the header delimiter and
by requiring a boundary before the header start (start of string or block/tag
boundary) so the "/On\s+(?=.*\d).*\swrote:\s*$/im" and
"/From:\s[\s\S]*?Subject:/i" matches also when headers are wrapped in markup;
adjust the two regexes to accept trailing HTML tags/line-break elements and
preceding block boundaries and add a regression test that passes an
HTML-formatted reply header like "<div>On ... wrote:<br>" and an HTML-formatted
"From: ... Subject:" block to ensure splitting still occurs.

The quoted-content detection regex `On .* wrote` was too greedy,
matching normal prose like "Jon Kuperman wrote about..." and splitting
the email at the wrong point. The `>` stripping regexes were also
corrupting HTML content.

- Tighten splitQuotedContent patterns to require a colon after "wrote",
  a digit (date) between "On" and "wrote", and line-boundary anchoring
- Remove aggressive `>` / `&gt;` stripping from sanitizePreviewHtml
- Add tests for splitQuotedContent covering false-positives and
  legitimate reply headers
Address CodeRabbit feedback: the "On ... wrote:" regex now matches
headers wrapped in HTML tags (<div>, <p>, <br>) by using [^<] to stay
within text content boundaries instead of relying on end-of-line anchors.
@Israeltheminer Israeltheminer force-pushed the fix/email-preview-quoted-content-detection branch from 13810d2 to 873b89a Compare March 20, 2026 20:36
@Israeltheminer Israeltheminer merged commit 4465f01 into main Mar 20, 2026
17 checks passed
@Israeltheminer Israeltheminer deleted the fix/email-preview-quoted-content-detection branch March 20, 2026 20:40
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.

1 participant