From 5212d1271ff676dc3324556cadfc03f53c1b8e78 Mon Sep 17 00:00:00 2001 From: Nicholas Wylie Date: Fri, 5 Jun 2020 11:04:08 +1000 Subject: [PATCH 1/3] Update client developer guide --- client-guide/jmap-client-guide.mdown | 1108 ++++++++++++++------------ 1 file changed, 617 insertions(+), 491 deletions(-) diff --git a/client-guide/jmap-client-guide.mdown b/client-guide/jmap-client-guide.mdown index 7b3bb582..16f317da 100644 --- a/client-guide/jmap-client-guide.mdown +++ b/client-guide/jmap-client-guide.mdown @@ -1,8 +1,6 @@ Guide for client developers =========================== -**Warning: this guide is based on an older draft of the JMAP specification. While techniques within are still valid, the actual API structure has changed somewhat. The guide will be updated once the final JMAP spec is published.** - This guide shows how you can use JMAP to efficiently minimise bandwidth usage and round trips whilst still giving the user a complete view of their mail. This is particularly relevant to clients on mobile devices, where there is not the space to store a complete cache of all messages, or for web clients where you often do not have a permanent cache at all and must efficiently start from scratch each time the app is loaded. A single login may have access to multiple accounts. In this guide I'm going to ignore this and just use the primary account, which I'm going to presume has full read-write mail access. @@ -11,278 +9,294 @@ A single login may have access to multiple accounts. In this guide I'm going to When a user first logs in and you have no data cached for them, first call: - [ - [ "getMailboxes", {}, "#0" ] - ] +```json +[[ "Mailbox/get", { + "accountId": "u123456", + "ids": null +}, "0" ]] +``` This will fetch the list of mailboxes for the user, and the permissions and roles for each. Here's an example of the response you might receive: - [ - [ "mailboxes", { - accountId: 'user@example.com', - state: "m123456789", - list: [ - { - id: "mailbox1", - name: "Inbox", - parentId: null, - role: "inbox", - mustBeOnlyMailbox: false, - mayAddMessages: true, - mayRemoveMessages: true, - mayCreateChild: false, - mayRenameMailbox: true, - mayDeleteMailbox: false, - totalMessages: 1424, - unreadMessages: 3, - totalThreads: 1213, - unreadThreads: 2 - }, - { - id: "mailbox2", - name: "Sent", - parentId: null, - role: "sent", - mustBeOnlyMailbox: false, - mayAddMessages: true, - mayRemoveMessages: true, - mayCreateChild: false, - mayRenameMailbox: true, - mayDeleteMailbox: false, - totalMessages: 41, - unreadMessages: 0, - totalThreads: 32, - unreadThreads: 2 - }, - { - id: "mailbox3", - name: "Trash", - parentId: null, - role: "trash", - mustBeOnlyMailbox: true, - mayAddMessages: true, - mayRemoveMessages: true, - mayCreateChild: false, - mayRenameMailbox: true, - mayDeleteMailbox: false, - totalMessages: 3, - unreadMessages: 0, - totalThreads: 2, - unreadThreads: 0 - }, - { - id: "mailbox4", - name: "Awaiting Reply", - parentId: "mailbox2", - role: null, - mustBeOnlyMailbox: false, - mayAddMessages: true, - mayRemoveMessages: true, - mayCreateChild: true, - mayRenameMailbox: true, - mayDeleteMailbox: true, - totalMessages: 0, - unreadMessages: 0, - totalThreads: 0, - unreadThreads: 0 - } - ], - notFound: null - }, "#0"] - ] +```json +[[ "Mailbox/get", { + "accountId": "u123456", + "state": "123", + "list": [{ + "id": "mailbox1", + "name": "Inbox", + "parentId": null, + "role": "inbox", + "sortOrder": 0, + "totalEmails": 1424, + "unreadEmails": 3, + "totalThreads": 1213, + "unreadThreads": 2, + "myRights": { + "mayAddItems": true, + "mayRename": false, + "maySubmit": true, + "mayDelete": false, + "maySetKeywords": true, + "mayRemoveItems": true, + "mayCreateChild": true, + "maySetSeen": true, + "mayReadItems": true + }, + "isSubscribed": true + }, { + "id": "mailbox2", + "name": "Sent", + "parentId": null, + "role": "sent", + "sortOrder": 0, + "totalEmails": 41, + "unreadEmails": 0, + "totalThreads": 32, + "unreadThreads": 2, + "myRights": { + "mayAddItems": true, + "mayRename": false, + "maySubmit": true, + "mayDelete": false, + "maySetKeywords": true, + "mayRemoveItems": true, + "mayCreateChild": true, + "maySetSeen": true, + "mayReadItems": true + }, + "isSubscribed": true + }, { + "id": "mailbox3", + "name": "Trash", + "parentId": null, + "role": "trash", + "sortOrder": 0, + "totalEmails": 3, + "unreadEmails": 0, + "totalThreads": 2, + "unreadThreads": 0, + "myRights": { + "mayAddItems": true, + "mayRename": false, + "maySubmit": true, + "mayDelete": false, + "maySetKeywords": true, + "mayRemoveItems": true, + "mayCreateChild": false, + "maySetSeen": true, + "mayReadItems": true + }, + "isSubscribed": true + }, { + "id": "mailbox4", + "name": "Awaiting Reply", + "parentId": "mailbox2", + "role": null, + "sortOrder": 0, + "totalEmails": 0, + "unreadEmails": 0, + "totalThreads": 0, + "unreadThreads": 0, + "myRights": { + "mayAddItems": true, + "mayRename": false, + "maySubmit": true, + "mayDelete": false, + "maySetKeywords": true, + "mayRemoveItems": true, + "mayCreateChild": true, + "maySetSeen": true, + "mayReadItems": true + }, + "isSubscribed": true + } ], + "notFound": [] +}, "0" ]] +``` In this (simple) example, the user has four mailboxes. Three at the top level (Inbox, Sent and Trash) and one submailbox of Sent called "Awaiting Reply". The first 3 have `role` attributes, so they are to be used for the designated system roles (these are much as you would expect, but see the spec for full details). Note, you should always use the `role` attribute, as names may be localised (or even different between different servers with the same language)! -The Inbox, Sent and Awaiting Reply mailboxes all have `mustBeOnlyMailbox:false`. The Trash mailbox on the other hand has `mustBeOnlyMailbox:true`. This means that a message in the trash may not be in any other mailbox, and vice versa. However, a message belonging to the Sent mailbox could also be in, for example, the Awaiting Reply mailbox. - The Sent mailbox has no unread messages, but 2 unread threads. This is not an error! A thread is considered unread if any of the messages in it are unread, even if those messages are actually in a different mailbox. In this case, the 3 unread messages in the Inbox must all be replies to messages in the Sent mailbox. Email clients will probably want to hide unread thread counts for mailboxes with a role of "sent" or "archive". -Presuming the client defaults to showing the `role=inbox` mailbox, we now get the list of messages at the top of the mailbox, and the data for each one that we need to show it in the interface. - - [ - [ "getMessageList", { - filter: { - inMailboxes: [ "mailbox1" ] - }, - sort: [ "date desc", "id desc" ] - collapseThreads: true, - position: 0, - limit: 10, - fetchThreads: true, - fetchMessages: true, - fetchMessageProperties: [ - "threadId", - "mailboxId", - "isUnread", - "isFlagged", - "isAnswered", - "isDraft", - "hasAttachment", - "from", - "to", - "subject", - "date", - "preview" - ], - fetchSearchSnippets: false - }, "call1"] - ] +Presuming the client defaults to showing the `role=inbox` mailbox, we now use a chain of method calls to get all the data we need to display the messages at the top of the mailbox and the threads they participate in. + +First we do a query for the `id` of first 10 messages in the mailbox, sorted descending by received date: + +```json +[ + // First we do a query for the id of first 10 messages in the mailbox + [ "Email/query", { + "accountId": "u123456", + "filter": { + "inMailbox": "mailbox1" + }, + "sort": [ + { "property": "receivedAt", "isAscending": false } + ], + "collapseThreads": true, + "limit": 10 + }, "0" ], + + // Then we fetch the threadId of each of those messages + [ "Email/get", { + "accountId": "u123456", + "#ids": { + "name": "Email/query", + "path": "/ids", + "resultOf": "0" + }, + "properties": [ "threadId" ] + }, "1" ], + + // Next we get the emailIds of the messages in those threads + [ "Thread/get", { + "accountId": "u123456", + "#ids": { + "name": "Email/get", + "path": "/list/*/threadId", + "resultOf": "1" + } + }, "2" ], + + // Finally we get the data for all those emails + [ "Email/get", { + "accountId": "u123456", + "#ids": { + "name": "Thread/get", + "path": "/list/*/emailIds", + "resultOf": "2" + }, + "properties": [ ... ] + }, "3" ] +] +``` This might return the following: - [ - [ "messageList", { - accountId: 'user@example.com', - filter: { - inMailboxes: [ "mailbox1" ] - }, - sort: [ "date desc", "id desc" ] - collapseThreads: true, - state: "m8231u341", - canCalculateUpdates: true, - position: 0, - total: 1213, - messageIds: [ - "fm1u314", - "fm1u312", - "fm1u298", - "fm1u286", - "fm1u265", - "fm1u254", - "fm1u241", - "fm1u211", - "fm1u109", - "fm1u3" - ], - threadIds: [ - "4f512aafed75e7fb", - "fed75e7fb4f512aa", - "75e7fb4f512aafed", - "512aafed75e7fb4f", - "fb4f512aafed75e7", - "2aafed75e7fb4f51", - "afed75fb4f512ae7", - "e7fb4f512aafed75", - "ed75e74f51fb2aaf", - "b4f5ed75e712aaff" - ] - }, "call1" ], - [ "threads", { - accountId: 'user@example.com', - state: "mc1264092", - list: [{ - id: "4f512aafed75e7fb", - messageIds: [ "fm1u314" ] - }, { - id: "fed75e7fb4f512aa", - messageIds: [ "fm1u312", "fm2u12", "fm1u304" ] - }, - … 8 more thread objects, omitted for brevity … +```json +[ + [ "Email/query", { + "accountId": "u123456", + "filter": { + "inMailbox": "mailbox1" + }, + "ids": [ + "fm1u314", + "fm1u312", + "fm1u298", + "fm1u286", + "fm1u265", + "fm1u254", + "fm1u241", + "fm1u211", + "fm1u109", + "fm1u313" + ], + "sort": [ + { "property": "receivedAt", "isAscending": false } + ], + "queryState": "123:0", + "collapseThreads": true, + "total": 10 + }, "0" ], + [ "Email/get", { + "accountId": "u123456", + "list": [ + { "id": "fm1u314", "threadId": "4f512aafed75e7fb" }, + { "id": "fm1u312", "threadId": "fed75e7fb4f512aa" }, + { "id": "fm1u298", "threadId": "75e7fb4f512aafed" }, + { "id": "fm1u286", "threadId": "512aafed75e7fb4f" }, + { "id": "fm1u265", "threadId": "fb4f512aafed75e7" }, + { "id": "fm1u254", "threadId": "2aafed75e7fb4f51" }, + { "id": "fm1u241", "threadId": "afed75fb4f512ae7" }, + { "id": "fm1u211", "threadId": "e7fb4f512aafed75" }, + { "id": "fm1u109", "threadId": "ed75e74f51fb2aaf" }, + { "id": "fm1u313", "threadId": "b4f5ed75e712aaff" } + ], + "state": "123", + "notFound": [] + }, "1" ], + [ "Thread/get", { + "accountId": "u123456", + "list": [ + { "id": "4f512aafed75e7fb", "emailIds": [ ... ] }, + { "id": "fed75e7fb4f512aa", "emailIds": [ ... ] }, + { "id": "75e7fb4f512aafed", "emailIds": [ ... ] }, + { "id": "512aafed75e7fb4f", "emailIds": [ ... ] }, + { "id": "fb4f512aafed75e7", "emailIds": [ ... ] }, + { "id": "2aafed75e7fb4f51", "emailIds": [ ... ] }, + { "id": "afed75fb4f512ae7", "emailIds": [ ... ] }, + { "id": "e7fb4f512aafed75", "emailIds": [ ... ] }, + { "id": "ed75e74f51fb2aaf", "emailIds": [ ... ] }, + { "id": "b4f5ed75e712aaff", "emailIds": [ ... ] } + ], + "state": "123" + }, "2" ], + [ "Email/get", { + "accountId": "u123456", + "list": [{ + "id": "fm1u314", + "threadId": "4f512aafed75e7fb", + "mailboxIds": [ "mailbox1" ], + "isUnread": true, + "isFlagged": false, + "isAnswered": false, + "isDraft": false, + "hasAttachment": false, + "from": [ + { "name": "Joe Bloggs", "email": "joebloggs@fastmail.fm" } ], - notFound: null - }], - [ "messages", { - accountId: 'user@example.com', - state: "m815034", - list: [{ - "id": "fm1u314", - "threadId": "4f512aafed75e7fb", - "mailboxIds": [ "mailbox1" ], - "isUnread": true, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, - "hasAttachment": false, - "from": [ - { name: "Joe Bloggs", email: "joebloggs@fastmail.fm" } - ], - "to": [ - { name: "Jane Doe", email: "janedoe@fastmail.fm" } - ], - "subject": "Camping trip", - "date": "2014-07-24T15:04:51Z", - "preview": "Hey Joe. Fancy a trip out west next week? I hea…" - }, - { - "id": "fm1u312", - "threadId": "fed75e7fb4f512aa", - "mailboxIds": [ "mailbox1" ], - "isUnread": false, - "isFlagged": true, - "isAnswered": false, - "isDraft": false, - "hasAttachment": true, - "from": [ - { name: "James Connor", email: "jamesconnorwork@fastmail.fm" } - ], - "to": [ - { name: "Jane Doe", email: "janedoe@fastmail.fm" }, - { name: "Joe Bloggs", email: "joebloggs@fastmail.fm" } - ], - "subject": "Re: I need the swallow velocity report ASAP", - "date": "2014-07-24T12:01:43Z", - "preview": "Come on you guys. How long can it take to do a simple scientif…" - }, - { - "id": "fm2u12", - "threadId": "fed75e7fb4f512aa", - "mailboxIds": [ "mailbox2" ], - "isUnread": false, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, - "hasAttachment": false, - "from": [ - { name: "Jane Doe", email: "janedoe@fastmail.fm" } - ], - "to": [ - { name: "James Connor", email: "jamesconnorwork@fastmail.fm" }, - { name: "Joe Bloggs", email: "joebloggs@fastmail.fm" } - ], - "subject": "Re: I need the swallow velocity report ASAP", - "date": "2014-07-24T11:32:15Z", - "preview": "It's on its way. Jane." - }, - … more message objects, omitted for brevity … + "to": [ + { "name": "Jane Doe", "email": "janedoe@fastmail.fm" } ], - notFound: null - }, "call1" ] - ] + "subject": "Camping trip", + "date": "2014-07-24T15:04:51Z", + "preview": "Hey Joe. Fancy a trip out west next week? I hea…" + }, ... ], + "state": "123", + "notFound": [] + }, "3" ] +] +``` We now have the header information for all the messages in the top 10 threads in the Inbox, plus a full list of mailboxes and their unread counts. Providing the screen cannot fit more than 10 messages without scrolling, this is sufficient to display a standard mail interface as though **all data was loaded**, even though we have only made 2 round trips to the server, and transferred minimal data. (Obviously, you can request more than 10 in the request if you need more to show the initial screen). ## Paging in data as the interface is navigated -In our example Inbox, there are 1213 threads, but so far we have only loaded in data for the first 10. As the user scrolls down, we need to page in the data for the section of the mailbox that becomes visible (and indeed, to avoid the user having to wait, it's advisable to preload a little way ahead too). This is just another call to `getMessageList`, as in the cold boot example, but with the `position` property changed to the index for the section required. +In our example Inbox, there are 1213 threads, but so far we have only loaded in data for the first 10. As the user scrolls down, we need to page in the data for the section of the mailbox that becomes visible (and indeed, to avoid the user having to wait, it's advisable to preload a little way ahead too). This is just another call to `Email/query`, as in the cold boot example, but with the `position` property changed to the index for the section required. Similarly, if we switch mailboxes, or want to do a search, we can use the same call as well. However, remember in JMAP the same message may appear in multiple mailboxes, so to avoid downloading the same data multiple times, it's advisable to just fetch the message list without also getting the message or thread objects (except in certain situations, such as the very first request; the exact heuristics for deciding between the two can be made arbitrarily clever and complex). - [ - [ "getMessageList", { - filter: { - inMailboxes: [ "mailbox2" ] - }, - sort: [ "date desc", "id desc" ] - collapseThreads: true, - position: 11, - limit: 10, - fetchThreads: false, - fetchMessages: false, - fetchMessageProperties: null, - fetchSearchSnippets: false - }, "call1"] - ] - -After the list has been returned, a second request can be made directly to `getThreads` with the thread ids (or to `getMessages` with the message ids) to fetch the ones you are missing. +```json +[ + [ "Email/query", { + "accountId": "u123456", + "filter": { + "inMailbox": "mailbox1" + }, + "sort": [ + { "property": "receivedAt", "isAscending": false } + ], + "collapseThreads": true, + "position": 10, + "limit": 10 + }, "0" ] +] +``` + +After the list has been returned, a second request can be made directly to `Thread/get` with the thread ids (or to `Email/get` with the message ids) to fetch the ones you are missing. ## Opening a thread So far we have only fetched the minimal amount of information we need to display a mailbox entry for a message or thread. When opening a thread from the mailbox, we now need to fetch the rest of the message details. Exactly what you wish to fetch depends on what information your client displays. Suppose we open the 2nd thread in the example Inbox above. I'm presuming we already know the list of message ids in the thread from the data received when we fetched the mailbox. +```json [ - [ "getMessages", { - ids: [ "fm1u312", "fm2u12", "fm1u304" ], - properties: [ + [ "Email/get", { + "accountId": "u123456", + "ids": [ "fm1u312", "fm2u12", "fm1u304" ], + "properties": [ "threadId", "mailboxIds", "isUnread", @@ -304,8 +318,9 @@ So far we have only fetched the minimal amount of information we need to display ] }] ] +``` -Alternatively, a client may want to just request the "rawUrl" property, then download the original RFC2822 message from the URL returned and parse it in the client. +Alternatively, a client may want to just request the `blobId` property, then download the original RFC2822 message using the `downloadUrl` template retrieved from the Session Object. ## Staying in sync @@ -313,57 +328,109 @@ Suppose a new message arrives, or the user performs some actions on their messag To efficiently stay in sync, we can call: - [ - [ "getMailboxUpdates", { - sinceState: "m123456789", - fetchRecords: true, - fetchRecordProperties: null - }, "call1" ], - [ "getMessageListUpdates", { - filter: { - inMailboxes: [ "mailbox1" ] - }, - sort: [ "date desc", "id desc" ] - collapseThreads: true, - sinceState: "m8231u341", - uptoMessageId: "fm1u3", - maxChanges: 100 - }, "call2" ], - [ "getMessageUpdates", { - sinceState: "m815034" - maxChanges: 30, - fetchRecords: true, - fetchRecordProperties: [ - "threadId", - "mailboxIds", - "isUnread", - "isFlagged", - "isAnswered", - "isDraft", - "hasAttachment", - "labels", - "from", - "to", - "subject", - "date", - "preview" - ] - }, "call3" ], - [ "getThreadUpdates", { - sinceState: "mc1264092" - maxChanges: 20, - fetchRecords: true - }, "call4" ] - ] +```json +[ + // Fetch a list of mailbox ids that have changed + [ "Mailbox/changes", { + "accountId": "u123456", + "sinceState": "123" + }, "0" ], + + // Fetch any mailboxes that have been created + [ "Mailbox/get", { + "accountId": "u123456", + "#ids": { + "name": "Mailbox/changes", + "path": "/created", + "resultOf": "0", + } + }, "1" ], + + // Fetch any mailboxes that have been updated + [ "Mailbox/get", { + "accountId": "u123456", + "#ids": { + "name": "Mailbox/changes", + "path": "/updated", + "resultOf": "0" + }, + "#properties": { + "name": "Mailbox/changes", + "path": "/updatedProperties", + "resultOf": "0" + } + }, "2" ], + + // Get the updated result of our previous query + [ "Email/queryChanges", { + "accountId": "u123456", + "filter": { + "inMailbox": "mailbox1" + }, + "sort": [ + { "property": "receivedAt", "isAscending": false } + ], + "sinceQueryState": "123:0", + "maxChanges": 100, + "upToId": "fm1u313" + }, "3" ], + + // Fetch the threadId for emails in the update query result + [ "Email/get", { + "accountId": "u123456", + "#ids": { + "name": "Email/queryChanges", + "path": "/added", + "resultOf": "3" + }, + "properties": [ "threadId" ] + }, "4" ], + + // Fetch threads for those emails + [ "Thread/get", { + "accountId": "u123456", + "#ids": { + "name": "Email/get", + "path": "/list/*/threadId", + "resultOf": "4" + } + }, "5" ], + + // Fetch emails for those threads + [ "Email/get", { + "accountId": "u123456", + "#ids": { + "name": "Thread/get", + "path": "/list/*/emailIds", + "resultOf": "5" + }, + "properties": [ ... ] + }, "6" ], + + // Fetch a list of created/updated/deleted Emails + [ "Email/changes", { + "accountId": "u123456", + "sinceState": "123", + "maxChanges": 30 + }, "7" ], + + // Fetch a list of created/udpated/deleted Threads + [ "Thread/changes", { + "accountId": "u123456", + "sinceState": "123", + "maxChanges": 30 + }, "8" ] +] +``` This is a good example of multiple method calls combined into a single request. Let's have a look at what they are doing. -1. `getMailboxUpdates`: This will return the ids of any mailboxes that have been created or modified (e.g. renamed, or have changed counts). It will also return the ids of any mailboxes that have been deleted. Because we set `fetchMailboxes == true`, any new or changed mailboxes will be fetched. If the server supports the `onlyCountsChanged` property of the mailboxes response, then we will only receive the counts properties for the changed mailboxes if that is the only change (the common case). -2. `getMessageListUpdates`: All our message lists may have changed, so we must mark all of them as needing a refresh, and immediately refresh the one that is currently selected in the client (here, presuming the Inbox). We'll look at the response to this and how it is used to update the client cache below. -3. `getMessageUpdates`: Gets the list of ids for all messages which have been added or modified, plus the list of messages which have been deleted. We have also specified `fetchMessages` and `fetchMessageProperties` arguments here to request the standard header information we need to display a message in a mailbox for any new/changed messages. This includes all mutable properties of a message, so is sufficient to bring any changed messages up to date. -4. `getThreadUpdates`: Gets the list of threads which have had messages added or removed from the thread. We also fetch the `Thread` object for those threads that have changed. +1. `Mailbox/changes`: This will return the ids of any mailboxes that have been created or modified (e.g. renamed, or have changed counts). It will also return the ids of any mailboxes that have been deleted. We then use one call to `Mailbox/get` to fetch any newly created mailboxes and another call to `Mailbox/get` to refetch the any properties that have changed on updated mailboxes. Note that the `Mailbox/changes` call returns an array of `updatedProperties` that we can use in the second `Mailbox/get` to only fetch the count properties (if those are the only changes). If some other property changes `updatedProperties` will be `null`, causing the second `Mailbox/get` to fetch all properties. +2. `Email/queryChanges`: Our query result may have changed, so we fetch a list of email ids that have been added to or removed from the result. We're also refetching the `threadId` of any emails added to the result, the `emailIds` of the emails in those threads, and the data used to display those emails in the interface. We'll look at the response to this and how it is used to update the client cache below. +3. `Email/changes`: Gets the list of ids for all messages which have been created or updated, plus the list of messages which have been deleted. +4. `Thread/changes`: Gets the list of threads which have had messages added or removed from the thread. -In each case, the `sinceState` argument comes from the response to our previous calls to get the records of that type. +In each case, the `sinceState` and `sinceQueryState` arguments come from the response to our previous calls to get the records of that type. ### Handling a standard response @@ -373,143 +440,144 @@ The `maxChanges` argument prevents methods from returning huge volumes of data i Let's look at a common case example, where two new messages have been delivered to the Inbox and one other existing message has been marked as read. We might get back a response something like: - [ - [ "mailboxUpdates", { - accountId: 'user@example.com', - oldState: "m123456789", - newState: "m123471231", - changed: [ "mailbox1" ], - removed: [], - onlyCountsChanged: true - }, "call1" ], - [ "mailboxes", { - accountId: 'user@example.com', - state: "m123471231" - list: [{ - totalMessages: 1426, - unreadMessages: 4, - totalThreads: 1214, - unreadThreads: 3 - }], - notFound: null - }, "call1" ], - [ "messageListUpdates", { - accountId: 'user@example.com', - filter: { - inMailboxes: [ "mailbox1" ] - }, - sort: [ "date desc", "id desc" ] - collapseThreads: true, - oldState: "m8231u341", - newState: "m8239u342", - uptoMessageId: "fm1u3", - removed: [{ - messageId: "fm1u241", - threadId: - }], - added: [{ - messageId: "fm1u316", - threadId: "afed75fb4f512ae7", - index: 0 - }, { - messageId: "fm1u315", - threadId: "b4aae3925af0a0a2", - index: 1 - }], - total: 1214 - }, "call2" ], - [ "messageUpdates", { - accountId: 'user@example.com', - oldState: "m815034", - newState: "m815039", - changed: [ "fm1u316", "fm1u315", "fm1u314" ] - removed: [] - }, "call3" ], - [ "messages", { - accountId: 'user@example.com', - state: "m815039", - list: [{ - "id": "fm1u316", - "threadId": "afed75fb4f512ae7", - "mailboxId": "mailbox1", - "isUnread": true, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, - "hasAttachment": false, - "from": [ - { name: "Joe Bloggs", email: "joebloggs@fastmail.fm" } - ], - "to": [ - { name: "Jane Doe", email: "janedoe@fastmail.fm" } - ], - "subject": "Camping trip", - "date": "2014-07-24T15:04:51Z", - "preview": "Hey Joe. Fancy a trip out west next week? I hea…" - }, { - "id": "fm1u315", - "threadId": "b4aae3925af0a0a2", - "mailboxId": "mailbox1", - "isUnread": true, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, - "hasAttachment": false, - "from": [ - { name: "Joe Bloggs", email: "joebloggs@fastmail.fm" } - ], - "to": [ - { name: "Jane Doe", email: "janedoe@fastmail.fm" } - ], - "subject": "Camping trip", - "date": "2014-07-24T15:04:51Z", - "preview": "Hey Joe. Fancy a trip out west next week? I hea…" - }, { - "id": "fm1u314", - "threadId": "4f512aafed75e7fb", - "mailboxId": "mailbox1", - "isUnread": false, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, - "hasAttachment": false, - "from": [ - { name: "Joe Bloggs", email: "joebloggs@fastmail.fm" } - ], - "to": [ - { name: "Jane Doe", email: "janedoe@fastmail.fm" } - ], - "subject": "Camping trip", - "date": "2014-07-24T15:04:51Z", - "preview": "Hey Joe. Fancy a trip out west next week? I hea…" - }], - notFound: null - }, "call3" ], - [ "threadUpdates", { - accountId: 'user@example.com', - oldState: "mc1264092", - newState: "mc1264097", - changed: [ "afed75fb4f512ae7", "b4aae3925af0a0a2" ], - removed: [] - }, "call4" ] - [ "threads", { - accountId: 'user@example.com', - state: "mc1264097", - list: [{ - id: "afed75fb4f512ae7", - messageIds: [ "fm1u241", "fm1u316" ] - }, { - id: "b4aae3925af0a0a2", - messageIds: [ "fm1u315" ] - }], - notFound: null - }, "call4" ] - ] +```json +[ + [ "Mailbox/changes", { + "accountId": "u123456", + "oldState": "123", + "newState": "124", + "created": [], + "destroyed": [], + "updated": [ "mailbox1" ], + "updatedProperties": [ "totalEmails", "unreadEmails", "totalThreads", "unreadThreads" ] + }, "0" ], + [ "Mailbox/get", { + "accountId": "u123456", + "list": [], + "notFound": [], + "state": "124" + }, "1" ], + [ "Mailbox/get", { + "accountId": "u123456", + "list": [{ + "id": "mailbox1", + "totalEmails": 1426, + "totalThreads": 1214, + "unreadEmails": 4, + "unreadThreads": 3 + }], + "notFound": [], + "state": "124" + }, "2" ], + [ "Email/queryChanges", { + "accountId": "u123456", + "filter": { + "inMailbox": "mailbox1" + }, + "sort": [ + { "property": "receivedAt", "isAscending": false } + ], + "collapseThreads": true, + "newQueryState": "124:0", + "oldQueryState": "123:0", + "added": [{ + "id": "fm1u316", + "index": 0 + }, { + "id": "fm1u315", + "index": 1 + }], + "removed": [], + "upToId": "fm1u313" + }, "3" ], + [ "Email/get", { + "accountId": "u123456", + "list": [{ + "id": "fm1u316", + "threadId": "afed75fb4f512ae7" + }, { + "id": "fm1u315", + "threadId": "b4aae3925af0a0a2" + }], + "notFound": [], + "state": "124" + }, "4" ], + [ "Thread/get", { + "accountId": "u123456", + "list": [{ + "id": "afed75fb4f512ae7", + "emailIds": [ "fm1u241", "fm1u316" ] + }, { + "id": "b4aae3925af0a0a2", + "emailIds": [ "fm1u315" ] + }], + "notFound": [], + "state": "124" + }, "5" ], + [ "Email/get", { + "accountId": "u123456", + "list": [{ + "id": "fm1u316", + "threadId": "afed75fb4f512ae7", + "mailboxId": "mailbox1", + "isUnread": true, + "isFlagged": false, + "isAnswered": false, + "isDraft": false, + "hasAttachment": false, + "from": [ + { "name": "Joe Bloggs", "email": "joebloggs@fastmail.fm" } + ], + "to": [ + { "name": "Jane Doe", "email": "janedoe@fastmail.fm" } + ], + "subject": "Camping trip", + "date": "2014-07-24T15:04:51Z", + "preview": "Hey Joe. Fancy a trip out west next week? I hea…" + }, { + "id": "fm1u315", + "threadId": "b4aae3925af0a0a2", + "mailboxId": "mailbox1", + "isUnread": true, + "isFlagged": false, + "isAnswered": false, + "isDraft": false, + "hasAttachment": false, + "from": [ + { "name": "Joe Bloggs", "email": "joebloggs@fastmail.fm" } + ], + "to": [ + { "name": "Jane Doe", "email": "janedoe@fastmail.fm" } + ], + "subject": "Camping trip", + "date": "2014-07-24T15:04:51Z", + "preview": "Hey Joe. Fancy a trip out west next week? I hea…" + }], + "notFound": [], + "state": "124" + }, "6" ], + [ "Email/changes", { + "accountId": "u123456", + "created": [ "fm1u316", "fm1u315" ], + "destroyed": [], + "updated": [ "fm1u314" ], + "newState": "124", + "oldState": "123" + }, "7" ], + [ "Thread/changes", { + "accountId": "u123456", + "created": [ "b4aae3925af0a0a2" ], + "destroyed": [], + "updated": [ "afed75fb4f512ae7", "4f512aafed75e7fb" ], + "newState": "124", + "oldState": "123" + }, "8" ] +``` Here's how we apply this information to our current state to stay in sync: -1. `mailboxUpdates`/`mailboxes`: The inbox is the only mailbox to have changed, and only the counts have changed. The new counts are returned in the `mailboxes` response, so we just need to update our cache with the new properties to bring us fully in sync. -2. `messageListUpdates`: This is more interesting. +1. `Mailbox/changes`/`Mailbox/get`: The inbox is the only mailbox to have changed, and only the counts have changed. The new counts are returned in the second `Mailbox/get` response, so we just need to update our cache with the new properties to bring us fully in sync. +2. `Email/queryChanges`: This is more interesting. Suppose the client has a sparse list of messageIds (for example, the user opened the mailbox, loading the first section, then jumped to the middle): @@ -517,25 +585,26 @@ Here's how we apply this information to our current state to stay in sync: To update this to match the new server state: - 1. Check the oldState property matches the current state of the list. Also check the sort and search are the same. If any of these don't match, abort and re-request an update from the actual current state. - 2. If the newState property is the same as the current state of the list, nothing to do, so return. - 3. If there's an `uptoMessageId`, search for this id. If found, remove anything after it in the list. If not found, abort, reset the list and start again with `getMailboxMessageList`. - 4. Search for each of the messageIds in the `removed` list and remove them from the client's list (without leaving a gap – this is a splice operation). If any can't be found, keep processing but after finishing, null out anything after the first gap in the list. e.g. referring to the example sparse list above, 'm1u8' would be removed as it's after the first gap. - 5. Iterate through the `added` list **in order**, inserting the messageIds at the positions indicated (again this is a splice operation and will shift everything else further along). + 1. Check the `oldQueryState` property matches the current state of the query. Also check the sort and search are the same. If any of these don't match, abort and re-request an update from the actual current state. + 2. If the `newQueryState` property is the same as the current state of the query, nothing to do, so return. + 3. If there's an `upToId`, search for this id. If found, remove anything after it in the results. If not found, abort, reset the results and start again with `Email/query`. + 4. Search for each email `id` in the `removed` list and remove them from the client's results (without leaving a gap – this is a splice operation). If any can't be found, keep processing but after finishing, null out anything after the first gap in the list. e.g. referring to the example sparse list above, 'm1u8' would be removed as it's after the first gap. + 5. Iterate through the `added` list **in order**, inserting the email `id` at the positions indicated (again this is a splice operation and will shift everything else further along). 6. Set the list length to that given in the `total` property. - Note, adding or removing an item to/from the list shifts the position of + Note, adding or removing an item to/from the results shifts the position of everything around it. e.g. adding 'm2' in position 2: `[ 'm1', 'm3' ] -> [ 'm1', 'm2', 'm3' ]` e.g. removing 'm2': `[ 'm1', 'm2', 'm3' ] -> [ 'm1', 'm3' ]` -3. `messageUpdates`: The `removed` array has 0 length (so, although a message was removed from the Inbox message list, it has not been deleted: it is simply no longer the first message in the thread in the given sort order). The `changed` array has three message ids: the first two we don't have in memory, so we can ignore, but the last one we have in our cache so we should mark is as needing an update (i.e. the flags might be out of date). -4. `messages`: Because we specified a `fetchMessages` argument to `getMessageUpdates`, this response contains the requested data for the messages that have been modified or added. The first two are new messages, and we can add this data to our header cache information so we have the info we need to display the mailbox. The final message is one we already have in cache, but a property of it has now changed (in this case, it is no longer unread). We can update this data and clear the flag we set in step 3 indicating it needs refreshing (the reason we set the flag is so the `messageUpdates` response is correctly handled regardless of whether we specified `fetchMessages` or not. -5. `threadUpdates`: There are two changed threads here. One existing thread has a new message in it, the other is a brand new thread to create in our cache. +3. `Email/changes`: The `destroyed` array has 0 length. The `created` array has two message ids that we don’t have in memory, so we can ignore them. The `updated` array has one message id, which we have in our cache so we should mark is as needing an update (i.e. the flags might be out of date). +4. `Thread/changes`: There are two changed threads here. One existing thread has a new message in it, the other is a brand new thread to create in our cache. -After applying these changes, our cache is completely in sync with the server, even though we only have a partial data set cached, and we only made a single HTTP request. +After applying these changes, our cache is nearly in sync with the server. We need to inspect the result of both `Email/changes` and `Thread/changes` and perform one more request to fetch the properties of any objects we have in memory that are now out of date. + +After the second request our cache is completely in sync with the server, even though we only have a partial data set cached, and we only made two HTTP requests. Now let's look at the more difficult cases, when errors occur. @@ -543,17 +612,17 @@ Now let's look at the more difficult cases, when errors occur. The most common error will be a `tooManyChanges` error, when the number of changes exceeds the number we were prepared to accept. In this case, it would be more efficient to throw away much of our cache, or mark it as potentially dirty, and then just fetch the information we need right now (similar to the cold boot situation), rather than fetching a potentially large set of updates. Let's look at the errors for each method. -`getMessageListUpdates`: If there are more changes than the `maxChanges` argument, or the server is unable to calculate updates from the state requested, you will receive an appropriate error back. In these cases, you simply have to throw away the current message list cache and request the section you are interested in with a standard `getMessageList` call. +`Email/queryChanges`: If there are more changes than the `maxChanges` argument, or the server is unable to calculate updates from the state requested, you will receive an appropriate error back. In these cases, you simply have to throw away the current query result in the cache and request the section you are interested in with a standard `Email/query` call. -`getMessageUpdates`: If there are too many changes, you will get an error back. In this case, there are two strategies you could adopt. The first is simple: mark each message you have in cache as needing an update, and fetch these when the message is next required by the user (note, since only the flags and mailboxes it belongs to are mutable, the data you need to fetch can be reduced). As an extra possible optimisation, you could try another `getMessageUpdates` call first, with a higher `maxChanges`, but with `fetchMessages` set to `null`. If it succeeds, this will give you back an exact list of the message ids for messages with changes, so you can mark just those as needing a refresh rather than every message in your cache. If there are still too many changes, you will have to fall back to refetching all the flags and labels. +`Email/changes`: Mark each message you have in cache as needing an update, and fetch these when the message is next required by the user (note, since only the flags and mailboxes it belongs to are mutable, the data you need to fetch can be reduced). -`getThreadUpdates`: Just like with `getMessageUpdates`, if there are too many changes you can either flush your cache of threads, or try with a higher `maxChanges` but `fetchThreads: false`. +`Thread/changes`: Just like with `Email/changes`, flush your cache of threads. In each of the error cases, a single further HTTP request should be sufficient to get the necessary data to update the client to the correct state. ### Handling message list without delta updates -The response to `getMessageList` includes a property called `canCalculateUpdates`, which lets you know whether the server supports a call to `getMessageListUpdates` for the given message list (servers may not support it at all, or may only support it when there is no search involved etc.). In this case, we have to fetch the bit of the message list currently on display, and just throw away all of our cached data for the message list. Note, however, we don't have to throw away all the message data, we just have to fetch the message ids, so it's still not too inefficient. +The response to `Email/query` includes a property called `canCalculateChanges`, which lets you know whether the server supports a call to `Email/queryChanges` for the given query (servers may not support it at all, or may only support it when there is no search involved etc.). In this case, we have to fetch the bit of the query currently on display, and just throw away all of our cached data for the query. Note, however, we don't have to throw away all the message data, we just have to fetch the message ids, so it's still not too inefficient. ## Performing actions @@ -563,19 +632,23 @@ Modifying the state is the most complex operation to get right, as changes to me If you select all, you need to fetch the complete message list for the mailbox currently displayed. -When applying actions to threads, you will often wish to apply the same action to every message in the thread in the same mailbox as the one explicitly selected, or even to all the messages in the thread, regardless of mailbox. The most efficient way to do the former is to fetch the same message list, but with `collapseConversations == false`. You can then easily build a map of threadId to messages ids for messages in the list. If you need to find all messages in the thread, regardless of message list, you will need to fetch the Thread object for every thread in the message list (but you don't need to fetch any message details). You can do this in a single `getMessageList` call, with `fetchThreads: true`, but `fetchMessages: null`, although if it's a long message list you may wish to break this up into a few calls to avoid a single large request blocking the UI for too long. +When applying actions to threads, you will often wish to apply the same action to every message in the thread in the same mailbox as the one explicitly selected, or even to all the messages in the thread, regardless of mailbox. The most efficient way to do the former is to perform the same query, but with `collapseThreads: false`. You can then easily build a map of threadId to messages ids for messages in the list. If you need to find all messages in the thread, regardless of query, you will need to fetch the Thread object for every thread in the query result (but you don't need to fetch any message details). You can do this in a single `Email/query`/`Thread/get` request, although if it's a long message list you may wish to break this up into a few calls to avoid a single large request blocking the UI for too long. ### Moving a message Moving a message from the Inbox to the Trash is simple: - [ "setMessages", { - update: { - "fm1u254": { - mailboxes: [ "mailbox3" ] - } +```json +[ "Email/set", { + "accountId": "u123456", + "update": { + "fm1u254": { + "mailboxIds/mailbox3": true, + "mailboxIds/mailbox1": null } - }, "call1" ] + } +}, "0" ] +``` We can then do a resync as in section 4 to update the client cache. This is easy, but means there's a noticeable delay performing every action, and we cannot operate in an offline mode and resync later. We can improve on this, although it makes it considerably more complicated. We can apply the effects we think the changes will have instantly then compare this with the results we get back from the server. @@ -599,7 +672,7 @@ We can then do a resync as in section 4 to update the client cache. This is easy There are slight added complexities if moving a message into or out of the Trash; refer to the spec for full details. -2. **Message list**. Splice each selected message being moved from the current message list (from which it was selected by the user). You may also try to insert them at the correct position in the message list of the destination mailbox: +2. **Query**. Splice each selected message being moved from the current query (from which it was selected by the user). You may also try to insert them at the correct position in the query of the destination mailbox: From the thread object, you know if there are any other messages in the thread already in the mailbox. As the message list in the thread object is sorted by date, as long as the mailbox list is also sorted by date, you can now work out if the message is a new exemplar in the message list or not. If it is, binary search the list by date to find where to insert it. If you don't have message headers for all the message list loaded, you may not be able to determine the correct spot. In this case, it should be inserted anyway so the user can access it; the mistake will be corrected when the next sync with the server occurs. @@ -613,43 +686,96 @@ When you next do resync, whether that's a second or several days later, apply th JMAP can also be used to efficiently download and keep in sync the entire set of a user's mail. To do this, you would firstly get the full set of mailboxes, then page in the full list of message ids and download the actual messages. From this point on, you would only need to get the delta updates. Presuming you also want to optimise for fetching new mail first, you could do something like when you want to get the latest updates: - [ - [ "getMailboxUpdates", { - sinceState: "m123456789", - fetchRecords: true, - fetchRecordProperties: null - }, "call1" ], - [ "getMessageUpdates", { - sinceState: "m815034" - maxChanges: 50, - fetchRecords: true, - fetchRecordProperties: [ - "threadId", - "mailboxIds", - "isUnread", - "isFlagged", - "isAnswered", - "isDraft", - "hasAttachment", - "labels", - "from", - "to", - "subject", - "date", - "preview" - ] - }, "call2" ], - [ "getMessageList", { - filter: { - inMailboxes: [ "${inboxId}" ] - }, - sort: [ "date desc", "id desc" ] - collapseThreads: false, - position: 0, - limit: 100 - }, "call3" ] - ] - -The first two calls get the delta updates to mailboxes and messages (if the client has a copy of all messages locally, it has no need to use the server to get threads as it already has all the information). In the common case where there are fewer than 50 message changes since last time, this will bring the client fully up to date (barring downloading new message bodies, attachments and other details, which it can easily schedule at its leisure). - -However, if there have been a large number of changes since last time, the client is not yet fully up to date. It can continue to call getMessageUpdates to fetch more changes until it reaches the current state. Simultaneously, it can use the response to the getMessageList call in the first request to see if there are any new message ids at the top of the Inbox. These can be downloaded first so the user has immediate access to new messages (by the end of the second round trip) while the other changes then continue to sync across afterwards. +```json +[ + // Sync mailbox changes + [ "Mailbox/changes", { + "accountId": "u123456", + "sinceState": "m123456789", + "maxChanges": 50 + }, "0" ], + [ "Mailbox/get", { + "accountId": "u123456", + "#ids": { + "name": "Mailbox/changes", + "path": "/added", + "resultOf": "0" + } + }, "1" ], + [ "Mailbox/get", { + "accountId": "u123456", + "#ids": { + "name": "Mailbox/changes", + "path": "/updated", + "resultOf": "0" + }, + "#properties": { + "name": "Mailbox/changes", + "path": "/updatedProperties", + "resultOf": "0" + } + }, "2" ], + + // Sync message changes + [ "Email/changes", { + "accountId": "u123456", + "sinceState": "m815034", + "maxChanges": 50 + }, "3" ], + [ "Email/get", { + "accountId": "u123456", + "#ids": { + "name": "Email/changes", + "path": "/added", + "resultOf": "3" + }, + "properties": [ + "id", + "threadId", + "mailboxIds", + "keywords", + "hasAttachment", + "from", + "to", + "subject", + "receivedAt", + "preview" + ] + }, "4" ], + [ "Email/get", { + "accountId": "u123456", + "#ids": { + "name": "Email/changes", + "path": "/updated", + "resultOf": "3" + }, + "properties": [ + "id", + "threadId", + "mailboxIds", + "keywords", + "hasAttachment", + "from", + "to", + "subject", + "receivedAt", + "preview" + ] + }, "5" ], + + + [ "Email/query", { + "filter": { + "inMailboxes": [ "${inboxId}" ] + }, + "sort": [ "date desc", "id desc" ], + "collapseThreads": false, + "position": 0, + "limit": 100 + }, "6" ] +] +``` + +The first two method call chains get the delta updates to mailboxes and messages (if the client has a copy of all messages locally, it has no need to use the server to get threads as it already has all the information). In the common case where there are fewer than 50 message changes since last time, this will bring the client fully up to date (barring downloading new message bodies, attachments and other details, which it can easily schedule at its leisure). + +However, if there have been a large number of changes since last time, the client is not yet fully up to date. It can continue to call `Email/changes` to fetch more changes until it reaches the current state. Simultaneously, it can use the response to the `Email/query` call in the first request to see if there are any new message ids at the top of the Inbox. These can be downloaded first so the user has immediate access to new messages (by the end of the second round trip) while the other changes then continue to sync across afterwards. From 185d6a0e743bfedfdee62c70ee184c76c7ae5fc1 Mon Sep 17 00:00:00 2001 From: Nicholas Wylie Date: Fri, 5 Jun 2020 14:41:09 +1000 Subject: [PATCH 2/3] Make suggested changes --- client-guide/jmap-client-guide.mdown | 136 +++++++++++++-------------- 1 file changed, 66 insertions(+), 70 deletions(-) diff --git a/client-guide/jmap-client-guide.mdown b/client-guide/jmap-client-guide.mdown index 16f317da..e2c9ff50 100644 --- a/client-guide/jmap-client-guide.mdown +++ b/client-guide/jmap-client-guide.mdown @@ -121,7 +121,7 @@ The Sent mailbox has no unread messages, but 2 unread threads. This is not an er Presuming the client defaults to showing the `role=inbox` mailbox, we now use a chain of method calls to get all the data we need to display the messages at the top of the mailbox and the threads they participate in. -First we do a query for the `id` of first 10 messages in the mailbox, sorted descending by received date: +First we do a query for the `id`s of first 10 messages in the mailbox, sorted descending by received date: ```json [ @@ -134,8 +134,10 @@ First we do a query for the `id` of first 10 messages in the mailbox, sorted des "sort": [ { "property": "receivedAt", "isAscending": false } ], + "position": 0, "collapseThreads": true, - "limit": 10 + "limit": 10, + "calculateTotal": true }, "0" ], // Then we fetch the threadId of each of those messages @@ -178,9 +180,6 @@ This might return the following: [ [ "Email/query", { "accountId": "u123456", - "filter": { - "inMailbox": "mailbox1" - }, "ids": [ "fm1u314", "fm1u312", @@ -193,11 +192,9 @@ This might return the following: "fm1u109", "fm1u313" ], - "sort": [ - { "property": "receivedAt", "isAscending": false } - ], "queryState": "123:0", - "collapseThreads": true, + "position": 0, + "canCalculateChanges": true, "total": 10 }, "0" ], [ "Email/get", { @@ -238,20 +235,24 @@ This might return the following: "list": [{ "id": "fm1u314", "threadId": "4f512aafed75e7fb", - "mailboxIds": [ "mailbox1" ], - "isUnread": true, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, + "mailboxIds": { + "mailbox1": true + }, + "keywords": { + "$seen": false, + "$flagged": false, + "$answered": false, + "$draft": false + }, "hasAttachment": false, "from": [ - { "name": "Joe Bloggs", "email": "joebloggs@fastmail.fm" } + { "name": "Joe Bloggs", "email": "joebloggs@example.com" } ], "to": [ - { "name": "Jane Doe", "email": "janedoe@fastmail.fm" } + { "name": "Jane Doe", "email": "janedoe@example.com" } ], "subject": "Camping trip", - "date": "2014-07-24T15:04:51Z", + "receivedAt": "2014-07-24T15:04:51Z", "preview": "Hey Joe. Fancy a trip out west next week? I hea…" }, ... ], "state": "123", @@ -264,7 +265,7 @@ We now have the header information for all the messages in the top 10 threads in ## Paging in data as the interface is navigated -In our example Inbox, there are 1213 threads, but so far we have only loaded in data for the first 10. As the user scrolls down, we need to page in the data for the section of the mailbox that becomes visible (and indeed, to avoid the user having to wait, it's advisable to preload a little way ahead too). This is just another call to `Email/query`, as in the cold boot example, but with the `position` property changed to the index for the section required. +In our example Inbox, there are 1213 threads, but so far we have only loaded in data for the first 10. As the user scrolls down, we need to page in the data for the section of the mailbox that becomes visible (and indeed, to avoid the user having to wait, it's advisable to preload a little way ahead too). This is just another call to `Email/query`, as in the cold boot example, but with the `position` argument changed to the index for the section required. Similarly, if we switch mailboxes, or want to do a search, we can use the same call as well. However, remember in JMAP the same message may appear in multiple mailboxes, so to avoid downloading the same data multiple times, it's advisable to just fetch the message list without also getting the message or thread objects (except in certain situations, such as the very first request; the exact heuristics for deciding between the two can be made arbitrarily clever and complex). @@ -281,7 +282,16 @@ Similarly, if we switch mailboxes, or want to do a search, we can use the same c "collapseThreads": true, "position": 10, "limit": 10 - }, "0" ] + }, "0" ], + [ "Email/get", { + "accountId": "u123456", + "#ids": { + "name": "Email/query", + "path": "/ids", + "resultOf": "0" + }, + "properties": [ "threadId" ] + }, "1" ] ] ``` @@ -297,25 +307,19 @@ So far we have only fetched the minimal amount of information we need to display "accountId": "u123456", "ids": [ "fm1u312", "fm2u12", "fm1u304" ], "properties": [ - "threadId", - "mailboxIds", - "isUnread", - "isFlagged", - "isAnswered", - "isDraft", - "hasAttachment", - "from", - "to", + "blobId", + "messageId", + "inReplyTo", + "references", + "sender", "cc", "bcc", "replyTo", - "subject", - "date", - "size", - "body", - "attachments", - "attachedMessages" - ] + "sentAt", + "htmlBody", + "bodyValues" + ], + "fetchHTMLBodyValues": true }] ] ``` @@ -430,7 +434,7 @@ This is a good example of multiple method calls combined into a single request. 3. `Email/changes`: Gets the list of ids for all messages which have been created or updated, plus the list of messages which have been deleted. 4. `Thread/changes`: Gets the list of threads which have had messages added or removed from the thread. -In each case, the `sinceState` and `sinceQueryState` arguments come from the response to our previous calls to get the records of that type. +In each case, the `sinceState` and `sinceQueryState` arguments come from the response to our previous calls to get the records or queries of that type. ### Handling a standard response @@ -471,13 +475,6 @@ Let's look at a common case example, where two new messages have been delivered }, "2" ], [ "Email/queryChanges", { "accountId": "u123456", - "filter": { - "inMailbox": "mailbox1" - }, - "sort": [ - { "property": "receivedAt", "isAscending": false } - ], - "collapseThreads": true, "newQueryState": "124:0", "oldQueryState": "123:0", "added": [{ @@ -487,8 +484,7 @@ Let's look at a common case example, where two new messages have been delivered "id": "fm1u315", "index": 1 }], - "removed": [], - "upToId": "fm1u313" + "removed": [] }, "3" ], [ "Email/get", { "accountId": "u123456", @@ -519,38 +515,46 @@ Let's look at a common case example, where two new messages have been delivered "list": [{ "id": "fm1u316", "threadId": "afed75fb4f512ae7", - "mailboxId": "mailbox1", - "isUnread": true, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, + "mailboxIds": { + "mailbox1": true + }, + "keywords": { + "$seen": false, + "$flagged": false, + "$answered": false, + "$draft": false + }, "hasAttachment": false, "from": [ - { "name": "Joe Bloggs", "email": "joebloggs@fastmail.fm" } + { "name": "Joe Bloggs", "email": "joebloggs@example.com" } ], "to": [ - { "name": "Jane Doe", "email": "janedoe@fastmail.fm" } + { "name": "Jane Doe", "email": "janedoe@example.com" } ], "subject": "Camping trip", - "date": "2014-07-24T15:04:51Z", + "receivedAt": "2014-07-24T15:04:51Z", "preview": "Hey Joe. Fancy a trip out west next week? I hea…" }, { "id": "fm1u315", "threadId": "b4aae3925af0a0a2", - "mailboxId": "mailbox1", - "isUnread": true, - "isFlagged": false, - "isAnswered": false, - "isDraft": false, + "mailboxIds": { + "mailbox1": true + }, + "keywords": { + "$seen": false, + "$flagged": false, + "$answered": false, + "$draft": false + }, "hasAttachment": false, "from": [ - { "name": "Joe Bloggs", "email": "joebloggs@fastmail.fm" } + { "name": "Joe Bloggs", "email": "joebloggs@example.com" } ], "to": [ - { "name": "Jane Doe", "email": "janedoe@fastmail.fm" } + { "name": "Jane Doe", "email": "janedoe@example.com" } ], "subject": "Camping trip", - "date": "2014-07-24T15:04:51Z", + "receivedAt": "2014-07-24T15:04:51Z", "preview": "Hey Joe. Fancy a trip out west next week? I hea…" }], "notFound": [], @@ -599,7 +603,7 @@ Here's how we apply this information to our current state to stay in sync: e.g. removing 'm2': `[ 'm1', 'm2', 'm3' ] -> [ 'm1', 'm3' ]` -3. `Email/changes`: The `destroyed` array has 0 length. The `created` array has two message ids that we don’t have in memory, so we can ignore them. The `updated` array has one message id, which we have in our cache so we should mark is as needing an update (i.e. the flags might be out of date). +3. `Email/changes`: The `destroyed` array has 0 length. The `created` array has two message ids that we don’t have in memory, so we can ignore them. The `updated` array has one message id, which we have in our cache so we should mark is as needing an update (i.e. the keywords might be out of date). 4. `Thread/changes`: There are two changed threads here. One existing thread has a new message in it, the other is a brand new thread to create in our cache. After applying these changes, our cache is nearly in sync with the server. We need to inspect the result of both `Email/changes` and `Thread/changes` and perform one more request to fetch the properties of any objects we have in memory that are now out of date. @@ -750,16 +754,8 @@ JMAP can also be used to efficiently download and keep in sync the entire set of "resultOf": "3" }, "properties": [ - "id", - "threadId", "mailboxIds", "keywords", - "hasAttachment", - "from", - "to", - "subject", - "receivedAt", - "preview" ] }, "5" ], From 45de735e724ef0449ba2fb29c381525d00826a23 Mon Sep 17 00:00:00 2001 From: Nicholas Wylie Date: Fri, 5 Jun 2020 15:11:01 +1000 Subject: [PATCH 3/3] Update keywords in responses --- client-guide/jmap-client-guide.mdown | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/client-guide/jmap-client-guide.mdown b/client-guide/jmap-client-guide.mdown index e2c9ff50..11d26307 100644 --- a/client-guide/jmap-client-guide.mdown +++ b/client-guide/jmap-client-guide.mdown @@ -239,10 +239,7 @@ This might return the following: "mailbox1": true }, "keywords": { - "$seen": false, - "$flagged": false, - "$answered": false, - "$draft": false + "$seen": true }, "hasAttachment": false, "from": [ @@ -518,12 +515,7 @@ Let's look at a common case example, where two new messages have been delivered "mailboxIds": { "mailbox1": true }, - "keywords": { - "$seen": false, - "$flagged": false, - "$answered": false, - "$draft": false - }, + "keywords": {}, "hasAttachment": false, "from": [ { "name": "Joe Bloggs", "email": "joebloggs@example.com" } @@ -540,12 +532,7 @@ Let's look at a common case example, where two new messages have been delivered "mailboxIds": { "mailbox1": true }, - "keywords": { - "$seen": false, - "$flagged": false, - "$answered": false, - "$draft": false - }, + "keywords": {}, "hasAttachment": false, "from": [ { "name": "Joe Bloggs", "email": "joebloggs@example.com" }