Skip to content

fix(email): add <hr> to HTML body detection (Codex P2 follow-up) - #38

Closed
dizhaky wants to merge 2 commits into
mainfrom
fix/email-hr-tag-detection
Closed

fix(email): add <hr> to HTML body detection (Codex P2 follow-up)#38
dizhaky wants to merge 2 commits into
mainfrom
fix/email-hr-tag-detection

Conversation

@dizhaky

@dizhaky dizhaky commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to PR #37 Codex P2 review — the one remaining unaddressed structural gap in _is_html_body().

What changed

_HTML_TAGS in gateway/platforms/email.py (line 241) lacked hr, a common void element used in HTML digest emails. Outgoing emails whose only or first recognizable markup was <hr> or <hr/> were misclassified as plain text, sending the horizontal rule as a literal <hr> string inside a text/plain part.

One-character change: added hr| to the alternation.

Why safe

<hr> is a void element with no closing tag and takes no text content, so:

  • No false-positive risk: the regex requires > or /> directly after hr, so prose comparisons like x<hr do not match.
  • <style>/<script> stripping (lines 172–179) and all other _strip_html passes are unaffected.
  • The _HTML_CLOSE_TAGS list (used for closing-tag detection) does not need hr since </hr> is not valid HTML.

Codex P2 status after this PR

All 15 Codex P2 findings from PR #37 are now addressed:

Finding Status
Preserve literal HTML snippets in plain replies Handled: _text_to_html() escapes < > & for non-HTML bodies
Recognize common standalone HTML tags (img, pre) Fixed in commit 69871ee
Recognize <hr> standalone tag Fixed by this PR
Preserve whitespace in generated HTML alternatives Fixed: pre-wrap; word-wrap: break-word
Strip HTML for plain alternative Fixed: _strip_html() on HTML bodies
Avoid treating compact comparisons as anchor tags Fixed: anchor requires href/name attribute
Avoid matching p, code, div comparisons as HTML Fixed: regex requires > or /> or attr=
Preserve link targets in plain fallbacks Fixed: label (url) format
Keep block boundaries in plain fallbacks Fixed: </p>, </li>, </tr> → newlines
Separate table cells in plain fallbacks Fixed: </td><td> → tab
Remove style and script blocks from plain fallbacks Fixed: lines 172–179
Keep image references in plain fallbacks Fixed: [image: alt (url)] format
Allow generated HTML alternatives to wrap long lines Fixed: white-space: pre-wrap

🤖 Generated with Claude Code


Generated by Claude Code


Note

Low Risk
Single-tag addition to an existing heuristic regex with no auth, data, or API surface changes.

Overview
Adds hr to the _HTML_TAGS alternation used by _HTML_BODY_RE / _is_html_body() in gateway/platforms/email.py.

Outgoing bodies whose only recognizable markup was a void <hr> or <hr/> were treated as plain text, so _attach_body() escaped them and recipients saw a literal <hr> string instead of a horizontal rule. With hr in the detector, those digests are classified as HTML and the HTML part is sent as-is.

No change to _HTML_CLOSE_TAGS (void element). Existing regex rules still require a real tag terminator, so prose like x<hr should not match.

Reviewed by Cursor Bugbot for commit 01c8bd2. Configure here.

@github-actions

Copy link
Copy Markdown

🔎 Lint report: fix/email-hr-tag-detection vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8649 on HEAD, 8649 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4570 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@dizhaky
dizhaky marked this pull request as ready for review June 28, 2026 02:30
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@dizhaky
dizhaky enabled auto-merge (squash) June 28, 2026 02:30
@dizhaky

dizhaky commented Jun 28, 2026

Copy link
Copy Markdown
Owner Author

Closing: the branch had unsigned commits (CI cursor-agent + my empty re-trigger commit). Reopened with signed commit at #40.

@dizhaky dizhaky closed this Jun 28, 2026
auto-merge was automatically disabled June 28, 2026 02:43

Pull request was closed

@dizhaky
dizhaky deleted the fix/email-hr-tag-detection branch June 28, 2026 15:00
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