Skip to content

#1076: a JMAP account's contacts made, changed and deleted here go to its server - #1133

Closed
nextxch wants to merge 4 commits into
UCSLabs:mainfrom
nextxch:pr/1076-contacts-write
Closed

nextxch wants to merge 4 commits into
UCSLabs:mainfrom
nextxch:pr/1076-contacts-write

Conversation

@nextxch

@nextxch nextxch commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #1015 (the desktop app reads JMAP accounts) and on #1123 (#1068: a JMAP account's contacts come down), neither of which is on main yet: the branch is main with #1015 merged in, the one commit of #1123 on top of that, and the one commit of this pull request on top of both. It is a draft until those two are merged; then it is brought up to date with main and only its own commit is left.

Closes #1076.

What changes for the person using MailCraft

A JMAP account's contacts were a read-only copy of what its server keeps. Now, in the desktop app, where the server offers JMAP for Contacts (RFC 9610), what you do to them here goes to the server:

  • New Contact makes the contact in the account whose contacts People shows, when that is a JMAP account (else on this computer, as before). It goes into the server's default address book.
  • Edit changes such a contact, and only the parts you changed are written: the name, the nickname, company and department, the title, the e-mail addresses, the phone numbers, the postal addresses, the web addresses, the birthday, the notes. What the server keeps besides stays as it is: other anniversaries, a picture, what another program wrote into the card.
  • Delete deletes it on the server too, and the question says so. Merge takes such contacts like any others.
  • A change goes a few seconds after the last one while Send/Receive runs by itself, and otherwise with the next Send/Receive of the account that you ask for; with the password or token that Send/Receive went with.
  • When both sides changed a contact, a part you changed here stays and goes up, and every other part is the server's. A contact you deleted here is not brought back by a list that still shows it. A contact you changed here that the server no longer has is made again there.
  • What the server refuses is said where a Send/Receive's problems are, and is not sent again as it is.

A Microsoft account's contacts stay read-only, as before.

What it leaves out

What goes where

  • crates/model: remote.rs gets what a change is said in (ContactOp, ContactOpKind, ContactField with its ten parts, ContactsUpload, ContactOutcome, ContactResult, ContactsUploaded); sync/jmap.rs gets changes on JmapContactsRequest and changed on JmapContactsResult (both left out of the JSON when empty, both printed by Debug as counts only). contact.rs: a contact remembers what its server last said of it (Contact::synced), changed_fields is the difference, as_remote and set_part go between the two shapes. mailbox.rs: Account::writes_contacts (a JMAP account that is no shared mailbox), Mailbox::contact_gone (deletions the server is yet to hear of, 5,000 at the most), remove_contact notes one and remove_contact_quietly does not. A mailbox file from before opens unchanged, and one without the new fields is written as before (contact_sync_tests.rs).
  • crates/jmap: contacts/changes.rs (one run's changes: which go in which call, the patch of an update, how an answer to ContactCard/set is read), contacts/write.rs (a contact written as the properties of a JSContact card, the other way of card.rs), and contacts.rs, where sync_contacts now tells the changes before it reads (the reading is still reader.rs's Calls::read_all, untouched). card.rs shares its bounds and the choice of the birthday's entry with write.rs. mail.rs gets refusal (a SetError as a few clean words).
  • crates/engine: cmd/contacts_remote.rs is new: sync.contactChanges (what is to be told: deletions, then changes, then new contacts), sync.applyContactChanges (what came of it), and merge_written, the part-by-part merge of a download for an account that writes. cmd/people.rs: people.new takes account, people.edit and people.delete no longer refuse a contact of such an account; people_merge.rs likewise; cmd/remote.rs: merge_contacts hands such an account to merge_written, and forgetting an account keeps a contact its server was yet to be given, on this computer. Both new commands are on the agent gate's never list, and sync.contactChanges is among the commands that ask a server.
  • crates/ui-egui: jmap_contacts.rs carries the upload with the job, takes the outcomes in before the download of the same answer, and decides when a change goes (the quiet moment, the back-off when a job gets nothing through); JmapContacts is now the shared SideJob of jmap_side_job.rs with what the job carries and what waits beside it. dialogs.rs: the question before deleting says the contact goes from the server too. people_view.rs: such a contact's card no longer says it is read-only. forms.rs: a new contact's categories are those of the account it will be made in.
  • apps/mailcraft: jmap_runner.rs needs no new code: run_contacts hands the request to mailcraft-jmap as it is, changes and all. Its comments say so, and a test says that a change goes nowhere without a credential.
  • PRIVACY.md (the JMAP row: what of a contact is written, and when), 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/1076.md. cargo xtask i18n adds five texts to the catalogues, untranslated: two command labels, the sentence in the delete question, and two lines said when something can't be done.

Caps, and how an answer is read without trusting it

  • A run takes 100 changes (MAX_CONTACT_OPS), 50 of them new contacts at the most; the rest go with the next run. A call carries as many as the server takes (maxObjectsInSet) and as fit half of its maxSizeRequest (64 KiB at the least), never two changes of one card, and no change twice in a run.
  • An answer to ContactCard/set, to AddressBook/get and to the look for a card that went unanswered is held to 2 MiB; the read of a card before its birthday or notes are changed to 24 MiB, as any read of cards.
  • Of an answer to a set, only the keys that were asked are looked up (outcome_of): a creation id made of the change's place in the request (nothing of the contact is in it), or the card's id. Whatever else the answer holds is not read. An id the server gives a new card is held to the JMAP alphabet, or the creation counts as refused. 10,000 entries of a list are looked at, 500 address books.
  • A patch names only properties of the parts that changed (a property test over arbitrary cards says so), a key in a path is escaped as a JSON Pointer, and a key longer than 255 bytes is not named at all.
  • What is written is cut to what card.rs reads back: a line has no control character, a note is 16 KiB at the most, 50 entries to a map. A property test writes any contact as a card and reads it back as the same contact.
  • The engine takes 1,000 outcomes of one answer, cuts a server's reason to one short line, refuses an answer for another account whole, and tidies every id and text again (ContactOutcome::tidy).
  • A reason a server gives is cleaned as every line is: the secret, the account's address, the session's address and any word with an @ in it are taken out. The log names the account's id and counts only.

Conflicts and refusals

  • Refused by the server, an update: the refused parts are put back to what the server has (a part changed again since it was sent stays, and is tried by itself). A new contact: it stays, on this computer. A deletion: it is forgotten here, and the contact comes back with the next read. Each is said once, with the server's reason.
  • Refused here, before the server is asked to change anything: a web address that is not http or https (written without it, the address would be lost at the next read), a change of the notes where the server keeps several notes for the contact, an id no server hands out, and a new contact when the account has no address book it may write to.
  • Gone (notFound, or a card the answer passed over and a look does not find): a changed contact is made again, a deletion is done.
  • Unanswered: a change the answer says nothing of, or any change of a call that failed as a whole, is not reported. The engine works it out again for the next run, and the later changes of that card wait. A new contact whose answer was lost is recognised in the next download as the same person and is not made twice.
  • A sign-in refused, a busy server and a stop end the run where they happen; the changes answered until then are still handed over and taken in.
  • Once a deletion has gone to the server, the undo history is forgotten: going back would bring the contact back here alone.

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,591 tests pass, 0 fail, 21 ignored.
  • New tests, all against scripted servers or the in-process stand-in, with example.org names: 34 in mailcraft-jmap (25 in contacts/changes_tests.rs, 9 in contacts/write_tests.rs, property tests among them over arbitrary answers at every step, arbitrary cards under a patch, and any contact written and read back), 19 in mailcraft-engine (cmd/contacts_remote_tests.rs), 6 in mailcraft-model (contact_sync_tests.rs), 6 in mailcraft-ui-egui (jmap_contacts_tests.rs, 14 there now), and 1 in the desktop app (jmap_runner_tests.rs). One test of #1068: a JMAP account's contacts come down from its server #1123 changed: people.edit of a JMAP account's contact is no longer refused.
  • The same code was also run by the author against a real JMAP server in a container on loopback, outside the repository: making, changing and deleting a contact pass there.

What a reviewer should look at first

  1. crates/jmap/src/contacts/changes.rs: Run::changes and Run::call (what goes in a call and in what order), patch and keyed (what an update names), outcome_of (how an answer is read).
  2. crates/engine/src/cmd/contacts_remote.rs: merge_written (the part-by-part merge, and what makes a download remove a contact) and apply_contact_outcomes_of (each kind of outcome).
  3. crates/jmap/src/contacts/write.rs: written, and has_unkept_link.
  4. PRIVACY.md: the JMAP row.
  5. crates/ui-egui/src/jmap_contacts.rs: jmap_contacts_push and jmap_contacts_settle (when a change goes by itself), JmapContacts::answer (what a job carried comes back with its answer), and the taking in of result.changed before the download.

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 writes to the server something it only read before. Say if you would rather word it yourselves.

  • What the engine says of a refusal is an English line, as it is for to-dos and events on main.

  • 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 12, 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
  • 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

… 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/1076-contacts-write branch from 21a8ca8 to ba2f377 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.
…e go to its server

Builds on UCSLabs#1068 (the contacts read) and on UCSLabs#1015, the desktop app's
JMAP runner. Contacts of a JMAP account were a read-only copy of the
server's; now what is done to them here goes to the server.

- mailcraft-model: ContactOp, ContactField, ContactsUpload and their
  outcomes; `changes` on JmapContactsRequest and `changed` on its
  result. A contact remembers what its server last said of it
  (`synced`), and what differs from that is what waits to go. A
  deletion is remembered (`contact_gone`) until the server has heard.
  A JMAP account that is no shared mailbox writes its contacts.
- mailcraft-jmap: ContactCard/set before the read. A new card goes
  into the default address book (AddressBook/get, once in a run); an
  update is a patch that names only the properties of the parts that
  changed, the birthday by the key of its own anniversary, the notes
  only where the server has one note or none, so that what MailCraft
  does not map stays as the server has it. A web address that is not
  http or https is refused and said, not left out. A card the answer
  says nothing of is looked up once. A hundred changes in a run, as
  many to a call as the server takes, an answer read for the changes
  that were asked and for nothing else.
- mailcraft-engine: sync.contactChanges says what is to be told,
  sync.applyContactChanges takes in what came of it. A download is
  merged part by part: a part changed here stays and goes up, every
  other part is the server's; what was deleted here is not brought
  back, and a contact still to be made is not removed or made twice.
  A change the server refuses is put back and told. people.new,
  people.edit, people.delete and people.merge no longer refuse such a
  contact, and a new contact goes into the account People shows when
  that account writes its contacts. Microsoft accounts' contacts stay
  read-only.
- mailcraft-ui-egui: the contacts job carries the changes, takes
  their outcomes in before the download, and goes a few seconds after
  a change while Send/Receive runs by itself (what it carries and what
  waits are kept beside the shared state of jmap_side_job.rs); deleting
  such a contact says that it goes from the server too.
- mailcraft (desktop): the runner's contacts job carries the request
  as it is; a test that a change goes nowhere without a credential.
- PRIVACY.md (what of a contact is written, and when), README.md,
  ROADMAP.md, docs/jmap.md, docs/gaps.md, docs/architecture.md with
  their fragments, and the release note.

A contact's picture is neither read nor written, and groups are not
written.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@nextxch
nextxch force-pushed the pr/1076-contacts-write branch from ba2f377 to 56ff11a 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 as well: #1942 sends contacts made, changed and deleted here to the server and closed #1076. Thank you.

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: contacts made, changed and deleted here go to the server (ContactCard/set)

3 participants