<?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-ietf-jmap-blob-14" submissionType="IETF" category="std" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" updates="8620" indexInclude="true" consensus="true">

<front>
<title abbrev="JMAP Blob">JMAP Blob management extension</title><seriesInfo value="draft-ietf-jmap-blob-14" 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="2022" month="October" day="21"></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 POST 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 data types.</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 were extended by <xref target="RFC7888"></xref>,
embedding small blobs directly into the JMAP method calls array can be an
option for reducing 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>Since raw blobs may contain arbitrary binary data, this document defines
a use of the base64 coding specified in <xref target="RFC4648"></xref> for both creating and
fetching blob data.</t>
<t>Where JMAP is being proxied through a system which applies additional
access restrictions, it can be useful to know which objects reference
any particular blob, and this document defines a way to discover those
references.</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>
<t>The definitions of JSON keys and datatypes in the document follow
the conventions described in the core JMAP specification <xref target="RFC8620"></xref>.</t>
</section>

<section anchor="addition-to-the-capabilities-object"><name>Addition to the Capabilities Object</name>
<t>The capabilities object is returned as part of the JMAP Session
object; see <xref target="RFC8620"></xref>, Section 2.</t>
<t>This document defines an additional capability URI.</t>

<section anchor="urn-ietf-params-jmap-blob"><name>urn:ietf:params:jmap:blob</name>
<t>The capability <tt>urn:ietf:params:jmap:blob</tt> being present in the
&quot;accountCapabilities&quot; property of an account represents support
for additional API methods on the Blob datatype.  Servers that
include the capability in one or more &quot;accountCapabilities&quot;
properties MUST also include the property in the &quot;capabilities&quot;
property.</t>
<t>The value of this property in the JMAP session &quot;capabilities&quot;
property MUST be an empty object.</t>
<t>The value of this property in an account's &quot;accountCapabilities&quot;
property is an object that MAY contain the following information on
server capabilities and permissions for that account:</t>

<ul>
<li><t>maxSizeBlobSet: <tt>UnsignedInt|null</tt></t>
<t>If present, this is the maximum size of blob (in octets) that the server
will allow to be created (including blobs created by concatenating
multiple data sources together).</t>
<t>Clients MUST NOT attempt to create blobs larger than this size.</t>
<t>If this value is not present or <tt>null</tt>, then clients are not required to
limit the size of blob they try to create, though servers can always
reject creation of blobs regardless of size; e.g. due to lack of
disk space, or per-user rate limits.</t>
</li>
<li><t>maxDataSources: <tt>UnsignedInt|null</tt></t>
<t>If present, gives the maximum number of of DataSourceObjects allowed per
creation in a Blob/upload.  Servers MUST allow at least 64 items.</t>
<t>If this value is not present or <tt>null</tt>, then clients MUST assume
a limit of 64 items.</t>
</li>
<li><t>supportedTypeNames: <tt>String[]|null</tt></t>
<t>An array of data type names that are supported for <tt>Blob/lookup</tt>.  If the
server does not support lookups then this could be the empty list, not present
or <tt>null</tt>.</t>
</li>
<li><t>supportedDigestAlgorithms <tt>String[]|null</tt></t>
<t>An array of supported digest algorithms that are supported for <tt>Blob/get</tt>.
If the server does not support calculating blob digests, then this could be
the empty list, not present, or <tt>null</tt>.  Algorithms on this list MUST be
present in the HTTP Digest Alogirthms registry defined by <xref target="RFC3230"></xref>,
and are always lowercased.</t>
</li>
</ul>

<section anchor="capability-example"><name>Capability Example</name>

<artwork>{
  &quot;capabilities&quot;: {
    ...,
    &quot;urn:ietf:params:jmap:blob&quot;: {}
  },
  &quot;accounts&quot;: {
    &quot;A13842&quot;: {
      ...
      &quot;accountCapabilities&quot;: {
        &quot;urn:ietf:params:jmap:blob&quot;: {
          &quot;maxSizeBlobSet&quot;: 50000000,
          &quot;maxDataSources&quot;: 100,
          &quot;supportedTypeNames&quot; : [
            &quot;Mailbox&quot;,
            &quot;Thread&quot;,
            &quot;Email&quot;
          ],
          &quot;supportedDigestAlgorithms&quot; : [
            &quot;sha&quot;,
            &quot;sha-256&quot;
          ]
        }
      }
    }
  }
}
</artwork>
</section>
</section>
</section>

<section anchor="blob-methods"><name>Blob Methods</name>
<t>A blob is a sequence of zero or more octets.</t>
<t>The JMAP base spec <xref target="RFC8620"></xref> defines the <tt>Blob/copy</tt> method, which
is unchanged by this specfication, and is selected by the
<tt>urn:ietf:params:jmap:core</tt> capability.</t>
<t>The following JMAP Methods are selected by the
<tt>urn:ietf:params:jmap:blob</tt> capability.</t>

<section anchor="blob-upload"><name>Blob/upload</name>
<t>This is similar to a Foo/set from <xref target="RFC8620"></xref> in some ways, however blobs can't
be updated or deleted, so only <tt>create</tt> is allowed in the method call, and blobs
don't have state, so there is no <tt>state</tt> field present in the method response.</t>
<t><strong>Parameters</strong></t>

<ul>
<li><t>accountId: <tt>Id</tt></t>
<t>The id of the account in which the blobs will be created.</t>
</li>
<li><t>create: <tt>Id[UploadObject]</tt></t>
<t>A map of creation id to UploadObjects.</t>
</li>
</ul>
<t><strong>Result</strong></t>
<t>The result is the same as for Foo/set in RFC8620, with <tt>created</tt> and <tt>notCreated</tt> objects
mapping from the creationId.</t>
<t>The <tt>created</tt> objects contain:</t>

<ul>
<li><t>id: <tt>Id</tt></t>
<t>the blobId which was created</t>
</li>
<li><t>type: <tt>String|null</tt></t>
<t>the media type as given in the creation (if any); or detected from content; or null</t>
</li>
<li><t>size: <tt>UnsignedInt</tt></t>
<t>as per RFC8620 - the size of the created blob in octets</t>
</li>
</ul>
<t>Plus any other properties identical to those that would be returned in the
JSON response of the RFC8620 upload endpoint (which may be extended in
the future - this document anticipates that implementations will
extend both the upload endpoint and the Blob/upload responses in the
same way)</t>
<t>Or if there is a problem with a creation, then the server will return a <tt>notCreated</tt>
response with a map from the failed creationId to a <tt>SetError</tt> object.</t>
<t>For each sucessful upload, servers MUST add an entry to the <tt>creationIds</tt> map
for the request.  This allows the blob id to be used via back-reference in
subsequent method calls.</t>
<t><strong>UploadObject</strong></t>

<ul>
<li><t>data: <tt>DataSourceObject[]</tt></t>
<t>an array of zero or more octet sources in order (zero to create an empty blob).
The result of each of these sources is concatenated together in order to create
the blob.</t>
</li>
<li><t>type: <tt>String|null</tt> (default: null)</t>
<t>hint for media type of the data</t>
</li>
</ul>
<t><strong>DataSourceObject</strong></t>
<t>Exactly one of:</t>

<ul>
<li><t>data:asText: <tt>String|null</tt> (raw octets, must be UTF-8)</t>
</li>
<li><t>data:asBase64: <tt>String|null</tt> (base64 representation of octets)</t>
</li>
</ul>
<t>or a blobId source:</t>

<ul>
<li><t>blobId: <tt>Id</tt></t>
</li>
<li><t>offset: <tt>UnsignedInt|null</tt> (MAY be zero)</t>
</li>
<li><t>length: <tt>UnsignedInt|null</tt> (MAY be zero)</t>
</li>
</ul>
<t>If <tt>null</tt> then offset is assumed to be zero.</t>
<t>If <tt>null</tt> then length is the remaining octets in the blob.</t>
<t>If the range can not be fully satisfied (i.e. begins or extends past
the end of the data in the blob) then the DataSourceObject is invalid
and results in a notCreated response for this creation id.</t>
<t>If the data properties have any invalid references or invalid data
contained in them, the server MUST NOT guess as to the user's intent,
and MUST reject the creation and return a notCreated response for that
creation id.</t>
<t>Likewise, invalid characters in the base64 of data:asBase64, or invalid
UTF-8 in data:asText MUST result in a nonCreated response.</t>
<t>It is envisaged that the definition for DataSourceObject might be
extended in future, for example to fetch external content.</t>
<t>A server MUST accept at least 64 DataSourceObjects per create, as
described in Section 3.1 of this document.</t>

<section anchor="blob-upload-simple-example"><name>Blob/upload simple example</name>
<t>The data:asBase64 field is set over multiple lines for ease of
publication here, however all data:asBase64 would be sent as a
continuous string with no whitespace on the wire.</t>

<artwork>Method Call:

[
  &quot;Blob/upload&quot;,
  {
    &quot;accountId&quot;: &quot;account1&quot;,
    &quot;create&quot;: {
      &quot;1&quot;: {
        &quot;data&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/upload&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 anchor="blob-upload-complex-example"><name>Blob/upload complex example</name>

<artwork>Method Calls:

[
  [
    &quot;Blob/upload&quot;,
    {
      &quot;create&quot;: {
        &quot;b4&quot;: {
          &quot;data&quot;: [
            {
              &quot;data:asText&quot;: &quot;The quick brown fox jumped over the lazy dog.&quot;
            }
          ]
        }
      }
    },
    &quot;S4&quot;
  ],
  [
    &quot;Blob/upload&quot;,
    {
      &quot;create&quot;: {
        &quot;cat&quot;: {
          &quot;data&quot;: [
            {
              &quot;data:asText&quot;: &quot;How&quot;
            },
            {
              &quot;blobId&quot;: &quot;#b4&quot;,
              &quot;length&quot;: 7,
              &quot;offset&quot;: 3
            },
            {
              &quot;data:asText&quot;: &quot;was t&quot;
            },
            {
              &quot;blobId&quot;: &quot;#b4&quot;,
              &quot;length&quot;: 1,
              &quot;offset&quot;: 1
            },
            {
              &quot;data:asBase64&quot;: &quot;YXQ/&quot;
            }
          ]
        }
      }
    },
    &quot;CAT&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;properties&quot;: [
        &quot;data:asText&quot;,
        &quot;size&quot;
      ],
      &quot;ids&quot;: [
        &quot;#cat&quot;
      ]
    },
    &quot;G4&quot;
  ]
]

Responses:

[
  [
    &quot;Blob/upload&quot;,
    {
      &quot;oldState&quot;: null,
      &quot;created&quot;: {
        &quot;b4&quot;: {
          &quot;id&quot;: &quot;Gc0854fb9fb03c41cce3802cb0d220529e6eef94e&quot;,
          &quot;size&quot;: 45,
          &quot;type&quot;: &quot;application/octet-stream&quot;
        }
      },
      &quot;notCreated&quot;: null,
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;S4&quot;
  ],
  [
    &quot;Blob/upload&quot;,
    {
      &quot;oldState&quot;: null,
      &quot;created&quot;: {
        &quot;cat&quot;: {
          &quot;id&quot;: &quot;Gcc60576f036321ae6e8037ffc56bdee589bd3e23&quot;,
          &quot;size&quot;: 19,
          &quot;type&quot;: &quot;application/octet-stream&quot;
        }
      },
      &quot;notCreated&quot;: null,
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;CAT&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;Gcc60576f036321ae6e8037ffc56bdee589bd3e23&quot;,
          &quot;data:asText&quot;: &quot;How quick was that?&quot;,
          &quot;size&quot;: 19
        }
      ],
      &quot;notFound&quot;: [],
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;G4&quot;
  ]
]
</artwork>
</section>
</section>

<section anchor="blob-get"><name>Blob/get</name>
<t>A standard JMAP get, with two additional optional parameters:</t>

<ul>
<li><t>offset: <tt>UnsignedInt|null</tt></t>
<t>start this many octets into the blob data.  If null or
unspecified, this defaults to zero.</t>
</li>
<li><t>length: <tt>UnsignedInt|null</tt></t>
<t>return at most this many octets of the blob data.  If null or
unspecified, then all remaining octets in the blob are returned.
This can be considered equivalent to an infinitely large length
value, except that the isTruncated warning is not given unless
the start offset is past the end of the blob.</t>
</li>
</ul>
<t><strong>Request Properties:</strong></t>
<t>Any of</t>

<ul spacing="compact">
<li>data:asText</li>
<li>data:asBase64</li>
<li>data (returns data:asText if the selected octets are valid UTF-8, or data:asBase64)</li>
<li>digest:&lt;algorithm&gt; (where &lt;algorithm&gt; is one of the named algorithms in the <tt>supportedDigestAlgorithms</tt> capability)</li>
<li>size</li>
</ul>
<t>If not given, properties defaults to <tt>data</tt> and <tt>size</tt>.</t>
<t><strong>Result Properties:</strong></t>

<ul>
<li><t>data:asText: <tt>String|null</tt></t>
<t>the raw octets of the selected range if they are valid UTF-8, otherwise null</t>
</li>
<li><t>data:asBase64: <tt>String</tt></t>
<t>the base64 encoding of the octets in the selected range</t>
</li>
<li><t>digest:&lt;algorithm&gt; <tt>String</tt></t>
<t>the base64 encoding of the digest of the octets in the selected range,
calculated using the named algorithm</t>
</li>
<li><t>isEncodingProblem: <tt>Boolean</tt> (default: false)</t>
</li>
<li><t>isTruncated: <tt>Boolean</tt> (default: false)</t>
</li>
<li><t>size: <tt>UnsignedInt</tt></t>
<t>the number of octets in the entire blob</t>
</li>
</ul>
<t>The size value MUST always be the number of octets in the underlying blob,
regardless of offset and length.</t>
<t>The data fields contain a representation of the octets within the selected
range that are present in the blob.  If the octets selected are not valid
UTF-8 (including truncating in the middle of a multi-octet sequence)
and <tt>data</tt> or <tt>data:asText</tt> was requested, then the key <tt>isEncodingProblem</tt>
MUST be set to <tt>true</tt> and the <tt>data:asText</tt> response value MUST be <tt>null</tt>.
In the case where <tt>data</tt> was requested and the data is not valid UTF-8,
then <tt>data:asBase64</tt> MUST be returned.</t>
<t>If the selected range requests data outside the blob (i.e. the offset+length
is larger than the blob) then the result is either just the octets from the
offset to the end of the blob, or an empty string if the offset is past the
end of the blob.  Either way, the <tt>isTruncated</tt> property in the result MUST
be set to <tt>true</tt> to tell the client that the requested range could not be
fully satisfied.  If digest was requested, any <tt>digest</tt> is calculated on the
octets that would be returned for a <tt>data</tt> field.</t>
<t>Servers SHOULD store the size for blobs in a format which is efficient to
read, and clients SHOULD limit their request to just the size parameter if
that is all they need, as fetching blob content could be significantly more
expensive and slower for the server.</t>

<section anchor="blob-get-simple-example"><name>Blob/get simple example</name>
<t>Where a blob containing the string &quot;The quick brown fox jumped over
the lazy dog.&quot; has blobId <tt>Gc0854fb9fb03c41cce3802cb0d220529e6eef94e</tt>.</t>
<t>The first method call requests just the size for multiple blobs, and
the second requests both size and a short range of the data for one
of the blobs.</t>

<artwork>Method Calls:

[
  [
    &quot;Blob/get&quot;,
    {
      &quot;ids&quot; : [
        &quot;Gc0854fb9fb03c41cce3802cb0d220529e6eef94e&quot;
        &quot;not-a-blob&quot;
      ],
      &quot;properties&quot; : [
        &quot;data:asText&quot;,
        &quot;digest:sha&quot;,
        &quot;size&quot;
      ]
    },
    &quot;R1&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;accountId&quot; : &quot;account1&quot;,
      &quot;ids&quot; : [
        &quot;Gc0854fb9fb03c41cce3802cb0d220529e6eef94e&quot;
      ],
      &quot;properties&quot; : [
        &quot;data:asText&quot;,
        &quot;data:asBase64&quot;,
        &quot;digest:sha&quot;,
        &quot;digest:sha-256&quot;,
        &quot;size&quot;
      ],
      &quot;offset&quot; : 4,
      &quot;length&quot; : 9
    },
    &quot;R2&quot;
  ]
]

Responses:

[
  [
    &quot;Blob/get&quot;,
    {
      &quot;accountId&quot;: &quot;account1&quot;,
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;Gc0854fb9fb03c41cce3802cb0d220529e6eef94e&quot;,
          &quot;data:asText&quot;: &quot;The quick brown fox jumped over the lazy dog.&quot;,
          &quot;digest:sha&quot;: &quot;wIVPufsDxBzOOALLDSIFKebu+U4=&quot;,
          &quot;size&quot;: 45
        }
      ],
      &quot;notFound&quot;: [
        &quot;not-a-blob&quot;
      ]
    },
    &quot;R1&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;accountId&quot;: &quot;account1&quot;,
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;Gc0854fb9fb03c41cce3802cb0d220529e6eef94e&quot;,
          &quot;data:asText&quot;: &quot;quick bro&quot;,
          &quot;digest:sha&quot;: &quot;QiRAPtfyX8K6tm1iOAtZ87Xj3Ww=&quot;,
          &quot;digest:sha-256&quot;: &quot;gdg9INW7lwHK6OQ9u0dwDz2ZY/gubi0En0xlFpKt0OA=&quot;,
          &quot;size&quot;: 45
        }
      ]
    },
    &quot;R2&quot;
  ]
]

</artwork>
</section>

<section anchor="blob-get-example-with-range-and-encoding-errors"><name>Blob/get example with range and encoding errors</name>
<t>The <tt>b1</tt> value is the text: &quot;The quick brown fox jumped over the \x81\x81 fox&quot;
which contains an invalid utf8 sequence.</t>
<t>The results have the following interesting properties:</t>

<ul>
<li><t>G1: defaults to <tt>data</tt> and <tt>size</tt> - so b1 returns <tt>isEncodingProblem</tt>
and a base64 value.</t>
</li>
<li><t>G2: since <tt>data:asText</tt> was explicitly selected, does not attempt to
return a value for the data, just <tt>isEncodingProblem</tt> for b1.</t>
</li>
<li><t>G3: since only <tt>data:asBase64</tt> was requested, there is no encoding
problem and both values are returned.</t>
</li>
<li><t>G4: since the requested range could be satisfied as text, both blobs
are returned as <tt>data:asText</tt> and there is no encoding problem.</t>
</li>
<li><t>G5: both blobs cannot satisfy the requested range, so isTruncated is
true for both.</t>
</li>
</ul>
<t>Note: some values have been wrapped for line length - there would be
no whitespace in the <tt>data:asBase64</tt> values on the wire</t>

<artwork>Method calls:

[
  [
    &quot;Blob/upload&quot;,
    {
      &quot;create&quot;: {
        &quot;b1&quot;: {
          &quot;data&quot;: [
            {
              &quot;data:asBase64&quot;: &quot;VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZW
                                Qgb3ZlciB0aGUggYEgZG9nLg==&quot;
            }
          ]
        },
        &quot;b2&quot;: {
          &quot;data&quot;: [
            {
              &quot;data:asText&quot;: &quot;hello world&quot;
            }
          ],
          &quot;type&quot; : &quot;text/plain&quot;
        }
      }
    },
    &quot;S1&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;ids&quot;: [
        &quot;#b1&quot;,
        &quot;#b2&quot;
      ]
    },
    &quot;G1&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;ids&quot;: [
        &quot;#b1&quot;,
        &quot;#b2&quot;
      ],
      &quot;properties&quot;: [
        &quot;data:asText&quot;,
        &quot;size&quot;
      ]
    },
    &quot;G2&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;ids&quot;: [
        &quot;#b1&quot;,
        &quot;#b2&quot;
      ],
      &quot;properties&quot;: [
        &quot;data:asBase64&quot;,
        &quot;size&quot;
      ]
    },
    &quot;G3&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;offset&quot;: 0,
      &quot;length&quot;: 5,
      &quot;ids&quot;: [
        &quot;#b1&quot;,
        &quot;#b2&quot;
      ]
    },
    &quot;G4&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;offset&quot;: 20,
      &quot;length&quot;: 100,
      &quot;ids&quot;: [
        &quot;#b1&quot;,
        &quot;#b2&quot;
      ]
    },
    &quot;G5&quot;
  ]
]

Responses:

[
  [
    &quot;Blob/upload&quot;,
    {
      &quot;oldState&quot;: null,
      &quot;created&quot;: {
        &quot;b2&quot;: {
          &quot;id&quot;: &quot;G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed&quot;,
          &quot;size&quot;: 11,
          &quot;type&quot;: &quot;application/octet-stream&quot;
        },
        &quot;b1&quot;: {
          &quot;id&quot;: &quot;G72cfa4804194563685d9a4b695f7ba20e7739576&quot;,
          &quot;size&quot;: 43,
          &quot;type&quot;: &quot;text/plain&quot;
        }
      },
      &quot;updated&quot;: null,
      &quot;destroyed&quot;: null,
      &quot;notCreated&quot;: null,
      &quot;notUpdated&quot;: null,
      &quot;notDestroyed&quot;: null,
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;S1&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;G72cfa4804194563685d9a4b695f7ba20e7739576&quot;,
          &quot;isEncodingProblem&quot;: true,
          &quot;data:asBase64&quot;: &quot;VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZW
                            Qgb3ZlciB0aGUggYEgZG9nLg==&quot;,
          &quot;size&quot;: 43
        },
        {
          &quot;id&quot;: &quot;G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed&quot;,
          &quot;data:asText&quot;: &quot;hello world&quot;,
          &quot;size&quot;: 11
        }
      ],
      &quot;notFound&quot;: [],
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;G1&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;G72cfa4804194563685d9a4b695f7ba20e7739576&quot;,
          &quot;isEncodingProblem&quot;: true,
          &quot;size&quot;: 43
        },
        {
          &quot;id&quot;: &quot;G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed&quot;,
          &quot;data:asText&quot;: &quot;hello world&quot;,
          &quot;size&quot;: 11
        }
      ],
      &quot;notFound&quot;: [],
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;G2&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;G72cfa4804194563685d9a4b695f7ba20e7739576&quot;,
          &quot;data:asBase64&quot;: &quot;VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZW
                            Qgb3ZlciB0aGUggYEgZG9nLg==&quot;,
          &quot;size&quot;: 43
        },
        {
          &quot;id&quot;: &quot;G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed&quot;,
          &quot;data:asBase64&quot;: &quot;aGVsbG8gd29ybGQ=&quot;,
          &quot;size&quot;: 11
        }
      ],
      &quot;notFound&quot;: [],
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;G3&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;G72cfa4804194563685d9a4b695f7ba20e7739576&quot;,
          &quot;data:asText&quot;: &quot;The q&quot;,
          &quot;size&quot;: 43
        },
        {
          &quot;id&quot;: &quot;G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed&quot;,
          &quot;data:asText&quot;: &quot;hello&quot;,
          &quot;size&quot;: 11
        }
      ],
      &quot;notFound&quot;: [],
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;G4&quot;
  ],
  [
    &quot;Blob/get&quot;,
    {
      &quot;list&quot;: [
        {
          &quot;id&quot;: &quot;G72cfa4804194563685d9a4b695f7ba20e7739576&quot;,
          &quot;isTruncated&quot;: true,
          &quot;isEncodingProblem&quot;: true,
          &quot;data:asBase64&quot;: &quot;anVtcGVkIG92ZXIgdGhlIIGBIGRvZy4=&quot;,
          &quot;size&quot;: 43
        },
        {
          &quot;id&quot;: &quot;G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed&quot;,
          &quot;isTruncated&quot;: true,
          &quot;data:asText&quot;: &quot;&quot;,
          &quot;size&quot;: 11
        }
      ],
      &quot;notFound&quot;: [],
      &quot;accountId&quot;: &quot;account1&quot;
    },
    &quot;G5&quot;
  ]
]
</artwork>
</section>
</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 type names to find the list of Ids within that data type
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><t>accountId: <tt>Id</tt></t>
<t>The id of the account used for the call.</t>
</li>
<li><t>typeNames: <tt>String[]</tt></t>
<t>A list of names from the &quot;JMAP Data Types&quot; registry.  Only names
for which &quot;Can reference blobs&quot; is true may be specified, and the
capability which defines each type must also be used by the overall
JMAP request in which this method is called.</t>
<t>If a type name is not known by the server, or the associated capability
has not been requested, then the server returns an &quot;unknownDataType&quot;
error.</t>
</li>
<li><t>ids: <tt>Id[]</tt></t>
<t>A list of blobId values to be looked for.</t>
</li>
</ul>
<t><strong>Response</strong></t>

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

<ul>
<li><t>id: <tt>Id</tt></t>
<t>The Blob Identifier.</t>
</li>
<li><t>matchedIds: <tt>String[Id[]]</tt></t>
<t>A map from type name to list of Ids of that data type (e.g. the name
&quot;Email&quot; maps to a list of emailIds)</t>
</li>
</ul>
<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 type name,
as it may not be able to know if other data types do reference that blob.</t>

<section anchor="blob-lookup-example"><name>Blob/lookup example</name>

<artwork>Method call:

[
  &quot;Blob/lookup&quot;,
  {
    &quot;typeNames&quot;: [
      &quot;Mailbox&quot;,
      &quot;Thread&quot;,
      &quot;Email&quot;
    ],
    &quot;ids&quot;: [
      &quot;Gd2f81008cf07d2425418f7f02a3ca63a8bc82003&quot;,
      &quot;not-a-blob&quot;
    ]
  },
  &quot;R1&quot;
]

Response:

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

<section anchor="security-considerations"><name>Security considerations</name>
<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 only return a null value
if <tt>data:asText</tt> is requested for a range of octets which is not valid UTF-8,
and set <tt>isEncodingProblem: true</tt>.</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 server might sometimes return all names empty rather than putting a
blobId in the notFound response to a Blob/get, then the server SHOULD
always return the same type of response, regardless of whether a blob
exists but the user can't access it, or doesn't exist at all.  This
avoids leaking information about the existence of the blob.</t>
<t>The server MUST NOT trust that the data given to a Blob/upload is a well formed
instance of the specified media type, and if the server attempts to parse
the given blob, only hardened parsers designed to deal with arbitrary untrusted
data should be used.  The server SHOULD NOT reject data on the grounds that
it is not a valid specimen of the stated type.</t>
<t>Blob/upload with carefully chosen data sources can be used to recreate dangerous
content on the far side of security scanners (anti-virus or exfiltration scanners
for example) which may be watching the upload endpoint.  Server implementations
SHOULD provide a hook to allow security scanners to check the resulting blob after
concatenating the data sources in the same way that they do for the upload endpoint.</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-data-types-registry"><name>Creation of &quot;JMAP Data Types&quot; Registry</name>
<t>IANA is requested to create a new registry &quot;JMAP Data Types&quot; with the initial content:</t>
<table>
<thead>
<tr>
<th>Type 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><t>This policy for this registry is &quot;Specification required&quot;, either an RFC or a simiarly
stable reference document which defines a JMAP Data Type and associated capability.</t>
<t>IANA is asked to appoint designated experts to review requests for additions to this
registry, with guidance to allow any registration which provides a stable document describing
the capability, and control over the URI namespace where the capability URI points.</t>
</section>
</section>

<section anchor="changes"><name>Changes</name>
<t>EDITOR: please remove this section before publication.</t>
<t>The source of this document exists on github at: <eref target="https://github.com/brong/draft-gondwana-jmap-blob/">https://github.com/brong/draft-gondwana-jmap-blob/</eref></t>
<t><strong>draft-ietf-jmap-blob-13</strong></t>

<ul spacing="compact">
<li>added examples of digest responses</li>
</ul>
<t><strong>draft-ietf-jmap-blob-12</strong></t>

<ul spacing="compact">
<li><t>updates based on Neil Jenkins' feedback:</t>

<ul spacing="compact">
<li>fixed [] positions for type specs</li>
<li>documented delta between /upload and /set better</li>
<li>allowed zero-length blobId sources</li>
<li>fixed examples with /set leftovers</li>
<li>documented datatypes registry policy</li>
</ul></li>
<li>added optional &quot;digest&quot; support</li>
</ul>
<t><strong>draft-ietf-jmap-blob-11</strong>:</t>

<ul spacing="compact">
<li><t>updates based on IETF113 feedback:</t>

<ul spacing="compact">
<li>added wording to suggest the a Blob/get of just size might be faster</li>
<li>added an example with just the size field being selected</li>
</ul></li>
</ul>
<t><strong>draft-ietf-jmap-blob-10</strong>:</t>

<ul spacing="compact">
<li>removed remaining references to <tt>catenate</tt>.</li>
</ul>
<t><strong>draft-ietf-jmap-blob-09</strong>:</t>

<ul spacing="compact">
<li>tidied up introduction text</li>
<li>replaced Blob/set with Blob/upload</li>
<li>made all upload creates take an array of sources to normalise behaviour at the cost of a slightly more
complex default case.</li>
</ul>
<t><strong>draft-ietf-jmap-blob-08</strong>:</t>

<ul spacing="compact">
<li>Fixed spelling of Neil's name in acknowledgements</li>
<li><t>Last call review (thanks Jim Fenton)</t>

<ul spacing="compact">
<li>fixed mmark sillyness causing RFC8620 to be non-normative in the references</li>
<li>clarified the capability object and accountCapability object requirements</li>
<li>made capability keys much more tightly defined, with mandatory minimum
catenate limit and default values.</li>
<li>increased use of normative language generally</li>
<li>lowercased 'blob' anywhere it wasn't explicitly the object</li>
<li>lowercased titles of the columns in the registry</li>
</ul></li>
</ul>
<t><strong>draft-ietf-jmap-blob-07</strong>:</t>

<ul spacing="compact">
<li>more examples to cover the interactions of offset, length and encoding checks.</li>
</ul>
<t><strong>draft-ietf-jmap-blob-06</strong>:</t>

<ul spacing="compact">
<li>removed asHex - we only need base64 and text</li>
<li>added reference to where base64 is defined</li>
<li>made 'destroy' not be allowed</li>
<li>expanded JSON examples for readability</li>
<li>removed 'expires' from examples</li>
</ul>
<t><strong>draft-ietf-jmap-blob-05</strong>:</t>

<ul spacing="compact">
<li>discovered I hadn't actually included <tt>typeNames</tt> and <tt>matchedIds</tt> anywhere except the
updates section, oops!</li>
<li>added a catenate example</li>
<li>tightened up some text</li>
</ul>
<t><strong>draft-ieft-jmap-blob-04</strong>:</t>

<ul spacing="compact">
<li>added security considerations for scanning <tt>catenate</tt> results</li>
</ul>
<t><strong>draft-ieft-jmap-blob-03</strong>:</t>

<ul spacing="compact">
<li>added capabilities object</li>
<li>renamed types to typeNames and matchedIds</li>
<li>added details of how to handle non-UTF8 data and truncation in Blob/get</li>
<li>added isTruncated and isEncodingProblem to Blob/get to tell the client
if the request wasn't entirely satisfied.</li>
</ul>
<t><strong>draft-ieft-jmap-blob-02</strong>:</t>

<ul spacing="compact">
<li>fixed incorrect RFC number in reference and HTTP PUT -&gt; POST, thanks Ken.</li>
<li>added acknowledgements section</li>
<li>removed all 'datatype' text and changed to 'data type' or 'type name' as
appropriate (issue #1 proposal)</li>
<li>expanded security considerations section and moved optional Blob/lookup
empty case into Blob/lookup section</li>
</ul>
<t><strong>draft-ieft-jmap-blob-01</strong>:</t>

<ul spacing="compact">
<li>renamed 'datatypes' to 'types' to align with PushSubscription from RFC8620.</li>
<li>added example for Blob/get</li>
<li>specified offset and length precisely</li>
</ul>
<t><strong>draft-ieft-jmap-blob-00</strong>:</t>

<ul spacing="compact">
<li>initial adoption as an IETF document, otherwise identical to draft-gondwana-jmap-blob-02</li>
</ul>
<t><strong>draft-gondwana-jmap-blob-02</strong></t>

<ul spacing="compact">
<li>renamed 'objects' to 'datatypes'</li>
<li>specified Blob/lookup</li>
<li>added IANA registry for datatypes</li>
</ul>
<t><strong>draft-gondwana-jmap-blob-01</strong></t>

<ul spacing="compact">
<li>added an example</li>
</ul>
<t><strong>draft-gondwana-jmap-blob-00</strong></t>

<ul spacing="compact">
<li>initial proposal</li>
</ul>
</section>

<section anchor="acknowledgements"><name>Acknowledgements</name>
<t>Joris Baum, Jim Fenton, Neil Jenkins, Alexey Melnikov, Ken Murchison, Robert Stepanek and
the JMAP working group at the IETF.</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.3230.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4648.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.8620.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.8621.xml"/>
</references>

</back>

</rfc>
