#20

Improve composer and email rendering

MergedstylesshOwnermerged intofrom

Summary

  • keep optimistic sends visible through queued, sending, and delivered states, then reconcile the same card with the provider message
  • add a Lexical composer that preserves authored line breaks and supports bold, italic, underline, and strikethrough from the ghost toolbar beside Attach
  • add the default Sent from redakt.app footer for new mail and replies, with a persisted composing preference to turn it off
  • preserve safe, useful email HTML and CSS, including color-scheme media queries, compatible image sources, CID rewriting, and iframe isolation
  • carry rich HTML, draft context, and stable delivery metadata through hosted, demo, and Gmail providers

Validation

  • pnpm test (73 passing)
  • pnpm exec next typegen && pnpm exec tsc --noEmit
  • changed-file ESLint pass
  • pnpm build
  • browser QA on desktop and 320px: rich formatting, line breaks, footer on/off persistence, toolbar layout, no horizontal overflow, and queued reply reconciliation

Baseline note

Repository-wide pnpm lint still reports the two pre-existing @typescript-eslint/no-require-imports errors in babel.config.js and postcss.config.js; no changed file has a lint error.

Activity

7
mikeyreviewed3mo ago
mikey3mo ago

Review summary — PR #20 "Improve composer and email rendering"

Reviewed via three focused passes over the diff (base ee2af65 → head 949f669): the HTML sanitizer/XSS surface, the optimistic-send/reconciliation state machine and new Lexical composer, and the MIME/provider/migration changes.

No blocking correctness or security issues found.

Verification performed:

  • lib/render/sanitize.ts (rewritten to a real DOMPurify pass + custom CSS sanitizer): confirmed SVG profile is excluded, meta/@import/CSS expression()/javascript: URLs are stripped, CID image rewriting only ever resolves to locally-created blob: URLs (never attacker-redirectable), and the rendering iframe in message-body.tsx has no allow-scripts in its sandbox — a solid backstop even against a hypothetical sanitizer bypass. Test coverage for these paths is strong.
  • Optimistic send / reconciliation (lib/mail/use-pending-send.ts, pending-send.tsx, thread-view.tsx): reconciliation matches by threadId/inReplyTo rather than weak subject/timestamp heuristics; deliver() re-checks state before sending, guarding against duplicate-send races from a timer firing concurrently with a manual "Send now."
  • Lexical rich text editor output: never trusted directly — both client (message-body.tsx) and server (lib/mail/compose.ts via validateComposeInput) re-sanitize through sanitizeEmailHtml before render/send, confirmed by compose.test.mjs's script/onclick-stripping test.
  • MIME construction (lib/gmail/mime.ts): multipart boundaries are per-message random UUIDs (not attacker-influenceable), existing header-injection stripping (safeHeader) for To/Subject/From/Cc/Bcc is untouched.
  • Migration 0004_far_mathemanic.sql: adds include_redakt_footer boolean DEFAULT true NOT NULL — safe for existing rows.
  • app/api/mail/send/route.ts: the only behavior change is a stricter authored-content check (hasAuthoredComposeText); session/account authorization is untouched.

Non-blocking follow-ups (left as inline comments)

  1. app/api/mail/send/route.ts:18 — the authored-content guard only inspects input.text, not input.html; a rich-HTML message with an empty text mirror and no attachments could be incorrectly rejected.
  2. lib/stalwart/provider.ts:364 — post-submit JMAP lookup failure is silently swallowed with no logging.
  3. lib/mail/use-pending-send.ts:117 — the 30s reconcile-window timer force-removes the optimistic card even if the real message hasn't appeared in messageIds yet, a narrow window for the sent message to briefly vanish from the thread on a slow provider sync.
  4. lib/mail/use-pending-send.ts:102 — a malformed-but-200 send response is silently treated as success with fallback data; reasonable to avoid duplicate sends, but worth at least a console.error for observability.
  5. lib/mail/compose.ts:100 — normalizeComposeInput appears to be dead code (exported + tested but unused by current callers).

Also worth noting for follow-up (not left inline): lib/mail/use-pending-send.test.mjs covers only the pure helper functions: the hook's deliver() fetch-failure/retry/timer-cleanup logic — the core of this PR's reliability claims — has no unit coverage and relies on the manual browser QA described in the PR body.

stylessh force-pushed the stylessh/improve-composer branch from 949f669 to 0a848fd3mo ago
stylesshOwner3mo ago

Addressed all five inline follow-ups in 0a848fd and added state-machine coverage for failure/retry, timer cleanup, reconciliation persistence, malformed accepted responses, and concurrent send attempts.

Validation on the current rebased head:

  • 80 tests passing
  • generated route types and TypeScript passing
  • focused ESLint passing for every changed review file
  • production build passing (29 routes)
  • browser QA confirms the queued reply card transitions in place to the delivered card, preserves paragraph breaks, and reports no page errors

Repository-wide lint remains limited only by the existing require() import errors in babel.config.js and postcss.config.js; neither file is changed by this PR.

stylessh merged commit 8fb0d9c into main3mo ago

Branch stylessh/improve-composer has been merged.

Checking branch