#25

Add folders, labels, and drag-to-organize mail

MergedstylesshOwnermerged intofrom

Summary

  • add provider-backed folders for hosted mail and labels for Gmail, including create, rename, delete, navigation, counts, and mobile access
  • persist folder icon and color appearance with a bounded Hugeicons picker, OKLCH-aware rendering, and the new mail_collection_appearances migration
  • add master, modifier-key, and shift-range mail selection with contextual bulk actions
  • add Motion-powered drag stacks, responsive folder drop feedback, curved drop completion, and staged list reflow
  • support moving selected mail into custom folders, Inbox, Archive, Spam, Trash, or Unread with source-aware provider mutations

Validation

  • pnpm test — 108 passed
  • pnpm exec tsc --noEmit — passed
  • ESLint across every changed TypeScript/TSX/MJS file — passed
  • pnpm build — passed with Next.js 16.3.3
  • git diff --check origin/main...HEAD — passed
  • browser-tested folder creation and appearance controls, selection states, drag/drop feedback, custom-folder and Archive moves, Inbox moves, Unread drops, and staged exit/reflow behavior

Activity

7
mikeyreviewed3mo ago
mikey3mo ago

Review summary

Reviewed the folder/label + drag-to-organize changes: API routes (app/api/mail/collections/**, app/api/mail/threads/[id]/route.ts), the mail_collection_appearances migration and schema, provider mutation logic (lib/gmail/provider.ts, lib/stalwart/provider.ts, lib/demo/provider.ts) plus their client layers, and the selection/drag logic (lib/mail/thread-selection.ts, lib/mail/thread-drag.ts, bulk-action handling in components/mail/thread-list.tsx).

Auth/ownership: every mutating route (collections POST/PATCH/DELETE, threads/[id] PATCH) checks getSessionUser() and resolves the target account through resolveMailAccount, which scopes lookups by user.id via findStoredMailAccount(user.id, accountId) — no cross-account/IDOR path found for collection or thread mutations.

Input validation: normalizeCollectionIcon/normalizeCollectionColor use a closed allowlist and a strict hex regex before anything is persisted or rendered, so the new appearance fields aren't an injection/XSS vector. normalizeCollectionName bounds length. Gmail/Stalwart client calls consistently encodeURIComponent path segments and JSON-encode bodies.

Migration: 0005_cool_trauma.sql adds mail_collection_appearances with ON DELETE CASCADE on user_id and a unique index over (user_id, account_id, collection_id) matching the onConflictDoUpdate target in saveMailCollectionAppearance — consistent and safe for concurrent upserts.

Provider contract note (non-blocking): MailProvider.setThreadCollection is typed to support selected: false for any collection kind, but StalwartProvider/DemoProvider unconditionally return false when selected is false (only Gmail's implementation actually removes a label). Today no UI path calls it with selected: false for a "folder" kind collection (thread-toolbar.tsx and list-toolbar.tsx both hardcode selected: true for folders), so this isn't currently reachable, but it's a latent trap if a future "remove from folder" affordance is added — worth a comment or a narrower type (selected only meaningful for "label").

No blocking correctness or security issues found in this pass. Validation in the PR description (tests, tsc, eslint, build, manual browser testing) is consistent with what I saw in the diff.

stylesshOwner3mo ago

Addressed the provider contract note in 24d49ca.

  • Folder deselection now moves mail from the custom folder back to Inbox in both the demo and Stalwart providers.
  • Add/remove operations share explicit source and destination transfer semantics.
  • Added regression coverage for both transfer directions.

Validation on the pushed commit: 109 tests, TypeScript, production build, changed-file ESLint, and diff checks all pass.

stylessh merged commit ac766cd into main3mo ago

Branch stylessh/mail-folders-drag-drop has been merged.

Checking branch