Skip to content

#1068: a JMAP account's contacts come down from its server - #1123

Closed
nextxch wants to merge 3 commits into
UCSLabs:mainfrom
nextxch:pr/1068-contacts-read
Closed

nextxch wants to merge 3 commits into
UCSLabs:mainfrom
nextxch:pr/1068-contacts-read

Conversation

@nextxch

@nextxch nextxch commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #1015 (the desktop app reads JMAP accounts), which is not on main yet: the branch is main with #1015 merged in as its first commit, and the one commit of this pull request on top. It is a draft until #1015 is merged; then it is brought up to date with main and the merge commit goes.

Closes #1068.

What changes for the person using MailCraft

A JMAP account's contacts come down from its server, in the desktop app, where the server offers JMAP for Contacts (RFC 9610). People shows them beside the contacts kept on this computer:

  • every contact of every address book of the account: names, nickname, company, department and title, e-mail addresses, phone numbers, postal addresses, web addresses, birthday and notes;
  • they are read by themselves after the account's first Send/Receive and after each one you ask for, and otherwise every quarter of an hour while Send/Receive runs by itself, with the password or token the Send/Receive went with (nothing asks for one for the contacts alone);
  • a contact the server no longer has goes from here, but only after the whole list could be read; a list read in part adds and updates and removes nothing;
  • a server that offers no contacts for the account says so once and is not asked again in that session, unless you ask for the account's Send/Receive.

They are read only: a contact the server keeps is not changed or deleted here, with the reason, as a Microsoft account's is not.

What it leaves out

What goes where

  • crates/jmap: contacts.rs (sync_contacts, failed_contacts: whose contacts, what is asked for them (kind), what "complete" means), contacts/card.rs (one JSContact card, RFC 9553, made into a contact within bounds), and reader.rs, which holds what a reader of one kind of data does and the calendars' reader will share: whose data is read (account_for), a request of one call with its answer (Calls::one_call), why a run stops (Stop), what a failed sign-in says, and the reading itself (Calls::read_all): the list page by page (<Type>/query) and the <Type>/get in chunks that is halved until the item that breaks it is found, written once for every kind: the methods, what is asked besides, the caps and the words of a failure are a Kind, what one object becomes is the caller's (Made), and what came of it is an Outcome. Its tests are its own (reader/tests.rs, against a made-up kind of data).
  • crates/model: the contract JmapContactsRequest and JmapContactsResult (sync/jmap.rs, with Debug that prints counts only), and Account::keeps_contacts is true for a JMAP account that is no shared mailbox.
  • crates/engine: no change to the code: apply_contacts takes a JMAP account's download as it takes a Microsoft account's. A test says so, and that people.edit refuses such a contact.
  • crates/ui-egui: jmap_side_job.rs (what a job beside an account's Send/Receive is, whatever it reads: when one is due, one at a time, never beside the account's Send/Receive, the back-off, how long a busy server is believed, the stale-answer checks, forgetting an account), jmap_contacts.rs (what is asked for contacts, and how an answer is taken in), its hooks in jmap_mail.rs (a run that ended well is followed by the contacts; the owner's own Send/Receive asks again whatever came before), lib.rs (Services::jmap_contacts, the tick, forgetting an account) and unconfirmed.rs (the host is held back with the others until a mailbox from a file is confirmed).
  • apps/mailcraft: jmap_runner.rs gets run_contacts on top of M6 (#1014): the desktop app reads JMAP accounts #1015's runner, using its Transport, Stop and credentials as they are, through two helpers that any job of this kind goes through (on_thread: the thread, the job's own stop and the one answer; signed_in: the credential, the sign-in, and the line a job without a credential says); nothing of M6 (#1014): the desktop app reads JMAP accounts #1015's part of the file is changed. main.rs hands it to the window.
  • PRIVACY.md (the JMAP row says that the contacts are read, when, and that nothing of a contact is written and nothing in one is fetched), README.md, ROADMAP.md (M6), docs/jmap.md, docs/gaps.md (gap 5), docs/architecture.md, each table row as a fragment under docs/log.d/, and the release note packaging/release-notes.d/new/1068.md. The .po files change by one source reference: the one text the window says here is one it had already.

Caps on what a server sends

  • The list: 500 ids to a page, 400 pages and 20,000 contacts at the most (MAX_CONTACTS); a page that brings nothing new ends the list; what is no JMAP id is not asked for; an answer to a page is held to 1 MiB.
  • The cards: 200 to a request, or as many as the server takes in a get; an answer is held to 24 MiB; a call that fails or is too large is halved, 64 times a run at the most, until the card that breaks it is found; after three calls failing one after the other the rest is left for another run. Only cards that were asked for are read, each once.
  • A card: 200 entries of a map are looked at and 50 kept, 64 components of a name or an address, a line cut at 1,024 bytes at a character's edge, a note at 16 KiB and all notes at 64 KiB, a web address longer than 2,048 bytes left out, only http and https addresses kept as web sites. The model cuts again (RemoteContact::tidy).
  • The list and the cards are capped in reader.rs, for every kind of data read with it; the two caps that are the contacts' own (20,000 ids, 24 MiB) are in contacts.rs.
  • The window keeps 20 problems of a job, believes a busy server for an hour at the most, and waits one minute after a job that came to nothing, twice as long after each one more, half an hour at the most.

The credential is where it was: in memory, handed over with the job. A line about a failure is scrubbed of the secret, the account's address, the session's address and any word with an @ in it; the log names the account's id and counts only.

How it was checked

  • cargo xtask ci: all 12 steps pass (fmt, test, assets, spdx, test-files, workflows, layers, wasm, deny, i18n, release-notes, docs-log; cargo-deny is not installed here and its step says skipped), and cargo clippy --locked --workspace --all-targets --exclude mailcraft -- -D warnings and cargo clippy --locked -p mailcraft --bin mailcraft -- -D warnings beside it. 7,525 tests pass, 0 fail, 21 ignored.
  • New tests, all against scripted servers or the in-process stand-in, with example.org names: 30 in mailcraft-jmap (18 in contacts/tests.rs, two of them property tests over arbitrary JSON as a card and as the answers, and 12 in reader/tests.rs for the paging and the halving by themselves: the page size and the most pages and ids, a list that repeats itself, what is no id, the three failures in a row, the most halvings, only what was asked and each once), 8 in mailcraft-ui-egui (jmap_contacts_tests.rs), 1 in mailcraft-engine, 1 in mailcraft-model, and 6 in the desktop app (jmap_runner_tests.rs: no credential, a credential that can't be sent, one the server refuses, called off, a server without contacts over HTTP on loopback, and the line a failure is said in).
  • The same code was also run by the author against a real JMAP server in a container on loopback, outside the repository: the contacts read passes there.

What a reviewer should look at first

  1. crates/jmap/src/reader.rs: Calls::list and Calls::get (what is asked, and how an answer is read without trusting it), Calls::read_all (the halving), and Outcome::clean, which decides whether the engine may remove what the answer lacks; then crates/jmap/src/contacts.rs: kind and sync_contacts (what is asked for contacts, and what is said of a run).
  2. crates/jmap/src/contacts/card.rs: entries (the bounded, ordered reading of a map) and card.
  3. crates/ui-egui/src/jmap_side_job.rs: MailApp::jmap_side_free, SideJob::held and SideJob::wanted (when a job is due), SideJob::answer and MailApp::jmap_side_meant (the checks that an answer is still for this account, address, server and mailbox); then crates/ui-egui/src/jmap_contacts.rs: jmap_contacts_due and the taking in of an answer.
  4. PRIVACY.md: the JMAP row.
  5. apps/mailcraft/src/jmap_runner.rs: only the part after the comment "What follows is not in the runner above": on_thread, signed_in and run_contacts_with.

Notes

  • PRIVACY.md is one of the documents a change to which is the owners' call (CONTRIBUTING.md): the row is changed here because the program now asks the server for something it did not ask before. Say if you would rather word it yourselves.

  • cargo xtask ci passes

  • "Allow edits by maintainers" is ticked (the box beside Create pull request)

  • I have signed the CLA, or will by commenting on this pull request

Human-reviewed, AI-assisted, nobody's mailbox harmed.

The desktop app gets the host the browser build has for a JMAP account:
apps/mailcraft/src/jmap_runner.rs runs mailcraft-jmap's Send/Receive and
its whole-message fetch over mailcraft_net::https, each job on a thread of
its own, the pieces streamed to the window. main.rs sets Services::jmap and
Services::jmap_fetch; the window already takes JMAP accounts into
Send/Receive once its host runs them.

- mailcraft-net: an answer's Content-Type is kept (a JMAP answer must be
  JSON; one too long to be a media type is none); https::send_with gives an
  exchange a time limit of the caller's (at most 10 min); is_too_slow and
  is_too_long are public.
- Each request kind has its own time limit (session 30 s, API 2 min,
  download 5 min). Stop is heard before each request and latched per job; a
  job never sets the window's shared flag. A Retry-After date is handed to
  the client as seconds, and ignored while the clock is plainly not set.
- The credential stays in memory: the read of the credential store leaves
  JMAP accounts out, so a password kept under an install's old name is no
  longer moved to a JMAP account with that address (it was written to the
  store, though never used to send).
- docs/jmap.md, the architecture table, README, gap 5, M6's row; fragments
  for the logs and the release notes.

Tests: jmap_runner_tests.rs runs the real transport over loopback sockets
against the JMAP stand-in (a whole run, Basic and Bearer, refusals, no
secret and Stop sending nothing, an unreachable server, plain http refused,
messages fetched whole, time limits, the stop latch, Retry-After); a net
test for Content-Type; the_old_name_never_moves_to_a_jmap_account fails
without its fix. cargo xtask ci passes (all 13 steps, deny included).

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
Pre-merge checks: Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Description check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Every author has signed the CLA. Thank you.

@nextxch

nextxch commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

I have read the MailCraft CLA and I agree to it.

… until it is on main

README.md: both sides changed the Servers and Files lines. Kept main's
lines (nothing is sent yet; a .pst file's calendar, tasks, notes and
journal come in) and UCSLabs#1015's word that JMAP is on the desktop too.

ROADMAP.md: both sides changed the M6 row. Kept main's row (the marks,
moves and deletions go up, UCSLabs#1074 part 1) and UCSLabs#1015's word that JMAP
reads mail in the desktop app too.

docs/architecture.md, docs/gaps.md, docs/jmap.md: both sides changed the
sentences that say where a JMAP account is read. Kept main's word that
what is changed in its mail goes up and UCSLabs#1015's that the desktop app is
a host too; the desktop app runs the same `sync_mail`, so the changes go
up from there as well.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@nextxch
nextxch force-pushed the pr/1068-contacts-read branch from 22da72d to 4f15885 Compare November 13, 2026 06:34
Builds on UCSLabs#1015, the desktop app's JMAP runner. Read only: nothing of
a contact goes up (that is UCSLabs#1076).

- mailcraft-jmap: sync_contacts reads the account's contacts (JMAP for
  Contacts, RFC 9610; cards in JSContact, RFC 9553) where the server
  offers them: ContactCard/query a page at a time, ContactCard/get 200
  to a request, a call that fails halved until the card that breaks it
  is found, 20,000 contacts at the most, every map, list and text of a
  card bounded. A card's picture is not read, and nothing in a card is
  fetched. reader.rs holds what the readers of one kind of data share:
  whose data is read, a request of one call, and the reading itself
  (Calls::read_all: the list page by page, the get in chunks and its
  halving), with tests of its own; contacts.rs says what is asked for
  contacts and what a card becomes.
- mailcraft-model: JmapContactsRequest and JmapContactsResult; a JMAP
  account keeps contacts.
- mailcraft-engine: a JMAP account's download is merged as a Microsoft
  account's is (a test; no change to the code).
- mailcraft-ui-egui: the contacts are a job of their own, after the
  account's Send/Receive and every quarter of an hour, one at a time,
  with the credential the Send/Receive went with. jmap_side_job.rs
  holds what such a job is whatever it reads (when one is due, the wait
  after one that came to nothing, whose an answer is); jmap_contacts.rs
  what is asked for contacts and how they are taken in.
- mailcraft (desktop): run_contacts on top of UCSLabs#1015's runner, through
  on_thread and signed_in, which any such job goes through.
- PRIVACY.md, README.md, ROADMAP.md, docs/jmap.md, docs/gaps.md,
  docs/architecture.md with their fragments, and the release note.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@nextxch
nextxch force-pushed the pr/1068-contacts-read branch from 4f15885 to 03d3216 Compare November 13, 2026 07:46
@sonarqubecloud

Copy link
Copy Markdown

@nextxch

nextxch commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing this: #1942 keeps a JMAP account's contacts in step both ways and closed #1068, so this draft is no longer needed. Thank you for taking it on.

Human-reviewed, AI-assisted, nobody's mailbox harmed.

@nextxch nextxch closed this Nov 26, 2026
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.

JMAP accounts: read contacts from the server (JMAP for Contacts, RFC 9610)

3 participants