Skip to content

fix(gmail): stop wrapping draft/send HTML body in per-paragraph <p> tags#5479

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/gmail-draft-html-formatting
Jul 7, 2026
Merged

fix(gmail): stop wrapping draft/send HTML body in per-paragraph <p> tags#5479
waleedlatif1 merged 2 commits into
stagingfrom
fix/gmail-draft-html-formatting

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Gmail drafts/sends always include an HTML alternative part alongside plain text — Gmail renders that HTML part, so it's what actually shows up in the compose window
  • plainTextToHtml was wrapping each paragraph in <p> tags, which carries default paragraph margins that Gmail flags as "formatting" (requiring the "Remove formatting" button to strip)
  • Switched to a single white-space: pre-wrap block, which preserves line breaks/blank lines without introducing any margin/styling

Type of Change

  • Bug fix

Testing

Updated unit tests in apps/sim/tools/gmail/utils.test.ts; full suite passes (5716/5716)

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 7, 2026 5:20pm

Request Review

@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Localized change to HTML generation for plain-text email bodies with updated tests; no auth or API contract changes.

Overview
Gmail draft/send HTML for plain-text bodies no longer wraps each paragraph in <p> tags. plainTextToHtml now escapes the full body and turns every newline into <br> inside a single <body>, so blank lines become consecutive <br> without default paragraph margins that Gmail treats as “formatting.”

Comments in utils.ts explain why <br> was chosen over <p> or CSS white-space. Unit tests in utils.test.ts were updated for plainTextToHtml, buildSimpleEmailMessage, and buildMimeMessage HTML parts.

Reviewed by Cursor Bugbot for commit e3a2a5e. Configure here.

white-space: pre-wrap has inconsistent email-client support (including
Gmail for non-Google accounts per caniemail.com); <br> is the
client-agnostic standard for plain-text-to-HTML line breaks.
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes Gmail's "Remove formatting" prompt by replacing the per-paragraph <p>-tag approach in plainTextToHtml with a flat <br>-per-newline strategy. The <p> margins are what Gmail flags as rich formatting; <br> tags preserve visual line breaks without introducing any margin/styling that email clients would treat as formatting.

  • plainTextToHtml now normalises line endings and replaces every \n with <br>, wrapping the result in a bare <body> — no <p> splits, no CSS properties.
  • All dependent tests (buildSimpleEmailMessage, buildMimeMessage) updated to match the new HTML shape.

Confidence Score: 5/5

Safe to merge — the change is confined to a single utility function and its tests, with no side effects on surrounding logic.

The rewrite of plainTextToHtml is minimal and mechanically correct: escapeHtml runs before the newline replacement, so HTML injection from user content is not affected. The new br approach is a well-understood, universally supported HTML email primitive. All related tests pass and cover the key contract.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/tools/gmail/utils.ts Replaces per-paragraph <p> tag wrapping with flat <br> newline conversion in plainTextToHtml; JSDoc updated to explain the client-compatibility rationale.
apps/sim/tools/gmail/utils.test.ts Tests updated to assert <br> line breaks and absence of <p> tags; the buildMimeMessage attachment assertion is now a weaker toContain('Hello') but still valid.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["plainTextToHtml(body)"] --> B["Normalize line endings"]
    B --> C["Escape HTML special chars"]
    C --> D["Replace newlines with br tags"]
    D --> E["Wrap in bare HTML document"]
    E --> F["Return HTML string"]
    style A fill:#4A90D9,color:#fff
    style E fill:#27AE60,color:#fff
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["plainTextToHtml(body)"] --> B["Normalize line endings"]
    B --> C["Escape HTML special chars"]
    C --> D["Replace newlines with br tags"]
    D --> E["Wrap in bare HTML document"]
    E --> F["Return HTML string"]
    style A fill:#4A90D9,color:#fff
    style E fill:#27AE60,color:#fff
Loading

Reviews (2): Last reviewed commit: "fix(gmail): use <br> instead of CSS whit..." | Re-trigger Greptile

Comment thread apps/sim/tools/gmail/utils.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e3a2a5e. Configure here.

@waleedlatif1 waleedlatif1 merged commit 954fdd8 into staging Jul 7, 2026
18 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/gmail-draft-html-formatting branch July 7, 2026 17:28
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