<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' []>
<rfc ipr="trust200902" category="std" docName="draft-ietf-jmap-quotas-03">
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc private=""?>
<?rfc topblock="yes"?>
<?rfc comments="no"?>
<front>
<title abbrev="JMAP Quotas">JMAP for Quotas</title>

<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>
<region></region>
</postal>
<phone></phone>
<email>rcordier@linagora.com</email>
<uri>https://linagora.vn</uri>
</address>
</author>
<date year="2022" month="February" day="7"/>

<area>Applications</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 JMAP.
</t>
</abstract>


</front>

<middle>

<section anchor="introduction" title="Introduction">
<t>JMAP (<xref target="RFC8620"/> – 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 you to read and explain quota information.
</t>
<t>This specification does not address quota administration, which should be handled by other means.
</t>

<section anchor="notational-conventions" title="Notational conventions">
<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 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 section 1.1
of <xref target="RFC8620"/>. Data types defined in the core specification are also used in this document.
</t>
<t>Servers MUST support all properties specified for the new data types defined in this document.
</t>
</section>

<section anchor="terminology" title="Terminology">
<t>The same terminology is used in this document as in the core JMAP specification.
</t>
<t>The term Quota (with that specific capitalization) is used to refer to the data type defined in this document and instance of that data type.
</t>
</section>

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

<section anchor="urnietfparamsjmapquota" title="urn::ietf::params::jmap::quota">
<t>This represents support for the Quota data type and associated API methods. Servers supporting this specification MUST 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="data-types" title="Data types">
<t>In addition to the standard JSON data types, a couple of additional data types are common to the definition of Quota objects and properties.
</t>

<section anchor="scope" title="Scope">
<t>The <spanx style="strong">Scope</spanx> is a <spanx style="verb">String</spanx> from an enumeration defined list of values, handled by the server.
</t>
<t>It explains the entities this value applies to. Values for the <spanx style="strong">Scope</spanx> are:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">account</spanx>: Applies for this account</t>
<t><spanx style="verb">domain</spanx>: All accounts of this domain share this part of the quota</t>
<t><spanx style="verb">global</spanx>: All accounts of this server share this part of the quota</t>
</list>
</t>
</section>

<section anchor="resourcetype" title="ResourceType">
<t>The <spanx style="strong">ResourceType</spanx> is a <spanx style="verb">String</spanx> from an enumeration defined list of values, handled by the server.
</t>
<t>A resource type is like an unit of measure for the quota usage. Values for the <spanx style="strong">ResourceType</spanx> are:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">count</spanx>: The quota is measured in number of data type objects. For example, a quota can have a limit of 50 <spanx style="verb">Mail</spanx> objects.</t>
<t><spanx style="verb">octets</spanx>: The quota is measured in size (in <spanx style="verb">octets</spanx>). For example, a quota can have a limit of 25000 <spanx style="verb">octets</spanx>.</t>
</list>
</t>
</section>
</section>

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

<section anchor="quota" title="Quota">
<t>The quota is an object that displays the limit set to an account usage as well as the current usage in regard to that limit.
</t>
<t>The quota object MUST contain the following fields:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">id</spanx>: <spanx style="verb">Id</spanx> The unique identifier for this object. It should respect the JMAP ID datatype defined in section 1.2 of <xref target="RFC8620"/></t>
<t><spanx style="strong">resourceType</spanx>: <spanx style="verb">ResourceType</spanx> The resource type of the quota.</t>
<t><spanx style="strong">used</spanx>: <spanx style="verb">UnsignedInt</spanx> The current usage of the defined quota. Computation of this value is handled by the server.</t>
<t><spanx style="strong">limit</spanx>: <spanx style="verb">UnsignedInt</spanx> The hard limit set by this quota. Objects in scope may not be created or updated if we reach this limit. It should be higher than the <spanx style="verb">warnLimit</spanx> and the <spanx style="verb">softLimit</spanx>.</t>
<t><spanx style="strong">scope</spanx>: <spanx style="verb">Scope</spanx> The <spanx style="verb">Scope</spanx> of this quota.</t>
<t><spanx style="strong">name</spanx>: <spanx style="verb">String</spanx> The name of the quota object. Useful for managing quotas and use queries for searching.</t>
<t><spanx style="strong">datatypes</spanx>: <spanx style="verb">String[]</spanx> A list of all the data types values that are applying to this quota. This allows to assign
quotas to separated or shared data types. This MAY include data types the client does not recognise. Clients MUST
ignore any unknown data type in the list.</t>
</list>
</t>
<t>The quota object MAY contain the following field:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">warnLimit</spanx>: <spanx style="verb">UnsignedInt|null</spanx> The warn limit set by this quota object. 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 should be lower than the
<spanx style="verb">softLimit</spanx> and the <spanx style="verb">limit</spanx>.</t>
<t><spanx style="strong">softLimit</spanx>: <spanx style="verb">UnsignedInt|null</spanx> The soft limit set by this quota object. It can be used to still allow some operations,
but refusing some others. What is allowed or not is up to the server. If set, it should be higher than the <spanx style="verb">warnLimit</spanx> but
lower than the <spanx style="verb">limit</spanx>.</t>
<t><spanx style="strong">description</spanx>: <spanx style="verb">String|null</spanx> Arbitrary free, human readable, description of this quota. Might be used to explain
where the limit comes from and explain the entities and data types this quota applies to.</t>
</list>
</t>

<section anchor="quotaget" title="Quota/get">
<t>Standard “/get” method as described in <xref target="RFC8620"/> section 5.1. The ids argument may be <spanx style="verb">null</spanx> to fetch all at once.
</t>
</section>

<section anchor="quotachanges" title="Quota/changes">
<t>Standard “/changes” method as described in <xref target="RFC8620"/> section 5.2 but with one extra argument to the response:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">updatedProperties</spanx>: <spanx style="verb">String[]|null</spanx> If only the “used” Quota properties has changed since the old state, this
will be the list of properties that may have changed. If the server is unable to tell if only &quot;used&quot; has changed, it
MUST just be null.</t>
</list>
</t>
<t>Since &quot;used&quot; 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 MAY decide to add other properties to the list that they judge changing frequently.
</t>
</section>

<section anchor="quotaquery" title="Quota/query">
<t>This is a standard “/query” method as described in <xref target="RFC8620"/>, Section 5.5.
</t>
<t>A <spanx style="strong">FilterCondition</spanx> object has the following properties, any of which may be omitted:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">name</spanx>: <spanx style="verb">String</spanx> The Quota <spanx style="emph">name</spanx> property contains the given string.</t>
<t><spanx style="strong">scopes</spanx>: <spanx style="verb">Scope[]</spanx> The Quota <spanx style="emph">scope</spanx> property must be in this list to match the condition.</t>
<t><spanx style="strong">resourceTypes</spanx>: <spanx style="verb">ResourceType[]</spanx> The Quota <spanx style="emph">resourceType</spanx> property must be in this list to match the condition.</t>
<t><spanx style="strong">datatypes</spanx>: <spanx style="verb">String[]</spanx> The Quota <spanx style="emph">datatypes</spanx> property must contain the elements in this list to match the condition.</t>
</list>
</t>
<t>A Quota object matches the FilterCondition if and only if all of the given conditions match. If zero properties are
specified, it is automatically true for all objects.
</t>
<t>The following Quota properties MUST be supported for sorting:
</t>
<t>
<list style="symbols">
<t><spanx style="strong">name</spanx></t>
<t><spanx style="strong">used</spanx></t>
</list>
</t>
</section>

<section anchor="quotaquerychanges" title="Quota/queryChanges">
<t>This is a standard “/queryChanges” method as described in <xref target="RFC8620"/>, Section 5.6.
</t>
</section>

<section anchor="examples" title="Examples">

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

<figure align="center"><artwork align="center">
[[ "Quota/get", {
  "accountId": "u33084183",
  "ids": null
}, "0" ]]
</artwork></figure>
<t>With response :
</t>

<figure align="center"><artwork align="center">
[[ "Quota/get", {
  "accountId": "u33084183",
  "state": "78540",
  "list": [{
    "id": "2a06df0d-9865-4e74-a92f-74dcc814270e",
    "resourceType": "count",
    "used": 1056,
    "warnLimit": 1600,
    "softLimit": 1800,
    "limit": 2000,
    "scope": "account",
    "name": "bob@example.com",
    "description": "Personal account usage",
    "datatypes" : [ "Mail", "Calendar", "Contact" ]
  }, {
    "id": "3b06df0e-3761-4s74-a92f-74dcc963501x",
    "resourceType": "size",
    ...
  }, ...],
  "notFound": []
}, "0" ]]
</artwork></figure>
</section>

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

<figure align="center"><artwork align="center">
[[ "Quota/changes", {
  "accountId": "u33084183",
  "sinceState": "10824",
  "maxChanges": 20
}, "0" ],
[ "Quota/get", {
  "accountId": "u33084183",
  "#ids": {
    "resultOf": "0",
    "name": "Quota/changes",
    "path": "/updated"
  },
  "#properties": {
    "resultOf": "0",
    "name": "Quota/changes",
    "path": "/updatedProperties"
  }
}, "1" ]]
</artwork></figure>
<t>With response:
</t>

<figure align="center"><artwork align="center">
[[ "Quota/changes", {
  "accountId": "u33084183",
  "oldState": "10824",
  "newState": "10826",
  "hasMoreChanges": false,
  "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" ]]
</artwork></figure>
</section>
</section>
</section>

<section anchor="security-considerations" title="Security considerations">
<t>All security considerations of JMAP (<xref target="RFC8620"/>) apply to this specification.
</t>
</section>

<section anchor="iana-considerations" title="IANA Considerations">

<section anchor="jmap-capability-registration-for-quota" title="JMAP Capability Registration for &quot;quota&quot;">
<t>IANA will register the &quot;quota&quot; JMAP Capability as follows:
</t>
<t>Capability Name: <spanx style="verb">urn:ietf:params:jmap:quota</spanx>
</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 4.
</t>
</section>
</section>

</middle>
<back>
<references title="Normative References">
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8620.xml"?>
</references>

</back>
</rfc>
