<?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-quotas-12" number="9425" submissionType="IETF" category="std" consensus="true" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" tocInclude="true" sortRefs="true" symRefs="true" updates="" obsoletes="">

<front>

<title abbrev="JMAP Quotas">JSON Meta Application Protocol (JMAP) for Quotas</title>
<seriesInfo name="RFC" value="9425"/>
<author role="editor" initials="R." surname="Cordier" fullname="René Cordier"><organization>Linagora Vietnam</organization>
<address><postal><street>5 Dien Bien Phu</street>
<city>Hanoi</city>
<code>10000</code>
<country>Vietnam</country>
</postal><email>rcordier@linagora.com</email>
<uri>https://linagora.vn</uri>
</address></author>
<date year="2023" month="June"></date>
<area>art</area>
<workgroup>jmap</workgroup>
<keyword>JMAP</keyword>
<keyword>JSON</keyword>
<keyword>email</keyword>
<keyword>quotas</keyword>

<abstract>
<t>This document specifies a data model for handling quotas on accounts with a server using the JSON Meta Application Protocol (JMAP).</t>
</abstract>

</front>

<middle>

<section anchor="introduction"><name>Introduction</name>
<t>The JSON Meta Application Protocol (JMAP) <xref target="RFC8620"/> is a
generic protocol for synchronizing data, such as mails, calendars, or contacts
between a client and a server. It is optimized 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 handling quotas over JMAP,
allowing a user to obtain details about a certain quota.</t>
<t>This specification does not address quota administration, which should be handled by other means.</t>

<section anchor="notational-conventions">
<name>Notational Conventions</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>Type signatures, examples, and property descriptions in this document
follow the conventions established in <xref target="RFC8620"
sectionFormat="of" section="1.1"></xref>. Data types defined in the core
specification are also used in this document.</t>
</section>

<section anchor="terminology"><name>Terminology</name>
<t>This document reuses the terminology from the core JMAP specification established in <xref target="RFC8620" sectionFormat="of" section="1.6"></xref>.</t>

<t>The term "Quota" (when capitalized) is used to refer to the data type
defined in <xref target="quota"/> and instance of that
data type.</t>
</section>
</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 one additional capability URI.</t>

<section anchor="urn-ietf-params-jmap-quota"><name>urn:ietf:params:jmap:quota</name>
<t>This represents support for the Quota data type and associated API methods. Servers supporting this specification <bcp14>MUST</bcp14> add a property called "urn:ietf:params:jmap:quota" to the capabilities object.</t>
<t>The value of this property is an empty object in both the JMAP Session capabilities property and an account's accountCapabilities property.</t>
</section>
</section>

<section anchor="sub-types-of-the-quota-data-type"><name>Sub-types of the Quota Data Type</name>
<t>There are two fields within the Quota data type, which have an enumerated set of possible values.  These are:</t>

<section anchor="scope"><name>Scope</name>
<t>The Scope data type is used to represent the entities the quota applies to. It is defined as a "String" with values from the following set:</t>

<ul>
  <li><t>account: The quota information applies to just the client's account.</t></li>
  <li><t>domain: The quota information applies to all accounts sharing this domain.</t></li>
  <li><t>global: The quota information applies to all accounts belonging to the server.</t></li>
</ul>
</section>

<section anchor="resourcetype"><name>ResourceType</name>
<t>The ResourceType data type is used to act as a unit of measure for the quota usage. It is defined as a "String" with values from the following set:</t>

<ul>
  <li><t>count: The quota is measured in a number of data type objects. For example, a
  quota can have a limit of 50 "Mail" objects.</t></li>

  <li><t>octets: The quota is measured in size (in octets). For example, a quota can have a limit of 25000 octets.</t></li>
</ul>
</section>
</section>

<section anchor="quota"><name>Quota</name>
<t>The Quota is an object that displays the limit set to an account usage. It then shows as well the current usage in regard to that limit.</t>

<section anchor="properties-of-the-quota-object"><name>Properties of the Quota Object</name>
<t>The Quota object <bcp14>MUST</bcp14> contain the following fields:</t>

<ul>
  <li><t>id: <tt>Id</tt></t>
  <t>The unique identifier for this object.</t></li>

  <li><t>resourceType: <tt>String</tt></t>
  <t>The resource type of the quota as defined in <xref
  target="resourcetype"></xref>.</t></li>

  <li><t>used: <tt>UnsignedInt</tt></t>
  <t>The current usage of the defined quota, using the "resourceType" defined as
  unit of measure.  Computation of this value is handled by the
  server.</t></li>

  <li><t>hardLimit: <tt>UnsignedInt</tt></t>
  <t>The hard limit set by this quota, using the "resourceType" defined as unit
  of measure. Objects in scope may not be created or updated if this limit is
  reached.</t></li>

  <li><t>scope: <tt>String</tt></t>
  <t>The "Scope" of this quota as defined in <xref
  target="scope"></xref>.</t></li>

  <li><t>name: <tt>String</tt></t>
  <t>The name of the quota. Useful for managing quotas and using queries for searching.</t></li>

  <li><t>types: <tt>String[]</tt></t>
  <t>A list of all the type names as defined in the "JMAP Types Names" registry (e.g., Email, Calendar, etc.) to which this quota applies.

  This allows the quotas to be assigned to distinct or shared data types.</t>
  <t>The server <bcp14>MUST</bcp14> filter out any types for which the client did not request the associated capability in the "using" section of the request.
  Further, the server <bcp14>MUST NOT</bcp14> return Quota objects for which there are no types recognized by the client.</t></li>
</ul>

<t>The Quota object <bcp14>MAY</bcp14> contain the following fields:</t>

<ul>
  <li><t>warnLimit: <tt>UnsignedInt|null</tt></t>
  <t>The warn limit set by this quota, using the "resourceType"
  defined as unit of measure.  It can be used to send a warning to an entity
  about to reach the hard limit soon, but with no action taken yet. If set, it
  <bcp14>SHOULD</bcp14> be lower than the "softLimit" (if present and
  different from null) and the "hardLimit".</t></li>

  <li><t>softLimit: <tt>UnsignedInt|null</tt></t>
  <t>The soft limit set by this quota, using the "resourceType" defined
  as unit of measure.  It can be used to still allow some operations but refuse
  some others. What is allowed or not is up to the server. For example, it could
  be used for blocking outgoing events of an entity (sending emails, creating
  calendar events, etc.) while still receiving incoming events (receiving emails,
  receiving calendars events, etc.). If set, it <bcp14>SHOULD</bcp14> be higher
  than the "warnLimit" (if present and different from null) but lower
  than the "hardLimit".</t></li>

  <li><t>description: <tt>String|null</tt></t>
  <t>Arbitrary, free, human-readable description of this quota. It might be used
  to explain where the different limits come from and explain the entities and
  data types this quota applies to. The description <bcp14>MUST</bcp14> be
  encoded in UTF-8 <xref target="RFC3629"/> as described in <xref
  target="RFC8620" sectionFormat="comma" section="1.5"/>, and selected based on an
  Accept-Language header in the request (as defined in <xref target="RFC9110"
  sectionFormat="comma" section="12.5.4"/>) or out-of-band information about the
  user's language or locale.</t></li>
</ul>

<t>The following JMAP methods are supported.</t>
</section>

<section anchor="quota-get"><name>Quota/get</name>
<t>Standard "/get" method as described in <xref target="RFC8620"
sectionFormat="comma" section="5.1"/>. The <em>id</em>'s argument may be "null"
to fetch all quotas of the account at once, as demonstrated in <xref target="fetching-quotas"/>.</t>
</section>

<section anchor="quota-changes"><name>Quota/changes</name>
<t>Standard "/changes" method as described in <xref target="RFC8620" sectionFormat="comma" section="5.2"/>, but with one extra argument in the response:</t>

<ul>
  <li><t>updatedProperties: <tt>String[]|null</tt></t>
  <t>If only the "used" Quota property has changed since the old
  state, this will be a list containing only that property. If the server is
  unable to tell if only "used" has changed, it <bcp14>MUST</bcp14> be
  null.</t></li>
</ul>

<t>Since "used" frequently changes, but other properties are generally only
changed rarely, the server can help the client optimize data transfer by
keeping track of changes to quota usage separate from other state changes. The
updatedProperties array may be used directly via a back-reference in a
subsequent Quota/get call in the same request, so only these properties are
returned if nothing else has changed.</t>
<t>Servers <bcp14>MAY</bcp14> decide to add other properties to the list that
they judge to be changing frequently.</t>
<t>This method's usage is demonstrated in <xref
target="requesting-latest-quota-changes"/>.</t>
</section>

<section anchor="quota-query"><name>Quota/query</name>
<t>This is a standard "/query" method as described in <xref target="RFC8620" sectionFormat="comma" section="5.5"/>.</t>
<t>A FilterCondition object has the following properties, any of which may be included or  omitted:</t>

<ul>
  <li><t>name: <tt>String</tt></t>
  <t>The Quota <em>name</em> property contains the given string.</t></li>

  <li><t>scope: <tt>String</tt></t>
  <t>The Quota <em>scope</em> property must match the given value exactly.</t></li>

  <li><t>resourceType: <tt>String</tt></t>
  <t>The Quota <em>resourceType</em> property must match the given value exactly.</t></li>

  <li><t>type: <tt>String</tt></t>
  <t>The Quota <em>types</em> property contains the given value.</t></li>
</ul>

<t>A Quota object matches the FilterCondition if, and only if, all the given conditions
match. If zero properties are specified, it is automatically true for all objects.</t>
<t>The following Quota properties <bcp14>MUST</bcp14> be supported for sorting:</t>

<ul spacing="normal">
<li>name</li>
<li>used</li>
</ul>
</section>

<section anchor="quota-querychanges"><name>Quota/queryChanges</name>
<t>This is a standard "/queryChanges" method as described in <xref target="RFC8620" sectionFormat="comma" section="5.6"/>.</t>
</section>
</section>

<section anchor="examples"><name>Examples</name>

<section anchor="fetching-quotas"><name>Fetching Quotas</name>
<t>Request fetching all quotas related to an account:</t>

<sourcecode type="json"><![CDATA[
[[ "Quota/get", {
  "accountId": "u33084183",
  "ids": null
}, "0" ]]
]]></sourcecode>

<t>With response:</t>

<sourcecode type="json"><![CDATA[
[[ "Quota/get", {
  "accountId": "u33084183",
  "state": "78540",
  "list": [{
    "id": "2a06df0d-9865-4e74-a92f-74dcc814270e",
    "resourceType": "count",
    "used": 1056,
    "warnLimit": 1600,
    "softLimit": 1800,
    "hardLimit": 2000,
    "scope": "account",
    "name": "bob@example.com",
    "description": "Personal account usage. When the soft limit is 
                    reached, the user is not allowed to send mails or 
                    create contacts and calendar events anymore.",
    "types" : [ "Mail", "Calendar", "Contact" ]
  }, {
    "id": "3b06df0e-3761-4s74-a92f-74dcc963501x",
    "resourceType": "octets",
    ...
  }, ...],
  "notFound": []
}, "0" ]]
]]></sourcecode>
</section>

<section anchor="requesting-latest-quota-changes"><name>Requesting Latest Quota Changes</name>
<t>Request fetching the changes for a specific quota:</t>

<sourcecode type="json"><![CDATA[
[[ "Quota/changes", {
  "accountId": "u33084183",
  "sinceState": "78540",
  "maxChanges": 20
}, "0" ],
[ "Quota/get", {
  "accountId": "u33084183",
  "#ids": {
    "resultOf": "0",
    "name": "Quota/changes",
    "path": "/updated"
  },
  "#properties": {
    "resultOf": "0",
    "name": "Quota/changes",
    "path": "/updatedProperties"
  }
}, "1" ]]
]]></sourcecode>

<t>With response:</t>

<sourcecode type="json"><![CDATA[
[[ "Quota/changes", {
  "accountId": "u33084183",
  "oldState": "78540",
  "newState": "78542",
  "hasMoreChanges": false,
  "updatedProperties": ["used"],
  "created": [],
  "updated": ["2a06df0d-9865-4e74-a92f-74dcc814270e"],
  "destroyed": []
}, "0" ],
[ "Quota/get", {
  "accountId": "u33084183",
  "state": "10826",
  "list": [{
    "id": "2a06df0d-9865-4e74-a92f-74dcc814270e",
    "used": 1246
  }],
  "notFound": []
}, "1" ]]
]]></sourcecode>
</section>
</section>

<section anchor="push"><name>Push</name>
<t>Servers <bcp14>MUST</bcp14> support the JMAP push mechanisms, as specified
in <xref target="RFC8620" sectionFormat="comma" section="7"/>, to allow
clients to receive notifications when the state changes for the Quota type
defined in this specification.</t>
</section>

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

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

<dl spacing="normal" newline="false">
<dt>Capability Name:</dt>
<dd>urn:ietf:params:jmap:quota</dd>
<dt>Reference:</dt>
<dd>RFC 9425</dd>
<dt>Intended Use:</dt>
<dd>common</dd>
<dt>Change Controller:</dt>
<dd>IETF</dd>
<dt>Security and Privacy Considerations:</dt>
<dd>RFC 9425, <xref target="security-considerations"></xref></dd>
</dl>
</section>

<section anchor="jmap-datatype-registration-for-quota"><name>JMAP Data Type Registration for "Quota"</name>
<t>IANA has registered the "Quota" Data Type as follows:</t>

<dl spacing="normal" newline="false">
<dt>Type Name:</dt>
<dd>Quota</dd>
<dt>Can Reference Blobs:</dt>
<dd>No</dd>
<dt>Can Use for State Change:</dt>
<dd>Yes</dd>
<dt>Capability:</dt>
<dd>urn:ietf:params:jmap:quota</dd>
<dt>Reference:</dt>
<dd>RFC 9425</dd>
</dl>
</section>
</section>

<section anchor="security-considerations"><name>Security Considerations</name>
<t>All security considerations of JMAP <xref target="RFC8620"/> apply to this
specification.</t>
<t>Implementors should be careful to make sure the implementation of the
extension specified in this document does not violate the site's security
policy. The resource usage of other users is likely to be considered
confidential information and should not be divulged to unauthorized
persons.</t>
<t>As for any resource shared across users (for example, a quota with the
"domain" or "global" scope), a user that can consume the resource can affect
the resources available to the other users. For example, a user could spam
themselves with events and make the shared resource hit the limit and unusable
for others (implementors could mitigate that with some rate-limiting
implementation on the server).</t>
<t>Also, revealing domain and global quota counts to all users may cause
privacy leakage of other sensitive data, or at least the existence of other
sensitive data. For example, some users are part of a private list belonging
to the server, so they shouldn't know how many users are in there. However, by
comparing the quota count before and after sending a message to the list, it
could reveal the number of people of the list, as the domain or global quota
count would go up by the number of people subscribed. In order to limit those
attacks, quotas with "domain" or "global" scope <bcp14>SHOULD</bcp14> only be
visible to server administrators and not to general users.</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.3629.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"/>
<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.9110.xml"/>
</references>

<section anchor="acknowledgements" numbered="false" toc="default">
<name>Acknowledgements</name>
<t>Thank you to <contact fullname="Michael Bailly"/>, who co-wrote the first
draft version of this document, before deciding to turn to other matters.</t>
<t>Thank you to <contact fullname="Benoit Tellier"/> for his constant help and
support on writing this document.</t>
<t>Thank you to <contact fullname="Raphael Ouazana"/> for sharing his own
experience on how to write an RFC after finalizing his own document: <xref
target="RFC9007"/>.</t>
<t>Thank you to <contact fullname="Bron Gondwana"/>, <contact fullname="Neil
Jenkins"/>, <contact fullname="Alexey Melnikov"/>, <contact fullname="Joris
Baum"/>, and the people from the IETF JMAP working group in general, who
helped with extensive discussions, reviews, and feedback.</t>
<t>Thank you to the people in the IETF organization, who took the time to
read, understand, comment, and give great feedback in the last rounds.</t>
</section>

</back>

</rfc>
