Skip to content

feat(mail): subscriptions read, List-Unsubscribe targets, bots by what they send - #3379

Merged
leemour merged 1 commit into
mainfrom
feat/subscriptions-read
Nov 26, 2026
Merged

leemour merged 1 commit into
mainfrom
feat/subscriptions-read

Conversation

@leemour

@leemour leemour commented Nov 26, 2026

Copy link
Copy Markdown
Member

Task

Close the gaps in #3371, so WireCat Desktop can build its Subscriptions view and the Bots filters (owner's rulings of 2026-11-25; Desktop PR WireCatLabs/wirecat-desktop#482 lists what it could not read).

Why

  • Subscriptions is a view beside mail: broadcast mail grouped by List-Id, else by sender, with a mail count, the newest mail and an unsubscribe action. mailSenders groups by sender only, pages in JavaScript, and the store kept list-unsubscribe only as true.
  • The Bots tab filters by what a bot sends (alerts and codes, receipts, newsletters, marketing, messenger bots). listBots took only query and organization, and Desktop never filters a list in the browser.

What

  • store.mail.subscriptions({ accountIds, since, until, types, limit, offset }) (experimental). Broadcast mail grouped by List-Id, else by the sender (sender-bot:<id>, person:<id> or address:<address>), newest group first. Grouping, counting and paging run in SQL. Each group gives:

    • key, listId, name, and the sender ref and address of its newest email;
    • emails, the count;
    • newest: id, Message-ID, subject and time;
    • unsubscribe: https, mailto, oneClick and the email it came from, or null.

    The target is the newest one the list or the sender named. It is looked up for the page's groups only, through emails_by_list_id or the sender's identities.

  • List-Unsubscribe targets. mailHeadersOf now also keeps list-unsubscribe-https and list-unsubscribe-mailto (the first of each scheme). It keeps them only when the From domain's DKIM signature that Gmail passed covers List-Unsubscribe: a forged target would send the owner's unsubscribe somewhere else. list-unsubscribe: true and list-unsubscribe-post stay as they are, because the mail types and the bot rules read them.

  • people.listBots({ sends }): alerts (security, system_alert, account_notice), receipts (order, bill, shipping), newsletters, marketing (promotion) and messenger (a bot with an account other than email). Several names are joined with OR, in SQL, as EXISTS subqueries. The map is BOT_SENDS in src/store/sqlite/bot-sends.ts, exported with BotSends from ./store and ./store/areas. An unknown name is refused with sender-bot.unknown-sends.

  • A store opened read-only works the mail types out in memory for both reads, as the type filters already do.

No store version

The brief asked for the next store version (79, after #3374's 78). None is needed:

  • The targets live in the existing JSON column emails.headers.
  • The read stays fast on the existing indexes (timings below).
  • Old mail cannot be backfilled, because the store never kept the raw headers.

So mail stored before this change has no target until mail sync stores it again. A group shows unsubscribe: null until a newer issue arrives. Reserving 79 would also block this pull request on #3374, which is a major.

Not done

  • Unsubscribing. Nothing here sends anything. A one-click unsubscribe (RFC 8058) would need:

    • an https target, and List-Unsubscribe and List-Unsubscribe-Post both covered by the From domain's passing DKIM signature, which is what oneClick checks;
    • a POST to that URL with the body List-Unsubscribe=One-Click (application/x-www-form-urlencoded), with no cookies, no credentials and no redirects followed;
    • an owner-only action with a network-write effect and a confirmation, logged per list.

    A mailto target needs a sent email from the account that received the list, which is the mail CLI's job.

  • Channels in Subscriptions. The ruling says mail and channels. This read covers mail. Messenger channels are chats, not emails.

Timings

100,000 synthetic emails, 60,000 of them broadcast, in 1,600 groups. Load average 19 to 22. Each warm step is the median of 5 runs. Full page: cli-testing performance/mail/subscriptions (PR linked in a comment).

  • Warm subscriptions: 162 ms for the first 50, 132 ms for the first 500, 62 ms with types: [promotion]. For comparison, mailSenders takes 398 ms.
  • The first read on a writable open types all 100,000 emails: 20.5 s. A read-only open of an untyped store takes 0.9 s and writes nothing.
  • Warm listBots sends: 48 to 52 ms, and 3 ms for messenger.
  • A trap found on the way: for "a sender's mail with no List-Id", SQLite chose emails_by_list_id, and most mail has no List-Id. That cost 10 ms a group, and 3.5 s for a page of 500. A unary + keeps it on emails_by_from_identity_id.

Testing

  • src/store/mail-subscriptions.test.ts: groups, newest and target, a forged target refused, paging and total, types and accountIds, a read-only open of an untyped store that writes nothing, and bots by sends (alerts, receipts, messenger, OR, unknown name).
  • src/mail/headers.test.ts: targets kept only under the From domain's signature.
  • pnpm typecheck, pnpm lint, the related store and mail tests with one worker, pnpm docs:check parts, pnpm schema:check, pnpm check:dist, cli-dev api-report.

🤖 Generated with Claude Code

@leemour

leemour commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Timings page: WireCatLabs/cli-testing#417

leemour added a commit to WireCatLabs/cli-testing that referenced this pull request Nov 26, 2026
)

Adds `performance/mail/subscriptions` with `bench.mjs`, for
[cli-core#3379](WireCatLabs/cli-core#3379)
(issue #3371). The run uses 100,000 synthetic emails, 60,000 of them
broadcast in 1,600 groups, at a load average of 19 to 22:

- **Warm Subscriptions page:** 162 ms for the first 50, 132 ms for the
first 500. With a type filter it takes 62 ms. For comparison,
`mailSenders` takes 398 ms.
- **First read:** 20.5 s on a writable open, because it types every
email first. A read-only open takes 0.9 s and keeps nothing.
- **Bots filter by what they send:** 48 to 52 ms warm, 3 ms for
messenger bots.
- **No store version needed.** One query-plan trap was found and fixed:
a unary `+` on the List-Id expression, which cut a page of 500 from 3.5
s.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…t they send

Closes the gaps of #3371 for WireCat Desktop's Subscriptions view and Bots
filters (owner's rulings, 2026-11-25).

- store.mail.subscriptions: broadcast mail grouped by List-Id, else by the
  sender, newest group first, grouped, counted and paged in SQL. Each group
  gives its key, List-Id, name, sender ref and address, mail count, newest
  email and unsubscribe target (https, mailto, oneClick). The target is
  looked up for the page's groups only, through emails_by_list_id or the
  sender's identities.
- mailHeadersOf keeps list-unsubscribe-https and list-unsubscribe-mailto,
  only under the From domain's passing DKIM signature that covers
  List-Unsubscribe. list-unsubscribe and list-unsubscribe-post are unchanged.
- people.listBots takes sends: alerts, receipts, newsletters, marketing,
  messenger, mapped to mail types in BOT_SENDS, filtered in SQL.

No store version: the targets live in emails.headers, and the read stays
fast on the existing indexes (cli-testing performance/mail/subscriptions).
Nothing unsubscribes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leemour
leemour force-pushed the feat/subscriptions-read branch from 43f0714 to 0e1b712 Compare November 26, 2026 00:46
@leemour
leemour merged commit 120bedc into main Nov 26, 2026
38 of 41 checks passed
@leemour
leemour deleted the feat/subscriptions-read branch November 26, 2026 00:57
leemour added a commit that referenced this pull request Nov 26, 2026
…sktop#482 built

The bot: rename (#3374) is built but not merged: older builds read the
renamed agent rows wrongly, so when it ships is the owner's call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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