Skip to content

fix: paginate mailbox retrieval beyond maxObjectsInGet - #906

Open
pirate wants to merge 1 commit into
bulwarkmail:mainfrom
pirate:fix/mailbox-pagination
Open

fix: paginate mailbox retrieval beyond maxObjectsInGet#906
pirate wants to merge 1 commit into
bulwarkmail:mainfrom
pirate:fix/mailbox-pagination

Conversation

@pirate

@pirate pirate commented Aug 25, 2026

Copy link
Copy Markdown

Design

Paginate folder retrieval and ensure parent folders are sent to frontend before nested child folders.

  • Mailbox/query returns parent-first ID pages with sortAsTree, bounded by the server-advertised maxObjectsInGet.
  • Each ID page feeds Mailbox/get through a result reference in the same JMAP request. Request count scales by page, never by folder.
  • The first page records the total and query state. Every page must preserve that state, contain only unique string IDs, and return the requested object count; otherwise the snapshot is rejected.
  • Primary, delegated, and shared accounts use the same complete loader before mailbox mapping and tree construction.
  • The sidebar builds the complete tree once, flattens expanded nodes parent-first, and mounts 250 rows at a time. Each rendered child therefore has its parent earlier in the rendered prefix.
  • The complete mailbox model remains available while additional 250-row batches are revealed on demand. Fresh profiles with more than 1,000 mailboxes begin collapsed.

Capped object slice

A capped response showing arbitrary generated child mailboxes at the top level

Complete parent-first hierarchy

The complete hierarchy showing generated child mailboxes nested beneath their parent

Validation

  • Stalwart + Playwright integration tests: one parent and 520 children load with correct parent IDs and indentation
  • Vitest suites: 40 tests pass, including split hierarchies, server-clamped pages, missing or malformed IDs, and delegated-account namespacing.
  • A disposable 20,000-folder model check built and flattened the hierarchy and selected its first 250 rows in 53 ms

Copilot AI lite review requested due to automatic review settings August 25, 2026 09:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incomplete mailbox hierarchy loading when a JMAP server caps Mailbox/get responses at maxObjectsInGet (e.g., Stalwart), by switching to a paginated Mailbox/query + result-referenced Mailbox/get approach that loads all mailbox ids and fetches them page-by-page.

Changes:

  • Add a new getRawMailboxes() helper that paginates Mailbox/query and fetches each page via result-referenced Mailbox/get, rejecting inconsistent page results.
  • Update getMailboxes() and getAllMailboxes() to use the new complete mailbox loader for both primary and delegated/shared accounts.
  • Add/adjust Vitest coverage to validate pagination edge cases (split parent/child across pages, server page clamping, exact page multiples, later-page failures, and shared-account id namespacing).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/jmap/client.ts Implements mailbox pagination via Mailbox/query + result-reference Mailbox/get and routes mailbox loaders through it.
lib/tests/jmap-recipient-mailboxes.test.ts Updates mocks/docs to allow mailbox loading via query+get.
lib/tests/jmap-mailbox-pagination.test.ts Adds dedicated tests for pagination correctness and failure handling.
lib/tests/jmap-draft-lifecycle.test.ts Updates request mocking to answer mailbox loading via query+get.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/jmap/client.ts
Comment thread lib/jmap/client.ts Outdated
@pirate pirate changed the title fix: paginate mailbox retrieval beyond maxObjectsInGet fix: support rendering more than maxObjectsInGet=500 subfolders Aug 25, 2026
@pirate
pirate marked this pull request as draft August 25, 2026 09:36
@pirate
pirate force-pushed the fix/mailbox-pagination branch from b442e9d to d5e19a7 Compare August 25, 2026 10:20
@pirate pirate changed the title fix: support rendering more than maxObjectsInGet=500 subfolders fix: paginate mailbox retrieval beyond maxObjectsInGet Aug 25, 2026
@pirate
pirate force-pushed the fix/mailbox-pagination branch 5 times, most recently from ad5d69b to 1e4cc54 Compare August 25, 2026 22:06
@pirate
pirate marked this pull request as ready for review August 25, 2026 23:57
@pirate
pirate force-pushed the fix/mailbox-pagination branch from 1e4cc54 to 5558692 Compare August 28, 2026 03:12
@pirate
pirate force-pushed the fix/mailbox-pagination branch from 5558692 to d4cdbab Compare August 28, 2026 03:19
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.

2 participants