Moving an app from IMAP to JMAP
If you've written IMAP code, most ideas carry over, but a few work differently. Here's what maps to what, and the habits worth dropping.
| In IMAP | In JMAP |
|---|---|
| LOGIN or AUTHENTICATE | An Authorization header on each https request |
| SELECT a folder first | No selecting. Filter with inMailbox instead |
| UID, only unique in one folder | An email id, the same wherever the message is |
| \Seen, \Flagged, \Answered, \Draft | Keywords $seen, $flagged, $answered, $draft |
| COPY and MOVE | Change the message's mailboxIds |
| A message in one folder | A message can be in several mailboxes, like labels |
| UIDVALIDITY, CONDSTORE, QRESYNC | A state string and /changes methods |
| IDLE | EventSource, WebSocket or Web Push, for the whole account |
| SEARCH | Email/query with a filter |
| FETCH of bodies and parts | Email/get with body values, or download the blob |
| APPEND | Upload the message, then Email/import |
| Sending through SMTP | EmailSubmission/set |
| Special use folders | Mailbox role |
| Folder paths with separators | Mailboxes with a parentId |
Habits to drop
- Syncing folder by folder. In JMAP you sync the whole account: one
Email/changescovers every mailbox. - Waiting for each reply. Put several steps in one request and link them with back references.
- Keeping a connection open per folder. One alert feed covers the whole account.
- Treating ids as numbers. JMAP ids are short strings. Don't sort by them or guess the next one.
Things to handle
cannotCalculateChanges: the server can't say what changed since your state, so fetch the list again.- Limits from the session, such as the most calls in one request and the most objects in one get. Split big jobs to fit.
- Threads come from the server, so you don't need to work them out from headers.
Most JMAP servers also speak IMAP, so you can move one part of your app at a time.
Words you don't know? See the glossary.