Skip to content

Mail unsubscribe page and settings email card - #580

Merged
neuromechanist merged 16 commits into
stagingfrom
feature/mail-unsubscribe-settings
Nov 21, 2026
Merged

neuromechanist merged 16 commits into
stagingfrom
feature/mail-unsubscribe-settings

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Phase P5 of the community-mail epic (nemarOrg/nemar-cli#2260): the public unsubscribe page and the Settings "Email" card. Refs nemarOrg/nemar-cli#2265.

Merge order. Stacked on #573 (the mail.* account copy) and must merge after it. It must also wait until the nemar-cli epic #2260 reaches nemar-cli dev: the backend routes (/mail/unsubscribe/*, /users/me/email-preferences) are not on staging's API until then, and the strict drift tests in CI (account copy and the new mail category table) are red against nemar-cli dev until then, on purpose.

Summary

  • src/pages/unsubscribe/[token].astro: public, server-rendered from GET /mail/unsubscribe/:token/info. Shows the category and masked address and two buttons ("Unsubscribe from ", "Unsubscribe from all NEMAR community mail"), explains why recalls cannot be turned off (mail.recall.why), links /settings and the community mail policy. It never acts on load. A malformed token or the backend's 410 link_invalid renders one sentence and the settings link (status 410); a 503, 429 or network failure renders an "unavailable" sentence without the buttons. After a press the page shows "done" only when the backend's own info answer confirms the category is off, so a hand-typed ?result=all shows nothing false.
  • src/pages/api/mail/unsubscribe.ts: the endpoint both buttons post to (a plain form POST, works without JavaScript). Token in the body, not the URL; token shape (the backend's TOKEN_RE) and scope are checked before anything is sent; forwards List-Unsubscribe=One-Click plus from=page or scope=all; never forwards the visitor's cookie, Authorization or identity headers; answers a 303 back to the page with ?result=category|all|invalid|error.
  • Privacy on /unsubscribe/*: Cache-Control: no-store, X-Robots-Tag: noindex, nofollow, a robots meta (new noindex prop on Base.astro), no analytics installer (isAnalyticsExcludedPath, gated in Base.astro and checked again inside the installer), no OSA widget, not in the sitemap, and rel="noreferrer" on every link. apiFetch log lines now redact the token segment of /mail/unsubscribe/<token> paths. /unsubscribe and /api/mail are classified as app-host routes (the backend's link points at APP_BASE_URL).
  • src/pages/settings.astro: an "Email" card before "Privacy" with three switches (news, rfcs, maintenance) and a locked "Recalls: always on" row with the mail.recall.why sentence. Loaded and saved in the browser through the /api/v1 proxy (src/lib/mail-prefs-api.ts); the switches stay disabled until the load answers; a refused save puts the switch back and shows the backend's message for the four refusal codes. Labels and descriptions come from the transcribed account copy.
  • src/lib/mail-categories.ts: hand copy of nemar-cli shared/contract/mail-categories.ts (ids, canBeTurnedOff, defaultOn, refusal codes), with test/mail-categories-drift.test.ts in the same strict/soft shape as the mail-admin drift test; CI's sparse checkout of nemar-cli dev now includes the file (NEMAR_CLI_MAIL_CATEGORIES).

Deviation from the brief

The page sends Referrer-Policy: same-origin, not no-referrer. Under no-referrer a browser sends Origin: null with the page's own form post, and the site's cross-site form check (ADR 0031) refuses it with 403, so the buttons would not work. same-origin sends no Referer to any other origin, which is what keeps the token in; the middleware honors it as it does for the OIDC consent page.

Test plan

  • bun run lint: clean
  • bun run typecheck: 0 errors, 0 warnings
  • bun run test with nemar-cli's epic branch as the contract: 202 files passed, 3 skipped; 5737 tests passed, 13 skipped
  • bun run build: complete
  • Against nemar-cli dev (what CI uses): the mail category drift test and the account-copy parity test fail, as expected until the epic merges
  • Revert checks: acting on load, a POST info read, a forwarded cookie or Authorization header, the analytics gate removed (layout, installer, exclusion list) and the token check removed or loosened each fail a named test
  • astro dev: /unsubscribe/<bad> answers 410 with the privacy headers, the robots meta, and no analytics installer script (present on /about); a cross-site POST to the endpoint gets 403
  • On test.nemar.org after the epic reaches nemar-cli dev: open a real unsubscribe link, press each button, and toggle each switch in Settings

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 3562ecb into staging Nov 21, 2026
6 of 7 checks passed
@neuromechanist
neuromechanist deleted the feature/mail-unsubscribe-settings branch November 21, 2026 19:46
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