<?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="0000" 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">JMAP for Quotas</title>
<seriesInfo name="RFC" value="0000"/>
<author role="editor" initials="R.C." 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="March"></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>JMAP (<xref target="RFC8620"></xref> <u format="char-num">-</u> JSON Meta Application Protocol) is a generic protocol for synchronising data, such as mails,
calendars or contacts, between a client and a server. It is optimised for mobile and web environments, and aims
to provide a consistent interface to different data types.</t>
<t>This specification defines a data model for 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 this document
in <xref target="quota"></xref> 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 datatype which have an enumerated set of possible values.  These are:</t>

<section anchor="scope"><name>Scope</name>
<t>The <strong>Scope</strong> 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>

<dl spacing="normal" newline="false">
<dt>account:</dt>
<dd>The Quota information applies to just the client's account</dd>
<dt>domain:</dt>
<dd>The Quota information applies to all accounts sharing this domain</dd>
<dt>global:</dt>
<dd>The Quota information applies to all accounts belonging to the server</dd>
</dl>
</section>

<section anchor="resourcetype"><name>ResourceType</name>
<t>The <strong>ResourceType</strong> 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>

<dl spacing="normal" newline="false">
<dt>count:</dt> 
<dd>The quota is measured in number of data type objects. For
example, a quota can have a limit of 50 "Mail" objects.</dd>
<dt>octets:</dt>
<dd>The quota is measured in size (in "octets"). For example, a quota can have a limit of 25000 "octets".</dd>
</dl>
</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>

<dl spacing="normal" newline="false">
<dt>id:</dt> 
<dd><t>"Id"</t>
<t>The unique identifier for this object.</t></dd>

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

<dt>used:</dt> 
<dd><t>"UnsignedInt"</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></dd>

<dt>hardLimit:</dt>
<dd><t>"UnsignedInt"</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></dd>

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

<dt>name:</dt>
<dd><t>"String"</t>
<t>The name of the quota object. Useful for managing quotas and using queries for searching.</t></dd>

<dt>types:</dt>
<dd><t>"String[]"</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 to assign quotas 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 recognised by the client.</t></dd>
</dl>

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

<dl spacing="normal" newline="false">
<dt>warnLimit:</dt>
<dd><t>"UnsignedInt|null"</t>
<t>The warn limit set by this quota object, 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></dd>

<dt>softLimit:</dt>
<dd><t>"UnsignedInt|null"</t>
<t>The soft limit set by this quota object, 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, ...) while still receiving incoming events (receiving emails,
receiving calendars events, ...). If set, it <bcp14>SHOULD</bcp14> be higher
than the "warnLimit" (if present and different from null) but lower
than the "hardLimit".</t></dd>

<dt>description:</dt>
<dd><t>"String|null"</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"></xref> as described in <xref
target="RFC8620" sectionFormat="comma" section="1.5"/>, 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/locale.</t></dd>
</dl>

<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>ids</em> argument may be "null"
to fetch all Quotas of the account at once, as demonstrated in this document
in <xref target="fetching-quotas"></xref>.</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>

<dl spacing="normal" newline="false">
<dt>updatedProperties:</dt>
<dd><t>"String[]|null"</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></dd>
</dl>

<t>Since "used" frequently changes but other properties are generally only changed rarely, the server can help the client
optimise 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 this document at <xref target="requesting-latest-quota-changes"></xref>.</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 <strong>FilterCondition</strong> object has the following properties, any of which may be included or  omitted:</t>

<dl spacing="normal" newline="false">
<dt>name:</dt>
<dd><t>"String"</t>
<t>The Quota <em>name</em> property contains the given string.</t></dd>

<dt>scope:</dt>
<dd><t>"String"</t>
<t>The Quota <em>scope</em> property must match the given value exactly.</t></dd>

<dt>resourceType:</dt>
<dd><t>"String"</t>
<t>The Quota <em>resourceType</em> property must match the given value exactly.</t></dd>

<dt>type:</dt>
<dd><t>"String"</t>
<t>The Quota <em>types</em> property contains the given value.</t></dd>
</dl>

<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="security-considerations"><name>Security considerations</name>
<t>All security considerations of JMAP (<xref target="RFC8620"></xref>) 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. But 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>

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

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

<dl spacing="normal" newline="false">
<dt>Capability Name:</dt>
<dd>"urn:ietf:params:jmap:quota"</dd>
<dt>Specification document:</dt>
<dd>this document</dd>
<dt>Intended use:</dt>
<dd>common</dd>
<dt>Change Controller:</dt>
<dd>IETF</dd>
<dt>Security and privacy considerations:</dt>
<dd>this document, <xref target="security-considerations"></xref>.</dd>
</dl>
</section>

<section anchor="jmap-datatype-registration-for-quota"><name>JMAP Datatype Registration for "Quota"</name>
<t>IANA will register the "Quota" Data Type as folows:</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>this document</dd>
</dl>
</section>
</section>

<section anchor="acknowledgements"><name>Acknowledgements</name>
<t>Thank you to <contact fullname="Michael Bailly"/>, that 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 a RFC after finalizing his own document, the <xref target="RFC9007"></xref>.</t>
<t>Thank you to <contact fullname="Bron Gondwana"/>, <contact fullname="Neil Jenkins"/>, <contact fullname="Alexei Melnikov"/>, <contact fullname="Joris Baum"/> and the people from the IETF JMAP working group in general
that helped with extensive discussions, reviews and feedbacks.</t>
<t>Thank you to the people in the IETF organization that took the time to read, understand, comment and give great feedbacks
in the last rounds.</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>

</back>

<!-- [rfced] Please review the "type" attribute of each sourcecode element
in the XML file to ensure correctness. If the current list of preferred
values for "type" (https://www.rfc-editor.org/materials/sourcecode-types.txt) 
does not contain an applicable type, then feel free to let us
know. Also, it is acceptable to leave the "type" attribute not
set.  
-->


</rfc>
