feat(gateway): add HTML detection and multipart/alternative support to email adapter - #25441
feat(gateway): add HTML detection and multipart/alternative support to email adapter#25441brotherko wants to merge 1 commit into
Conversation
…o email adapter The email adapter previously always sent responses as text/plain, even when the body contained HTML content. This adds automatic HTML detection and sends a multipart/alternative email with both plain-text and HTML parts when HTML is detected, ensuring proper rendering across all email clients while maintaining a fallback for text-only clients. Co-authored-by: Cursor <cursoragent@cursor.com>
8c57952 to
5652b21
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused multipart/alternative implementation. The feature premise still holds on current main, but this branch cannot be applied as-is after the email-plugin migration.
Problems
- The PR changes
gateway/platforms/email.py, while commit560010547moved the live adapter toplugins/platforms/email/adapter.py. Current outbound paths still attachtext/plainatplugins/platforms/email/adapter.py:949,:1063, and:1143. - The current standalone sender also emits
text/plainatplugins/platforms/email/adapter.py:1219; it needs a deliberate decision if this feature covers all outbound email paths. - The detector at
gateway/platforms/email.py:160excludes valid inline-only HTML such as<a>,<span>, and<b>(also asserted by the added tests), so those bodies remain plain text.
Suggested changes
- Salvage the implementation into
plugins/platforms/email/adapter.py, update test imports, and cover the standalone route or document its exclusion. - Define the detection contract and test valid inline-only HTML before keeping the narrow tag list.
Automated hermes-sweeper review.
| if stripped.startswith(("<!DOCTYPE", "<html", "<HTML", "<!doctype")): | ||
| return True | ||
| return bool(re.search(r"<(p|div|br|h[1-6]|ul|ol|table|html)\b", stripped, re.IGNORECASE)) | ||
|
|
There was a problem hiding this comment.
This detector deliberately excludes valid inline-only HTML (<a>, <span>, <b>), which the added tests also assert. Those bodies will still be sent as text/plain; please either broaden and test the detection contract or narrow the feature claim.
|
Overlap note (2026-08-03): this PR addresses the same topic (HTML email delivery). PR #73294 (swissly) consolidates Markdown-to-HTML rendering for ALL 4 send paths + allowlist sanitizer + 20 tests, and was just rebased onto current main (commit 9529ee30). Please review #73294 for consolidation rather than duplicating send-path fixes. |
What does this PR do?
Adds automatic HTML detection to the email gateway adapter's outbound path. When the response body contains HTML content, the adapter now sends a
multipart/alternativeemail with both a plain-text fallback and the original HTML — ensuring proper rendering across all email clients while maintaining backward compatibility for text-only responses.Related Issue
Fixes #11941
Type of Change
Changes Made
gateway/platforms/email.py: Added_is_html(text)— detects HTML by checking for<!DOCTYPE/<html>prefixes and common block-level tags (<p>,<div>,<br>,<h1>–<h6>,<ul>,<ol>,<table>)gateway/platforms/email.py: Added_build_body_part(body)— returnsmultipart/alternative(plain + HTML) when HTML detected, otherwise plainMIMETextas beforegateway/platforms/email.py: Updated_send_email,_send_email_with_attachment, and_send_email_with_attachmentsto use_build_body_part()instead of hardcodedMIMEText(body, "plain", ...)How to Test
mustrstripe) show the plain-text fallback from themultipart/alternativeChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AMade with Cursor