<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->
<rfc version="3" ipr="trust200902" docName="draft-gondwana-jmap-blob-02" submissionType="IETF" category="std" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" updates="8620" indexInclude="false" consensus="true">

<front>
<title abbrev="JMAP Blob">JMAP Blob management extension</title><seriesInfo value="draft-gondwana-jmap-blob-02" stream="IETF" status="standard" name="Internet-Draft"></seriesInfo>
<author role="editor" initials="B." surname="Gondwana" fullname="Bron Gondwana"><organization>Fastmail</organization><address><postal><street>Level 2, 114 William St</street>
<city>Melbourne</city>
<code>VIC 3000</code>
<country>Australia</country>
</postal><email>brong@fastmailteam.com</email>
<uri>https://www.fastmail.com</uri>
</address></author><date year="2021" month="July" day="12"></date>
<area>Applications</area>
<workgroup>JMAP</workgroup>
<keyword>jmap</keyword>

<abstract>
<t>The JMAP base protocol (RFC8620) provides the ability to upload and download
arbitrary binary data via HTTP PUT and GET on defined endpoint.  This binary
data is called a &quot;Blob&quot;.</t>
<t>This extension adds additional ways to create and access Blobs, by making
inline method calls within a standard JMAP request.</t>
<t>This extension also adds a reverse lookup mechanism to discover where blobs
are referenced within other datatypes.</t>
</abstract>

</front>

<middle>

<section anchor="introduction"><name>Introduction</name>
<t>Sometimes JMAP (<xref target="RFC8620"></xref>) interactions require creating a Blob and then
referencing it.  In the same way that IMAP Literals (<xref target="RFC7888"></xref>) were extended
to reduce roundtrips for simple data, embedding simple small blobs into the
JMAP method stream can reduce roundtrips.</t>
<t>Likewise, when fetching an object, it can be useful to also fetch the raw
content of that object without a separate roundtrip.</t>
<t>Where JMAP is being proxied through a system which applies additional
access restrictions, it can be useful to be able to see where a blob is
referenced in order to decide whether to allow it to be downloaded.</t>
</section>

<section anchor="conventions-used-in-this-document"><name>Conventions Used In This Document</name>
<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;NOT RECOMMENDED&quot;,
&quot;MAY&quot;, and &quot;OPTIONAL&quot; in this document are to be interpreted as
described in BCP 14 <xref target="RFC2119"></xref> <xref target="RFC8174"></xref> when, and only when,
they appear in all capitals, as shown here.</t>
</section>

<section anchor="blobs"><name>Blobs</name>
<t>A blob is a sequence of zero or more octets.</t>
<t>The JMAP base spec <xref target="RFC8210"></xref> defines the <tt>Blob/copy</tt> method, which
is unchanged by this specfication.</t>

<section anchor="blob-set"><name>Blob/set</name>
<t>This is a standard JMAP <tt>set</tt> method.</t>

<section anchor="create"><name>create</name>
<t><strong>Properties:</strong></t>
<t>Any one of:</t>

<ul>
<li>data:asText: String|null</li>
<li>data:asBase64: String|null</li>
<li>data:asHex: String|null</li>
<li>catenate: [SetObject] <em>list of octet sources in order</em></li>
</ul>
<t>Also:</t>

<ul>
<li>type: String|null</li>
</ul>
<t>Result is:</t>

<ul>
<li>id: Id the blobId</li>
<li>type: String|null <em>as given in the creation (if any); or detected from content; or null</em></li>
<li>size: UnsignedInt <em>as per RFC8620 - the size of the file in Octets</em></li>
</ul>
<t>Any other properties identical to those that would be returned in the JSON response of the
RFC8620 upload endpoint.</t>
<t>SetObject:</t>
<t>Any one of</t>

<ul>
<li><t>data:asText: String|null</t>
</li>
<li><t>data:asBase64: String|null</t>
</li>
<li><t>data:asHex: String|null</t>
</li>
</ul>
<t>OR a blobId source:</t>

<ul>
<li>blobId: Id</li>
<li>offset: UnsignedInt|null</li>
<li>length: UnsignedInt|null</li>
</ul>
</section>

<section anchor="update"><name>update</name>
<t>It is not possible to update a Blob, so any update will result in a <tt>notUpdated</tt> response.</t>
</section>

<section anchor="destroy"><name>destroy</name>
<t>If an uploaded Blob is not referenced by any persistent object, the server SHOULD destroy the object.
Some systems use a content-based ID for blobs, so the server MAY respond <tt>destroyed</tt> and yet that
blobId still exist with the same content.</t>
<t>Example:</t>

<artwork>Method Call:

[ &quot;Blob/set&quot;, {
  &quot;accountId&quot; : &quot;account1&quot;,
  &quot;create&quot; : {
    &quot;1&quot;: {
      &quot;data:asBase64&quot;: &quot;iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKA
                        AAAA1BMVEX/AAAZ4gk3AAAAAXRSTlN/gFy0ywAAAApJRE
                        FUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=&quot;,
      &quot;type&quot; : &quot;image/png&quot;
    },
  },
}, &quot;R1&quot; ]

Response:

[ &quot;Blob/set&quot;, {
  &quot;accountId&quot; : &quot;account1&quot;,
  &quot;created&quot; : {
    &quot;1&quot;: {
      &quot;id&quot; : &quot;G4c6751edf9dd6903ff54b792e432fba781271beb&quot;,
      &quot;type&quot; : &quot;image/png&quot;,
      &quot;size&quot; : 95
    },
  },
}, &quot;R1&quot; ]

</artwork>
</section>
</section>

<section anchor="blob-get"><name>Blob/get</name>
<t>A standard JMAP get.</t>
<t><strong>Properties:</strong></t>
<t>Any of</t>

<ul>
<li>data:asText</li>
<li>data:asBase64</li>
<li>data:asHex</li>
<li>data <em>selects data:asText if the content is UTF-8, or data:asBase64</em></li>
<li>size</li>
</ul>
<t>If not given, returns <tt>data</tt> and <tt>size</tt>.</t>
<t>QUESTION: do we want to add range operators?</t>

<ul>
<li>offset: UnsignedInt|null</li>
<li>length: UnsignedInt|null</li>
</ul>
<t>Returns that range of octets (not characters!) from the blob.  Alternative
possible syntax - ranges within the properties, e.g: <tt>data:asText:0:3000</tt></t>
</section>

<section anchor="blob-lookup"><name>Blob/lookup</name>
<t>Given a list of blobIds, this method does a reverse lookup in each of
the provided datatypes to find the list of Ids within that datatype
which reference the provided blob.</t>
<t>The definition of reference is somewhat loosely defined, but roughly
means &quot;you could discover this blobId by looking inside this object&quot;,
for example if a Mailbox contains an Email which references the blobId,
then it references that blobId.  Likewise for a Thread.</t>
<t><strong>Parameters</strong></t>

<ul>
<li>accountId: &quot;Id&quot;</li>
</ul>
<t>The id of the account used for the call.</t>

<ul>
<li>datatypes: [String]</li>
</ul>
<t>A list of datatype names from the &quot;JMAP Datatypes&quot; registry for which
  &quot;Can Reference Blobs&quot; is &quot;Yes&quot;.  The capability which defines each
  type must also be requested.</t>
<t>If a datatype is not known by the server or the associated capability
  has not been included then the server returns an &quot;unknownDataType&quot;
  error.</t>

<ul>
<li>ids: [Id]</li>
</ul>
<t>A list of blobId values to be looked for.</t>
<t><strong>Response</strong></t>

<ul>
<li>list: [BlobInfo]</li>
</ul>
<t>A list of BlobInfo objects.</t>
<t><strong>BlobInfo Object</strong></t>

<ul>
<li>id: Id</li>
</ul>
<t>The Blob Identifier.</t>

<ul>
<li>datatypes: DataType[Id List]</li>
</ul>
<t>A map from datatype to list of Ids of that datatype (e.g. the datatype
  &quot;Email&quot; maps to a list of emailIds)</t>
<t>e.g.</t>

<artwork>[ &quot;Blob/lookup&quot;, {
  &quot;datatypes&quot;: [&quot;Mailbox&quot;, &quot;Thread&quot;, &quot;Email&quot;],
  &quot;ids&quot;: [&quot;Gd2f81008cf07d2425418f7f02a3ca63a8bc82003&quot;,
          &quot;G6f954bcb620f7f50fc8f21426bde3669da3d9067&quot;]
}, &quot;R1&quot; ]
</artwork>
<t>Response:</t>

<artwork>[ &quot;Blob/lookup&quot;, {
  &quot;list&quot;: [
    {
      &quot;id&quot;: &quot;Gd2f81008cf07d2425418f7f02a3ca63a8bc82003&quot;,
      &quot;datatypes&quot;: {
        &quot;Mailbox&quot;: [&quot;M54e97373&quot;, Mcbe6b662&quot;],
        &quot;Thread&quot;: [&quot;T1530616e&quot;],
        &quot;Email&quot;: [&quot;E16e70a73eb4&quot;, &quot;E84b0930cf16&quot;]
      }
    }
  ],
  &quot;notFound&quot;: [&quot;G6f954bcb620f7f50fc8f21426bde3669da3d9067&quot;]
}, &quot;R1&quot;]
</artwork>
</section>
</section>

<section anchor="security-considerations"><name>Security considerations</name>
<t>TO BE IMPROVED:</t>
<t>JSON parsers are not all consistent in handling non-UTF-8 data.  JMAP requires
that all JSON data be UTF-8 encoded, so servers MUST either return
<tt>data:asBase64</tt> or <tt>isEncodingProblem: true</tt> and modify the data to be UTF-8
safe.</t>
<t>Servers MUST apply any access controls such that if the authenticated user would
be unable to discover the blobId by making queries, then this fact can't be
discovered via a Blob/lookup.  For example, if an Email exists in a Mailbox which
the authenticated user does not have access to see, then that emailId MUST not be
returned in a lookup for a blob which is referenced by that email.</t>
<t>If a blob is not visible to a user at all, then the server SHOULD return that blobId
in the notFound array, however it may also return an empty list for each datatype, as
it may not be able to know if other datatypes do reference that blob.</t>
</section>

<section anchor="iana-considerations"><name>IANA considerations</name>

<section anchor="jmap-capability-registration-for-blob"><name>JMAP Capability registration for &quot;blob&quot;</name>
<t>IANA is requested to register the &quot;blob&quot; JMAP Capability as follows:</t>
<t>Capability Name: urn:ietf:params:jmap:blob</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 XXX</t>
</section>

<section anchor="jmap-error-codes-registration-for-unknowndatatype"><name>JMAP Error Codes Registration for &quot;unknownDataType&quot;</name>
<t>IANA is requested to register the &quot;unknownDataType&quot; JMAP Error Code as follows:</t>
<t>JMAP Error Code: unknownDataType</t>
<t>Intended use: common</t>
<t>Change Controller: IETF</t>
<t>Reference: this document</t>
<t>Description: The server does not recognise this data type, or the capability to enable it was not present.</t>
</section>

<section anchor="creation-of-jmap-datatypes-registry"><name>Creation of &quot;JMAP Datatypes&quot; Registry</name>
<t>IANA is requested to create a new registry &quot;JMAP Datatypes&quot; with the initial content:</t>
<table>
<thead>
<tr>
<th>Datatype name</th>
<th>Can Reference Blobs</th>
<th>Can use for State Change</th>
<th>Capability</th>
<th>Reference</th>
</tr>
</thead>

<tbody>
<tr>
<td>Core</td>
<td>No</td>
<td>No</td>
<td>urn:ietf:params:jmap:core</td>
<td><xref target="RFC8620"></xref></td>
</tr>

<tr>
<td>PushSubscription</td>
<td>No</td>
<td>No</td>
<td>urn:ietf:params:jmap:core</td>
<td><xref target="RFC8620"></xref></td>
</tr>

<tr>
<td>Mailbox</td>
<td>Yes</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:mail</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>Thread</td>
<td>Yes</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:mail</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>Email</td>
<td>Yes</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:mail</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>EmailDelivery</td>
<td>No</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:mail</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>SearchSnippet</td>
<td>No</td>
<td>No</td>
<td>urn:ietf:params:jmap:mail</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>Identity</td>
<td>No</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:submission</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>EmailSubmission</td>
<td>No</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:submission</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>VacationResponse</td>
<td>No</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:vacationresponse</td>
<td><xref target="RFC8621"></xref></td>
</tr>

<tr>
<td>MDN</td>
<td>No</td>
<td>No</td>
<td>urn:ietf:params:jmap:mdn</td>
<td>[RFC9007]</td>
</tr>
</tbody>
</table></section>
</section>

<section anchor="acknowledgements"><name>Acknowledgements</name>
<t>TBD</t>
</section>

</middle>

<back>
<references><name>Normative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8210.xml"/>
</references>
<references><name>Informative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7888.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8620.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8621.xml"/>
</references>

</back>

</rfc>
