Skip to Content
ReferenceActionsJMAP

JMAP Action

The JMAP action calls JMAP  methods (RFC 8620 , RFC 8621 ). It fetches the session, fills in the account of each call, sends the calls in one request, and returns the responses by call id, with the method errors gathered in one list. A step that names no calls fetches the session alone.

It is an external action, published in mozership/probe-jmap . Probe downloads it the first time a workflow uses it, and runs the executable whose SHA-256 the action.yml at the pinned commit names. It needs Probe v1.21.0 or later, which reads the guard and the params its action.yml declares. The examples write <commit SHA> for the commit to pin: probe guide jmap prints the uses line of the latest release, and so do the notes of each release.

Basic Syntax

A step pins the action by a full commit SHA. The notes of each release  start with the uses line to copy.

steps: - name: Read the latest message uses: github.com/mozership/probe-jmap@<commit SHA> with: url: https://jmap.example.com basic_auth: username: "{{vars.user}}" password: "{{vars.pass}}" calls: - method: Email/query id: latest args: sort: [{property: receivedAt, isAscending: false}] limit: 1 - method: Email/get id: email args: "#ids": {resultOf: latest, path: /ids} properties: [subject, from, receivedAt] test: status == 0 && len(res.results.email.list) == 1 echo: "Latest: {{res.results.email.list[0].subject}}"

Parameters

ParameterTypeRequiredDefaultDescription
urlStringYes-The server, http or https. A URL with no path is taken as the server, whose session is at /.well-known/jmap; a URL with a path is the session URL itself
callsArrayNo-The method calls, sent in one request in this order. A step without the key fetches the session alone; a list that is empty is an error
usingArrayNoinferredThe capabilities the request uses, sent as written. By default the core capability and those that define the methods in calls
using_alsoArrayNo-Capabilities to add to the inferred ones, such as the one of a vendor. Not a key of JMAP, and not given together with using
account_idStringNoprimary accountThe account of each call whose args give no accountId
basic_authObjectNo-username and password for HTTP Basic authentication
headersObjectNo-Request headers, such as Authorization: Bearer <token>
keep_sessionBooleanNofalseKeeps the session in the job, so that the later steps that keep it send their calls without fetching it again. See Keeping the Session
timeoutDurationNo30sTime limit for both requests together, as 10s or a number of seconds. 0 removes it

A call in calls takes:

FieldRequiredDescription
methodYesThe method name, such as Email/get
argsNoThe arguments of the method
idNoThe call id, which a back-reference and res.results use. Defaults to c and the position of the call, from c0

A call whose args give neither accountId nor #accountId is made in account_id, or else in the primary account the session names for the capability of the method. Core/echo and the methods of PushSubscription take no accountId, and are given none.

A back-reference, an argument whose name starts with #, may leave out name: it is given the method of the call that resultOf names. A back-reference takes the place of the whole argument, so it cannot be put inside one, such as inside filter.

Capabilities

using is inferred from the type in the method name:

TypeCapability
Core, PushSubscriptionurn:ietf:params:jmap:core
Mailbox, Thread, Email, SearchSnippeturn:ietf:params:jmap:mail
Identity, EmailSubmissionurn:ietf:params:jmap:submission
VacationResponseurn:ietf:params:jmap:vacationresponse
MDNurn:ietf:params:jmap:mdn
Bloburn:ietf:params:jmap:blob
Quotaurn:ietf:params:jmap:quota
SieveScripturn:ietf:params:jmap:sieve
AddressBook, ContactCardurn:ietf:params:jmap:contacts

Blob/copy is the exception: RFC 8620 defines it, so it is inferred as the core capability, and it is made in the primary account of that capability when the session names one.

A method of any other type needs using or using_also:

  • using replaces what is inferred, and is sent as written. It is how to leave a capability out, or to send one the server does not have.
  • using_also is added after what is inferred, without a capability twice. A method of a type that is not in the table is taken to belong to one of them, so the standard types and those of a vendor are written together without listing every capability:
with: using_also: [urn:example:vendor] calls: - method: Mailbox/get - method: x:Domain/query

This sends using as the core capability, urn:ietf:params:jmap:mail and urn:example:vendor. The method of the vendor is given no accountId, as its capability is not known.

A step cannot give both. When the defaults of a job give using_also, a step that gives using sets using_also: null.

A key of with that is not one of the parameters above fails the step before anything is sent. Its action.yml declares the parameters as params, so probe check reports such a key with its line.

The Session Alone

A step without calls fetches the session and sends nothing to the API. It is how to wait for a server, or to test what the session says. This example and the next give the action the name jmap under actions, so that uses and defaults take the name:

- name: Wait for the server uses: jmap retry: {max_attempts: 60, interval: 1s} test: status == 0 && res.session.capabilities["urn:ietf:params:jmap:mail"] != nil

res is then the response to the session request, res.results and res.responses are empty, and status is 0 when the server gave a session. using, using_also and account_id are for the calls, and such a step does not read them, so the defaults of a job may give them.

Only the key left out does this. calls with an empty list or no value fails the step, as a list that lost its calls would otherwise pass for a step that asks for none.

Keeping the Session

The action fetches the session in every step. With keep_session: true, a step keeps the session it fetched in the job, and a later step of the job that keeps the session too sends its calls with that one, in one request instead of two. In the defaults of a job it applies to every step:

jobs: - name: jmap defaults: jmap: url: https://jmap.example.com keep_session: true

Nothing is fetched before the first step: the first step that keeps the session fetches it, as it would without keep_session.

  • The session is kept for the session URL and the headers it was asked with, basic_auth among them, so a step of another user fetches its own.
  • A step without calls asks for the session itself: it always fetches it, and keeps what it got.
  • The API names the state of the session in each response. When that is not the state of the session kept, or the API answers with a status other than 2xx, the session is dropped, and the next step fetches it again.
  • A session the server did not give is not kept.
  • The session is kept for one run of the job, and is not shared with another job.

req.session_kept tells whether res.session is the session the job kept or one fetched for the step, and rt is then the time of the API request alone. With a session kept, credentials the server no longer takes show as the response of the API, not as an error of the session kind.

Response Object

PropertyTypeDescription
res.codeIntegerHTTP status code
res.statusStringHTTP status line, such as "200 OK"
res.headersObjectResponse headers, keyed by canonical name
res.sessionObjectThe session object as the server sent it, to this step or to the one that kept it, or null when there is none
res.resultsObjectThe arguments of each method response, keyed by call id. A method error is there too, as the error object
res.responsesArrayEvery method response in order, as name, args and id
res.errorsArrayWhat failed, described below; empty when nothing did
res.bodyAnyThe whole response body, parsed when it is JSON, otherwise the raw string
res.rawbodyStringThe unparsed body, present when the body is JSON
reqObjectThe session_url, session_kept, the API url, using, the calls as sent and the headers. In a step without calls, url is "" and using and calls are empty
rtDurationTime for the session and the API request together, or for the API request alone when the session was kept
statusInteger0 when the API answered 2xx with method responses and res.errors is empty, or, in a step without calls, when the server gave a session; 1 otherwise

A JMAP server answers a method it could not run with HTTP 200, so res.code alone does not tell that the calls succeeded. res.errors gathers every failure, each the error object the server sent with these fields added:

kindWhat failedAdded fields
methodA method call, answered with an error responseid, method
notCreated, notUpdated, notDestroyedA record of a /set callid, method, key (the creation id or the record id)
requestThe whole request, answered with a problem details object-
sessionThe session, which the server did not givedescription

When the server gives no session, the method calls are not sent, and res is the response to the session request, as it is in a step without calls.

Any response the server sends is a result, so a test can assert on a method error or a 401. Only a request that gets no response, such as a refused connection or a timeout, fails the step as an error.

Examples

Sending a Message and Waiting for It

Email/set makes the message and EmailSubmission/set sends it, naming the message by its creation id #msg. The steps that follow wait for it with retry.

steps: - name: Send a message to bob uses: github.com/mozership/probe-jmap@<commit SHA> with: url: "{{vars.url}}" basic_auth: {username: "{{vars.alice}}", password: "{{vars.alice_pass}}"} calls: - method: Email/set id: create args: create: msg: mailboxIds: "{{outputs.alice.sent}}": true from: [{email: "{{vars.alice}}"}] to: [{email: "{{vars.bob}}"}] subject: "{{vars.subject}}" bodyValues: {body: {value: Sent by probe.}} textBody: [{partId: body, type: text/plain}] - method: EmailSubmission/set id: submit args: create: sub: identityId: "{{outputs.alice.identity}}" emailId: "#msg" test: status == 0 && res.results.submit.created.sub.id != nil - name: Wait for it in bob's mailbox uses: github.com/mozership/probe-jmap@<commit SHA> with: url: "{{vars.url}}" basic_auth: {username: "{{vars.bob}}", password: "{{vars.bob_pass}}"} calls: - method: Email/query id: query args: filter: {subject: "{{vars.subject}}"} - method: Email/get id: get args: "#ids": {resultOf: query, path: /ids} properties: [subject, receivedAt] retry: max_attempts: 30 interval: 1s test: status == 0 && len(res.results.get.list) == 1

Asserting on a Failure

steps: - name: A record that cannot be created uses: github.com/mozership/probe-jmap@<commit SHA> with: url: "{{vars.url}}" basic_auth: {username: "{{vars.user}}", password: "{{vars.pass}}"} calls: - method: Email/set args: create: bad: mailboxIds: {no-such-mailbox: true} test: | status == 1 && res.errors[0].kind == "notCreated" && res.errors[0].key == "bad"

Guard

Under --read-only, a step whose calls include a method other than /get, /query, /changes, /queryChanges, /lookup and /echo is refused before anything is sent. A host that --allow-host does not allow is refused, for the session, the API URL and any redirect. Its action.yml declares guard: [read-only, allow-host], so Probe runs it under either without --allow-action. See Guard.

See Also

  • External Actions - How Probe resolves and checks an external action
  • IMAP - Mailboxes over IMAP
  • SMTP - Delivering mail to a server
  • GraphQL - The other external action published alongside Probe
Updated at