#20
Improve composer and email rendering
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.appfooter 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
7mikeyreviewed3mo 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.
8fb0d9c into main3mo ago
Review summary — PR #20 "Improve composer and email rendering"
Reviewed via three focused passes over the diff (base
ee2af65→ head949f669): 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/CSSexpression()/javascript:URLs are stripped, CID image rewriting only ever resolves to locally-createdblob:URLs (never attacker-redirectable), and the rendering iframe inmessage-body.tsxhas noallow-scriptsin its sandbox — a solid backstop even against a hypothetical sanitizer bypass. Test coverage for these paths is strong.lib/mail/use-pending-send.ts,pending-send.tsx,thread-view.tsx): reconciliation matches bythreadId/inReplyTorather 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."message-body.tsx) and server (lib/mail/compose.tsviavalidateComposeInput) re-sanitize throughsanitizeEmailHtmlbefore render/send, confirmed bycompose.test.mjs's script/onclick-stripping test.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.0004_far_mathemanic.sql: addsinclude_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)
app/api/mail/send/route.ts:18— the authored-content guard only inspectsinput.text, notinput.html; a rich-HTML message with an empty text mirror and no attachments could be incorrectly rejected.lib/stalwart/provider.ts:364— post-submit JMAP lookup failure is silently swallowed with no logging.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 inmessageIdsyet, a narrow window for the sent message to briefly vanish from the thread on a slow provider sync.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 aconsole.errorfor observability.lib/mail/compose.ts:100—normalizeComposeInputappears 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.mjscovers only the pure helper functions: the hook'sdeliver()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.