<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<?rfc strict="yes" ?>
<?rfc toc="yes"?>
<?rfc tocdepth="4"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes" ?>
<?rfc compact="yes" ?>
<?rfc subcompact="no" ?>
<?rfc private="Dovecot" ?>

<rfc category="std" docName="draft-ietf-extra-imap-inprogress-01"
     ipr="trust200902" consensus="true" submissionType="IETF"
     xml:lang="en" version="3" xmlns:xi="http://www.w3.org/2001/XInclude">

<front><!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<title abbrev="IMAP4 Response Code for Command Progress">
IMAP4 Response Code for Command Progress Notifications.
</title>
<seriesInfo name="Internet-Draft" value="draft-ietf-extra-imap-inprogress"/>

<author fullname="Marco Bettini" initials="M." surname="Bettini">
	<organization>Open-Xchange Oy</organization>
  <address>
    <postal>
      <street>Lars Sonckin kaari 10</street>
      <code>02600</code>
      <city>Espoo</city>
      <country>Finland</country>
    </postal>
    <email>marco.bettini@open-xchange.com</email>
  </address>
</author>

<date/>

<area>ART</area>
<workgroup>EXTRA</workgroup>
<keyword>IMAP</keyword>
<keyword>response code</keyword>

<abstract>
<t>
This document defines a new IMAP untagged response code, "INPROGRESS",
that provides structured numeric progress status indication for
long-running commands.
</t>
</abstract>

</front><!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<middle><!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<section title="Introduction">
<t>
Internet Message Access Protocol (IMAP) <xref target="RFC9051"/> commands
can require a considerable amount of time to be completed by the server.
In these cases, the client has no information about the progress of the
commands. It is already possible to expose updates with a generic untagged
response, like "* OK Still on it, 57% done"; however, this does not provide
a standard way to communicate with the client and allow it to inform the
user of the progress of the long-running actions.
</t>
<t>
This document extends the Internet Message Access Protocol (IMAP)
<xref target="RFC9051"/> with:
</t>
<ul>
<li>a new "INPROGRESS" response code <xref target="RFC5530"/>.
    The new response code provides consistent means for a client to receive
    progress update notifications on command completion status.</li>
<li>a new "INPROGRESS" capability <xref target="RFC9051"/>.
    The new capability informs the client that the server emits progress
    update notifications, via the "INPROGRESS" response code</li>
</ul>
</section>

<section title="Conventions Used in This Document">
<t>
"Conventions" are basic principles or procedures. Document conventions are
noted in this section.
</t>
<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 14
<xref target="RFC2119"/> <xref target="RFC8174"/>
when, and only when, they appear in all capitals, as shown here.
</t>
<t>
The word "can" (not "may") is used to refer to a possible
circumstance or situation, as opposed to an optional facility of the
protocol.
</t>
<t>
Conventions for notations are as in <xref target="RFC9051"/> and
<xref target="RFC5530"/>.
</t>
<t>
In examples, "C:" and "S:" indicate lines sent by the client and
server, respectively. Note that each line includes the terminating CRLF.
</t>
</section>

<section title="CAPABILITY Identification">
<t>
IMAP servers that support this extension <bcp14>MUST</bcp14> include
"INPROGRESS" in the response list to the CAPABILITY command.
</t>
</section>

<section title="The &quot;INPROGRESS&quot; Response Code">
<t>
The server <bcp14>MAY</bcp14> send the "INPROGRESS" Response Code to notify
the client about the progress of the commands in execution, or simply to
prevent the client from timing out and terminating the connection.
The notifications <bcp14>MAY</bcp14> be sent for any IMAP command.
If the server elects to send notifications, it is <bcp14>RECOMMENDED</bcp14>
that these are sent every 10...15 seconds.
</t>
<t>
The response code is meant to appear embedded inside an untagged OK reply.
The response code <bcp14>MUST NOT</bcp14> appear in a tagged response
(as that implies the command has completed and that no further progress
notifications are needed).
</t>

<t>
The response code <bcp14>MAY</bcp14> embed a list of details, composed
in order of:
</t>
<ol>
<li>CMD-TAG: the cmd-tag <xref target="RFC9051"/> that originated the
    long-running command. If the tag is not available, or if it contains "]"
    characters, it <bcp14>MUST</bcp14> be replaced by NIL</li>
<li>PROGRESS: a number indicating the number of items processed so far.
    If the PROGRESS is not available, both PROGRESS and GOAL <bcp14>MUST</bcp14>
    be replaced by NIL.
</li>
<li>GOAL: a number indicating the total number of items to be processed.
    This is the number that PROGRESS is expected to reach at the completion
    of the command. If the GOAL is not known, it <bcp14>MUST</bcp14> be
    replaced by NIL.</li>
</ol>
<t>
The server can provide the progress notifications details with different
degrees of completeness:
</t>
<sourcecode>
- bare keepalive
  * OK [INPROGRESS] Hang in there..
- keepalive with indication of the command tag
  * OK [INPROGRESS ("tag" NIL NIL)] Hang in there..
- progress indication with unknown GOAL
  * OK [INPROGRESS ("tag" 175 NIL)] Processed 175 items so far
- progress indication with the indication of the GOAL
  * OK [INPROGRESS ("tag" 175 1000)] Processed 17% of the items
</sourcecode>
<t>
Example:
</t>
<sourcecode>
  C: 001 search text very-long-to-complete
  ... time passes ...
  S: * OK [INPROGRESS ("001" 454 1000)] Processed 45% of the items
  ... time passes ...
  S: * OK [INPROGRESS ("001" 999 1000)] Processed 99% of the items
  ... time passes, but less than the threshold ...
  S: [...] actual results for the command
  S: 001 OK done
</sourcecode>

<t>
If all the details are NIL, the whole details section <bcp14>MAY</bcp14>
be omitted, i.e.:
</t>
<sourcecode>
* OK [INPROGRESS (NIL NIL NIL)] Working on it
</sourcecode>
<t>
can be replaced by:
</t>
<sourcecode>
* OK [INPROGRESS] Working on it
</sourcecode>

<t>
The cmd-tag detail <bcp14>MUST NOT</bcp14> contain "]". If that is the
case, the server <bcp14>MUST</bcp14> replace the cmd-tag with NIL.
This still produces a usable notification, unless multiple commands are
in flight simultaneously. A client can ensure to receive notifications with
cmd-tag(s) by simply refraining to embed the character "]" in the originating
command tags.
</t>
<t>
The PROGRESS number <bcp14>MUST</bcp14> be non-negative and
<bcp14>SHOULD</bcp14> be monotonically increasing.
</t>
<t>
The GOAL number <bcp14>MUST</bcp14> be positive when provided, and it
<bcp14>SHOULD NOT</bcp14> change between successive notifications for
the same command (i.e. for the same cmd-tag).
</t>
<t>
PROGRESS and GOAL <bcp14>SHOULD</bcp14> be counts of the kind of item
being processed - in most cases, message counts. If that is not possible,
the counts <bcp14>SHOULD</bcp14> be percentages (progress varies from 0
to 99 and goal stays fixed at 100). In this case, the numbers are suffixed
by "%" and the goal <bcp14>MUST</bcp14> be 100%.
</t>
<t>
The command is completed when PROGRESS equals GOAL. In this case, the
server <bcp14>SHOULD NOT</bcp14> send a progress notification but just
the proper command completion. If the command isn't completed yet,
PROGRESS <bcp14>MUST</bcp14> be strictly less than GOAL.
</t>
<t>
If the command completes before the first server interval, there will
be no notifications. The client <bcp14>MUST</bcp14> assume PROGRESS=0 and
GOAL unknown until the server issues a notification for the command.
</t>
<t>
While the server <bcp14>SHOULD</bcp14> keep GOAL constant and PROGRESS
monotonically increasing, there are circumstances where this might not
be possible. The client <bcp14>MUST</bcp14> be prepared to handle cases
where the server cannot keep GOAL constant and/or PROGRESS monotonically
increasing. When the GOAL changes or the PROGRESS goes backward, the
<bcp14>RECOMMENDED</bcp14> interpretation is that the previous GOAL has
been reached, but the server discovered that further (long-running) work
is required (either with known or unknown new GOAL),
</t>
<t>
The client <bcp14>MAY</bcp14> disregard progress notifications entirely or
process them only in relation with specific commands. If a UI is involved,
it is the client's duty to decide which of these commands are blocking on
the user experience, since this may differ based on implementation details.
</t>
<t>
Also, the client <bcp14>MUST NOT</bcp14> consider the values to be authoritative
for any other use than evaluating the progress of the commands progress.
E.g.: the client must not use the GOAL field in place of the proper output of a
SEARCH command to know the number of messages in a folder.
</t>
</section>

<section title="Formal Syntax">
<t>
The following syntax specification uses the Augmented Backus-Naur Form
(ABNF) <xref target="RFC5234"/> notation. Elements not defined here can
be found in the formal syntax of the ABNF <xref target="RFC5234"/>, IMAP
<xref target="RFC9051"/> and IMAP ABNF extension <xref target="RFC4466"/>
specifications.
</t>
<t>
Except as noted otherwise, all alphabetic characters are case-insensitive.
The use of uppercase or lowercase characters to define token strings are
for editorial clarity only. Implementations <bcp14>MUST</bcp14> accept
these strings in a case-insensitive fashion.
</t>
<sourcecode>
inprogress-tag        = quoted / nil
inprogress-state-unknown    = nil        SP nil
inprogress-state-counting   = number     SP nil
inprogress-state-known-goal = number     SP nz-number
inprogress-state-percentage = number "%" SP "100" "%"

inprogress-state = inprogress-state-unknown
                 / inprogress-state-counting
                 / inprogress-state-known-goal
                 / inprogress-state-percentage

resp-text-code =/ "INPROGRESS" [ SP "(" inprogress-tag SP
                                        inprogress-state ")" ]
</sourcecode>
</section>

<section title="Security Considerations">
<t>
The details of the response code are not expected to disclose any information
that isn't currently available from commands output. The progress details
could be obtained anyway by a series of sending commands with different
workloads - either by constructing data sets or searching in the appropriate
way into them.
</t>
<t>
The client must protect itself against data sent by a malicious server.
Specifically, the client should guard against values that can cause arithmetic
exceptions, like GOAL = 0, GOAL/VALUE &lt; 0, GOAL/VALUE &gt;= 2^32.
(these are not possible within a correct implementation of the ABNF syntax
above), and VALUE &gt; GOAL.
</t>
</section>

<section title="IANA Considerations">
<t>
   IANA is requested to add "INPROGRESS" to the "IMAP Response Codes" registry
   located at &lt;https://www.iana.org/assignments/imap-response-codes&gt;,
   with a reference to this document.
</t>
<t>
   IANA is requested to add "INPROGRESS" to the "IMAP Capabilities" registry
   located at &lt;https://www.iana.org/assignments/imap-capabilities&gt;,
   with a reference to this document.
</t>
</section>

</middle><!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<back><!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<references title="Normative References">
  <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml"/>
  <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4466.xml"/>
  <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.5234.xml"/>
  <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.5530.xml"/>
  <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8174.xml"/>
  <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.9051.xml"/>
</references>

<!--<references title="Informative References">

</references> -->
</back><!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

</rfc>
