<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' []>
<rfc ipr="trust200902" category="std" docName="draft-ietf-jmap-mail-09" updates="5788">
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc private=""?>
<?rfc topblock="yes"?>
<?rfc comments="no"?>
<front>
<title abbrev="JMAP Mail">JMAP for Mail</title>

<author initials="N.M." surname="Jenkins" fullname="Neil Jenkins">
<organization>FastMail</organization>
<address>
<postal>
<street>PO Box 234, Collins St West</street>
<city>Melbourne</city>
<code>VIC 8007</code>
<country>Australia</country>
<region></region>
</postal>
<phone></phone>
<email>neilj@fastmailteam.com</email>
<uri>https://www.fastmail.com</uri>
</address>
</author>
<author initials="C." surname="Newman" fullname="Chris Newman">
<organization>Oracle</organization>
<address>
<postal>
<street>440 E. Huntington Dr., Suite 400</street>
<city>Arcadia</city>
<code>CA 91006</code>
<country>United States of America</country>
<region></region>
</postal>
<phone></phone>
<email>chris.newman@oracle.com</email>
<uri></uri>
</address>
</author>
<date year="2018" month="October" day="23"/>

<area>Applications</area>
<workgroup>JMAP</workgroup>
<keyword>JMAP</keyword>
<keyword>JSON</keyword>
<keyword>email</keyword>


<abstract>
<t>This document specifies a data model for synchronising email data with a server using JMAP.
</t>
</abstract>


</front>

<middle>

<section anchor="introduction" title="Introduction">
<t>JMAP <eref target="https://tools.ietf.org/html/draft-ietf-jmap-core-05"/> is a generic protocol for synchronising data, such as mail, calendars or contacts, between a client and a server. It is optimised for mobile and web environments, and aims to provide a consistent interface to different data types.
</t>
<t>This specification defines a data model for synchronising mail between a client and a server using JMAP.
</t>

<section anchor="notational-conventions" title="Notational conventions">
<t>The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL NOT&quot;, &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;MAY&quot;, and &quot;OPTIONAL&quot; in this document are to be interpreted as described in <xref target="RFC2119"/>.
</t>
<t>Type signatures, examples and property descriptions in this document follow the conventions established in Section 1.1 of <eref target="https://tools.ietf.org/html/draft-ietf-jmap-core-05"/>.
</t>
<t>Object properties may also have a set of attributes defined along with the type
signature. These have the following meanings:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">server-set</spanx>: Only the server can set the value for this property. The
client MUST NOT send this property when creating a new object of this type.</t>
<t><spanx style="strong">immutable</spanx>: The value MUST NOT change after the object is created.</t>
<t><spanx style="strong">default</spanx>: (This is followed by a JSON value). The value that will be used
for this property if it is omitted in an argument, or when creating a new object of this type.</t>
</list>
</t>
<t>Data types defined in the core specification are used in this document.
</t>
</section>

<section anchor="terminology" title="Terminology">
<t>The same terminology is used in this document as in the core JMAP specification.
</t>
</section>

<section anchor="additions-to-the-capabilities-object" title="Additions to the capabilities object">
<t>The capabilities object is returned as part of the standard JMAP Session object; see the JMAP Core specification.
</t>
<t>This document defines three additional capability objects.
</t>

<section anchor="urnietfparamsjmapmail" title="urn:ietf:params:jmap:mail">
<t>This represents support for the Mailbox, Thread, Email, and SearchSnippet data types and associated API methods. The value of this property is an object which MUST contain the following information on server capabilities:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">maxMailboxesPerEmail</spanx>: <spanx style="verb">PositiveInt|null</spanx>
The maximum number of mailboxes that can be can assigned to a single email. This MUST be an integer &gt;= 1, or <spanx style="verb">null</spanx> for no limit (or rather, the limit is always the number of mailboxes in the account).</t>
<t><spanx style="strong">maxMailboxDepth</spanx>: <spanx style="verb">PositiveInt|null</spanx>
The maximum depth of the mailbox hierarchy (i.e. one less than the maximum number of ancestors a mailbox may have), or <spanx style="verb">null</spanx> for no limit.</t>
<t><spanx style="strong">maxSizeMailboxName</spanx>: <spanx style="verb">PositiveInt</spanx>
The maximum length, in (UTF-8) octets, allowed for the name of a mailbox. This MUST be &gt;= 255.</t>
<t><spanx style="strong">maxSizeAttachmentsPerEmail</spanx>: <spanx style="verb">PositiveInt</spanx>
The maximum total size of attachments, in octets, allowed for a single email. A server MAY still reject import or creation of emails with a lower attachment size total (for example, if the body includes several megabytes of text, causing the size of the encoded MIME structure to be over some server-defined limit).
Note, this limit is for the sum of unencoded attachment sizes. Users are generally not knowledgeable about encoding overhead etc., nor should they need to be, so services marketing and help materials normally tells them the &quot;max size attachments&quot;. This is the unencoded size they see on their hard drive, and so this capability matches that and allows the client to consistently enforce what the user understands as the limit.
The server may separately have a limit for the total size of the RFC5322 message, which will have attachments Base64 encoded and message headers and bodies too. For example, suppose the server advertises <spanx style="verb">maxSizeAttachmentsPerEmail: 50000000</spanx> (50 MB). The enforced server limit may be for an RFC5322 size of 70000000 octets (70 MB). Even with Base64 encoding and a 2 MB HTML body, 50 MB attachments would fit under this limit.</t>
<t><spanx style="strong">emailsListSortOptions</spanx>: <spanx style="verb">String[]</spanx>
A list of all the email properties the server supports for sorting by. This MAY include properties the client does not recognise (for example custom properties specified in a vendor extension). Clients MUST ignore any unknown properties in the list.</t>
</list>
</t>
</section>

<section anchor="urnietfparamsjmapsubmission" title="urn:ietf:params:jmap:submission">
<t>This represents support for the Identity and MessageSubmission data types and associated API methods. The value of this property is an object which MUST contain the following information on server capabilities:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">maxDelayedSend</spanx>: <spanx style="verb">PositiveInt</spanx>
The number in seconds of the maximum delay the server supports in sending
(see the EmailSubmission object description). This is <spanx style="verb">0</spanx> if the server does
not support delayed send.</t>
<t><spanx style="strong">submissionExtensions</spanx>: <spanx style="verb">String[String[]]</spanx>
A JMAP implementation that talks to a Submission <xref target="RFC6409"/> server SHOULD have a configuration setting that allows an administrator to expose a new submission EHLO capability in this field. This allows a JMAP server to gain access to a new submission extension without code changes. By default, the JMAP server should show only known safe-to-expose EHLO capabilities in this field, and hide EHLO capabilities that are only relevant to the JMAP server.
Each key in the object is the <spanx style="emph">ehlo-name</spanx>, and the value is a list of <spanx style="emph">ehlo-args</spanx>.
Examples of safe-to-expose Submission extensions include:
<list style="symbols">
<t>FUTURERELEASE (<xref target="RFC4865"/>)</t>
<t>SIZE (<xref target="RFC1870"/>)</t>
<t>DSN (<xref target="RFC3461"/>)</t>
<t>DELIVERYBY (<xref target="RFC2852"/>)</t>
<t>MT-PRIORITY (<xref target="RFC6710"/>)</t>
</list>
A JMAP server MAY advertise an extension and implement the semantics of that extension locally on the JMAP server even if a submission server used by JMAP doesn't implement it.
The full IANA registry of submission extensions can be found at <eref target="https://www.iana.org/assignments/mail-parameters/mail-parameters.xhtml#mail-parameters-2"/></t>
</list>
</t>
</section>

<section anchor="urnietfparamsjmapvacationresponse" title="urn:ietf:params:jmap:vacationresponse">
<t>This represents support for the VacationResponse data type and associated API methods. The value of this property is an empty object.
</t>
</section>
</section>

<section anchor="data-type-support-in-different-accounts" title="Data type support in different accounts">
<t>The server MUST include the appropriate capability strings in the <spanx style="emph">hasDataFor</spanx> property of any account in which the user may use the data types represented by that URN. Supported data types may differ between accounts the user has access to. For example, in the user's personal account they may have access to all three sets of data, but in a shared account they may only have data for <spanx style="verb">urn:ietf:params:jmap:mail</spanx>. This means they can access Mailbox/Thread/Email data in the shared account but are not allowed to send as that account (and so do not have access to Identity/MessageSubmission objects) or view/set its vacation response.
</t>
</section>

<section anchor="push" title="Push">
<t>Servers MUST support the standard JMAP push mechanisms to receive notifications when the state changes for any of the types defined in this specification.
</t>
<t>In addition, servers MUST support a psuedo-type called &quot;EmailDelivery&quot; in the push mechanisms. The state string for this MUST change whenever a new Email is added to the store, but SHOULD NOT change upon any other change to the Email objects.
</t>
<t>Clients in battery constrained environments may wish to delay fetching changes initiated by the user, but fetch new messages immediately so they can notify the user.
</t>
</section>
</section>

<section anchor="mailboxes" title="Mailboxes">
<t>A mailbox represents a named set of emails. This is the primary mechanism for organising emails within an account. It is analogous to a folder or a label in other systems. A mailbox may perform a certain role in the system; see below for more details.
</t>
<t>For compatibility with IMAP, an email MUST belong to one or more mailboxes. The email id does not change if the email changes mailboxes.
</t>
<t>A <spanx style="strong">Mailbox</spanx> object has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">id</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
The id of the mailbox.</t>
<t><spanx style="strong">name</spanx>: <spanx style="verb">String</spanx>
User-visible name for the mailbox, e.g. &quot;Inbox&quot;. This may be any Net-Unicode string (<xref target="RFC5198"/>) of at least 1 character in length, subject to the maximum size given in the capability object. Servers MUST forbid sibling Mailboxes with the same name. Servers MAY reject names that violate server policy (e.g., names containing slash (/) or control characters).</t>
<t><spanx style="strong">parentId</spanx>: <spanx style="verb">String|null</spanx> (default: null)
The mailbox id for the parent of this mailbox, or <spanx style="verb">null</spanx> if this mailbox is at the top level. Mailboxes form acyclic graphs (forests) directed by the child-to-parent relationship. There MUST NOT be a loop.</t>
<t><spanx style="strong">role</spanx>: <spanx style="verb">String|null</spanx> (default: null)
Identifies mailboxes that have a particular common purpose (e.g. the &quot;inbox&quot;), regardless of the <spanx style="emph">name</spanx> (which may be localised). This value is shared with IMAP (exposed in IMAP via the <xref target="RFC6154"/> SPECIAL-USE extension). However, unlike in IMAP, a mailbox may only have a single role, and no two mailboxes in the same account may have the same role.
The value MUST be one of the mailbox attribute names listed in the <eref target="https://www.iana.org/assignments/imap-mailbox-name-attributes/imap-mailbox-name-attributes.xhtml">IANA IMAP Mailbox Name Attributes Registry</eref>, as established in <xref target="RFC8457"/>, converted to lower-case. New roles may be established here in the future.
An account is not required to have mailboxes with any particular roles.</t>
<t><spanx style="strong">sortOrder</spanx>: <spanx style="verb">PositiveInt</spanx> (default: 0)
Defines the sort order of mailboxes when presented in the client's UI, so it
is consistent between devices. The number MUST be an integer in the range
0 &lt;= sortOrder &lt; 2^31.
A mailbox with a lower order should be displayed before a mailbox with a higher order (that has the same parent) in any mailbox listing in the client's UI. Mailboxes with equal order SHOULD be sorted in alphabetical order by name. The sorting SHOULD take into account locale-specific character order convention.</t>
<t><spanx style="strong">totalEmails</spanx>: <spanx style="verb">PositiveInt</spanx> (server-set)
The number of emails in this mailbox.</t>
<t><spanx style="strong">unreadEmails</spanx>: <spanx style="verb">PositiveInt</spanx> (server-set)
The number of emails in this mailbox that have neither the <spanx style="verb">$seen</spanx> keyword nor the <spanx style="verb">$draft</spanx> keyword.</t>
<t><spanx style="strong">totalThreads</spanx>: <spanx style="verb">PositiveInt</spanx> (server-set)
The number of threads where at least one email in the thread is in this mailbox.</t>
<t><spanx style="strong">unreadThreads</spanx>: <spanx style="verb">PositiveInt</spanx> (server-set)
An indication of the number of &quot;unread&quot; threads in the mailbox. This may be
presented by the client as a badge or marker associated with the mailbox.
For compatibility with existing implementations, the way &quot;unread threads&quot; is
determined is not mandated in this document. The simplest solution to implement is simply the number of threads where at least one email in the thread is both in this mailbox and has neither the <spanx style="verb">$seen</spanx> nor <spanx style="verb">$draft</spanx> keywords.
However, a quality implementation will make return the number of unread items the user would see if they opened that mailbox. A thread is shown as unread if it contains any unread messages that will be displayed when the thread is opened. Therefore <spanx style="verb">unreadThreads</spanx> should be the number of threads where at least one email in the thread has neither the <spanx style="verb">$seen</spanx> nor the <spanx style="verb">$draft</spanx> keyword AND at least one email in the thread is in this mailbox. Note, the unread email does not need to be the one in this mailbox. In addition, the Trash mailbox (that is a mailbox whose <spanx style="verb">role</spanx> is <spanx style="verb">trash</spanx>) is treated specially:
<list style="numbers">
<t>Emails that are <spanx style="strong">only</spanx> in the Trash (and no other mailbox) are ignored when calculating the <spanx style="verb">unreadThreads</spanx> count of other mailboxes.</t>
<t>Emails that are <spanx style="strong">not</spanx> in the Trash are ignored when calculating the <spanx style="verb">unreadThreads</spanx> count for the Trash mailbox.</t>
</list>
The result of this is that emails in the Trash are treated as though they are in a separate thread for the purposes of unread counts. It is expected that clients will hide emails in the Trash when viewing a thread in another mailbox and vice versa. This allows you to delete a single email to the Trash out of a thread.
So for example, suppose you have an account where the entire contents is a single thread with 2 emails: an unread email in the Trash and a read email in the Inbox. The <spanx style="verb">unreadThreads</spanx> count would be <spanx style="verb">1</spanx> for the Trash and <spanx style="verb">0</spanx> for the Inbox.</t>
<t><spanx style="strong">myRights</spanx>: <spanx style="verb">MailboxRights</spanx> (server-set)
The set of rights (ACLs) the user has in relation to this mailbox. A <spanx style="emph">MailboxRights</spanx> object has the following properties:
<list style="symbols">
<t><spanx style="strong">mayReadItems</spanx>: <spanx style="verb">Boolean</spanx>
If true, the user may use this mailbox as part of a filter in a <spanx style="emph">Email/query</spanx> call and the mailbox may be included in the <spanx style="emph">mailboxIds</spanx> set of <spanx style="emph">Email</spanx> objects. If a sub-mailbox is shared but not the parent mailbox, this may be <spanx style="verb">false</spanx>. Corresponds to IMAP ACLs <spanx style="verb">lr</spanx>.</t>
<t><spanx style="strong">mayAddItems</spanx>: <spanx style="verb">Boolean</spanx>
The user may add mail to this mailbox (by either creating a new email or moving an existing one). Corresponds to IMAP ACL <spanx style="verb">i</spanx>.</t>
<t><spanx style="strong">mayRemoveItems</spanx>: <spanx style="verb">Boolean</spanx>
The user may remove mail from this mailbox (by either changing the mailboxes of an email or deleting it). Corresponds to IMAP ACLs <spanx style="verb">te</spanx>.</t>
<t><spanx style="strong">maySetSeen</spanx>: <spanx style="verb">Boolean</spanx>
The user may add or remove the <spanx style="verb">$seen</spanx> keyword to/from an email. If an email belongs to multiple mailboxes, the user may only modify <spanx style="verb">$seen</spanx> if <spanx style="strong">all</spanx> of the mailboxes have this permission. Corresponds to IMAP ACL <spanx style="verb">s</spanx>.</t>
<t><spanx style="strong">maySetKeywords</spanx>: <spanx style="verb">Boolean</spanx>
The user may add or remove any keyword <spanx style="emph">other than</spanx> <spanx style="verb">$seen</spanx> to/from an email. If an email belongs to multiple mailboxes, the user may only modify keywords if <spanx style="strong">all</spanx> of the mailboxes have this permission. Corresponds to IMAP ACL <spanx style="verb">w</spanx>.</t>
<t><spanx style="strong">mayCreateChild</spanx>: <spanx style="verb">Boolean</spanx>
The user may create a mailbox with this mailbox as its parent. Corresponds to IMAP ACL <spanx style="verb">k</spanx>.</t>
<t><spanx style="strong">mayRename</spanx>: <spanx style="verb">Boolean</spanx>
The user may rename the mailbox or make it a child of another mailbox. Corresponds to IMAP ACL <spanx style="verb">x</spanx>.</t>
<t><spanx style="strong">mayDelete</spanx>: <spanx style="verb">Boolean</spanx>
The user may delete the mailbox itself. Corresponds to IMAP ACL <spanx style="verb">x</spanx>.</t>
<t><spanx style="strong">maySubmit</spanx>: <spanx style="verb">Boolean</spanx>
Messages may be submitted directly to this mailbox. Corresponds to IMAP ACL <spanx style="verb">p</spanx>.</t>
</list></t>
<t><spanx style="strong">isSubscribed</spanx>: <spanx style="verb">Boolean</spanx>
Has the user indicated they wish to see this mailbox in their client? This SHOULD default to <spanx style="verb">false</spanx> for mailboxes in shared accounts the user has access to, and <spanx style="verb">true</spanx> for any new mailboxes created by the user themself. This MUST be stored separately per-user where multiple users have access to a shared mailbox.
A user may have permission to access a large number of shared accounts, or a shared account with a very large set of mailboxes, but only be interested in the contents of a few of these. Clients may choose only to display mailboxes to the user that have the <spanx style="verb">isSubscribed</spanx> property set to <spanx style="verb">true</spanx>, and offer a separate UI to allow the user to see and subscribe/unsubscribe from the full set of mailboxes. However, clients MAY choose to ignore this property, either entirely, for ease of implementation, or just for the primary account (which is normally the user's own, rather than a shared account).</t>
</list>
</t>
<t>For IMAP compatibility, an email in both the Trash and another mailbox SHOULD be treated by the client as existing in both places (i.e. when emptying the trash, the client SHOULD just remove the Trash mailbox and leave it in the other mailbox).
</t>
<t>The following JMAP methods are supported:
</t>

<section anchor="mailboxget" title="Mailbox/get">
<t>Standard &quot;/get&quot; method. The <spanx style="emph">ids</spanx> argument may be <spanx style="verb">null</spanx> to fetch all at once.
</t>
</section>

<section anchor="mailboxchanges" title="Mailbox/changes">
<t>Standard &quot;/changes&quot; method, but with one extra argument to the response:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">updatedProperties</spanx>: <spanx style="verb">String[]|null</spanx>
If only the mailbox counts (unread/total emails/threads) have changed since the old state, this will be the list of properties that may have changed, i.e. <spanx style="verb">["totalEmails", "unreadEmails", "totalThreads", "unreadThreads"]</spanx>. If the server is unable to tell if only counts have changed, it MUST just be <spanx style="verb">null</spanx>.</t>
</list>
</t>
<t>Since counts frequently change but the rest of the mailboxes state for most use cases changes rarely, the server can help the client optimise data transfer by keeping track of changes to email/thread counts separately to other state changes. The <spanx style="emph">updatedProperties</spanx> array may be used directly via a result reference in a subsequent Mailbox/get call in a single request.
</t>
</section>

<section anchor="mailboxquery" title="Mailbox/query">
<t>Standard &quot;/query&quot; method.
</t>
<t>A <spanx style="strong">FilterCondition</spanx> object has the following properties, any of which may be omitted:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">parentId</spanx>: <spanx style="verb">String|null</spanx>
The Mailbox <spanx style="emph">parentId</spanx> property must match the given value exactly.</t>
<t><spanx style="strong">name</spanx>: <spanx style="verb">String</spanx>
The Mailbox <spanx style="emph">name</spanx> property contains the given string.</t>
<t><spanx style="strong">role</spanx>: <spanx style="verb">String|null</spanx>
The Mailbox <spanx style="emph">role</spanx> property must match the given value exactly.</t>
<t><spanx style="strong">hasAnyRole</spanx>: <spanx style="verb">Boolean</spanx>
If <spanx style="verb">true</spanx>, a Mailbox matches if it has any non-<spanx style="verb">null</spanx> value for its <spanx style="emph">role</spanx> property.</t>
<t><spanx style="strong">isSubscribed</spanx>: <spanx style="verb">Boolean</spanx>
The <spanx style="verb">isSubscribed</spanx> property of the mailbox must be identical to the value given to match the condition.</t>
</list>
</t>
<t>A Mailbox object matches the filter if and only if all of the given conditions given match. If zero properties are specified, it is automatically <spanx style="verb">true</spanx> for all objects.
</t>
<t>The following properties MUST be supported for sorting:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">sortOrder</spanx></t>
<t><spanx style="verb">name</spanx></t>
<t><spanx style="verb">parent/name</spanx>: This is a pseudo-property, just for sorting, with the
following semantics: if two mailboxes have a common parent, sort them by name. Otherwise, find the nearest ancestors of each that share a common parent and sort by their names instead. (i.e. This sorts the mailbox list in tree order).</t>
</list>
</t>
</section>

<section anchor="mailboxquerychanges" title="Mailbox/queryChanges">
<t>Standard &quot;/queryChanges&quot; method.
</t>
</section>

<section anchor="mailboxset" title="Mailbox/set">
<t>Standard &quot;/set&quot; method, but with the following additional argument:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">onDestroyRemoveMessages</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">false</spanx>, attempts to destroy a mailbox that still has any messages in it will be rejected with a <spanx style="verb">mailboxHasEmail</spanx> SetError. If <spanx style="verb">true</spanx>, any messages that were in the mailbox will be removed from it, and if in no other mailboxes will be destroyed when the mailbox is destroyed.</t>
</list>
</t>
<t>The following extra <spanx style="emph">SetError</spanx> types are defined:
</t>
<t>For <spanx style="strong">destroy</spanx>:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">mailboxHasChild</spanx>: The mailbox still has at least one child mailbox. The
client MUST remove these before it can delete the parent mailbox.</t>
<t><spanx style="verb">mailboxHasEmail</spanx>: The mailbox has at least one message assigned to it and
the <spanx style="emph">onDestroyRemoveMessages</spanx> argument was <spanx style="verb">false</spanx>.</t>
</list>
</t>
</section>

<section anchor="example" title="Example">
<t>Fetching all mailboxes in an account:
</t>

<figure align="center"><artwork align="center">
[[ "Mailbox/get", {
  "accountId": "u33084183",
  "ids": null
}, "0" ]]
</artwork></figure>
<t>And response:
</t>

<figure align="center"><artwork align="center">
[[ "Mailbox/get", {
  "accountId": "u33084183",
  "state": "78540",
  "list": [
  {
    "id": "23cfa8094c0f41e6",
    "name": "Inbox",
    "parentId": null,
    "role": "inbox",
    "sortOrder": 10,
    "totalEmails": 16307,
    "unreadEmails": 13905,
    "totalThreads": 5833,
    "unreadThreads": 5128,
    "myRights": {
      "mayAddItems": true,
      "mayRename": false,
      "maySubmit": true,
      "mayDelete": false,
      "maySetKeywords": true,
      "mayRemoveItems": true,
      "mayCreateChild": true,
      "maySetSeen": true,
      "mayReadItems": true
    },
    "isSubscribed": true
  },
  {
    "id": "674cc24095db49ce",
    "name": "Important mail",
    ...
  }
  ...
  ],
  "notFound": []
}, "0" ]]
</artwork></figure>
<t>Now suppose a message is marked read and we get a push update that the Mailbox state has changed. You might fetch the updates like this:
</t>

<figure align="center"><artwork align="center">
[[ "Mailbox/changes", {
  "accountId": "u33084183",
  "sinceState": "78540"
}, "0" ],
[ "Mailbox/get", {
  "accountId": "u33084183",
  "#ids": {
    "resultOf": "0",
    "name": "Mailbox/changes",
    "path": "/created"
  }
}, "1" ],
[ "Mailbox/get", {
  "accountId": "u33084183",
  "#ids": {
    "resultOf": "0",
    "name": "Mailbox/changes",
    "path": "/updated"
  },
  "#properties": {
    "resultOf": "0",
    "name": "Mailbox/changes",
    "path": "/updatedProperties"
  }
}, "2" ]]
</artwork></figure>
<t>This fetches the list of ids for created/updated/destroyed mailboxes, then using back references fetches the data for just the created/updated mailboxes in the same request. The response may look something like this:
</t>

<figure align="center"><artwork align="center">
[[ "Mailbox/changes", {
  "accountId": "u33084183",
  "oldState": "78541",
  "newState": "78542",
  "hasMoreChanges": false,
  "updatedProperties": [
    "totalEmails", "unreadEmails",
    "totalThreads", "unreadThreads"
  ],
  "created": [],
  "updated": ["23cfa8094c0f41e6"],
  "destroyed": []
}, "0" ],
[ "Mailbox/get", {
  "accountId": "u33084183",
  "state": "78542",
  "list": [],
  "notFound": []
}, "1" ],
[ "Mailbox/get", {
  "accountId": "u33084183",
  "state": "78542",
  "list": [{
    "id": "23cfa8094c0f41e6",
    "totalEmails": 16307,
    "unreadEmails": 13903,
    "totalThreads": 5833,
    "unreadThreads": 5127
  }],
  "notFound": []
}, "2" ]]
</artwork></figure>
<t>Here's an example where we try to rename one mailbox and destroy another:
</t>

<figure align="center"><artwork align="center">
[[ "Mailbox/set", {
  "accountId": "u33084183",
  "ifInState": "78542",
  "update": {
    "674cc24095db49ce": {
      "name": "Maybe important mail"
    }
  },
  "destroy": [ "23cfa8094c0f41e6" ]
}, "0" ]]
</artwork></figure>
<t>Suppose the rename succeeds, but we don't have permission to destroy the mailbox we tried to destroy, we might get back:
</t>

<figure align="center"><artwork align="center">
[[ "Mailbox/set", {
  "accountId": "u33084183",
  "oldState": "78542",
  "newState": "78549",
  "created": null,
  "notCreated": null,
  "updated": {
      "674cc24095db49ce": null
  },
  "notUpdated": null,
  "destroyed": null,
  "notDestroyed": {
    "23cfa8094c0f41e6": {
      "type": "forbidden"
    }
  }
}, "0" ]]
</artwork></figure>
</section>
</section>

<section anchor="threads" title="Threads">
<t>Replies are grouped together with the original message to form a thread. In JMAP, a thread is simply a flat list of emails, ordered by date. Every email MUST belong to a thread, even if it is the only email in the thread.
</t>
<t>The exact algorithm for determining whether two emails belong to the same thread is not mandated in this spec to allow for compatibility with different existing systems. For new implementations, it is suggested that two messages belong in the same thread if both of the following conditions apply:
</t>
<t>
<list style="numbers">
<t>An identical RFC5322 message id appears in both messages in any of the
 Message-Id, In-Reply-To and References headers.</t>
<t>After stripping automatically added prefixes such as &quot;Fwd:&quot;, &quot;Re:&quot;,
 &quot;[List-Tag]&quot; etc. and ignoring whitespace, the subjects are the same. This avoids the situation where a person replies to an old message as a convenient way of finding the right recipient to send to, but changes the subject and starts a new conversation.</t>
</list>
</t>
<t>If emails are delivered out of order for some reason, a user may receive two emails in the same thread but without headers that associate them with each other. The arrival of a third email in the thread may provide the missing references to join them all together into a single thread. Since the <spanx style="emph">threadId</spanx> of an email is immutable, if the server wishes to merge the threads, it MUST handle this by deleting and reinserting (with a new email id) the emails that change threadId.
</t>
<t>A <spanx style="strong">Thread</spanx> object has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">id</spanx>: <spanx style="verb">String</spanx> (immutable)
The id of the thread.</t>
<t><spanx style="strong">emailIds</spanx>: <spanx style="verb">String[]</spanx>
The ids of the emails in the thread, sorted by the <spanx style="emph">receivedAt</spanx> date of the email, oldest first. If two emails have an identical date, the sort is server-dependent but MUST be stable (sorting by id is recommended).</t>
</list>
</t>
<t>The following JMAP methods are supported:
</t>

<section anchor="threadget" title="Thread/get">
<t>Standard &quot;/get&quot; method.
</t>

<section anchor="example-1" title="Example">
<t>Request:
</t>

<figure align="center"><artwork align="center">
[[ "Thread/get", {
  "accountId": "acme",
  "ids": ["f123u4", "f41u44"],
}, "#1" ]]
</artwork></figure>
<t>with response:
</t>

<figure align="center"><artwork align="center">
[[ "Thread/get", {
  "accountId": "acme",
  "state": "f6a7e214",
  "list": [
    {
      "id": "f123u4",
      "emailIds": [ "eaa623", "f782cbb"]
    },
    {
      "id": "f41u44",
      "emailIds": [ "82cf7bb" ]
    }
  ],
  "notFound": []
}, "#1" ]]
</artwork></figure>
</section>
</section>

<section anchor="threadchanges" title="Thread/changes">
<t>Standard &quot;/changes&quot; method.
</t>
</section>
</section>

<section anchor="emails" title="Emails">
<t>The <spanx style="strong">Email</spanx> object is a representation of an <xref target="RFC5322"/> message, which allows clients to avoid the complexities of MIME parsing, transport encoding and character encoding.
</t>

<section anchor="properties-of-the-email-object" title="Properties of the Email object">
<t>Broadly, a message consists of two parts: a list of header fields, then a body. The JMAP Email object provides a way to access the full structure, or to use simplified properties and avoid some complexity if this is sufficient for the client application.
</t>
<t>While raw headers can be fetched and set, the vast majority of clients should use an appropriate parsed form for each of the headers it wants to process, as this allows it to avoid the complexities of various encodings that are required in a valid RFC5322 message.
</t>
<t>The body of a message is normally a MIME-encoded set of documents in a tree structure. This may be arbitrarily nested, but the majority of email clients present a flat model of an email body (normally plain text or HTML), with a set of attachments. Flattening the MIME structure to form this model can be difficult, and causes inconsistency between clients. Therefore in addition to the <spanx style="emph">bodyStructure</spanx> property, which gives the full tree, the Email object contains 3 alternate properties with flat lists of body parts:
</t>
<t>
<list style="symbols">
<t><spanx style="emph">textBody</spanx>/<spanx style="emph">htmlBody</spanx>: These provide a list of parts that should be
rendered sequentially as the &quot;body&quot; of the message. This is a list rather than a single part as messages may have headers and/or footers appended/prepended as separate parts as they are transmitted, and some clients send text and images, or even videos and sound clips, intended to be displayed inline in the body as multiple parts rather than a single HTML part with referenced images.</t>
</list>
</t>
<t>Because MIME allows for multiple representations of the same data (using <spanx style="verb">multipart/alternative</spanx>), there is a textBody property (which prefers a plain text representation) and an htmlBody property (which prefers an HTML representation) to accommodate the two most common client requirements. The same part may appear in both lists where there is no alternative between the two.
</t>
<t>
<list style="symbols">
<t><spanx style="emph">attachments</spanx>: This provides a list of parts that should be presented as
&quot;attachments&quot; to the message. Some images may be solely there for embedding within an HTML body part; clients may wish to not present these as attachments in the user interface if they are displaying the HTML with the embedded images directly. Some parts may also be in htmlBody/textBody; again, clients may wish to not present these as attachments in the user interface if rendered as part of the body.</t>
</list>
</t>
<t>The <spanx style="emph">bodyValues</spanx> property allows for clients to fetch the value of text parts directly without having to do a second request for the blob, and have the server handle decoding the charset into unicode. This data is in a separate property rather than on the EmailBodyPart object to avoid duplication of large amounts of data, as the same part may be included twice if the client fetches more than one of bodyStructure, textBody and htmlBody.
</t>
<t>Due to the number of properties involved, the set of <spanx style="emph">Email</spanx> properties is specified over the following three sub-sections.
</t>

<section anchor="metadata" title="Metadata">
<t>These properties represent metadata about the <xref target="RFC5322"/> message, and are not derived from parsing the message itself.
</t>
<t>
<list style="symbols">
<t><spanx style="strong">id</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
The id of the Email object. Note, this is the JMAP object id, NOT the <xref target="RFC5322"/> Message-ID header field value.</t>
<t><spanx style="strong">blobId</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
The id representing the raw octets of the <xref target="RFC5322"/> message. This may be used to download the raw original message, or to attach it directly to another Email etc.</t>
<t><spanx style="strong">threadId</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
The id of the Thread to which this Email belongs.</t>
<t><spanx style="strong">mailboxIds</spanx>: <spanx style="verb">String[Boolean]</spanx>
The set of mailbox ids this email belongs to. An email MUST belong to one or more mailboxes at all times (until it is deleted). The set is represented as an object, with each key being a <spanx style="emph">Mailbox id</spanx>. The value for each key in the object MUST be <spanx style="verb">true</spanx>.</t>
<t><spanx style="strong">keywords</spanx>: <spanx style="verb">String[Boolean]</spanx> (default: )
A set of keywords that apply to the email. The set is represented as an object, with the keys being the <spanx style="emph">keywords</spanx>. The value for each key in the object MUST be <spanx style="verb">true</spanx>.
Keywords are shared with IMAP. The six system keywords from IMAP are treated specially. The following four keywords have their first character changed from <spanx style="verb">\</spanx> in IMAP to <spanx style="verb">$</spanx> in JMAP and have particular semantic meaning:
<list style="symbols">
<t><spanx style="verb">$draft</spanx>: The email is a draft the user is composing.</t>
<t><spanx style="verb">$seen</spanx>: The email has been read.</t>
<t><spanx style="verb">$flagged</spanx>: The email has been flagged for urgent/special attention.</t>
<t><spanx style="verb">$answered</spanx>: The email has been replied to.</t>
</list>
The IMAP <spanx style="verb">\Recent</spanx> keyword is not exposed via JMAP. The IMAP <spanx style="verb">\Deleted</spanx> keyword is also not present: IMAP uses a delete+expunge model, which JMAP does not. Any message with the <spanx style="verb">\Deleted</spanx> keyword MUST NOT be visible via JMAP.
Users may add arbitrary keywords to an email. For compatibility with IMAP, a keyword is a case-insensitive string of 1–255 characters in the ASCII subset %x21–%x7e (excludes control chars and space), and MUST NOT include any of these characters: <spanx style="verb">( ) { ] % * " \</spanx>
Because JSON is case-sensitive, servers MUST return keywords in lower-case.
The <eref target="https://www.iana.org/assignments/imap-keywords/imap-keywords.xhtml">IANA Keyword Registry</eref> as established in <xref target="RFC5788"/> assigns semantic meaning to some other keywords in common use. New keywords may be established here in the future. In particular, note:
<list style="symbols">
<t><spanx style="verb">$forwarded</spanx>: The email has been forwarded.</t>
<t><spanx style="verb">$phishing</spanx>: The email is highly likely to be phishing. Clients SHOULD warn users to take care when viewing this email and disable links and attachments.</t>
<t><spanx style="verb">$junk</spanx>: The email is definitely spam. Clients SHOULD set this flag when users report spam to help train automated spam-detection systems.</t>
<t><spanx style="verb">$notjunk</spanx>: The email is definitely not spam. Clients SHOULD set this flag when users indicate an email is legitimate, to help train automated spam-detection systems.</t>
</list></t>
<t><spanx style="strong">size</spanx>: <spanx style="verb">PositiveInt</spanx> (immutable; server-set)
The size, in octets, of the raw data for the <xref target="RFC5322"/> message (as referenced by the <spanx style="emph">blobId</spanx>, i.e. the number of octets in the file the user would download).</t>
<t><spanx style="strong">receivedAt</spanx>: <spanx style="verb">UTCDate</spanx> (immutable; default: time of creation on server)
The date the email was received by the message store. This is the <spanx style="emph">internal date</spanx> in IMAP.</t>
</list>
</t>
</section>

<section anchor="header-fields-parsed-forms" title="Header fields parsed forms">
<t>Header field properties are derived from the <xref target="RFC5322"/> and <xref target="RFC6532"/> message header fields. All header fields may be fetched in a raw form. Some headers may also be fetched in a parsed form. The structured form that may be fetched depends on the header. The following forms are defined:
</t>

<section anchor="raw" title="Raw">
<t>Type: <spanx style="verb">String</spanx>
</t>
<t>The raw octets of the header field value from the first octet following the header field name terminating colon, up to but excluding the header field terminating CRLF. Any standards-compliant message MUST be either ASCII (RFC5322) or UTF-8 (RFC6532), however other encodings exist in the wild. A server MAY use heuristics to determine a charset and decode the octets, or MAY replace any octet or octet run with the high bit set that violates UTF-8 syntax with the unicode replacement character (U+FFFD). Any NUL octet MUST be dropped.
</t>
</section>

<section anchor="text" title="Text">
<t>Type: <spanx style="verb">String</spanx>
</t>
<t>The header field value with:
</t>
<t>
<list style="numbers">
<t>White space unfolded (as defined in <xref target="RFC5322"/> section 2.2.3)</t>
<t>The terminating CRLF at the end of the value removed</t>
<t>Any SP characters at the beginning of the value removed</t>
<t>Any syntactically correct <xref target="RFC2047"/> encoded sections with a known
character set decoded. Any <xref target="RFC2047"/> encoded NUL octets or control characters are dropped from the decoded value. Any text that looks like <xref target="RFC2047"/> syntax but violates <xref target="RFC2047"/> placement or whitespace rules MUST NOT be decoded.</t>
<t>Any <xref target="RFC6532"/> UTF-8 values decoded.</t>
<t>The resulting unicode converted to NFC form.</t>
</list>
</t>
<t>If any decodings fail, the parser SHOULD insert a unicode replacement
character (U+FFFD) and attempt to continue as much as possible.
</t>
<t>To prevent obviously nonsense behaviour, which can lead to interoperability issues, this form may only be fetched or set for the following header fields:
</t>
<t>
<list style="symbols">
<t>Subject</t>
<t>Comment</t>
<t>List-Id</t>
<t>Any header not defined in <xref target="RFC5322"/> or <xref target="RFC2369"/></t>
</list>
</t>
</section>

<section anchor="addresses" title="Addresses">
<t>Type: <spanx style="verb">EmailAddress[]</spanx>
</t>
<t>The header is parsed as an <spanx style="verb">address-list</spanx> value, as specified in <xref target="RFC5322"/> section 3.4, into the <spanx style="verb">EmailAddress[]</spanx> type. There is an EmailAddress item for each <spanx style="verb">mailbox</spanx> parsed from the <spanx style="verb">address-list</spanx>. Group and comment information is discarded.
</t>
<t>The <spanx style="strong">EmailAddress</spanx> object has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">name</spanx>: <spanx style="verb">String|null</spanx>
The <spanx style="emph">display-name</spanx> of the <xref target="RFC5322"/> <spanx style="emph">mailbox</spanx>, or <spanx style="verb">null</spanx> if none. If this is a <spanx style="emph">quoted-string</spanx>:
<list style="numbers">
<t>The surrounding DQUOTE characters are removed.</t>
<t>Any <spanx style="emph">quoted-pair</spanx> is decoded.</t>
<t>White-space is unfolded, and then any leading and trailing white-space
is removed.</t>
</list></t>
<t><spanx style="strong">email</spanx>: <spanx style="verb">String</spanx>
The <spanx style="emph">addr-spec</spanx> of the <xref target="RFC5322"/> <spanx style="emph">mailbox</spanx>.</t>
</list>
</t>
<t>Any syntactically correct <xref target="RFC2047"/> encoded sections with a known encoding MUST be decoded, following the same rules as for the <spanx style="emph">Text</spanx> form. Any <xref target="RFC6532"/> UTF-8 values MUST be decoded.
</t>
<t>Parsing SHOULD be best-effort in the face of invalid structure to
accommodate invalid messages and semi-complete drafts. EmailAddress objects
MAY have an <spanx style="emph">email</spanx> property that does not conform to the <spanx style="emph">addr-spec</spanx> form (for example, may not contain an @ symbol).
</t>
<t>For example, the following <spanx style="verb">address-list</spanx> string:
</t>

<figure align="center"><artwork align="center">
"  James Smythe" &lt;james@example.com&gt;, Friends: jane@example.com, =?UTF-8?Q?John_Sm=C3=AEth?= &lt;john@example.com&gt;;
</artwork></figure>
<t>would be parsed as:
</t>

<figure align="center"><artwork align="center">
[
  { "name": "James Smythe", "email": "james@example.com" },
  { "name": null, "email": "jane@example.com" },
  { "name": "John Smîth", "email": "john@example.com" },
]
</artwork></figure>
<t>To prevent obviously nonsense behaviour, which can lead to interoperability issues, this form may only be fetched or set for the following header fields:
</t>
<t>
<list style="symbols">
<t>From</t>
<t>Sender</t>
<t>Reply-To</t>
<t>To</t>
<t>Cc</t>
<t>Bcc</t>
<t>Resent-From</t>
<t>Resent-Sender</t>
<t>Resent-Reply-To</t>
<t>Resent-To</t>
<t>Resent-Cc</t>
<t>Resent-Bcc</t>
<t>Any header not defined in <xref target="RFC5322"/> or <xref target="RFC2369"/></t>
</list>
</t>
</section>

<section anchor="groupedaddresses" title="GroupedAddresses">
<t>Type: <spanx style="verb">EmailAddressGroup[]</spanx>
</t>
<t>This is similar to the Addresses form but preserves group information. The header is parsed as an <spanx style="verb">address-list</spanx> value, as specified in <xref target="RFC5322"/> section 3.4, into the <spanx style="verb">GroupedAddresses[]</spanx> type. Consecutive mailboxes that are not part of a group are still collected under an EmailAddressGroup object to provide a uniform type.
</t>
<t>The <spanx style="strong">EmailAddressGroup</spanx> object has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">name</spanx>: <spanx style="verb">String|null</spanx>
The <spanx style="emph">display-name</spanx> of the <xref target="RFC5322"/> <spanx style="emph">group</spanx>, or <spanx style="verb">null</spanx> if the addresses are not part of a group. If this is a <spanx style="emph">quoted-string</spanx> it is processed the same as the <spanx style="emph">name</spanx> in the <spanx style="emph">EmailAddress</spanx> type.</t>
<t><spanx style="strong">addresses</spanx>: <spanx style="verb">EmailAddress[]</spanx>
The <spanx style="emph">mailbox</spanx>es that belong to this group, represented as EmailAddress
objects.</t>
</list>
</t>
<t>Any syntactically correct <xref target="RFC2047"/> encoded sections with a known encoding MUST be decoded, following the same rules as for the <spanx style="emph">Text</spanx> form. Any <xref target="RFC6532"/> UTF-8 values MUST be decoded.
</t>
<t>Parsing SHOULD be best-effort in the face of invalid structure to
accommodate invalid messages and semi-complete drafts.
</t>
<t>For example, the following <spanx style="verb">address-list</spanx> string:
</t>

<figure align="center"><artwork align="center">
"  James Smythe" &lt;james@example.com&gt;, Friends: jane@example.com, =?UTF-8?Q?John_Sm=C3=AEth?= &lt;john@example.com&gt;;
</artwork></figure>
<t>would be parsed as:
</t>

<figure align="center"><artwork align="center">
[
  { "name": null, "addresses": [
    { "name": "James Smythe", "email": "james@example.com" }
  ]},
  { "name": "Friends", "addresses": [
    { "name": null, "email": "jane@example.com" },
    { "name": "John Smîth", "email": "john@example.com" }
  ]}
]
</artwork></figure>
<t>To prevent obviously nonsense behaviour, which can lead to interoperability issues, this form may only be fetched or set for the same header fields as the <spanx style="emph">Addresses</spanx> form.
</t>
</section>

<section anchor="messageids" title="MessageIds">
<t>Type: <spanx style="verb">String[]|null</spanx>
</t>
<t>The header is parsed as a list of <spanx style="verb">msg-id</spanx> values, as specified in <xref target="RFC5322"/> section 3.6.4, into the <spanx style="verb">String[]</spanx> type. CFWS and surrounding angle brackets (<spanx style="verb">&lt;&gt;</spanx>) are removed. If parsing fails, the value is <spanx style="verb">null</spanx>.
</t>
<t>To prevent obviously nonsense behaviour, which can lead to interoperability issues, this form may only be fetched or set for the following header fields:
</t>
<t>
<list style="symbols">
<t>Message-ID</t>
<t>In-Reply-To</t>
<t>References</t>
<t>Resent-Message-ID</t>
<t>Any header not defined in <xref target="RFC5322"/> or <xref target="RFC2369"/></t>
</list>
</t>
</section>

<section anchor="date" title="Date">
<t>Type: <spanx style="verb">Date|null</spanx>
</t>
<t>The header is parsed as a <spanx style="verb">date-time</spanx> value, as specified in <xref target="RFC5322"/> section 3.3, into the <spanx style="verb">Date</spanx> type. If parsing fails, the value is <spanx style="verb">null</spanx>.
</t>
<t>To prevent obviously nonsense behaviour, which can lead to interoperability issues, this form may only be fetched or set for the following header fields:
</t>
<t>
<list style="symbols">
<t>Date</t>
<t>Resent-Date</t>
<t>Any header not defined in <xref target="RFC5322"/> or <xref target="RFC2369"/></t>
</list>
</t>
</section>

<section anchor="urls" title="URLs">
<t>Type: <spanx style="verb">String[]|null</spanx>
</t>
<t>The header is parsed as a list of URLs, as described in <xref target="RFC2369"/>, into the <spanx style="verb">String[]</spanx> type. Values do not include the surrounding angle brackets or any comments in the header with the URLs. If parsing fails, the value is <spanx style="verb">null</spanx>.
</t>
<t>To prevent obviously nonsense behaviour, which can lead to interoperability issues, this form may only be fetched or set for the following header fields:
</t>
<t>
<list style="symbols">
<t>List-Help</t>
<t>List-Unsubscribe</t>
<t>List-Subscribe</t>
<t>List-Post</t>
<t>List-Owner</t>
<t>List-Archive</t>
<t>Any header not defined in <xref target="RFC5322"/> or <xref target="RFC2369"/></t>
</list>
</t>
</section>
</section>

<section anchor="header-fields-properties" title="Header fields properties">
<t>The following low-level <spanx style="strong">Email</spanx> property is specified for complete access to the header data of the message:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">headers</spanx>: <spanx style="verb">EmailHeader[]</spanx> (immutable)
This is a list of all <xref target="RFC5322"/> header fields, in the same order they appear in the message. An <spanx style="strong">EmailHeader</spanx> object has the following properties:
<list style="symbols">
<t><spanx style="strong">name</spanx>: <spanx style="verb">String</spanx>
The header <spanx style="emph">field name</spanx> as defined in <xref target="RFC5322"/>, with the same capitalization that it has in the message.</t>
<t><spanx style="strong">value</spanx>: <spanx style="verb">String</spanx>
The header <spanx style="emph">field value</spanx> as defined in <xref target="RFC5322"/>, in <spanx style="emph">Raw</spanx> form.</t>
</list></t>
</list>
</t>
<t>In addition, the client may request/send properties representing individual header fields of the form:
</t>

<figure align="center"><artwork align="center">
header:{header-field-name}
</artwork></figure>
<t>Where <spanx style="verb">{header-field-name}</spanx> means any series of one or more printable ASCII characters (i.e. characters that have values between 33 and 126, inclusive), except colon. The property may also have the following suffixes:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">:as{header-form}</spanx>
This means the value is in a parsed form, where <spanx style="verb">{header-form}</spanx> is one of the parsed-form names specified above. If not given, the value is in <spanx style="emph">Raw</spanx> form.</t>
<t><spanx style="strong">:all</spanx>
This means the value is an array, with the items corresponding to each instance of the header field, in the order they appear in the message. If this suffix is not used, the result is the value of the <spanx style="strong">last</spanx> instance of the header field (i.e. identical to the <spanx style="strong">last</spanx> item in the array if :all is used), or <spanx style="verb">null</spanx> if none.</t>
</list>
</t>
<t>If both suffixes are used, they MUST be specified in the order above. Header field names are matched case-insensitively. The value is typed according to the requested form, or an array of that type if :all is used. If no header fields exist in the message with the requested name, the value is <spanx style="verb">null</spanx> if fetching a single instance, or the empty array if requesting :all.
</t>
<t>As a simple example, if the client requests a property called <spanx style="verb">header:subject</spanx>, this means find the <spanx style="emph">last</spanx> header field in the message named &quot;subject&quot; (matched case-insensitively) and return the value in <spanx style="emph">Raw</spanx> form, or <spanx style="verb">null</spanx> if no header of this name is found.
</t>
<t>For a more complex example, consider the client requesting a property called <spanx style="verb">header:Resent-To:asAddresses:all</spanx>. This means:
</t>
<t>
<list style="numbers">
<t>Find <spanx style="emph">all</spanx> header fields named Resent-To (matched case-insensitively).</t>
<t>For each instance parse the header field value in the <spanx style="emph">Addresses</spanx> form.</t>
<t>The result is of type <spanx style="verb">EmailAddress[][]</spanx> – each item in the array
corresponds to the parsed value (which is itself an array) of the Resent-To
header field instance.</t>
</list>
</t>
<t>The following convenience properties are also specified for the <spanx style="strong">Email</spanx> object:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">messageId</spanx>: <spanx style="verb">String[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:Message-ID:asMessageIds</spanx>. For messages conforming to RFC5322 this will be an array with a single entry.</t>
<t><spanx style="strong">inReplyTo</spanx>: <spanx style="verb">String[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:In-Reply-To:asMessageIds</spanx>.</t>
<t><spanx style="strong">references</spanx>: <spanx style="verb">String[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:References:asMessageIds</spanx>.</t>
<t><spanx style="strong">sender</spanx>: <spanx style="verb">EmailAddress[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:Sender:asAddresses</spanx>.</t>
<t><spanx style="strong">from</spanx>: <spanx style="verb">EmailAddress[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:From:asAddresses</spanx>.</t>
<t><spanx style="strong">to</spanx>: <spanx style="verb">EmailAddress[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:To:asAddresses</spanx>.</t>
<t><spanx style="strong">cc</spanx>: <spanx style="verb">EmailAddress[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:Cc:asAddresses</spanx>.</t>
<t><spanx style="strong">bcc</spanx>:  <spanx style="verb">EmailAddress[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:Bcc:asAddresses</spanx>.</t>
<t><spanx style="strong">replyTo</spanx>: <spanx style="verb">EmailAddress[]|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:Reply-To:asAddresses</spanx>.</t>
<t><spanx style="strong">subject</spanx>: <spanx style="verb">String|null</spanx> (immutable)
The value is identical to the value of <spanx style="emph">header:Subject:asText</spanx>.</t>
<t><spanx style="strong">sentAt</spanx>: <spanx style="verb">Date|null</spanx> (immutable; default on creation: current server time)
The value is identical to the value of <spanx style="emph">header:Date:asDate</spanx>.</t>
</list>
</t>
</section>

<section anchor="body-parts" title="Body parts">
<t>These properties are derived from the <xref target="RFC5322"/> message body and its <xref target="RFC2045"/> MIME entities.
</t>
<t>A <spanx style="strong">EmailBodyPart</spanx> object has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">partId</spanx>: <spanx style="verb">String|null</spanx>
Identifies this part uniquely within the Email. This is scoped to the <spanx style="emph">emailId</spanx> and has no meaning outside of the JMAP Email object representation. This is <spanx style="verb">null</spanx> if, and only if, the part is of type <spanx style="verb">multipart/*</spanx>.</t>
<t><spanx style="strong">blobId</spanx>: <spanx style="verb">String|null</spanx>
The id representing the raw octets of the contents of the part after decoding any <spanx style="emph">Content-Transfer-Encoding</spanx> (as defined in <xref target="RFC2045"/>), or <spanx style="verb">null</spanx> if, and only if, the part is of type <spanx style="verb">multipart/*</spanx>. Note, two parts may be transfer-encoded differently but have same the same blob id if their decoded octets are identical and the server is using a secure hash of the data for the blob id.</t>
<t><spanx style="strong">size</spanx>: <spanx style="verb">PositiveInt</spanx>
The size, in octets, of the raw data after content transfer decoding (as referenced by the <spanx style="emph">blobId</spanx>, i.e. the number of octets in the file the user would download).</t>
<t><spanx style="strong">headers</spanx>: <spanx style="verb">EmailHeader[]</spanx>
This is a list of all header fields in the part, in the order they appear. The values are in <spanx style="emph">Raw</spanx> form.</t>
<t><spanx style="strong">name</spanx>: <spanx style="verb">String|null</spanx>
This is the <xref target="RFC2231"/> decoded <spanx style="emph">filename</spanx> parameter of the <spanx style="emph">Content-Disposition</spanx> header field, or (for compatibility with existing systems) if not present then the <xref target="RFC2047"/> decoded <spanx style="emph">name</spanx> parameter of the <spanx style="emph">Content-Type</spanx> header field.</t>
<t><spanx style="strong">type</spanx>: <spanx style="verb">String</spanx>
The value of the <spanx style="emph">Content-Type</spanx> header field of the part, if present, otherwise the implicit type as per the MIME standard (<spanx style="verb">text/plain</spanx>, or <spanx style="verb">message/rfc822</spanx> if inside a <spanx style="verb">multipart/digest</spanx>). CFWS is removed and any parameters are stripped.</t>
<t><spanx style="strong">charset</spanx>: <spanx style="verb">String|null</spanx>
The value of the charset parameter of the <spanx style="emph">Content-Type</spanx> header field, if present, or <spanx style="verb">null</spanx> if the header field is present but not of type <spanx style="verb">text/*</spanx>. If there is no <spanx style="emph">Content-Type</spanx> header field, or it exists and is of type <spanx style="verb">text/*</spanx> but has no charset parameter, this is the implicit charset as per the MIME standard: <spanx style="verb">us-ascii</spanx>.</t>
<t><spanx style="strong">disposition</spanx>: <spanx style="verb">String|null</spanx>
The value of the <spanx style="emph">Content-Disposition</spanx> header field of the part, if present, otherwise <spanx style="verb">null</spanx>. CFWS is removed and any parameters are stripped.</t>
<t><spanx style="strong">cid</spanx>: <spanx style="verb">String|null</spanx>
The value of the <spanx style="emph">Content-Id</spanx> header field of the part, if present, otherwise <spanx style="verb">null</spanx>. CFWS and surrounding angle brackets (<spanx style="verb">&lt;&gt;</spanx>) are removed. This may be used to reference the content from within an html body part using the <spanx style="verb">cid:</spanx> protocol.</t>
<t><spanx style="strong">language</spanx>: <spanx style="verb">String[]|null</spanx>
The list of language tags, as defined in <xref target="RFC3282"/>, in the <spanx style="emph">Content-Language</spanx> header field of the part, if present.</t>
<t><spanx style="strong">location</spanx>: <spanx style="verb">String|null</spanx>
The URI, as defined in <xref target="RFC2557"/>, in the <spanx style="emph">Content-Location</spanx> header field of the part, if present.</t>
<t><spanx style="strong">subParts</spanx>: <spanx style="verb">EmailBodyPart[]|null</spanx>
If type is <spanx style="verb">multipart/*</spanx>, this contains the body parts of each child.</t>
</list>
</t>
<t>In addition, the client may request/send EmailBodyPart properties representing individual header fields, following the same syntax and semantics as for the Email object, e.g. <spanx style="verb">header:Content-Type</spanx>.
</t>
<t>The following <spanx style="strong">Email</spanx> properties are specified for access to the body data of the message:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">bodyStructure</spanx>: <spanx style="verb">EmailBodyPart</spanx> (immutable)
This is the full MIME structure of the message body, represented as an array of the message's top-level MIME parts, without recursing into <spanx style="verb">message/rfc822</spanx> or <spanx style="verb">message/global</spanx> parts. Note that EmailBodyParts may have subParts if they are of type <spanx style="verb">multipart/*</spanx>.</t>
<t><spanx style="strong">bodyValues</spanx>: <spanx style="verb">String[EmailBodyValue]</spanx> (immutable)
This is a map of <spanx style="emph">partId</spanx> to an <spanx style="strong">EmailBodyValue</spanx> object for none, some or all <spanx style="verb">text/*</spanx> parts. Which parts are included and whether the value is truncated is determined by various arguments to <spanx style="emph">Email/get</spanx> and <spanx style="emph">Email/parse</spanx>.
An <spanx style="strong">EmailBodyValue</spanx> object has the following properties:
<list style="symbols">
<t><spanx style="strong">value</spanx>: <spanx style="verb">String</spanx>
The value of the body part after decoding <spanx style="emph">Content-Transport-Encoding</spanx> and
decoding the <spanx style="emph">Content-Type</spanx> charset, if known to the server, and with any CRLF replaced with a single LF. The server MAY use heuristics to determine the charset to use for decoding if the charset is unknown, or if no charset is given, or if it believes the charset given is incorrect. Decoding is best-effort and SHOULD insert the unicode replacement character (U+FFFD) and continue when a malformed section is encountered.
Note that due to the charset decoding and line ending normalisation, the length of this string will probably not be exactly the same as the <spanx style="emph">size</spanx> property on the corresponding EmailBodyPart.</t>
<t><spanx style="strong">isEncodingProblem</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
This is <spanx style="verb">true</spanx> if malformed sections were found while decoding the charset, or the charset was unknown.</t>
<t><spanx style="strong">isTruncated</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
This is <spanx style="verb">true</spanx> if the <spanx style="emph">value</spanx> has been truncated.</t>
</list>
See the security considerations section for issues related to truncation
and heuristic determination of content-type and charset.</t>
<t><spanx style="strong">textBody</spanx>: <spanx style="verb">EmailBodyPart[]</spanx> (immutable)
A list of <spanx style="verb">text/plain</spanx>, <spanx style="verb">text/html</spanx>, <spanx style="verb">image/*</spanx>, <spanx style="verb">audio/*</spanx> and/or <spanx style="verb">video/*</spanx> parts to display (sequentially) as the message body, with a preference for <spanx style="verb">text/plain</spanx> when alternative versions are available.</t>
<t><spanx style="strong">htmlBody</spanx>: <spanx style="verb">EmailBodyPart[]</spanx> (immutable)
A list of <spanx style="verb">text/plain</spanx>, <spanx style="verb">text/html</spanx>, <spanx style="verb">image/*</spanx>, <spanx style="verb">audio/*</spanx> and/or <spanx style="verb">video/*</spanx> parts to display (sequentially) as the message body, with a preference for <spanx style="verb">text/html</spanx> when alternative versions are available.</t>
<t><spanx style="strong">attachments</spanx>: <spanx style="verb">EmailBodyPart[]</spanx> (immutable)
A list of all parts in <spanx style="emph">bodyStructure</spanx>, traversing depth-first, which satisfy either of the following conditions:
<list style="symbols">
<t>not of type <spanx style="verb">multipart/*</spanx> and not included in <spanx style="emph">textBody</spanx> or <spanx style="emph">htmlBody</spanx></t>
<t>of type <spanx style="verb">image/*</spanx>, <spanx style="verb">audio/*</spanx> or <spanx style="verb">video/*</spanx> and not in both <spanx style="emph">textBody</spanx> and
<spanx style="emph">htmlBody</spanx></t>
</list>
None of these parts include subParts, including <spanx style="verb">message/*</spanx> types. Attached messages may be fetched using the Email/parse method and the blobId.
Note, an HTML body part may reference image parts in attachments using <spanx style="verb">cid:</spanx> links to reference the <spanx style="emph">Content-Id</spanx> or by referencing the <spanx style="emph">Content-Location</spanx>.</t>
<t><spanx style="strong">hasAttachment</spanx>: <spanx style="verb">Boolean</spanx> (immutable; server-set)
This is <spanx style="verb">true</spanx> if there are one or more parts in the message that a client UI should offer as downloadable. A server SHOULD set hasAttachment if either:
<list style="symbols">
<t>The <spanx style="emph">attachments</spanx> list contains at least one item that does not have
<spanx style="verb">Content-Disposition: inline</spanx>. The server MAY ignore parts in this list that are processed automatically in some way, or are referenced as embedded images in one of the <spanx style="verb">text/html</spanx> parts of the message.</t>
</list>
The server MAY set hasAttachment based on implementation-defined or site configurable heuristics.</t>
<t><spanx style="strong">preview</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
Up to 255 octets of plain text, summarising the message body. This is intended to be shown as a preview line on a mailbox listing, and may be truncated when shown. The server may choose which part of the message to include in the preview, for example skipping quoted sections and salutations and collapsing white-space can result in a more useful preview.</t>
</list>
</t>
<t>The exact algorithm for decomposing bodyStructure into textBody, htmlBody and attachments part lists is not mandated, as this is a quality-of-service implementation issue and likely to require workarounds for malformed content discovered over time. However, the following algorithm (expressed here in JavaScript) is suggested as a starting point, based on real-world experience:
</t>

<figure align="center"><artwork align="center">
function isInlineMediaType ( type ) {
  return type.startsWith( 'image/' ) ||
         type.startsWith( 'audio/' ) ||
         type.startsWith( 'video/' );
}

function parseStructure ( parts, multipartType, inAlternative,
        htmlBody, textBody, attachments ) {

    // For multipartType == alternative
    let textLength = textBody ? textBody.length : -1;
    let htmlLength = htmlBody ? htmlBody.length : -1;

    for ( let i = 0; i &lt; parts.length; i += 1 ) {
        let part = parts[i];
        let isMultipart = part.type.startsWith( 'multipart/' );
        // Is this a body part rather than an attachment
        let isInline = part.disposition != "attachment" &amp;&amp;
            // Must be one of the allowed body types
            ( part.type == "text/plain" ||
              part.type == "text/html" ||
              isInlineMediaType( part.type ) ) &amp;&amp;
            // If multipart/related, only the first part can be inline
            // If a text part with a filename, and not the first item in the
            // multipart, assume it is an attachment
            ( i === 0 ||
              ( multipartType != "related" &amp;&amp;
                ( isInlineMediaType( part.type ) || !part.name ) ) );

        if ( isMultipart ) {
            let subMultiType = part.type.split( '/' )[1];
            parseStructure( part.subParts, subMultiType,
                inAlternative || ( subMultiType == 'alternative' ),
                htmlBody, textBody, attachments );
        } else if ( isInline ) {
            if ( multipartType == 'alternative' ) {
                switch ( part.type ) {
                case 'text/plain':
                    textBody.push( part );
                    break;
                case 'text/html':
                    htmlBody.push( part );
                    break;
                default:
                    attachments.push( part );
                    break;
                }
                continue;
            } else if ( inAlternative ) {
                if ( part.type == 'text/plain' ) {
                    htmlBody = null;
                }
                if ( part.type == 'text/html' ) {
                    textBody = null;
                }
            }
            if ( textBody ) {
                textBody.push( part );
            }
            if ( htmlBody ) {
                htmlBody.push( part );
            }
            if ( ( !textBody || !htmlBody ) &amp;&amp;
                    isInlineMediaType( part.type ) ) {
                attachments.push( part );
            }
        } else {
            attachments.push( part );
        }
    }

    if ( multipartType == 'alternative' &amp;&amp; textBody &amp;&amp; htmlBody ) {
        // Found HTML part only
        if ( textLength == textBody.length &amp;&amp;
                htmlLength != htmlBody.length ) {
            for ( let i = htmlLength; i &lt; htmlBody.length; i += 1 ) {
                textBody.push( htmlBody[i] );
            }
        }
        // Found plain text part only
        if ( htmlLength == htmlBody.length &amp;&amp;
                textLength != textBody.length ) {
            for ( let i = textLength; i &lt; textBody.length; i += 1 ) {
                htmlBody.push( textBody[i] );
            }
        }
    }
}

// Usage:
let htmlBody = [];
let textBody = [];
let attachments = [];

parseStructure( [ bodyStructure ], 'mixed', false,
    htmlBody, textBody, attachments );
</artwork></figure>
<t>For instance, consider a message with both text and html versions that's then
gone through a list software manager that attaches a header/footer. It might have a MIME structure something like:
</t>

<figure align="center"><artwork align="center">
multipart/mixed
  text/plain, content-disposition=inline - A
  multipart/mixed
    multipart/alternative
      multipart/mixed
        text/plain, content-disposition=inline - B
        image/jpeg, content-disposition=inline - C
        text/plain, content-disposition=inline - D
      multipart/related
        text/html - E
        image/jpeg - F
    image/jpeg, content-disposition=attachment - G
    application/x-excel - H
    message/rfc822 - J
  text/plain, content-disposition=inline - K
</artwork></figure>
<t>In this case, the above algorithm would decompose this to:
</t>

<figure align="center"><artwork align="center">
textBody =&gt; [ A, B, C, D, K ]
htmlBody =&gt; [ A, E, K ]
attachments =&gt; [ C, F, G, H, J ]
</artwork></figure>
</section>
</section>

<section anchor="emailget" title="Email/get">
<t>Standard &quot;/get&quot; method, with the following additional arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">bodyProperties</spanx>: <spanx style="verb">String[]</spanx>
A list of properties to fetch for each EmailBodyPart returned. If omitted, this defaults to:

<figure align="center"><artwork align="center">
[ "partId", "blobId", "size", "name", "type", "charset",
  "disposition", "cid", "language", "location" ]
</artwork></figure></t>
<t><spanx style="strong">fetchTextBodyValues</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">true</spanx>, the <spanx style="emph">bodyValues</spanx> property includes any <spanx style="verb">text/*</spanx> part in the <spanx style="verb">textBody</spanx> property.</t>
<t><spanx style="strong">fetchHTMLBodyValues</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">true</spanx>, the <spanx style="emph">bodyValues</spanx> property includes any <spanx style="verb">text/*</spanx> part in the <spanx style="verb">htmlBody</spanx> property.</t>
<t><spanx style="strong">fetchAllBodyValues</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">true</spanx>, the <spanx style="emph">bodyValues</spanx> property includes any <spanx style="verb">text/*</spanx> part in the <spanx style="verb">bodyStructure</spanx> property.</t>
<t><spanx style="strong">maxBodyValueBytes</spanx>: <spanx style="verb">PositiveInt</spanx> (default: 0)
If greater than zero, the <spanx style="emph">value</spanx> property of any EmailBodyValue object returned in <spanx style="emph">bodyValues</spanx> MUST be truncated if necessary so it does not exceed this number of octets in size. If <spanx style="verb">0</spanx> (the default), no truncation occurs.
The server MUST ensure the truncation results in valid UTF-8 and does not occur mid-codepoint. If the part is of type <spanx style="verb">text/html</spanx>, the server SHOULD NOT truncate inside an HTML tag e.g. in the middle of <spanx style="verb">&lt;a href="https://example.com"&gt;</spanx>. There is no requirement for the truncated form to be a balanced tree or valid HTML (indeed, the original source may well be neither of these things).</t>
</list>
</t>
<t>If the standard <spanx style="emph">properties</spanx> argument is omitted or <spanx style="verb">null</spanx>, the following default MUST be used instead of &quot;all&quot; properties:
</t>

<figure align="center"><artwork align="center">
[ "id", "blobId", "threadId", "mailboxIds", "keywords", "size",
"receivedAt", "messageId", "inReplyTo", "references", "sender", "from",
"to", "cc", "bcc", "replyTo", "subject", "sentAt", "hasAttachment",
"preview", "bodyValues", "textBody", "htmlBody", "attachments" ]
</artwork></figure>
<t>The following properties are expected to be fast to fetch in a quality implementation:
</t>
<t>
<list style="symbols">
<t>id</t>
<t>blobId</t>
<t>threadId</t>
<t>mailboxIds</t>
<t>keywords</t>
<t>size</t>
<t>receivedAt</t>
<t>messageId</t>
<t>inReplyTo</t>
<t>sender</t>
<t>from</t>
<t>to</t>
<t>cc</t>
<t>bcc</t>
<t>replyTo</t>
<t>subject</t>
<t>sentAt</t>
<t>hasAttachment</t>
<t>preview</t>
</list>
</t>
<t>Clients SHOULD take care when fetching any other properties, as there may be significantly longer latency in fetching and returning the data.
</t>
<t>As specified above, parsed forms of headers may only be used on appropriate header fields. Attempting to fetch a form that is forbidden (e.g. <spanx style="verb">header:From:asDate</spanx>) MUST result in the method call being rejected with an <spanx style="verb">invalidArguments</spanx> error.
</t>
<t>Where a specific header is requested as a property, the capitalization of the property name in the response MUST be identical to that used in the request.
</t>

<section anchor="example-2" title="Example">
<t>Request:
</t>

<figure align="center"><artwork align="center">
[ "Email/get", {
  "ids": [ "f123u456", "f123u457" ],
  "properties": [ "threadId", "mailboxIds", "from", "subject", "receivedAt", "header:List-POST:asURLs", "htmlBody", "bodyValues" ],
  "bodyProperties": [ "partId", "blobId", "size", "type" ],
  "fetchHTMLBodyValues": true,
  "maxBodyValueBytes": 256
}, "#1" ]
</artwork></figure>
<t>and response:
</t>

<figure align="center"><artwork align="center">
[ "Email/get", {
  "accountId": "abc",
  "state": "41234123231",
  "list": [
    {
      "id": "f123u457",
      "threadId": "ef1314a",
      "mailboxIds": { "f123": true },
      "from": [{name: "Joe Bloggs", email: "joe@example.com"}],
      "subject": "Dinner on Thursday?",
      "receivedAt": "2013-10-13T14:12:00Z",
      "header:List-POST:asURLs": [ "mailto:partytime@lists.example.com" ],
      "htmlBody": [{
        "partId": "1",
        "blobId": "841623871",
        "size": 283331,
        "type": "text/html"
      }, {
        "partId": "2",
        "blobId": "319437193",
        "size": 10343,
        "type": "text/plain"
      }],
      "bodyValues": {
        "1": {
          "isEncodingProblem": false,
          "isTruncated": true,
          "value": "&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello ..."
        },
        "2": {
          "isEncodingProblem": false,
          "isTruncated": false,
          "value": "-- \nSent by your friendly mailing list ..."
        }
      }
    }
  ],
  notFound: [ "f123u456" ]
}, "#1" ]
</artwork></figure>
</section>
</section>

<section anchor="emailchanges" title="Email/changes">
<t>Standard &quot;/changes&quot; method. If generating intermediate states for a large set of changes, it is recommended that newer changes are returned first, as these are generally of more interest to users.
</t>
</section>

<section anchor="emailquery" title="Email/query">
<t>Standard &quot;/query&quot; method, but with the following additional arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">collapseThreads</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">true</spanx>, emails in the same thread as a previous email in the list (given the filter and sort order) will be removed from the list. This means at most only one email will be included in the list for any given thread.</t>
</list>
</t>
<t>In quality implementations, the query &quot;total&quot; property is expected to be fast to calculate when the filter consists solely of a single <spanx style="verb">inMailbox</spanx> property, as it is the same as the totalEmails or totalThreads properties (depending on whether collapseThreads is true) of the associated Mailbox object.
</t>

<section anchor="filtering" title="Filtering">
<t>A <spanx style="strong">FilterCondition</spanx> object has the following properties, any of which may be omitted:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">inMailbox</spanx>: <spanx style="verb">String</spanx>
A mailbox id. An email must be in this mailbox to match the condition.</t>
<t><spanx style="strong">inMailboxOtherThan</spanx>: <spanx style="verb">String[]</spanx>
A list of mailbox ids. An email must be in at least one mailbox not in this list to match the condition. This is to allow messages solely in trash/spam to be easily excluded from a search.</t>
<t><spanx style="strong">before</spanx>: <spanx style="verb">UTCDate</spanx>
The <spanx style="emph">receivedAt</spanx> date of the email must be before this date to match the condition.</t>
<t><spanx style="strong">after</spanx>: <spanx style="verb">UTCDate</spanx>
The <spanx style="emph">receivedAt</spanx> date of the email must be on or after this date to match the condition.</t>
<t><spanx style="strong">minSize</spanx>: <spanx style="verb">PositiveInt</spanx>
The <spanx style="emph">size</spanx> of the email in octets must be equal to or greater than this number to match the condition.</t>
<t><spanx style="strong">maxSize</spanx>: <spanx style="verb">PositiveInt</spanx>
The size of the email in octets must be less than this number to match the condition.</t>
<t><spanx style="strong">allInThreadHaveKeyword</spanx>: <spanx style="verb">String</spanx>
All emails (including this one) in the same thread as this email must have the given keyword to match the condition.</t>
<t><spanx style="strong">someInThreadHaveKeyword</spanx>: <spanx style="verb">String</spanx>
At least one email (possibly this one) in the same thread as this email must have the given keyword to match the condition.</t>
<t><spanx style="strong">noneInThreadHaveKeyword</spanx>: <spanx style="verb">String</spanx>
All emails (including this one) in the same thread as this email must <spanx style="strong">not</spanx> have the given keyword to match the condition.</t>
<t><spanx style="strong">hasKeyword</spanx>: <spanx style="verb">String</spanx>
This email must have the given keyword to match the condition.</t>
<t><spanx style="strong">notKeyword</spanx>: <spanx style="verb">String</spanx>
This email must not have the given keyword to match the condition.</t>
<t><spanx style="strong">hasAttachment</spanx>: <spanx style="verb">Boolean</spanx>
The <spanx style="verb">hasAttachment</spanx> property of the email must be identical to the value given to match the condition.</t>
<t><spanx style="strong">text</spanx>: <spanx style="verb">String</spanx>
Looks for the text in emails. The server SHOULD look up text in the <spanx style="emph">from</spanx>, <spanx style="emph">to</spanx>, <spanx style="emph">cc</spanx>, <spanx style="emph">bcc</spanx>, <spanx style="emph">subject</spanx> header fields of the message, and inside any <spanx style="verb">text/*</spanx> or other body parts that may be converted to text by the server. The server MAY extend the search to any additional textual property.</t>
<t><spanx style="strong">from</spanx>: <spanx style="verb">String</spanx>
Looks for the text in the <spanx style="emph">From</spanx> header field of the message.</t>
<t><spanx style="strong">to</spanx>: <spanx style="verb">String</spanx>
Looks for the text in the <spanx style="emph">To</spanx> header field of the message.</t>
<t><spanx style="strong">cc</spanx>: <spanx style="verb">String</spanx>
Looks for the text in the <spanx style="emph">Cc</spanx> header field of the message.</t>
<t><spanx style="strong">bcc</spanx>: <spanx style="verb">String</spanx>
Looks for the text in the <spanx style="emph">Bcc</spanx> header field of the message.</t>
<t><spanx style="strong">subject</spanx>: <spanx style="verb">String</spanx>
Looks for the text in the <spanx style="emph">subject</spanx> property of the email.</t>
<t><spanx style="strong">body</spanx>: <spanx style="verb">String</spanx>
Looks for the text in one of the body parts of the email. The server MAY exclude MIME body parts with content media types other than &quot;text/<spanx style="emph">&quot; and &quot;message/</spanx>&quot; from consideration in search matching. Care should be taken to match based on the text content actually presented to an end-user by viewers for that media type, or otherwise identified as appropriate for search indexing. Matching document metadata uninteresting to an end-user (e.g., markup tag and attribute names), is undesirable.</t>
<t><spanx style="strong">header</spanx>: <spanx style="verb">String[]</spanx>
The array MUST contain either one or two elements. The first element is the name of the header field to match against. The second (optional) element is the text to look for in the header field value. If not supplied, the message matches simply if it <spanx style="emph">has</spanx> a header field of the given name.</t>
</list>
</t>
<t>If zero properties are specified on the FilterCondition, the condition MUST always evaluate to <spanx style="verb">true</spanx>. If multiple properties are specified, ALL must apply for the condition to be <spanx style="verb">true</spanx> (it is equivalent to splitting the object into one-property conditions and making them all the child of an AND filter operator).
</t>
<t>The exact semantics for matching <spanx style="verb">String</spanx> fields is <spanx style="strong">deliberately not defined</spanx> to allow for flexibility in indexing implementation, subject to the following:
</t>
<t>
<list style="symbols">
<t>Any syntactically correct <xref target="RFC2047"/> encoded sections of header fields with a known encoding SHOULD be decoded before attempting to match text.</t>
<t>When searching inside a <spanx style="verb">text/html</spanx> body part, any text considered markup rather than content SHOULD be ignored, including HTML tags and most attributes, anything inside the <spanx style="verb">&lt;head&gt;</spanx> tag, CSS and JavaScript. Attribute content intended for presentation to the user such as &quot;alt&quot; and &quot;title&quot; SHOULD be considered in the search.</t>
<t>Text SHOULD be matched in a case-insensitive manner.</t>
<t>Text contained in either (but matched) single or double quotes SHOULD be treated as a <spanx style="strong">phrase search</spanx>, that is a match is required for that exact word or sequence of words, excluding the surrounding quotation marks. Use <spanx style="verb">\"</spanx>, <spanx style="verb">\'</spanx> and <spanx style="verb">\\</spanx> to match a literal <spanx style="verb">"</spanx>, <spanx style="verb">'</spanx> and <spanx style="verb">\</spanx> respectively in a phrase.</t>
<t>Outside of a phrase, white-space SHOULD be treated as dividing separate tokens that may be searched for separately, but MUST all be present for the email to match the filter.</t>
<t>Tokens MAY be matched on a whole-word basis using stemming (so for example a text search for <spanx style="verb">bus</spanx> would match &quot;buses&quot; but not &quot;business&quot;).</t>
</list>
</t>
</section>

<section anchor="sorting" title="Sorting">
<t>The following properties MUST be supported for sorting:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">receivedAt</spanx> - The <spanx style="emph">receivedAt</spanx> date as returned in the Email object.</t>
</list>
</t>
<t>The following properties SHOULD be supported for sorting:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">size</spanx> - The size as returned in the Email object.</t>
<t><spanx style="strong">from</spanx> – This is taken to be either the &quot;name&quot; part, or if <spanx style="verb">null</spanx>/empty then the &quot;email&quot; part, of the <spanx style="strong">first</spanx> EmailAddress object in the <spanx style="emph">from</spanx> property. If still none, consider the value to be the empty string.</t>
<t><spanx style="strong">to</spanx> - This is taken to be either the &quot;name&quot; part, or if <spanx style="verb">null</spanx>/empty then the &quot;email&quot; part, of the <spanx style="strong">first</spanx> EmailAddress object in the <spanx style="emph">to</spanx> property. If still none, consider the value to be the empty string.</t>
<t><spanx style="strong">subject</spanx> - This is taken to be the base subject of the email, as defined in section 2.1 of <xref target="RFC5256"/>.</t>
<t><spanx style="strong">sentAt</spanx> - The <spanx style="emph">sentAt</spanx> property on the Email object.</t>
<t><spanx style="strong">hasKeyword</spanx> - This value MUST be considered <spanx style="verb">true</spanx> if the email has the keyword given as an additional <spanx style="emph">keyword</spanx> property on the <spanx style="emph">Comparator</spanx> object, or <spanx style="verb">false</spanx> otherwise.</t>
<t><spanx style="strong">allInThreadHaveKeyword</spanx> - This value MUST be considered <spanx style="verb">true</spanx> for the email if <spanx style="strong">all</spanx> of the emails in the same thread (regardless of mailbox) have the keyword given as an additional <spanx style="emph">keyword</spanx> property on the <spanx style="emph">Comparator</spanx> object.</t>
<t><spanx style="strong">someInThreadHaveKeyword</spanx> - This value MUST be considered <spanx style="verb">true</spanx> for the email if <spanx style="strong">any</spanx> of the emails in the same thread (regardless of mailbox) have the keyword given as an additional <spanx style="emph">keyword</spanx> property on the <spanx style="emph">Comparator</spanx> object.</t>
</list>
</t>
<t>The server MAY support sorting based on other properties as well. A client can discover which properties are supported by inspecting the server's <spanx style="emph">capabilities</spanx> object (see section 1).
</t>
<t>Example sort:
</t>

<figure align="center"><artwork align="center">
[{
  "property": "someInThreadHaveKeyword",
  "keyword": "$flagged",
  "isAscending": false,
}, {
  "property": "subject",
  "collation": "i;ascii-casemap"
}, {
  "property": "receivedAt",
  "isAscending": false,
}]
</artwork></figure>
<t>This would sort emails in flagged threads first (the thread is considered flagged if any email within it is flagged), and then in subject order, then newest first for messages with the same subject. If two emails have both identical flagged status, subject and date, the order is server-dependent but must be stable.
</t>
</section>

<section anchor="thread-collapsing" title="Thread collapsing">
<t>When <spanx style="emph">collapseThreads</spanx> is <spanx style="verb">true</spanx>, then after filtering and sorting the email list, the list is further winnowed by removing any emails for a thread id that has already been seen (when passing through the list sequentially). A thread will therefore only appear <spanx style="strong">once</spanx> in the result, at the position of the first email in the list that belongs to the thread (given the current sort/filter).
</t>
</section>

<section anchor="response" title="Response">
<t>The response has the following additional argument:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">collapseThreads</spanx>: <spanx style="verb">Boolean</spanx>
The <spanx style="emph">collapseThreads</spanx> value that was used when calculating the email list
for this call.</t>
</list>
</t>
</section>
</section>

<section anchor="emailquerychanges" title="Email/queryChanges">
<t>Standard &quot;/queryChanges&quot; method, with the following additional arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">collapseThreads</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
The <spanx style="emph">collapseThreads</spanx> argument that was used with <spanx style="emph">Email/query</spanx>.</t>
</list>
</t>
<t>The response has the following additional argument:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">collapseThreads</spanx>: <spanx style="verb">Boolean</spanx>
The <spanx style="emph">collapseThreads</spanx> value that was used when calculating the email list
for this call.</t>
</list>
</t>
</section>

<section anchor="emailset" title="Email/set">
<t>Standard &quot;/set&quot; method. The <spanx style="emph">Email/set</spanx> method encompasses:
</t>
<t>
<list style="symbols">
<t>Creating a draft</t>
<t>Changing the keywords of an email (e.g. unread/flagged status)</t>
<t>Adding/removing an email to/from mailboxes (moving a message)</t>
<t>Deleting emails</t>
</list>
</t>
<t>The format of the keywords/mailboxIds properties means that when updating an email you can either replace the entire set of keywords/mailboxes (by setting the full value of the property) or add/remove individual ones using the JMAP patch syntax (see RFC XXXX, section 5.3 for the specification and section 5.7 for an example).
</t>
<t>Due to the format of the Email object, when creating an email there are a number of ways to specify the same information. To ensure that the RFC5322 email to create is unambiguous, the following constraints apply to Email objects submitted for creation:
</t>
<t>
<list style="symbols">
<t>The <spanx style="emph">headers</spanx> property MUST NOT be given, on either the top-level email or an
EmailBodyPart – the client must set each header field as an individual
property.</t>
<t>There MUST NOT be two properties that represent the same header field
(e.g. <spanx style="verb">header:from</spanx> and <spanx style="verb">from</spanx>) within the Email or particular EmailBodyPart.</t>
<t>Header fields MUST NOT be specified in parsed forms that are forbidden for
that particular field.</t>
<t>Header fields beginning <spanx style="verb">Content-</spanx> MUST NOT be specified on the Email object,
only on EmailBodyPart objects.</t>
<t>If a bodyStructure property is given, there MUST NOT be textBody, htmlBody or
attachments properties.</t>
<t>If given, the bodyStructure EmailBodyPart MUST NOT contain a property
representing a header field that is already defined on the top-level Email
object.</t>
<t>If given, textBody MUST contain exactly one body part, of type <spanx style="verb">text/plain</spanx>.</t>
<t>If given, htmlBody MUST contain exactly one body part, of type <spanx style="verb">text/html</spanx>.</t>
<t>Within an EmailBodyPart:
<list style="symbols">
<t>The client may specify a partId OR a blobId but not both. If a partId is
given, this partId MUST be present in the bodyValues property.</t>
<t>The charset property MUST be omitted if a partId is given (the part's
content is included in bodyValues and the server may choose any appropriate
encoding).</t>
<t>The size property MUST be omitted if a partId is given. If a blobId is
given, it may be included but is ignored by the server (the size is
actually calculated from the blob content itself).</t>
<t>A <spanx style="verb">Content-Transfer-Encoding</spanx> header field MUST NOT be given.</t>
</list></t>
<t>Within an EmailBodyValue object, isEncodingProblem and isTruncated MUST be
either <spanx style="verb">false</spanx> or omitted.</t>
</list>
</t>
<t>Creation attempts that violate any of this SHOULD be rejected with an <spanx style="verb">invalidProperties</spanx> error, however a server MAY choose to modify the Email (e.g. choose between conflicting headers, use a different content-encoding etc.) to comply with its requirements instead.
</t>
<t>The server MAY also choose to set additional headers. If not included, the server MUST generate and set a <spanx style="verb">Message-ID</spanx> header field in conformance with <xref target="RFC5322"/> section 3.6.4, and a <spanx style="verb">Date</spanx> header field in conformance with section 3.6.1.
</t>
<t>The final RFC5322 email generated may be invalid. For example, if it is a half-finished draft, the &quot;To&quot; field may data that does not currently conform to the required syntax for this header field. The message will be checked for strict conformance when submitted for sending (see the EmailSubmission object description).
</t>
<t>Destroying an email removes it from all mailboxes to which it belonged. To  just delete an email to trash, simply change the <spanx style="verb">mailboxIds</spanx> property so it is now in the mailbox with <spanx style="verb">role == "trash"</spanx>, and remove all other mailbox ids.
</t>
<t>When emptying the trash, clients SHOULD NOT destroy emails which are also in a mailbox other than trash. For those emails, they SHOULD just remove the Trash mailbox from the email.
</t>
<t>For successfully created Email objects, the <spanx style="emph">created</spanx> response contains the <spanx style="emph">id</spanx>, <spanx style="emph">blobId</spanx>, <spanx style="emph">threadId</spanx> and <spanx style="emph">size</spanx> properties of the object.
</t>
<t>The following extra <spanx style="emph">SetError</spanx> types are defined:
</t>
<t>For <spanx style="strong">create</spanx>:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">blobNotFound</spanx>: At least one blob id given for an EmailBodyPart doesn't
exist. An extra <spanx style="emph">notFound</spanx> property of type <spanx style="verb">String[]</spanx> MUST be included in the error object containing every <spanx style="emph">blobId</spanx> referenced by an EmailBodyPart that could not be found on the server.</t>
</list>
</t>
<t>For <spanx style="strong">create</spanx> and <spanx style="strong">update</spanx>:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">tooManyKeywords</spanx>: The change to the email's keywords would exceed a
server-defined maximum.</t>
<t><spanx style="verb">tooManyMailboxes</spanx>: The change to the email's mailboxes would exceed a
server-defined maximum.</t>
</list>
</t>
</section>

<section anchor="emailcopy" title="Email/copy">
<t>Standard &quot;/copy&quot; method, except only the <spanx style="emph">mailboxIds</spanx>, <spanx style="emph">keywords</spanx> and <spanx style="emph">receivedAt</spanx> properties may be set during the copy. This method cannot modify the RFC5322 representation of an email.
</t>
<t>The server MAY forbid two email objects with the same exact <xref target="RFC5322"/> content, or even just with the same <xref target="RFC5322"/> Message-ID, to coexist within an account; if the target account already has the email the copy will be rejected with a standard <spanx style="verb">alreadyExists</spanx> error.
</t>
<t>For successfully copied Email objects, the <spanx style="emph">created</spanx> response contains the <spanx style="emph">id</spanx>, <spanx style="emph">blobId</spanx>, <spanx style="emph">threadId</spanx> and <spanx style="emph">size</spanx> properties of the new object.
</t>
</section>

<section anchor="emailimport" title="Email/import">
<t>The <spanx style="emph">Email/import</spanx> method adds <xref target="RFC5322"/> messages to a user's set of emails. The messages must first be uploaded as a file using the standard upload mechanism. It takes the following arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">accountId</spanx>: <spanx style="verb">String</spanx>
The id of the account to use.</t>
<t><spanx style="strong">ifInState</spanx>: <spanx style="verb">String|null</spanx>
This is a state string as returned by the <spanx style="emph">Email/get</spanx> method. If supplied, the string must match the current state of the account referenced by the accountId, otherwise the method will be aborted and a <spanx style="verb">stateMismatch</spanx> error returned. If <spanx style="verb">null</spanx>, any changes will be applied to the current state.</t>
<t><spanx style="strong">emails</spanx>: <spanx style="verb">String[EmailImport]</spanx>
A map of creation id (client specified) to EmailImport objects</t>
</list>
</t>
<t>An <spanx style="strong">EmailImport</spanx> object has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">blobId</spanx>: <spanx style="verb">String</spanx>
The id of the blob containing the raw <xref target="RFC5322"/> message.</t>
<t><spanx style="strong">mailboxIds</spanx>: <spanx style="verb">String[Boolean]</spanx>
The ids of the mailboxes to assign this email to. At least one mailbox MUST be given.</t>
<t><spanx style="strong">keywords</spanx>: <spanx style="verb">String[Boolean]</spanx> (default: )
The keywords to apply to the email.</t>
<t><spanx style="strong">receivedAt</spanx>: <spanx style="verb">UTCDate</spanx> (default: time of import on server)
The <spanx style="emph">receivedAt</spanx> date to set on the email.</t>
</list>
</t>
<t>Each email to import is considered an atomic unit which may succeed or fail individually. Importing successfully creates a new email object from the data referenced by the blobId and applies the given mailboxes, keywords and receivedAt date.
</t>
<t>The server MAY forbid two email objects with the same exact <xref target="RFC5322"/> content, or even just with the same <xref target="RFC5322"/> Message-ID, to coexist within an account. In this case, it MUST reject attempts to import an email considered a duplicate with an <spanx style="verb">alreadyExists</spanx> SetError. An <spanx style="emph">existingId</spanx> property of type <spanx style="verb">String</spanx> MUST be included on the error object with the id of the existing email. If duplicates are allowed, the newly created Email object MUST have a separate id and independent mutable properties to the existing object.
</t>
<t>If the <spanx style="emph">blobId</spanx>, <spanx style="emph">mailboxIds</spanx>, or <spanx style="emph">keywords</spanx> properties are invalid (e.g. missing, wrong type, id not found), the server MUST reject the import with an <spanx style="verb">invalidProperties</spanx> SetError.
</t>
<t>If the email cannot be imported because it would take the account over quota, the import should be rejected with an <spanx style="verb">overQuota</spanx> SetError.
</t>
<t>If the blob referenced is not a valid <xref target="RFC5322"/> message, the server MAY modify the message to fix errors (such as removing NUL octets or fixing invalid headers). If it does this, the <spanx style="emph">blobId</spanx> on the response MUST represent the new representation and therefore be different to the <spanx style="emph">blobId</spanx> on the EmailImport object. Alternatively, the server MAY reject the import with an <spanx style="verb">invalidEmail</spanx> SetError.
</t>
<t>The response has the following arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">accountId</spanx>: <spanx style="verb">String</spanx>
The id of the account used for this call.</t>
<t><spanx style="strong">oldState</spanx>: <spanx style="verb">String|null</spanx>
The state string that would have been returned by <spanx style="emph">Email/get</spanx> on this account before making the requested changes, or <spanx style="verb">null</spanx> if the server doesn't know what the previous state string was.</t>
<t><spanx style="strong">newState</spanx>: <spanx style="verb">String</spanx>
The state string that will now be returned by <spanx style="emph">Email/get</spanx> on this account.</t>
<t><spanx style="strong">created</spanx>: <spanx style="verb">String[Email]</spanx>
A map of the creation id to an object containing the <spanx style="emph">id</spanx>, <spanx style="emph">blobId</spanx>, <spanx style="emph">threadId</spanx> and <spanx style="emph">size</spanx> properties for each successfully imported Email.</t>
<t><spanx style="strong">notCreated</spanx>: <spanx style="verb">String[SetError]</spanx>
A map of creation id to a SetError object for each Email that failed to be created. The possible errors are defined above.</t>
</list>
</t>
<t>The following additional errors may be returned instead of the <spanx style="emph">Foo/copy</spanx> response:
</t>
<t><spanx style="verb">stateMismatch</spanx>: An <spanx style="verb">ifInState</spanx> argument was supplied and it does not match the current state
</t>
</section>

<section anchor="emailparse" title="Email/parse">
<t>This method allows you to parse blobs as <xref target="RFC5322"/> messages to get Email objects. This can be used to parse and display attached emails without having to import them as top-level email objects in the mail store in their own right.
</t>
<t>The following metadata properties on the Email objects will be <spanx style="verb">null</spanx> if requested:
</t>
<t>
<list style="symbols">
<t>id</t>
<t>mailboxIds</t>
<t>keywords</t>
<t>receivedAt</t>
</list>
</t>
<t>The <spanx style="emph">threadId</spanx> property of the Email MAY be present if the server can calculate which thread the Email would be assigned to were it to be imported. Otherwise, this too is <spanx style="verb">null</spanx> if fetched.
</t>
<t>The <spanx style="emph">Email/parse</spanx> method takes the following arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">accountId</spanx>: <spanx style="verb">String</spanx>
The id of the account to use.</t>
<t><spanx style="strong">blobIds</spanx>: <spanx style="verb">String[]</spanx>
The ids of the blobs to parse.</t>
<t><spanx style="strong">properties</spanx>: <spanx style="verb">String[]</spanx>
If supplied, only the properties listed in the array are returned for each Email object. If omitted, defaults to:
[ &quot;messageId&quot;, &quot;inReplyTo&quot;, &quot;references&quot;, &quot;sender&quot;, &quot;from&quot;, &quot;to&quot;, &quot;cc&quot;, &quot;bcc&quot;, &quot;replyTo&quot;, &quot;subject&quot;, &quot;sentAt&quot;, &quot;hasAttachment&quot;, &quot;preview&quot;, &quot;bodyValues&quot;, &quot;textBody&quot;, &quot;htmlBody&quot;, &quot;attachments&quot; ]</t>
<t><spanx style="strong">bodyProperties</spanx>: <spanx style="verb">String[]</spanx>
A list of properties to fetch for each EmailBodyPart returned. If omitted, defaults to the same value as the Email/get &quot;bodyProperties&quot; default argument.</t>
<t><spanx style="strong">fetchTextBodyValues</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">true</spanx>, the <spanx style="emph">bodyValues</spanx> property includes any <spanx style="verb">text/*</spanx> part in the <spanx style="verb">textBody</spanx> property.</t>
<t><spanx style="strong">fetchHTMLBodyValues</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">true</spanx>, the <spanx style="emph">bodyValues</spanx> property includes any <spanx style="verb">text/*</spanx> part in the <spanx style="verb">htmlBody</spanx> property.</t>
<t><spanx style="strong">fetchAllBodyValues</spanx>: <spanx style="verb">Boolean</spanx> (default: false)
If <spanx style="verb">true</spanx>, the <spanx style="emph">bodyValues</spanx> property includes any <spanx style="verb">text/*</spanx> part in the <spanx style="verb">bodyStructure</spanx> property.</t>
<t><spanx style="strong">maxBodyValueBytes</spanx>: <spanx style="verb">PositiveInt</spanx> (default: 0)
If greater than zero, the <spanx style="emph">value</spanx> property of any EmailBodyValue object returned in <spanx style="emph">bodyValues</spanx> MUST be truncated if necessary so it does not exceed this number of octets in size. If <spanx style="verb">0</spanx> (the default), no truncation occurs.
The server MUST ensure the truncation results in valid UTF-8 and does not occur mid-codepoint. If the part is of type <spanx style="verb">text/html</spanx>, the server SHOULD NOT truncate inside an HTML tag e.g. in the middle of <spanx style="verb">&lt;a href="https://example.com"&gt;</spanx>. There is no requirement for the truncated form to be a balanced tree or valid HTML (indeed, the original source may well be neither of these things).</t>
</list>
</t>
<t>The response has the following arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">accountId</spanx>: <spanx style="verb">String</spanx>
The id of the account used for the call.</t>
<t><spanx style="strong">parsed</spanx>: <spanx style="verb">String[Email]|null</spanx>
A map of blob id to parsed Email representation for each successfully parsed blob, or <spanx style="verb">null</spanx> if none.</t>
<t><spanx style="strong">notParsable</spanx>: <spanx style="verb">String[]|null</spanx>
A list of ids given that corresponded to blobs that could not be parsed as emails, or <spanx style="verb">null</spanx> if none.</t>
<t><spanx style="strong">notFound</spanx>: <spanx style="verb">String[]|null</spanx>
A list of blob ids given that could not be found, or <spanx style="verb">null</spanx> if none.</t>
</list>
</t>
<t>As specified above, parsed forms of headers may only be used on appropriate header fields. Attempting to fetch a form that is forbidden (e.g. <spanx style="verb">header:From:asDate</spanx>) MUST result in the method call being rejected with an <spanx style="verb">invalidArguments</spanx> error.
</t>
<t>Where a specific header is requested as a property, the capitalization of the property name in the response MUST be identical to that used in the request.
</t>
</section>

<section anchor="examples" title="Examples">
<t>A client logs in for the first time. It first fetches the set of mailboxes. Now it will display the inbox to the user, which we will presume has mailbox id &quot;fb666a55&quot;. The inbox may be (very!) large, but the user's screen is only so big, so the client will just load the start and then can load in more as necessary. The client sends this request:
</t>

<figure align="center"><artwork align="center">
[[ "Email/query",{
  "accountId": "ue150411c",
  "filter": {
    "inMailbox": "fb666a55"
  },
  "sort": [{
    "isAscending": false,
    "property": "receivedAt"
  }],
  "collapseThreads": true,
  "position": 0,
  "limit": 30,
  "calculateTotal": true
}, "0" ],
[ "Email/get", {
  "accountId": "ue150411c",
  "#ids": {
    "resultOf": "0",
    "name": "Email/query",
    "path": "/ids"
  },
  "properties": [
    "threadId"
  ]
}, "1" ],
[ "Thread/get", {
  "accountId": "ue150411c",
  "#ids": {
    "resultOf": "1",
    "name": "Email/get",
    "path": "/list/*/threadId"
  }
}, "2" ],
[ "Email/get", {
  "accountId": "ue150411c",
  "#ids": {
    "resultOf": "2",
    "name": "Thread/get",
    "path": "/list/*/emailIds"
  },
  "properties": [
    "threadId",
    "mailboxIds",
    "keywords",
    "hasAttachment",
    "from",
    "subject",
    "receivedAt",
    "size",
    "preview"
  ]
}, "3" ]]
</artwork></figure>
<t>Let's break down the 4 method calls to see what they're doing:
</t>
<t>
<list style="numbers">
<t>This asks the server for the ids of the first 30 Email objects in the inbox,
sorted newest first, ignoring messages from the same thread as a newer message in the mailbox (i.e. it is the first 30 unique threads).</t>
<t>Now we use a backreference to fetch the thread ids for each of these email
ids.</t>
<t>Another backreference fetches the Thread object for each of these thread ids.</t>
<t>Finally, we fetch the information we need to display the mailbox listing (
but no more!) for every message in each of these 30 threads. The client may aggregate this data for display, for example showing the thread as &quot;flagged&quot; if any of the messages in it contain the <spanx style="verb">$flagged</spanx> keyword.</t>
</list>
</t>
<t>The response from the server may look something like this:
</t>

<figure align="center"><artwork align="center">
[[ "Email/query", {
  "accountId": "ue150411c",
  "filter": {
    "inMailbox": "fb666a55"
  },
  "sort": [{
    "property": "receivedAt",
    "isAscending": false
  }],
  "collapseThreads": true,
  "queryState": "09aa9a075588-780599:0",
  "canCalculateChanges": true,
  "position": 0,
  "total": 115,
  "ids": [ "Ma783e5cdf5f2deffbc97930a", "M9bd17497e2a99cb345fc1d0a", ... ]
}, "0" ],
[ "Email/get", {
  "accountId": "ue150411c",
  "state": "780599",
  "list": [{
    "id": "Ma783e5cdf5f2deffbc97930a",
    "threadId": "T36703c2cfe9bd5ed"
  }, {
    "id": "M9bd17497e2a99cb345fc1d0a"
    "threadId": "T0a22ad76e9c097a1",
  }, ... ],
  "notFound": []
}, "1" ],
[ "Thread/get", {
  "accountId": "ue150411c",
  "state": "22a8728b",
  "list": [{
    "id": "T36703c2cfe9bd5ed"
    "emailIds": [ "Ma783e5cdf5f2deffbc97930a" ],
  }, {
    "id": "T0a22ad76e9c097a1"
    "emailIds": [ "M3b568670a63e5d100f518fa5", "M9bd17497e2a99cb345fc1d0a" ],
  },  ... ],
  "notFound": []
}, "2" ],
[ "Email/get", {
  "accountId": "ue150411c",
  "state": "780599",
  "list": [{
    "id": "Ma783e5cdf5f2deffbc97930a"
    "threadId": "T36703c2cfe9bd5ed",
    "mailboxIds": {
      "fb666a55": true
    },
    "keywords": {
      "$seen": true,
      "$flagged": true
    },
    "hasAttachment": true,
    "from": [{
      "email": "jdoe@example.com",
      "name": "Jane Doe"
    }],
    "subject": "The Big Reveal",
    "receivedAt": "2018-06-27T00:20:35Z",
    "size": 175047,
    "preview": "As you may be aware, we are required to prepare a presentation where we wow a panel of 5 random members of the public, on or before 30 June each year. We have drafted the …",
  },
  ...
  ],
  "notFound": []
}, "3" ]]
</artwork></figure>
<t>Now, on another device the user marks the first message as unread, sending this API request:
</t>

<figure align="center"><artwork align="center">
[[ "Email/set", {
  "accountId": "ue150411c",
  "update": {
    "Ma783e5cdf5f2deffbc97930a": {
      "keywords/$seen": null
    }
  }
}, "0" ]]
</artwork></figure>
<t>The server applies this and sends the success response:
</t>

<figure align="center"><artwork align="center">
[[ "Email/set", {
  "accountId": "ue150411c",
  "oldState": "780605"
  "newState": "780606",
  "updated": {
    "Ma783e5cdf5f2deffbc97930a": null
  },
  ...
}, "0" ]]
</artwork></figure>
<t>The user also deletes a few messages, and then a new message arrives.
</t>
<t>Back on our original machine, we receive a push update that the state string for Email is now <spanx style="verb">780800</spanx>. As this does not match the client's current state, it issues a request for the changes:
</t>

<figure align="center"><artwork align="center">
[[ "Email/changes", {
  "accountId": "ue150411c",
  "sinceState": "780605",
  "maxChanges": 50
}, "3" ],
[ "Email/queryChanges", {
  "accountId": "ue150411c",
  "filter": {
    "inMailbox": "fb666a55"
  },
  "sort": [{
    "property": "receivedAt",
    "isAscending": false
  }],
  "collapseThreads": true,
  "sinceQueryState": "09aa9a075588-780599:0",
  "upToId": "Mc2781d5e856a908d8a35a564",
  "maxChanges": 25,
  "calculateTotal": true
}, "11" ]]
</artwork></figure>
<t>The response:
</t>

<figure align="center"><artwork align="center">
[ "Email/changes", {
  "accountId": "ue150411c",
  "oldState": "780605",
  "newState": "780800",
  "hasMoreChanges": false,
  "created": [ "Me8de6c9f6de198239b982ea2" ],
  "updated": [ "Ma783e5cdf5f2deffbc97930a" ],
  "destroyed": [ "M9bd17497e2a99cb345fc1d0a", ... ],
}, "3" ],
[ "Email/queryChanges", {
  "accountId": "ue150411c",
  "oldQueryState": "09aa9a075588-780599:0"
  "newQueryState": "e35e9facf117-780615:0",
  "filter": {
    "inMailbox": "fb666a55"
  },
  "sort": [{
    "property": "receivedAt",
    "isAscending": false
  }],
  "collapseThreads": true,
  "upToId": "Mc2781d5e856a908d8a35a564",
  "added": [{
    "id": "Me8de6c9f6de198239b982ea2",
    "index": 0
  }],
  "removed": [ "M9bd17497e2a99cb345fc1d0a" ],
  "total": 115,
}, "11" ],
</artwork></figure>
<t>The client can update its local cache of the query results by removing &quot;M9bd17497e2a99cb345fc1d0a&quot; and then splicing in &quot;Me8de6c9f6de198239b982ea2&quot; at position 0. As it does not have the data for this new email, it will then fetch it (it also could have done this in the same request using backreferences).
</t>
<t>It knows something has changed about &quot;Ma783e5cdf5f2deffbc97930a&quot;, so it will refetch the mailboxes and keywords (the only mutable properties) for this email too.
</t>
<t>The user composes a new message and saves a draft. The client sends:
</t>

<figure align="center"><artwork align="center">
[[ "Email/set", {
  "accountId": "ue150411c",
  "create": {
    "k1546": {
      "mailboxIds": {
        "2ea1ca41b38e": true
      },
      "keywords": {
        "$seen": true,
        "$draft": true
      },
      "from": [{
        "name": "Joe Bloggs",
        "email": "joe@example.com"
      }],
      "to": [{
        "name": "John",
        "email": "john@example.com"
      }],
      "subject": "World domination",
      "receivedAt": "2018-07-10T01:05:08Z",
      "sentAt": "2018-07-10T11:05:08+10:00",
      "bodyStructure": {
        "type": "multipart/alternative",
        "subParts": [{
          "partId": "49db",
          "type": "text/html"
        }, {
          "partId": "bd48",
          "type": "text/plain"
        }]
      },
      "bodyValues": {
        "bd48": {
          "value": "I have the most brilliant plan. Let me tell you all about it. What we do is, we",
          "isTruncated": false
        },
        "49db": {
          "value": "&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;style type=\"text/css\"&gt;div{font-size:16px}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;I have the most brilliant plan. Let me tell you all about it. What we do is, we&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;",
          "isTruncated": false
        }
      }
    }
  }
}, "0" ]]
</artwork></figure>
<t>The server creates the message and sends the success response:
</t>

<figure align="center"><artwork align="center">
[[ "Email/set", {
  "accountId": "ue150411c",
  "oldState": "780823",
  "newState": "780839",
  "created": {
    "k1546": {
      "id": "Md45b47b4877521042cec0938",
      "blobId": "Ge8de6c9f6de198239b982ea214e0f3a704e4af74",
      "threadId": "Td957e72e89f516dc",
      "size": 11721
    }
  },
  ...
}, "0" ]]
</artwork></figure>
<t>The client moves this draft to a different account. The only way to do this is via the <spanx style="verb">/copy</spanx> method. It MUST set a new mailboxIds property, since the current value will not be valid mailbox ids in the destination account:
</t>

<figure align="center"><artwork align="center">
[[ "Email/copy", {
  "fromAccountId": "ue150411c",
  "accountId": "6c6c41ac",
  "create": {
    "k45": {
      "id": "Md45b47b4877521042cec0938",
      "mailboxIds": {
        "75a4c956": true
      }
    }
  },
  "onSuccessDestroyOriginal": true
}, "0" ]]
</artwork></figure>
<t>The server successfully copies the email and deletes the original. Due to the implicit call to &quot;Email/set&quot;, there are two responses to the single method call, both with the same client id:
</t>

<figure align="center"><artwork align="center">
[[ "Email/copy", {
  "fromAccountId": "ue150411c",
  "accountId": "6c6c41ac",
  "oldState": "7ee7e9263a6d",
  "newState": "5a0d2447ed26",
  "created": {
    "k45": {
      "id": "M138f9954a5cd2423daeafa55",
      "blobId": "G6b9fb047cba722c48c611e79233d057c6b0b74e8",
      "threadId": "T2f242ea424a4079a",
      "size": 11721
    }
  },
  "notCreated": null
}, "0" ],
[ "Email/set", {
  "accountId": "ue150411c",
  "oldState": "780839"
  "newState": "780871",
  "destroyed": [ "Ma783e5cdf5f2deffbc97930a" ],
  ...
}, "0" ]]
</artwork></figure>
</section>
</section>

<section anchor="search-snippets" title="Search snippets">
<t>When doing a search on a <spanx style="verb">String</spanx> property, the client may wish to show the relevant section of the body that matches the search as a preview instead of the beginning of the message, and to highlight any matching terms in both this and the subject of the email. Search snippets represent this data.
</t>
<t>A <spanx style="strong">SearchSnippet</spanx> object has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">emailId</spanx>: <spanx style="verb">String</spanx>
The email id the snippet applies to.</t>
<t><spanx style="strong">subject</spanx>: <spanx style="verb">String|null</spanx>
If text from the filter matches the subject, this is the subject of the email HTML-escaped, with matching words/phrases wrapped in <spanx style="verb">&lt;mark&gt;&lt;/mark&gt;</spanx> tags. If it does not match, this is <spanx style="verb">null</spanx>.</t>
<t><spanx style="strong">preview</spanx>: <spanx style="verb">String|null</spanx>
If text from the filter matches the plain-text or HTML body, this is the relevant section of the body (converted to plain text if originally HTML), HTML-escaped, with matching words/phrases wrapped in <spanx style="verb">&lt;mark&gt;&lt;/mark&gt;</spanx> tags. It MUST NOT be bigger than 255 octets in size. If it does not match, this is <spanx style="verb">null</spanx>.</t>
</list>
</t>
<t>It is server-defined what is a relevant section of the body for preview. If the server is unable to determine search snippets, it MUST return <spanx style="verb">null</spanx> for both the <spanx style="emph">subject</spanx> and <spanx style="emph">preview</spanx> roperties.
</t>
<t>Note, unlike most data types, a SearchSnippet DOES NOT have a property called <spanx style="verb">id</spanx>.
</t>
<t>The following JMAP method is supported:
</t>

<section anchor="searchsnippetget" title="SearchSnippet/get">
<t>To fetch search snippets, make a call to <spanx style="verb">SearchSnippet/get</spanx>. It takes the following arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">accountId</spanx>: <spanx style="verb">String</spanx>
The id of the account to use.</t>
<t><spanx style="strong">filter</spanx>: <spanx style="verb">FilterOperator|FilterCondition|null</spanx>
The same filter as passed to Email/query; see the description of this method for details.</t>
<t><spanx style="strong">emailIds</spanx>: <spanx style="verb">String[]</spanx>
The list of ids of emails to fetch the snippets for.</t>
</list>
</t>
<t>The response has the following arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">accountId</spanx>: <spanx style="verb">String</spanx>
The id of the account used for the call.</t>
<t><spanx style="strong">filter</spanx>: <spanx style="verb">FilterOperator|FilterCondition|null</spanx>
Echoed back from the call.</t>
<t><spanx style="strong">list</spanx>: <spanx style="verb">SearchSnippet[]</spanx>
An array of SearchSnippet objects for the requested email ids. This may not be in the same order as the ids that were in the request.</t>
<t><spanx style="strong">notFound</spanx>: <spanx style="verb">String[]|null</spanx>
An array of email ids requested which could not be found, or <spanx style="verb">null</spanx> if all
ids were found.</t>
</list>
</t>
<t>Since snippets are only based on immutable properties, there is no state string or update mechanism needed.
</t>
<t>The following standard errors may be returned instead of the <spanx style="emph">searchSnippets</spanx> response:
</t>
<t><spanx style="verb">requestTooLarge</spanx>: The number of <spanx style="emph">emailIds</spanx> requested by the client exceeds the maximum number the server is willing to process in a single method call.
</t>
<t><spanx style="verb">unsupportedFilter</spanx>: The server is unable to process the given <spanx style="emph">filter</spanx> for any reason.
</t>
</section>

<section anchor="example-3" title="Example">
<t>Here we did an Email/query to search for any email in the account containing the word &quot;foo&quot;, now we are fetching the search snippets for some of the ids that were returned in the results:
</t>

<figure align="center"><artwork align="center">
[[ "SearchSnippet/get", {
  "accountId": "ue150411c",
  "filter": {
    "text": "foo"
  },
  "emailIds": [
    "M44200ec123de277c0c1ce69c",
    "M7bcbcb0b58d7729686e83d99",
    "M28d12783a0969584b6deaac0",
    ...
  ]
}, "tag-0" ]
</artwork></figure>
<t>Example response:
</t>

<figure align="center"><artwork align="center">
[[ "SearchSnippet/get", {
  "accountId": "ue150411c",
  "filter": {
    "text": "foo"
  },
  "list": [{
      "emailId": "M44200ec123de277c0c1ce69c"
      "subject": null,
      "preview": null
  }, {
      "emailId": "M7bcbcb0b58d7729686e83d99",
      "subject": "The &lt;mark&gt;Foo&lt;/mark&gt;sball competition",
      "preview": "...year the &lt;mark&gt;foo&lt;/mark&gt;sball competition will be held in the Stadium de ..."
  }, {
      "emailId": "M28d12783a0969584b6deaac0",
      "subject": null,
      "preview": "...mail &lt;mark&gt;Foo&lt;/mark&gt;/changes results often return current-state-minus-1 rather than new..."
  },
  ...
  ],
  "notFound": null
}, "tag-0" ]]
</artwork></figure>
</section>
</section>

<section anchor="identities" title="Identities">
<t>An <spanx style="strong">Identity</spanx> object stores information about an email address (or domain) the user may send from. It has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">id</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
The id of the identity.</t>
<t><spanx style="strong">name</spanx>: <spanx style="verb">String</spanx> (default: &quot;&quot;)
The &quot;From&quot; <spanx style="emph">name</spanx> the client SHOULD use when creating a new message from this identity.</t>
<t><spanx style="strong">email</spanx>: <spanx style="verb">String</spanx> (immutable)
The &quot;From&quot; email address the client MUST use when creating a new message from this identity. The value MAY alternatively be of the form <spanx style="verb">*@example.com</spanx>, in which case the client may use any valid email address ending in <spanx style="verb">@example.com</spanx>.</t>
<t><spanx style="strong">replyTo</spanx>: <spanx style="verb">EmailAddress[]|null</spanx> (default: null)
The Reply-To value the client SHOULD set when creating a new message from this identity.</t>
<t><spanx style="strong">bcc</spanx>: <spanx style="verb">EmailAddress[]|null</spanx> (default: null)
The Bcc value the client SHOULD set when creating a new message from this identity.</t>
<t><spanx style="strong">textSignature</spanx>: <spanx style="verb">String</spanx> (default: &quot;&quot;)
Signature the client SHOULD insert into new plain-text messages that will be sent from this identity. Clients MAY ignore this and/or combine this with a client-specific signature preference.</t>
<t><spanx style="strong">htmlSignature</spanx>: <spanx style="verb">String</spanx> (default: &quot;&quot;)
Signature the client SHOULD insert into new HTML messages that will be sent from this identity. This text MUST be an HTML snippet to be inserted into the <spanx style="verb">&lt;body&gt;&lt;/body&gt;</spanx> section of the new email. Clients MAY ignore this and/or combine this with a client-specific signature preference.</t>
<t><spanx style="strong">mayDelete</spanx>: <spanx style="verb">Boolean</spanx> (server-set)
Is the user allowed to delete this identity? Servers may wish to set this to <spanx style="verb">false</spanx> for the user's username or other default address. Attempts to destroy an identity with <spanx style="verb">mayDelete: false</spanx> will be rejected with a standard <spanx style="verb">forbidden</spanx> SetError.</t>
</list>
</t>
<t>See the &quot;Addresses&quot; header form description in the Email object for the definition of <spanx style="emph">EmailAddress</spanx>.
</t>
<t>Multiple identities with the same email address MAY exist, to allow for different settings the user wants to pick between (for example with different names/signatures).
</t>
<t>The following JMAP methods are supported:
</t>

<section anchor="identityget" title="Identity/get">
<t>Standard &quot;/get&quot; method. The <spanx style="emph">ids</spanx> argument may be <spanx style="verb">null</spanx> to fetch all at once.
</t>
</section>

<section anchor="identitychanges" title="Identity/changes">
<t>Standard &quot;/changes&quot; method.
</t>
</section>

<section anchor="identityset" title="Identity/set">
<t>Standard &quot;/set&quot; method. The following extra <spanx style="emph">SetError</spanx> types are defined:
</t>
<t>For <spanx style="strong">create</spanx>:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">forbiddenFrom</spanx>: The user is not allowed to send from the address given as
the <spanx style="emph">email</spanx> property of the identity.</t>
</list>
</t>
</section>

<section anchor="example-4" title="Example">
<t>Request:
</t>

<figure align="center"><artwork align="center">
[ "Identity/get", {
  "accountId": "acme",
}, "0" ]
</artwork></figure>
<t>with response:
</t>

<figure align="center"><artwork align="center">
[ "Identity/get", {
  "accountId": "acme",
  "state": "99401312ae-11-333",
  "list": [
    {
      "id": "3301-222-11_22AAz",
      "name": "Joe Bloggs",
      "email": "joe@example.com",
      "replyTo": null,
      "bcc": [{
        "name": null,
        "email": "joe+archive@example.com"
      }],
      "textSignature": "-- \nJoe Bloggs\nMaster of Email",
      "htmlSignature": "&lt;div&gt;&lt;b&gt;Joe Bloggs&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Master of Email&lt;/div&gt;",
      "mayDelete": false,
    },
    {
      "id": "9911312-11_22AAz",
      "name": "Joe B",
      "email": "joebloggs@example.com",
      "replyTo": null,
      "bcc": null,
      "textSignature": "",
      "htmlSignature": "",
      "mayDelete": true
    }
  ],
  "notFound": []
}, "0" ]
</artwork></figure>
</section>
</section>

<section anchor="email-submission" title="Email submission">
<t>An <spanx style="strong">EmailSubmission</spanx> object represents the submission of an email for delivery to one or more recipients. It has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">id</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
The id of the email submission.</t>
<t><spanx style="strong">identityId</spanx>: <spanx style="verb">String</spanx> (immutable)
The id of the identity to associate with this submission.</t>
<t><spanx style="strong">emailId</spanx>: <spanx style="verb">String</spanx> (immutable)
The id of the email to send. The email being sent does not have to be a draft, for example when &quot;redirecting&quot; an existing email to a different address.</t>
<t><spanx style="strong">threadId</spanx>: <spanx style="verb">String</spanx> (immutable; server-set)
The thread id of the email to send. This is set by the server to the <spanx style="emph">threadId</spanx> property of the email referenced by the <spanx style="emph">emailId</spanx>.</t>
<t><spanx style="strong">envelope</spanx>: <spanx style="verb">Envelope|null</spanx> (immutable; default: null)
Information for use when sending via SMTP.
An <spanx style="strong">Envelope</spanx> object has the following properties:
<list style="symbols">
<t><spanx style="strong">mailFrom</spanx>: <spanx style="verb">Address</spanx>
The email address to use as the return address in the SMTP submission, plus any parameters to pass with the MAIL FROM address. The JMAP server MAY allow the address to be the empty string.
When a JMAP server performs an SMTP message submission, it MAY use the
same id string for the <xref target="RFC3461"/> ENVID parameter and the
EmailSubmission object id. Servers that do this MAY replace a
client-provided value for ENVID with a server-provided value.</t>
<t><spanx style="strong">rcptTo</spanx>: <spanx style="verb">Address[]</spanx>
The email addresses to send the message to, and any RCPT TO parameters to pass with the recipient.</t>
</list>
An <spanx style="strong">Address</spanx> object has the following properties:
<list style="symbols">
<t><spanx style="strong">email</spanx>: <spanx style="verb">String</spanx>
The email address being represented by the object. This as a &quot;Mailbox&quot; as used in the Reverse-path or Forward-path of the MAIL FROM or RCPT TO command in <xref target="RFC5321"/>.</t>
<t><spanx style="strong">parameters</spanx>: <spanx style="verb">Object|null</spanx>
Any parameters to send with the email (either mail-parameter or rcpt-parameter as appropriate, as specified in <xref target="RFC5321"/>). If supplied, each key in the object is a parameter name, and the value either the parameter value (type <spanx style="verb">String</spanx>) or if the parameter does not take a value then <spanx style="verb">null</spanx>. For both name and value, any xtext or unitext encodings are removed (<xref target="RFC3461"/>, <xref target="RFC6533"/>) and JSON string encoding applied.</t>
</list>
If the <spanx style="emph">envelope</spanx> property is <spanx style="verb">null</spanx> or omitted on creation, the server MUST generate this from the referenced email as follows:
<list style="symbols">
<t><spanx style="strong">mailFrom</spanx>: The email in the <spanx style="emph">Sender</spanx> header, if present, otherwise
the <spanx style="emph">From</spanx> header, if present, and no parameters.
If multiple addresses are present in one of these headers, or there is more than one <spanx style="emph">Sender</spanx>/<spanx style="emph">From</spanx> header, the server SHOULD reject the email as invalid but otherwise MUST take the first address in the last <spanx style="emph">Sender</spanx>/<spanx style="emph">From</spanx> header in the <xref target="RFC5322"/> version of the message.
If the address found from this is not allowed by the identity associated with this submission, the <spanx style="emph">email</spanx> property from the identity MUST be used instead.</t>
<t><spanx style="strong">rcptTo</spanx>: The deduplicated set of email addresses from the <spanx style="emph">To</spanx>, <spanx style="emph">Cc</spanx>
and <spanx style="emph">Bcc</spanx> headers, if present, with no parameters for any of them.</t>
</list></t>
<t><spanx style="strong">sendAt</spanx>: <spanx style="verb">UTCDate</spanx> (immutable; server-set)
The date the email was/will be released for delivery.
If the client successfully used <xref target="RFC4865"/> FUTURERELEASE with the email, this MUST be the time when the server will release the email; otherwise it MUST be the time the EmailSubmission was created.</t>
<t><spanx style="strong">undoStatus</spanx>: <spanx style="verb">String</spanx> (server-set)
This represents whether the submission may be canceled. This is server set and MUST be one of the following values:
<list style="symbols">
<t><spanx style="verb">pending</spanx>: It MAY be possible to cancel this submission.</t>
<t><spanx style="verb">final</spanx>: The email has been relayed to at least one recipient in a
manner that cannot be recalled. It is no longer possible to cancel this
submission.</t>
<t><spanx style="verb">canceled</spanx>: The email submission was canceled and will not be delivered
to any recipient.</t>
</list>
On systems that do not support unsending, the value of this property will always be <spanx style="verb">final</spanx>. On systems that do support canceling submission, it will start as <spanx style="verb">pending</spanx>, and MAY transition to <spanx style="verb">final</spanx> when the server knows it definitely cannot recall the email, but MAY just remain <spanx style="verb">pending</spanx>. If in pending state, a client can attempt to cancel the submission by setting this property to <spanx style="verb">canceled</spanx>; if the update succeeds, the submission was successfully canceled and the email has not been delivered to any of the original recipients.</t>
<t><spanx style="strong">deliveryStatus</spanx>: <spanx style="verb">String[DeliveryStatus]|null</spanx> (server-set)
This represents the delivery status for each of the email's recipients, if known. This property MAY not be supported by all servers, in which case it will remain <spanx style="verb">null</spanx>. Servers that support it SHOULD update the EmailSubmission object each time the status of any of the recipients changes, even if some recipients are still being retried.
This value is a map from the email address of each recipient to a <spanx style="emph">DeliveryStatus</spanx> object.
A <spanx style="strong">DeliveryStatus</spanx> object has the following properties:
<list style="symbols">
<t><spanx style="strong">smtpReply</spanx>: <spanx style="verb">String</spanx>
The SMTP reply string returned for this recipient when the server last tried to relay the email, or in a later DSN response for the email. This SHOULD be the response to the RCPT TO stage, unless this was accepted and the email as a whole rejected at the end of the DATA stage, in which case the DATA stage reply SHOULD be used instead.
Multi-line SMTP responses should be concatenated to a single string as follows:
<list style="symbols">
<t>The hyphen following the SMTP code on all but the last line is
replaced with a space.</t>
<t>Any prefix in common with the first line is stripped from lines after
the first.</t>
<t>CRLF is replaced by a space.</t>
</list>
For example:

<figure align="center"><artwork align="center">
550-5.7.1 Our system has detected that this message is
550 5.7.1 likely spam, sorry.
</artwork></figure>
would become:

<figure align="center"><artwork align="center">
550 5.7.1 Our system has detected that this message is likely spam, sorry.
</artwork></figure>
For emails relayed via an alternative to SMTP, the server MAY generate a synthetic string representing the status instead. If it does this, the string MUST be of the following form:
<list style="symbols">
<t>A 3-digit SMTP reply code, as defined in <xref target="RFC5321"/>, section 4.2.3.</t>
<t>Then a single space character.</t>
<t>Then an SMTP Enhanced Mail System Status Code as defined in
<xref target="RFC3463"/>, with a registry defined in <xref target="RFC5248"/>.</t>
<t>Then a single space character.</t>
<t>Then an implementation-specific information string with a human
readable explanation of the response.</t>
</list></t>
<t><spanx style="strong">delivered</spanx>: <spanx style="verb">String</spanx>
Represents whether the email has been successfully delivered to the recipient. This MUST be one of the following values:
<list style="symbols">
<t><spanx style="verb">queued</spanx>: The email is in a local mail queue and status will change
once it exits the local mail queues. The <spanx style="emph">smtpReply</spanx> property may still change.</t>
<t><spanx style="verb">yes</spanx>: The email was successfully delivered to the mailbox of the
recipient. The <spanx style="emph">smtpReply</spanx> property is final.</t>
<t><spanx style="verb">no</spanx>: Delivery to the recipient permanently failed. The <spanx style="emph">smtpReply</spanx>
property is final.</t>
<t><spanx style="verb">unknown</spanx>: The final delivery status is unknown, (e.g. it was relayed
to an external machine and no further information is available). The <spanx style="emph">smtpReply</spanx> property may still change if a DSN arrives.</t>
</list>
Note, successful relaying to an external SMTP server SHOULD NOT be taken as an indication that the email has successfully reached the final mailbox. In this case though, the server MAY receive a DSN response, if requested.
If a DSN is received for the recipient with Action equal to &quot;delivered&quot;, as per <xref target="RFC3464"/> section 2.3.3, then the <spanx style="emph">delivered</spanx> property SHOULD be set to <spanx style="verb">yes</spanx>; if the Action equals &quot;failed&quot;, the property SHOULD be set to <spanx style="verb">no</spanx>. Receipt of any other DSN SHOULD NOT affect this property.
The server MAY also set this property based on other feedback channels.</t>
<t><spanx style="strong">displayed</spanx>: <spanx style="verb">String</spanx>
Represents whether the email has been displayed to the recipient. This MUST be one of the following values:
<list style="symbols">
<t><spanx style="verb">unknown</spanx>: The display status is unknown. This is the initial value.</t>
<t><spanx style="verb">yes</spanx>: The recipient's system claims the email content has been
displayed to the recipient. Note, there is no guarantee that the recipient has noticed, read, or understood the content.</t>
</list>
If an MDN is received for this recipient with Disposition-Type (as per <xref target="RFC3798"/> section 3.2.6.2) equal to &quot;displayed&quot;, this property SHOULD be set to <spanx style="verb">yes</spanx>.
The server MAY also set this property based on other feedback channels.</t>
</list></t>
<t><spanx style="strong">dsnBlobIds</spanx>: <spanx style="verb">String[]</spanx> (server-set)
A list of blob ids for DSNs received for this submission, in order of receipt, oldest first.</t>
<t><spanx style="strong">mdnBlobIds</spanx>: <spanx style="verb">String[]</spanx> (server-set)
A list of blob ids for MDNs received for this submission, in order of receipt, oldest first.</t>
</list>
</t>
<t>JMAP servers MAY choose not to expose DSN and MDN responses as Email objects if they correlate to a EmailSubmission object. It SHOULD only do this if it exposes them in the <spanx style="emph">dsnBlobIds</spanx> and <spanx style="emph">mdnblobIds</spanx> fields instead, and expects the user to be using clients capable of fetching and displaying delivery status via the EmailSubmission object.
</t>
<t>For efficiency, a server MAY destroy EmailSubmission objects a certain amount of time after the email is successfully sent or it has finished retrying sending the email. For very basic SMTP proxies, this MAY be immediately after creation, as it has no way to assign a real id and return the information again if fetched later.
</t>
<t>The following JMAP methods are supported:
</t>

<section anchor="emailsubmissionget" title="EmailSubmission/get">
<t>Standard &quot;/get&quot; method.
</t>
</section>

<section anchor="emailsubmissionchanges" title="EmailSubmission/changes">
<t>Standard &quot;/changes&quot; method.
</t>
</section>

<section anchor="emailsubmissionquery" title="EmailSubmission/query">
<t>Standard &quot;/query&quot; method.
</t>
<t>A <spanx style="strong">FilterCondition</spanx> object has the following properties, any of which may be omitted:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">emailIds</spanx>: <spanx style="verb">String[]</spanx>
The EmailSubmission <spanx style="emph">emailId</spanx> property must be in this list to match the
condition.</t>
<t><spanx style="strong">threadIds</spanx>: <spanx style="verb">String[]</spanx>
The EmailSubmission <spanx style="emph">threadId</spanx> property must be in this list to match the
condition.</t>
<t><spanx style="strong">undoStatus</spanx>: <spanx style="verb">String</spanx>
The EmailSubmission <spanx style="emph">undoStatus</spanx> property must be identical to the value given to match the condition.</t>
<t><spanx style="strong">before</spanx>: <spanx style="verb">UTCDate</spanx>
The <spanx style="emph">sendAt</spanx> property of the EmailSubmission object must be before this date to match the condition.</t>
<t><spanx style="strong">after</spanx>: <spanx style="verb">UTCDate</spanx>
The <spanx style="emph">sendAt</spanx> property of the EmailSubmission object must be after this date to match the condition.</t>
</list>
</t>
<t>A EmailSubmission object matches the filter if and only if all of the given conditions given match. If zero properties are specified, it is automatically <spanx style="verb">true</spanx> for all objects.
</t>
<t>The following properties MUST be supported for sorting:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">emailId</spanx></t>
<t><spanx style="verb">threadId</spanx></t>
<t><spanx style="verb">sentAt</spanx></t>
</list>
</t>
</section>

<section anchor="emailsubmissionquerychanges" title="EmailSubmission/queryChanges">
<t>Standard &quot;/queryChanges&quot; method.
</t>
</section>

<section anchor="emailsubmissionset" title="EmailSubmission/set">
<t>Standard &quot;/set&quot; method, with the following two extra arguments:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">onSuccessUpdateEmail</spanx>: <spanx style="verb">String[Email]|null</spanx>
A map of <spanx style="emph">EmailSubmission id</spanx> to an object containing properties to update on the Email object referenced by the EmailSubmission if the create/update/destroy succeeds. (For references to EmailSubmission creations, this is equivalent to a back reference so the id will be the creation id prefixed with a <spanx style="verb">#</spanx>.)</t>
<t><spanx style="strong">onSuccessDestroyEmail</spanx>: <spanx style="verb">String[]|null</spanx>
A list of <spanx style="emph">EmailSubmission ids</spanx> for which the email with the corresponding emailId should be destroyed if the create/update/destroy succeeds. (For references to EmailSubmission creations, this is equivalent to a back reference so the id will be the creation id prefixed with a <spanx style="verb">#</spanx>.)</t>
</list>
</t>
<t>A single implicit <spanx style="emph">Email/set</spanx> call MUST be made after all EmailSubmission create/update/destroy requests have been processed to perform any changes requested in these two arguments. The response to this MUST be returned after the <spanx style="emph">EmailSubmission/set</spanx> response.
</t>
<t>An email is sent by creating a EmailSubmission object. When processing each create, the server must check that the email is valid, and the user has sufficient authorization to send it. If the creation succeeds, the email will be sent to the recipients given in the envelope <spanx style="emph">rcptTo</spanx> parameter. The server MUST remove any <spanx style="emph">Bcc</spanx> header present on the email during delivery. The server MAY add or remove other headers from the submitted email, or make further alterations in accordance with the server's policy during delivery.
</t>
<t>If the referenced email is destroyed at any point after the EmailSubmission object is created, this MUST NOT change the behaviour of the email submission (i.e. it does not cancel a future send).
</t>
<t>Similarly, destroying a EmailSubmission object MUST NOT affect the deliveries it represents. It purely removes the record of the email submission. The server MAY automatically destroy EmailSubmission objects after a certain time or in response to other triggers, and MAY forbid the client from manually destroying EmailSubmission objects.
</t>
<t>If the email to be sent is larger than the server supports sending, a standard <spanx style="verb">tooLarge</spanx> SetError MUST be returned. A <spanx style="emph">maxSize</spanx> <spanx style="verb">PositiveInt</spanx> property MUST be present on the SetError specifying the maximum size of an email that may be sent, in octets.
</t>
<t>If the email or identity id given cannot be found, the submission creation is rejected with a standard <spanx style="verb">invalidProperties</spanx> SetError.
</t>
<t>The following extra <spanx style="emph">SetError</spanx> types are defined:
</t>
<t>For <spanx style="strong">create</spanx>:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">invalidEmail</spanx> - The email to be sent is invalid in some way. The
SetError SHOULD contain a property called <spanx style="emph">properties</spanx> of type <spanx style="verb">String[]</spanx> that lists <spanx style="strong">all</spanx> the properties of the email that were invalid.</t>
<t><spanx style="verb">tooManyRecipients</spanx> - The envelope (supplied or generated) has more
recipients than the server allows. A <spanx style="emph">maxRecipients</spanx> <spanx style="verb">PositiveInt</spanx> property MUST also be present on the SetError specifying the maximum number of allowed recipients.</t>
<t><spanx style="verb">noRecipients</spanx> – The envelope (supplied or generated) does not have any
rcptTo emails.</t>
<t><spanx style="verb">invalidRecipients</spanx> – The <spanx style="emph">rcptTo</spanx> property of the envelope (supplied or
generated) contains at least one rcptTo value which is not a valid email
for sending to. An <spanx style="emph">invalidRecipients</spanx> <spanx style="verb">String[]</spanx> property MUST also be present on the SetError, which is a list of the invalid addresses.</t>
<t><spanx style="verb">forbiddenMailFrom</spanx> – The server does not permit the user to send an email
with the <xref target="RFC5321"/> envelope From.</t>
<t><spanx style="verb">forbiddenFrom</spanx> – The server does not permit the user to send an email
with the <xref target="RFC5322"/> From header of the email to be sent.</t>
<t><spanx style="verb">forbiddenToSend</spanx> – The user does not have permission to send at all right
now for some reason. A <spanx style="emph">description</spanx> <spanx style="verb">String</spanx> property MAY be present on the SetError object to display to the user why they are not permitted. The server MAY choose to localise this string into the user's preferred language, if known.</t>
</list>
</t>
<t>For <spanx style="strong">update</spanx>:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">cannotUnsend</spanx>: The client attempted to update the <spanx style="emph">undoStatus</spanx> of a valid
EmailSubmission object from <spanx style="verb">pending</spanx> to <spanx style="verb">canceled</spanx>, but the email cannot be unsent.</t>
</list>
</t>

<section anchor="example-5" title="Example">
<t>The following example presumes a draft of the message to be sent has already been saved, and its Email id is &quot;M7f6ed5bcfd7e2604d1753f6c&quot;. This call then sends the email immediately, and if successful removes the draft flag and moves it from the Drafts folder (which has Mailbox id &quot;7cb4e8ee-df87-4757-b9c4-2ea1ca41b38e&quot;) to the Sent folder (which we presume has Mailbox id &quot;73dbcb4b-bffc-48bd-8c2a-a2e91ca672f6&quot;).
</t>

<figure align="center"><artwork align="center">
[[ "EmailSubmission/set", {
  "accountId": "ue411d190",
  "create": {
    "k1490": {
      "identityId": "64588216",
      "emailId": "M7f6ed5bcfd7e2604d1753f6c",
      "envelope": {
        "mailFrom": {
          "email": "john@example.com",
          "parameters": null
        },
        "rcptTo": [{
          "email": "jane@example.com",
          "parameters": null
        },
        ...
        ]
      }
    }
  },
  "onSuccessUpdateEmail": {
    "#k1490": {
      "mailboxIds/7cb4e8ee-df87-4757-b9c4-2ea1ca41b38e": null,
      "mailboxIds/73dbcb4b-bffc-48bd-8c2a-a2e91ca672f6": true,
      "keywords/$draft": null
    }
  }
}, "0" ]]
</artwork></figure>
<t>A successful response might look like this. Note there are two responses due to the implicit Email/set call, but both have the same tag as they are due to the same call in the request:
</t>

<figure align="center"><artwork align="center">
[[ "EmailSubmission/set", {
  "accountId": "ue411d190",
  "oldState": "012421s6-8nrq-4ps4-n0p4-9330r951ns21",
  "newState": "355421f6-8aed-4cf4-a0c4-7377e951af36",
  "created": {
    "k1490": {
      "id": "3bab7f9a-623e-4acf-99a5-2e67facb02a0"
    }
  },
  "notCreated": null,
  "updated": null,
  "notUpdated": null,
  "destroyed": null,
  "notDestroyed": null
}, "0" ],
[ "Email/set", {
  "accountId": "ue411d190",
  "oldState": "778193",
  "newState": "778197",
  "created": null,
  "notCreated": null,
  "updated": {
      "M7f6ed5bcfd7e2604d1753f6c": null
  },
  "notUpdated": null,
  "destroyed": null,
  "notDestroyed": null
}, "0" ]]
</artwork></figure>
<t>If the email submission was not accepted on the other hand, the response may look like this:
</t>

<figure align="center"><artwork align="center">
[[ "EmailSubmission/set", {
  "accountId": "ue411d190",
  "oldState": "012421s6-8nrq-4ps4-n0p4-9330r951ns21",
  "newState": "012421s6-8nrq-4ps4-n0p4-9330r951ns21",
  "created": null,
  "notCreated": {
    "k1490": {
      "type": "tooManyRecipients",
      "maxRecipients": 10
    }
  },
  "updated": null,
  "notUpdated": null,
  "destroyed": null,
  "notDestroyed": null
}, "0" ]]
</artwork></figure>
</section>
</section>
</section>

<section anchor="vacation-response" title="Vacation response">
<t>A vacation response automatically sends a reply to messages sent to a particular account, to inform the original sender that their message may not be processed for some time. Automated message sending can produce undesireable behaviour. To avoid this, implementors MUST follow the recommendations set forth in <xref target="RFC3834"/>.
</t>
<t>The <spanx style="strong">VacationResponse</spanx> object represents the state of vacation-response
related settings for an account. It has the following properties:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">id</spanx>: <spanx style="verb">String</spanx> (immutable)
The id of the object. There is only ever one vacation response object, and its id is <spanx style="verb">"singleton"</spanx>.</t>
<t><spanx style="strong">isEnabled</spanx>: <spanx style="verb">Boolean</spanx>
Should a vacation response be sent if an email arrives between the <spanx style="emph">fromDate</spanx> and <spanx style="emph">toDate</spanx>?</t>
<t><spanx style="strong">fromDate</spanx>: <spanx style="verb">UTCDate|null</spanx>
If <spanx style="emph">isEnabled</spanx> is <spanx style="verb">true</spanx>, the date/time in UTC after which emails that arrive should receive the user's vacation response. If <spanx style="verb">null</spanx>, the vacation response is effective immediately.</t>
<t><spanx style="strong">toDate</spanx>: <spanx style="verb">UTCDate|null</spanx>
If <spanx style="emph">isEnabled</spanx> is <spanx style="verb">true</spanx>, the date/time in UTC after which emails that arrive should no longer receive the user's vacation response. If <spanx style="verb">null</spanx>, the vacation response is effective indefinitely.</t>
<t><spanx style="strong">subject</spanx>: <spanx style="verb">String|null</spanx>
The subject that will be used by the message sent in response to emails when the vacation response is enabled. If null, an appropriate subject SHOULD be set by the server.</t>
<t><spanx style="strong">textBody</spanx>: <spanx style="verb">String|null</spanx>
The plain text part of the message to send in response to emails when the vacation response is enabled. If this is <spanx style="verb">null</spanx>, when the vacation message is sent a plain-text body part SHOULD be generated from the <spanx style="emph">htmlBody</spanx> but the server MAY choose to send the response as HTML only.</t>
<t><spanx style="strong">htmlBody</spanx>: <spanx style="verb">String|null</spanx>
The HTML message to send in response to emails when the vacation response is enabled. If this is <spanx style="verb">null</spanx>, when the vacation message is sent an HTML body part MAY be generated from the <spanx style="emph">textBody</spanx>, or the server MAY choose to send the response as plain-text only.</t>
</list>
</t>
<t>The following JMAP methods are supported:
</t>

<section anchor="vacationresponseget" title="VacationResponse/get">
<t>Standard &quot;/get&quot; method.
</t>
<t>There MUST only be exactly one VacationResponse object in an account. It MUST have the id &quot;singleton&quot;.
</t>
</section>

<section anchor="vacationresponseset" title="VacationResponse/set">
<t>Standard &quot;/set&quot; method.
</t>
</section>
</section>

<section anchor="security-considerations" title="Security considerations">
<t>All security considerations of JMAP (RFC XXXX) apply to this specification.
</t>

<section anchor="emailbodypart-value" title="EmailBodyPart value">
<t>Service providers typically perform security filtering on incoming email and it's important the detection of content-type and charset for the security filter aligns with the heuristics performed by JMAP servers. Servers that apply heuristics to determine the content-type or charset for <spanx style="emph">EmailBodyValue</spanx> SHOULD document the heuristics and provide a mechanism to turn them off in the event they are misaligned with the security filter used at a particular mailbox host.
</t>
<t>Automatic conversion of charsets that allow hidden channels for ASCII text, such as UTF-7, have been problematic for security filters in the past so server implementations can mitigate this risk by having such conversions  off-by-default and/or separately configurable.
</t>
<t>To allow the client to restrict the volume of data it can receive in response to a request, a maximum length may be requested for the data returned for a textual body part. However, truncating the data may change the semantic meaning, for example truncating a URL changes its location. Servers that scan for links to malicious sites should take care to either ensure truncation is not at a semantically significant point, or to rescan the truncated value for malicious content before returning it.
</t>
</section>

<section anchor="html-email-display" title="HTML email display">
<t>HTML message bodies provide richer formatting for emails but present a number of security challenges, especially when embedded in a webmail context in combination with interface HTML. Clients that render HTML email should make careful consideration of the potential risks, including:
</t>
<t>
<list style="symbols">
<t>Embedded JavaScript can rewrite the email to change its content on subsequent
opening, allowing users to be mislead. In webmail systems, if run in the same origin as the interface it can access and exfiltrate all private data accessible to the user, including all other emails and potentially contacts, calendar events, settings, and credentials. It can also rewrite the interface to undetectably phish passwords. A compromise is likely to be persistent, not just for the duration of page load, due to exfiltration of session credentials or installation of a service worker that can intercept all subsequent network requests (this however would only be possible if blob downloads are also available on the same origin, and the service worker script is attached to the message).</t>
<t>HTML documents may load content directly from the internet, rather than just
referencing attached resources. For example you may have an <spanx style="verb">&lt;img&gt;</spanx> tag with an external <spanx style="verb">src</spanx> attribute. This may leak to the sender when a message is opened, as well as the IP address of the recipient. Cookies may also be sent and set by the server, allowing tracking between different emails and even website visits and advertising profiles.</t>
<t>In webmail systems, CSS can break the layout or create phishing
vulnerabilities. For example, the use of <spanx style="verb">position:fixed</spanx> can allow an email to draw content outside of its normal bounds, potentially clickjacking a real interface element.</t>
<t>If in a webmail context and not inside a separate frame, any styles defined in
CSS rules will apply to interface elements as well if the selector matches, allowing the interface to be modified. Similarly, any interface styles that match elements in the email will alter their appearance, potentially breaking the layout of the email.</t>
<t>The link text in HTML has no necessary correlation with the actual target of
the link, which can be used to make phishing attacks more convincing.</t>
<t>Links opened from an email or embedded external content may leak private info
in the <spanx style="verb">Referer</spanx> header sent by default in most systems.</t>
<t>Forms can be used to mimic login boxes, providing a potent phishing vector if
allowed to submit directly from the email display.</t>
</list>
</t>
<t>There are a number of ways clients can mitigate these issues, and a defence-in-depth approach that uses a combination of techniques will provide the strongest security.
</t>
<t>
<list style="symbols">
<t>HTML can be filtered before rendering, stripping potentially malicious
content. Sanitizing HTML correctly is tricky, and implementers are strongly recommended to use a well-tested library with a carefully vetted whitelist-only approach. New features with unexpected security characteristics may be added to HTML rendering engines in the future; a blacklist approach is likely to result in security issues.</t>
</list>
</t>
<t>Subtle differences in parsing of HTML can introduce security flaws: to filter with 100% accurately you need to use the same parser when sanitizing that the HTML rendering engine will use.
</t>
<t>
<list style="symbols">
<t>Encapsulating the message in an <spanx style="verb">&lt;iframe sandbox&gt;</spanx> can help mitigate a number
of risks. This will:
<list style="symbols">
<t>Disable JavaScript.</t>
<t>Disable form submission.</t>
<t>Prevent drawing outside of its bounds, or conflict with interface CSS.</t>
<t>Establish a unique anonymous origin, separate to the containing origin.</t>
</list></t>
<t>A strong <eref target="https://www.w3.org/TR/CSP3/">Content Security Policy</eref> can, among
other things, block JavaScript and loading of external content should it manage to evade the filter.</t>
<t>The leakage of information in the Referer header can be mitigated with the
use of a <eref target="https://www.w3.org/TR/referrer-policy/">referrer policy</eref>.</t>
<t>A <spanx style="verb">crossorigin=anonymous</spanx> attribute on tags that load remote content can
prevent cookies from being sent.</t>
<t>If adding <spanx style="verb">target=_blank</spanx> to open links in new tabs, also add <spanx style="verb">rel=noopener</spanx>
to ensure the page that opens cannot change the URL in the original tab to
redirect the user to a phishing site.</t>
</list>
</t>
<t>As highly complex software components, HTML rendering engines increase the attack surface of a client considerably, especially when being used to process untrusted, potentially malicious content. Serious bugs have been found in image decoders, JavaScript engines and HTML parsers in the past, which could lead to full system compromise. Clients using an engine should ensure they get the latest version and continue to incorporate any security patches released by the vendor.
</t>
</section>

<section anchor="email-submission-1" title="Email submission">
<t>SMTP submission servers <xref target="RFC6409"/> use a number of mechanisms to mitigate damage caused by compromised user accounts and end-user systems including rate limiting, anti-virus/anti-spam milters and other technologies. The technologies work better when they have more information about the client connection. If JMAP email submission is implemented as a proxy to an SMTP Submission server, it is useful to communicate this information from the JMAP proxy to the submission server. The de-facto XCLIENT extension to SMTP (<eref target="http://www.postfix.org/XCLIENT_README.html"/>) can be used to do this, but use of an authenticated channel is recommended to limit use of that extension to explicitly authorized proxies.
</t>
<t>JMAP servers that proxy to an SMTP Submission server SHOULD allow use of the <spanx style="emph">submissions</spanx> port <xref target="RFC8314"/> and SHOULD implement SASL PLAIN over TLS <xref target="RFC4616"/> and/or TLS client certificate authentication with SASL EXTERNAL <xref target="RFC4422"/> appendix A. Implementation of a mechanism similar to SMTP XCLIENT is strongly encouraged.
</t>
<t>In the event the JMAP server directly relays mail to SMTP servers in other administrative domains, then implementation of the de-facto milter protocol is strongly encouraged to integrate with third-party products that address security issues including anti-virus/anti-spam, reputation protection, compliance archiving, and data loss prevention. Proxying to a local SMTP Submission server may be a simpler way to provide such security services.
</t>
</section>
</section>

<section anchor="iana-considerations" title="IANA considerations">

<section anchor="jmap-capability-registration-for-mail" title="JMAP capability registration for &quot;mail&quot;">
<t>IANA will register the &quot;mail&quot; JMAP Capability as follows:
</t>
<t>Capability Name: <spanx style="verb">urn:ietf:params:jmap:mail</spanx>
</t>
<t>Specification document: this document
</t>
<t>Intended use: common
</t>
<t>Change Controller: IETF
</t>
<t>Security and privacy considerations: this document, section 9
</t>
</section>

<section anchor="jmap-capability-registration-for-submission" title="JMAP capability registration for &quot;submission&quot;">
<t>IANA will register the &quot;submission&quot; JMAP Capability as follows:
</t>
<t>Capability Name: <spanx style="verb">urn:ietf:params:jmap:submission</spanx>
</t>
<t>Specification document: this document
</t>
<t>Intended use: common
</t>
<t>Change Controller: IETF
</t>
<t>Security and privacy considerations: this document, section 9
</t>
</section>

<section anchor="jmap-capability-registration-for-vacationresponse" title="JMAP capability registration for &quot;vacationresponse&quot;">
<t>IANA will register the &quot;vacationresponse&quot; JMAP Capability as follows:
</t>
<t>Capability Name: <spanx style="verb">urn:ietf:params:jmap:vacationresponse</spanx>
</t>
<t>Specification document: this document
</t>
<t>Intended use: common
</t>
<t>Change Controller: IETF
</t>
<t>Security and privacy considerations: this document, section 9
</t>
</section>

<section anchor="imap-and-jmap-keywords-registry" title="IMAP and JMAP keywords registry">
<t>This document makes two changes to the IMAP keywords registry as defined in <xref target="RFC5788"/>.
</t>
<t>First, the name of the registry is changed to the &quot;IMAP and JMAP keywords Registry&quot;.
</t>
<t>Second, a scope column is added to the template and registry indicating
whether a keyword applies to IMAP-only, JMAP-only, both, or reserved. All
keywords presently in the IMAP keyword registry will be marked with a
scope of both. The &quot;reserved&quot; status can be used to prevent future
registration of a name that would be confusing if registered.
Registration of keywords with scope 'reserved' omit most fields in the
registration template (see example for <spanx style="verb">$recent</spanx> subsection of this
section); such registrations are intended to be infrequent.
</t>
<t>IMAP clients MAY silently ignore any keywords marked JMAP-only or
reserved in the event they appear in protocol. JMAP clients MAY silently
ignore any keywords marked IMAP-only or reserved in the event they appear
in protocol.
</t>
<t>New JMAP-only keywords are registered in the following sub-sections.
These keywords correspond to IMAP system keywords and are thus not
appropriate for use in IMAP. These keywords can not be subsequently
registered for use in IMAP except via standards action.
</t>

<section anchor="registration-of-jmap-keyword-draft" title="Registration of JMAP keyword '$draft'">
<t>This registers the JMAP-only keyword '$draft' in the &quot;IMAP and JMAP keywords Registry&quot;.
</t>
<t>Keyword name: <spanx style="verb">$draft</spanx>
</t>
<t>Scope: JMAP-only
</t>
<t>Purpose (description): This is set when the user wants to treat the
message as a draft the user is composing. This is the JMAP equivalent of the IMAP \Draft flag.
</t>
<t>Private or Shared on a server: BOTH
</t>
<t>Is it an advisory keyword or may it cause an automatic action:
Automatic. If the account has a mailbox marked with the \Drafts special
use [RFC6154], setting this flag MAY cause the message to appear in that
mailbox automatically. Certain JMAP computed values such as
<spanx style="emph">unreadEmails</spanx> will change as a result of changing this flag. In
addition, mail clients typically will present draft messages in a
composer window rather than a viewer window.
</t>
<t>When/by whom the keyword is set/cleared:
This is typically set by a JMAP client when referring to a draft
message. One model for draft emails would result in clearing this flag
in an EmailSubmission/set operation with an onSuccessUpdateEmail
attribute. In a mailstore shared by JMAP and IMAP, this is also set and
cleared as necessary so it matches the IMAP \Draft flag.
</t>
<t>Related keywords: None
</t>
<t>Related IMAP/JMAP Capabilities: SPECIAL-USE [RFC6154]
</t>
<t>Security Considerations:
A server implementing this keyword as a shared keyword may disclose that
a user considers the message a draft message. This information would be
exposed to other users with read permission for the mailbox keywords.
</t>
<t>Published specification (recommended): this document
</t>
<t>Person &amp; email address to contact for further information:
(editor-contact-goes-here)
</t>
<t>Intended usage: COMMON
</t>
<t>Owner/Change controller: IESG
</t>
</section>

<section anchor="registration-of-jmap-keyword-seen" title="Registration of JMAP keyword '$seen'">
<t>This registers the JMAP-only keyword '$seen' in the &quot;IMAP and JMAP
keywords Registry&quot;.
</t>
<t>Keyword name: <spanx style="verb">$seen</spanx>
</t>
<t>Scope: JMAP-only
</t>
<t>Purpose (description): This is set when the user wants to treat the
message as read. This is the JMAP equivalent of the IMAP \Seen flag.
</t>
<t>Private or Shared on a server: BOTH
</t>
<t>Is it an advisory keyword or may it cause an automatic action:
Advisory. However, certain JMAP computed values such as <spanx style="emph">unreadEmails</spanx>
will change as a result of changing this flag.
</t>
<t>When/by whom the keyword is set/cleared:
This is set by a JMAP client when it presents the message content to the
user; clients often offer an option to clear this flag. In a mailstore
shared by JMAP and IMAP, this is also set and cleared as necessary so it
matches the IMAP \Seen flag.
</t>
<t>Related keywords: None
</t>
<t>Related IMAP/JMAP Capabilities: None
</t>
<t>Security Considerations:
A server implementing this keyword as a shared keyword may disclose that
a user considers the message to have been read. This information would be
exposed to other users with read permission for the mailbox keywords.
</t>
<t>Published specification (recommended): this document
</t>
<t>Person &amp; email address to contact for further information:
(editor-contact-goes-here)
</t>
<t>Intended usage: COMMON
</t>
<t>Owner/Change controller: IESG
</t>
</section>

<section anchor="registration-of-jmap-keyword-flagged" title="Registration of JMAP keyword '$flagged'">
<t>This registers the JMAP-only keyword '$flagged' in the &quot;IMAP and JMAP
keywords Registry&quot;.
</t>
<t>Keyword name: <spanx style="verb">$flagged</spanx>
</t>
<t>Scope: JMAP-only
</t>
<t>Purpose (description): This is set when the user wants to treat the
message as flagged for urgent/special attention. This is the JMAP
equivalent of the IMAP \Flagged flag.
</t>
<t>Private or Shared on a server: BOTH
</t>
<t>Is it an advisory keyword or may it cause an automatic action:
Automatic. If the account has a mailbox marked with the \Flagged special
use [RFC6154], setting this flag MAY cause the message to appear in that
mailbox automatically.
</t>
<t>When/by whom the keyword is set/cleared:
JMAP clients typically allow a user to set/clear this flag as desired.
In a mailstore shared by JMAP and IMAP, this is also set and cleared as
necessary so it matches the IMAP \Flagged flag.
</t>
<t>Related keywords: None
</t>
<t>Related IMAP/JMAP Capabilities: SPECIAL-USE [RFC6154]
</t>
<t>Security Considerations:
A server implementing this keyword as a shared keyword may disclose that
a user considers the message as flagged for urgent/special attention.
This information would be exposed to other users with read permission
for the mailbox keywords.
</t>
<t>Published specification (recommended): this document
</t>
<t>Person &amp; email address to contact for further information:
(editor-contact-goes-here)
</t>
<t>Intended usage: COMMON
</t>
<t>Owner/Change controller: IESG
</t>
</section>

<section anchor="registration-of-jmap-keyword-answered" title="Registration of JMAP keyword '$answered'">
<t>This registers the JMAP-only keyword '$answered' in the &quot;IMAP and JMAP
keywords Registry&quot;.
</t>
<t>Keyword name: <spanx style="verb">$answered</spanx>
</t>
<t>Scope: JMAP-only
</t>
<t>Purpose (description): This is set when the message has been answered.
</t>
<t>Private or Shared on a server: BOTH
</t>
<t>Is it an advisory keyword or may it cause an automatic action:
Advisory.
</t>
<t>When/by whom the keyword is set/cleared:
JMAP clients typically set this when submitting a reply or answer to the
message. It may be set by the EmailSubmission/set operation with an
onSuccessUpdateEmail attribute. In a mailstore shared by JMAP and IMAP,
this is also set and cleared as necessary so it matches the IMAP
\Answered flag.
</t>
<t>Related keywords: None
</t>
<t>Related IMAP/JMAP Capabilities: None
</t>
<t>Security Considerations:
A server implementing this keyword as a shared keyword may disclose that
a user considers the message as flagged for urgent/special attention.
This information would be exposed to other users with read permission
for the mailbox keywords.
</t>
<t>Published specification (recommended): this document
</t>
<t>Person &amp; email address to contact for further information:
(editor-contact-goes-here)
</t>
<t>Intended usage: COMMON
</t>
<t>Owner/Change controller: IESG
</t>
</section>

<section anchor="registration-of-recent-keyword" title="Registration of '$recent' keyword">
<t>This registers the keyword '$recent' in the &quot;IMAP and JMAP keywords Registry&quot;.
</t>
<t>Keyword name: <spanx style="verb">$recent</spanx>
</t>
<t>Scope: reserved
</t>
<t>Purpose (description): This keyword is not used to avoid confusion with
the IMAP \Recent system flag.
</t>
<t>Published specification (recommended): this document
</t>
<t>Person &amp; email address to contact for further information:
(editor-contact-goes-here)
</t>
<t>Owner/Change controller: IESG
</t>
</section>
</section>

<section anchor="registration-of-inbox-role-in" title="Registration of &quot;inbox&quot; role in">
<t>This registers the JMAP-only &quot;inbox&quot; attribute in the &quot;IMAP Mailbox Name Attributes Registry&quot;, as established in <xref target="RFC8457"/>.
</t>
<t>Attribute Name: Inbox
</t>
<t>Description: New mail is delivered here by default.
</t>
<t>Reference: This document, section 10.5.
</t>
<t>Usage Notes: JMAP only
</t>
</section>

<section anchor="jmap-error-codes-registry" title="JMAP Error Codes registry">
<t>The following sub-sections register several new error codes in the JMAP Error Codes registry, as defined in RFC XXXX.
</t>

<section anchor="mailboxhaschild" title="mailboxHasChild">
<t>JMAP Error Code: mailboxHasChild
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 2.5
</t>
</section>

<section anchor="mailboxhasemail" title="mailboxHasEmail">
<t>JMAP Error Code: mailboxHasEmail
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 2.5
</t>
</section>

<section anchor="blobnotfound" title="blobNotFound">
<t>JMAP Error Code: blobNotFound
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 4.6
</t>
</section>

<section anchor="toomanykeywords" title="tooManyKeywords">
<t>JMAP Error Code: tooManyKeywords
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 4.6
</t>
</section>

<section anchor="toomanymailboxes" title="tooManyMailboxes">
<t>JMAP Error Code: tooManyMailboxes
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 4.6
</t>
</section>

<section anchor="emailnotfound" title="emailNotFound">
<t>JMAP Error Code: emailNotFound
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>

<section anchor="emailtoolarge" title="emailTooLarge">
<t>JMAP Error Code: emailTooLarge
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>

<section anchor="invalidemail" title="invalidEmail">
<t>JMAP Error Code: invalidEmail
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>

<section anchor="toomanyrecipients" title="tooManyRecipients">
<t>JMAP Error Code: tooManyRecipients
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>

<section anchor="norecipients" title="noRecipients">
<t>JMAP Error Code: noRecipients
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>

<section anchor="invalidrecipients" title="invalidRecipients">
<t>JMAP Error Code: invalidRecipients
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>

<section anchor="forbiddenmailfrom" title="forbiddenMailFrom">
<t>JMAP Error Code: forbiddenMailFrom
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>

<section anchor="forbiddenfrom" title="forbiddenFrom">
<t>JMAP Error Code: forbiddenFrom
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, sections 6.3 and 7.5
</t>
</section>

<section anchor="forbiddentosend" title="forbiddenToSend">
<t>JMAP Error Code: forbiddenToSend
</t>
<t>Intended use: common
</t>
<t>Change controller: IETF
</t>
<t>Reference: This document, section 7.5
</t>
</section>
</section>
</section>

</middle>
<back>
<references title="Normative References">
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.1870.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2045.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2047.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2231.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2369.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2557.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2852.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3282.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3461.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3463.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3464.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3798.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3834.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4422.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4616.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4865.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5198.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5248.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5256.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5321.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5322.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5788.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6154.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6409.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6532.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6533.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6710.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8314.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8457.xml"?>
</references>

</back>
</rfc>
