<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rfc [
 <!ENTITY nbsp    "&#160;">
 <!ENTITY zwsp   "&#8203;">
 <!ENTITY nbhy   "&#8209;">
 <!ENTITY wj     "&#8288;">
]> 

<rfc version="3" ipr="trust200902" docName="draft-ietf-jmap-blob-18" number="9404" submissionType="IETF" category="std" consensus="true" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" updates="8620" obsoletes=""
symRefs="true" sortRefs="true" tocInclude="true">

<front>

  <title abbrev="JMAP Blob">JSON Meta Application Protocol (JMAP) Blob Management Extension</title>
  <seriesInfo name="RFC" value="9404"/>
  <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>
	<region>VIC</region> 
	<code>3000</code>
	<country>Australia</country>
      </postal>
      <email>brong@fastmailteam.com</email>
      <uri>https://www.fastmail.com</uri>
  </address></author>

  <date year="2023" month="August"></date>
  <area>art</area>
  <workgroup>jmap</workgroup>
  <keyword>jmap</keyword>

  <abstract>
<t>The JSON Meta Application Protocol (JMAP) base protocol (RFC 8620) provides
the ability to upload and download arbitrary binary data via HTTP POST and GET
on a defined endpoint.  This binary data is called a "blob".</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 round trips.</t>
<t>Likewise, when fetching an object, it can be useful to also fetch the raw
content of that object without a separate round trip.</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>When JMAP is proxied through a system that applies additional
access restrictions, it can be useful to know which objects reference
any particular blob; 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 "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
    "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
    NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
    "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are
    to be interpreted as described in BCP&nbsp;14 <xref target="RFC2119"/>
    <xref target="RFC8174"/> 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 <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" sectionFormat="comma" section="2"></xref>.</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 presence of the capability <tt>urn:ietf:params:jmap:blob</tt> in the
accountCapabilities property of an account represents support for additional
API methods on the Blob datatype.  Servers that include the capability in one
or more accountCapabilities properties <bcp14>MUST</bcp14> also include the
property in the capabilities property.</t>

<t>The value of this property in the JMAP Session capabilities
property <bcp14>MUST</bcp14> be an empty object.</t>
<t>The value of this property in an account's accountCapabilities
property is an object that <bcp14>MUST</bcp14> contain the following information
on server capabilities and permissions for that account:</t>

<ul>
  <li><t>maxSizeBlobSet: "UnsignedInt|null"</t>
  <t>The maximum size of the blob (in octets) that the server will
  allow to be created (including blobs created by concatenating multiple data
  sources together).</t>
  <t>Clients <bcp14>MUST NOT</bcp14> attempt to create blobs larger than this
  size.</t>

  <t>If this value is <tt>null</tt>, then clients are not required to limit
  the size of the 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: "UnsignedInt"</t>
  <t>The maximum number of DataSourceObjects allowed per creation in a
  Blob/upload.</t>
  <t>Servers <bcp14>MUST</bcp14> allow at least 64 DataSourceObjects per
  creation.</t></li>
  <li><t>supportedTypeNames: "String[]"</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 will be the empty list.</t>
  <t>Note that the supportedTypeNames list may include private types that are not
  in the "JMAP Data Types" registry defined by this document.  Clients
  <bcp14>MUST</bcp14> ignore type names they do not recognise.</t></li>
  <li><t>supportedDigestAlgorithms: "String[]"</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 will be the empty list.  Algorithms in this list
  <bcp14>MUST</bcp14> be present in the "HTTP Digest Algorithm Values"
  registry defined by <xref target="RFC3230"></xref>; however, in JMAP, they
  must be lowercased, e.g., "md5" rather than "MD5".</t>
  <t>Clients <bcp14>SHOULD</bcp14> prefer algorithms listed earlier in this
  list.</t></li>
</ul>

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

<sourcecode type="json"><![CDATA[{
  "capabilities": {
    ...,
    "urn:ietf:params:jmap:blob": {}
  },
  "accounts": {
    "A13842": {
      ...
      "accountCapabilities": {
        "urn:ietf:params:jmap:blob": {
          "maxSizeBlobSet": 50000000,
          "maxDataSources": 100,
          "supportedTypeNames" : [
            "Mailbox",
            "Thread",
            "Email"
          ],
          "supportedDigestAlgorithms" : [
            "sha",
            "sha-256"
          ]
        }
      }
    }
  }
}]]></sourcecode>


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

<section anchor="blob-methods"><name>Blob Methods</name>
<t>A blob is a sequence of zero or more octets.</t>
<t>JMAP <xref target="RFC8620" format="default"/> defines the
<tt>Blob/copy</tt> method, which is unchanged by this specification 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 in <xref target="RFC8620"></xref> in some
ways. However, blobs cannot be updated or deleted, so only <tt>create</tt> is
allowed in the method call. Also, blobs do not 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: "Id"</t>
  <t>The id of the account in which the blobs will be created.</t></li>
  <li><t>create: "Id[UploadObject]"</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 <xref target="RFC8620" format="default"/>, with <tt>created</tt> and <tt>notCreated</tt> objects
mapping from the creation id.</t>
<t>The <tt>created</tt> objects contain:</t>

<ul>
  <li><t>id: "Id"</t>
  <t>The blobId that was created.</t></li>
  <li><t>type: "String|null"</t>
  <t>The media type as given in the creation (if any). If not provided, the
  server <bcp14>MAY</bcp14> perform content analysis and return one of the
  following: the calculated value, "application/octet-string", or
  null.</t></li>
  <li><t>size: "UnsignedInt"</t>
  <t>As per <xref target="RFC8620" format="default"/>, the size of the
  created blob in octets.</t></li>
</ul>

   <t>The created objects will also contain any other properties identical to
   those that would be returned in the JSON response of the upload endpoint
   described in <xref target="RFC8620" format="default"/>.  This may be
   extended in the future; in this document, it is anticipated that
   implementations will extend both the upload endpoint and the Blob/upload
   responses in the same way.</t>

<t>If there is a problem with a creation, then the server will return a
<tt>notCreated</tt> response with a map from the failed creation id to a
<tt>SetError</tt> object.</t>
<t>For each successful upload, servers <bcp14>MUST</bcp14> add an entry to the
<tt>createdIds</tt> map (<xref target="RFC8620" sectionFormat="comma"
section="3.3"/>) for the request; even if the caller did not explicitly pass a
createdIds, the value must be available to later methods defined in the same
Request Object. This allows the blobId to be used via back-reference in
subsequent method calls.</t>
<t>The created blob will have the same lifetime and same expiry semantics as
any other binary object created via the mechanism specified in <xref
target="RFC8620" sectionFormat="comma" section="6"/>.</t>

<t>Uploads using this mechanism will be restricted by the maxUploadSize limit
for JMAP requests specified by the server, and clients <bcp14>SHOULD</bcp14>
consider using the upload mechanism defined by <xref target="RFC8620"
format="default"/> for blobs larger than a megabyte.</t>

<t><strong>UploadObject</strong></t>

<ul>
  <li><t>data: "DataSourceObject[]"</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 in
  order to create the blob.</t></li>
  <li><t>type: "String|null" (default: null)</t>
  <t>A hint for media type of the data.</t></li>
</ul>

<t><strong>DataSourceObject</strong></t>
<t>Exactly one of:</t>

<ul spacing="normal">
  <li><t>data:asText: "String|null" (raw octets, must be UTF-8)</t>
</li>
<li><t>data:asBase64: "String|null" (base64 representation of octets)</t>
</li>
</ul>

<t>or a blobId source:</t>

<ul spacing="normal">
<li><t>blobId: "Id"</t>
</li>
<li><t>offset: "UnsignedInt|null" (<bcp14>MAY</bcp14> be zero)</t>
</li>
<li><t>length: "UnsignedInt|null" (<bcp14>MAY</bcp14> 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 cannot be fully satisfied (i.e., it 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 <bcp14>MUST NOT</bcp14> guess the user's intent
and <bcp14>MUST</bcp14> 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 <bcp14>MUST</bcp14> result in a notCreated response.</t>
<t>It is envisaged that the definition for DataSourceObject might be
extended in the future, for example, to fetch external content.</t>
<t>A server <bcp14>MUST</bcp14> accept at least 64 DataSourceObjects per create, as
described in <xref target="urn-ietf-params-jmap-blob" format="default"/> 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, the entire data:asBase64 field would be sent as a continuous
string with no wrapping on the wire.</t>

<t>Method Call:</t>

<sourcecode type="json"><![CDATA[
[
 "Blob/upload",
 {
  "accountId": "account1",
  "create": {
   "1": {
    "data" : [
    {
     "data:asBase64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKA
                       AAAA1BMVEX/AAAZ4gk3AAAAAXRSTlN/gFy0ywAAAApJRE
                       FUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII="
    }
   ],
   "type": "image/png"
   }
  }
 },
 "R1"
]]]></sourcecode>


<t>Response:</t>


<sourcecode type="json"><![CDATA[[
  "Blob/upload",
  {
    "accountId" : "account1",
    "created" : {
      "1": {
        "id" : "G4c6751edf9dd6903ff54b792e432fba781271beb",
        "type" : "image/png",
        "size" : 95
      }
    }
  },
  "R1"
]]]></sourcecode>


</section>

<section anchor="blob-upload-complex-example"><name>Blob/upload Complex Example</name>

<t>Method Calls:</t>


<sourcecode type="json"><![CDATA[
[
 [
  "Blob/upload",
  {
   "create": {
    "b4": {
     "data": [
      {
       "data:asText": "The quick brown fox jumped over the lazy dog."
      }
    ]
   }
  }
 },
 "S4"
],
[
  "Blob/upload",
  {
   "create": {
     "cat": {
       "data": [
         {
           "data:asText": "How"
         },
         {
           "blobId": "#b4",
           "length": 7,
           "offset": 3
         },
         {
           "data:asText": "was t"
         },
         {
           "blobId": "#b4",
           "length": 1,
           "offset": 1
         },
         {
           "data:asBase64": "YXQ/"
         }
       ]
     }
   }
  },
  "CAT"
],
[
  "Blob/get",
  {
   "properties": [
     "data:asText",
     "size"
   ],
   "ids": [
     "#cat"
   ]
  },
  "G4"
 ]
]]]></sourcecode>


<t>Responses:</t>

<sourcecode type="json"><![CDATA[[
  [
    "Blob/upload",
    {
      "oldState": null,
      "created": {
        "b4": {
          "id": "Gc0854fb9fb03c41cce3802cb0d220529e6eef94e",
          "size": 45,
          "type": "application/octet-stream"
        }
      },
      "notCreated": null,
      "accountId": "account1"
    },
    "S4"
  ],
  [
    "Blob/upload",
    {
      "oldState": null,
      "created": {
        "cat": {
          "id": "Gcc60576f036321ae6e8037ffc56bdee589bd3e23",
          "size": 19,
          "type": "application/octet-stream"
        }
      },
      "notCreated": null,
      "accountId": "account1"
    },
    "CAT"
  ],
  [
    "Blob/get",
    {
      "list": [
        {
          "id": "Gcc60576f036321ae6e8037ffc56bdee589bd3e23",
          "data:asText": "How quick was that?",
          "size": 19
        }
      ],
      "notFound": [],
      "accountId": "account1"
    },
    "G4"
  ]
]]]></sourcecode>


</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: "UnsignedInt|null"</t>
  <t>Start this many octets into the blob data.  If null or unspecified, this
  defaults to zero.</t></li>
  <li><t>length: "UnsignedInt|null"</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="normal">
<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, the properties default to <tt>data</tt> and <tt>size</tt>.</t>

<t><strong>Result Properties:</strong></t>

<ul>
  <li><t>data:asText: "String|null"</t>
  <t>The raw octets of the selected range if they are valid UTF-8; otherwise,
  null.</t></li>
  <li><t>data:asBase64: "String"</t>
  <t>The base64 encoding of the octets in the selected range.</t></li>
  <li><t>digest:&lt;algorithm&gt;: "String"</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: "Boolean" (default: false)</t></li>
  <li><t>isTruncated: "Boolean" (default: false)</t></li>
  <li><t>size: "UnsignedInt"</t>
  <t>The number of octets in the entire blob.</t></li>
</ul>

<t>The size value <bcp14>MUST</bcp14> 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>
<bcp14>MUST</bcp14> be set to <tt>true</tt>, and the <tt>data:asText</tt> response value <bcp14>MUST</bcp14> 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> <bcp14>MUST</bcp14> 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 isTruncated
property in the result <bcp14>MUST</bcp14> 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 <bcp14>SHOULD</bcp14> store the size for blobs in a format that is
efficient to read, and clients <bcp14>SHOULD</bcp14> 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>In this example, a blob containing the string "The quick brown fox jumped over
the lazy dog." has blobId <tt>Gc0854fb9fb03c41cce3802cb0d220529e6eef94e</tt>.</t>
<t>The first method call requests just the size for multiple blobs, and
the second requests both the size and a short range of the data for one
of the blobs.</t>

<t>Method Calls:</t>

<sourcecode type="json"><![CDATA[[
  [
    "Blob/get",
    {
      "accountId" : "account1",
      "ids" : [
        "Gc0854fb9fb03c41cce3802cb0d220529e6eef94e",
        "not-a-blob"
      ],
      "properties" : [
        "data:asText",
        "digest:sha",
        "size"
      ]
    },
    "R1"
  ],
  [
    "Blob/get",
    {
      "accountId" : "account1",
      "ids" : [
        "Gc0854fb9fb03c41cce3802cb0d220529e6eef94e"
      ],
      "properties" : [
        "data:asText",
        "digest:sha",
        "digest:sha-256",
        "size"
      ],
      "offset" : 4,
      "length" : 9
    },
    "R2"
  ]
]]]></sourcecode>

<t>Responses:</t>

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

</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 "The quick brown fox jumped over the \x81\x81 dog.", which contains an invalid UTF-8 sequence.</t>
<t>The results have the following 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>
<aside><t>Note: Some values have been wrapped for line length. There would be
no wrapping in the <tt>data:asBase64</tt> values on the wire.</t></aside>

<t>Method Calls:</t>

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

<t>Responses:</t>

<sourcecode type="json"><![CDATA[[
  [
    "Blob/upload",
    {
      "oldState": null,
      "created": {
        "b2": {
          "id": "G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
          "size": 11,
          "type": "application/octet-stream"
        },
        "b1": {
          "id": "G72cfa4804194563685d9a4b695f7ba20e7739576",
          "size": 43,
          "type": "text/plain"
        }
      },
      "updated": null,
      "destroyed": null,
      "notCreated": null,
      "notUpdated": null,
      "notDestroyed": null,
      "accountId": "account1"
    },
    "S1"
  ],
  [
    "Blob/get",
    {
      "list": [
        {
          "id": "G72cfa4804194563685d9a4b695f7ba20e7739576",
          "isEncodingProblem": true,
          "data:asBase64": "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZW
                            Qgb3ZlciB0aGUggYEgZG9nLg==",
          "size": 43
        },
        {
          "id": "G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
          "data:asText": "hello world",
          "size": 11
        }
      ],
      "notFound": [],
      "accountId": "account1"
    },
    "G1"
  ],
  [
    "Blob/get",
    {
      "list": [
        {
          "id": "G72cfa4804194563685d9a4b695f7ba20e7739576",
          "isEncodingProblem": true,
          "size": 43
        },
        {
          "id": "G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
          "data:asText": "hello world",
          "size": 11
        }
      ],
      "notFound": [],
      "accountId": "account1"
    },
    "G2"
  ],
  [
    "Blob/get",
    {
      "list": [
        {
          "id": "G72cfa4804194563685d9a4b695f7ba20e7739576",
          "data:asBase64": "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZW
                            Qgb3ZlciB0aGUggYEgZG9nLg==",
          "size": 43
        },
        {
          "id": "G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
          "data:asBase64": "aGVsbG8gd29ybGQ=",
          "size": 11
        }
      ],
      "notFound": [],
      "accountId": "account1"
    },
    "G3"
  ],
  [
    "Blob/get",
    {
      "list": [
        {
          "id": "G72cfa4804194563685d9a4b695f7ba20e7739576",
          "data:asText": "The q",
          "size": 43
        },
        {
          "id": "G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
          "data:asText": "hello",
          "size": 11
        }
      ],
      "notFound": [],
      "accountId": "account1"
    },
    "G4"
  ],
  [
    "Blob/get",
    {
      "list": [
        {
          "id": "G72cfa4804194563685d9a4b695f7ba20e7739576",
          "isTruncated": true,
          "isEncodingProblem": true,
          "data:asBase64": "anVtcGVkIG92ZXIgdGhlIIGBIGRvZy4=",
          "size": 43
        },
        {
          "id": "G2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
          "isTruncated": true,
          "data:asText": "",
          "size": 11
        }
      ],
      "notFound": [],
      "accountId": "account1"
    },
    "G5"
  ]
]]]></sourcecode>

</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
that reference the provided blob.</t>
<t>Since different datatypes will have different semantics of "contains",
the definition of "reference" is somewhat loose but roughly
means "you could discover this blobId by looking at this object or
at other objects recursively contained within this object".</t>
<t>For example, with a server that supports <xref target="RFC8621"
format="default"/>, if a Mailbox references a blob and if any Emails
within that Mailbox reference the blobId, then the Mailbox references that
blobId.  For any Thread that references an Email that references a blobId, it
can be said that the Thread references the blobId.</t>
<t>However, this does not mean that if an Email references a Mailbox in its
mailboxIds property, then any blobId referenced by other Emails in
that Mailbox are also referenced by the initial Email.</t>
<t><strong>Parameters</strong></t>

<ul>
<li><t>accountId: "Id"</t>
<t>The id of the account used for the call.</t>
</li>
<li><t>typeNames: "String[]"</t>
<t>A list of names from the "JMAP Data Types" registry or defined by
private extensions that the client has requested.  Only names
for which "Can reference blobs" is true may be specified, and the
capability that 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 "unknownDataType"
error.</t>
</li>
<li><t>ids: "Id[]"</t>
<t>A list of blobId values to be looked for.</t>
</li>
</ul>
<t><strong>Response</strong></t>

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

<ul>
<li><t>id: "Id"</t>
<t>The blobId.</t>
</li>
<li><t>matchedIds: "String[Id[]]"</t>
<t>A map from type name to a list of Ids of that data type (e.g., the name
"Email" maps to a list of emailIds).</t>
</li>
</ul>
<t>If a blob is not visible to a user or does not exist on the server at all,
then the server <bcp14>MUST</bcp14> still return an empty array for each type
as this doesn't leak any information about whether the blob is on the server
but not visible to the requesting user.</t>

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

<t>Method Call:</t>

<sourcecode type="json"><![CDATA[[
  "Blob/lookup",
  {
    "typeNames": [
      "Mailbox",
      "Thread",
      "Email"
    ],
    "ids": [
      "Gd2f81008cf07d2425418f7f02a3ca63a8bc82003",
      "not-a-blob"
    ]
  },
  "R1"
]]]></sourcecode>

<t>Response:</t>

<sourcecode type="json"><![CDATA[[
  "Blob/lookup",
  {
    "list": [
      {
        "id": "Gd2f81008cf07d2425418f7f02a3ca63a8bc82003",
        "matchedIds": {
          "Mailbox": [
            "M54e97373",
            "Mcbe6b662"
          ],
          "Thread": [
            "T1530616e"
          ],
          "Email": [
            "E16e70a73eb4",
            "E84b0930cf16"
          ]
        }
      }
    ],
    "notFound": [
      "not-a-blob"
    ]
  },
  "R1"
]]]></sourcecode>

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

<section anchor="security-considerations"><name>Security Considerations</name>
<t>All security considerations for JMAP <xref target="RFC8620"></xref> apply to this specification.
Additional considerations specific to the data types and functionality
introduced by this document are described here.</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
<bcp14>MUST</bcp14> only return a null value if <tt>data:asText</tt> is
requested for a range of octets that is not valid UTF-8 and set
<tt>isEncodingProblem: true</tt>.</t>
<t>Servers <bcp14>MUST</bcp14> apply any access controls, such that if the authenticated user would
be unable to discover the blobId by making queries, then this fact cannot be
discovered via a Blob/lookup.  For example, if an Email exists in a Mailbox that
the authenticated user does not have access to see, then that emailId <bcp14>MUST NOT</bcp14> be
returned in a lookup for a blob that is referenced by that email.</t>
<t>The server <bcp14>MUST NOT</bcp14> trust that the data given to a
Blob/upload is a well-formed instance of the specified media type. Also, if
the server attempts to parse the given blob, only hardened parsers designed to
deal with arbitrary untrusted data should be used.  The server <bcp14>SHOULD
NOT</bcp14> reject data on the grounds that it is not a valid specimen of the
stated type.</t>
<t>With carefully chosen data sources, Blob/upload can be used to recreate
dangerous content on the far side of security scanners (anti-virus or
exfiltration scanners, for example) that may be watching the upload endpoint.
Server implementations <bcp14>SHOULD</bcp14> 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>
<t>Digest algorithms can be expensive for servers to calculate.  Servers that
share resources between multiple users should track resource usage by clients
and rate-limit expensive operations to avoid resource starvation.</t>
</section>

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

<section anchor="jmap-capability-registration-for-blob"><name>JMAP Capability Registration for "blob"</name>
<t>IANA has registered the "blob" JMAP capability as follows:</t>

<dl newline="false" spacing="compact">
  <dt>Capability Name:</dt> <dd>urn:ietf:params:jmap:blob</dd>
  <dt>Specification document:</dt> <dd>RFC 9404</dd>
  <dt>Intended use:</dt> <dd>common</dd>
  <dt>Change Controller:</dt> <dd>IETF</dd>
  <dt>Security and privacy considerations:</dt> <dd>RFC 9404, <xref
  target="security-considerations" format="default"/></dd>
</dl>

</section>

<section anchor="jmap-error-codes-registration-for-unknowndatatype"><name>JMAP Error Codes Registration for "unknownDataType"</name>
<t>IANA has registered the "unknownDataType" JMAP error code as follows:</t>

<dl newline="false" spacing="compact">
  <dt>JMAP Error Code:</dt> <dd>unknownDataType</dd>
  <dt>Intended use:</dt> <dd>common</dd>
  <dt>Change Controller:</dt> <dd>IETF</dd>
  <dt>Reference:</dt> <dd>RFC 9404</dd>
  <dt>Description:</dt> <dd>The server does not recognise this data type, or
  the capability to enable it is not present in the current Request
  Object.</dd>
</dl>
</section>

<section anchor="creation-of-jmap-data-types-registry"><name>Creation of "JMAP Data Types" Registry</name>
<t>IANA has created a new registry called "JMAP Data Types".  <xref
target="ianatable" format="default"/> shows the initial contents of this
new registry.</t>
<table anchor="ianatable">
<thead>
<tr>
<th>Type Name</th>
<th>Can Ref 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:&zwsp;submission</td>
<td><xref target="RFC8621"></xref></td>
</tr>

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

<tr>
<td>VacationResponse</td>
<td>No</td>
<td>Yes</td>
<td>urn:ietf:params:jmap:&zwsp;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><xref target="RFC9007"></xref></td>
</tr>
</tbody>
</table>

<t>The registration policy for this registry is "Specification Required" <xref target="RFC8126"></xref>. Either an RFC or a similarly stable reference document defines a JMAP Data Type
and associated capability.</t>
<t>IANA will appoint designated experts to review requests for additions to this
registry, with guidance to allow any registration that provides a stable document describing
the capability and control over the URI namespace to which the capability URI points.</t>
</section>
</section>

</middle>

<back>
<references><name>References</name>
<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"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9007.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8126.xml"/>
</references>
</references>

<section anchor="acknowledgements" numbered="false" toc="default">
<name>Acknowledgements</name>
<t><contact fullname="Joris Baum"/>, <contact fullname="Jim Fenton"/>, <contact fullname="Neil Jenkins"/>, <contact fullname="Alexey Melnikov"/>, <contact fullname="Ken Murchison"/>, <contact fullname="Robert Stepanek"/>, and
the JMAP Working Group in the IETF.</t>
</section>

</back>

</rfc>
