<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Inbox</title>
  <abstract>This specification proposes a mechanism by which clients can find a list of ongoing conversations and their state.</abstract>
  
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.</permissions>
<warranty>## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##</warranty>
<liability>In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.</liability>
<conformance>This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
  <number>0430</number>
  <status>Deferred</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0313</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>inbox</shortname>
  
    <author>
      <firstname>Dave</firstname>
      <surname>Cridland</surname>
      <email>dave@hellopando.com</email>
      <jid>dwd@dave.cridland.net</jid>
    </author>

  <revision>
    <version>0.2.0</version>
    <date>2020-02-03</date>
    <initials>dwd</initials>
    <remark>Updates from the Summit 24 discussion:
      <ul>
        <li>Remove Marked</li>
        <li>Metadata in sibling</li>
        <li>Ensure the last "mam id" is present in metadata, and describe how that can be used.</li>
        <li>Add options to control unread-only and elide messages.</li>
      </ul>
    </remark>
  </revision>
  <revision>
    <version>0.1.0</version>
    <date>2020-01-29</date>
    <initials>XEP Editor (jsc)</initials>
    <remark>Accepted by vote of Council on 2020-01-22.</remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2019-12-30</date>
    <initials>dwd</initials>
    <remark>
      <ul>
        <li>Initial Revision</li>
      </ul>
    </remark>
  </revision>
</header>

<section1 topic="Introduction" anchor="intro">
  <p>When initially run, a messaging client typically shows some list of contacts and chatrooms, and whether any new
    messages are present in each.</p>
  <p>The current mechanism for achieving this UX involves a complete synchronization of the server-side archive, and is both
    time-consuming and bandwidth-intensive. This specification proposes a solution to directly obtain such data from
    the server.</p>
  <p>Moreover, the information gathered by the server to support this can be used in support of mobile push notifications.</p>
  <section2 topic="Terminology">
    <p>Nomenclature used for instant messages versus ancillary messages will need to be adjusted to make it consistent
      with <span class="ref"><link url="https://xmpp.org/extensions/xep-0422.html">Message Fastening (XEP-0422)</link></span> <note>XEP-0422: Message Fastening &lt;<link url="https://xmpp.org/extensions/xep-0422.html">https://xmpp.org/extensions/xep-0422.html</link>&gt;.</note> et al.</p>
  </section2>
</section1>

<section1 topic="Overview" anchor="overview">
  <section2 topic="Discovering Support" anchor="feature">
    <p>Support for this protocol is advertised by the Service Discovery protocol defined in <span class="ref"><link url="https://xmpp.org/extensions/xep-0030.html">Service Discovery (XEP-0030)</link></span> <note>XEP-0030: Service Discovery &lt;<link url="https://xmpp.org/extensions/xep-0030.html">https://xmpp.org/extensions/xep-0030.html</link>&gt;.</note> using a feature
      of <tt>urn:xmpp:inbox:1</tt>.</p>
  </section2>
  <section2 topic="The Inbox">
    <p>The Inbox consists semantically of a list of conversations in order of last activity. Each conversation is
      identified by a jid - for group chats this would be the chatroom, and for individual contacts this would be their
      bare jid.</p>
    <p>Each Inbox entry includes a count of messages considered new, the last MAM stanza-id relating to this conversation,
      and the last MAM result for this conversation, as defined by <span class="ref"><link url="https://xmpp.org/extensions/xep-0313.html">Message Archive Management (XEP-0313)</link></span> <note>XEP-0313: Message Archive Management &lt;<link url="https://xmpp.org/extensions/xep-0313.html">https://xmpp.org/extensions/xep-0313.html</link>&gt;.</note>. In addition, a client-controlled boolean
      marker can be used to indicate a manual "set unread" state.</p>
    <p>Finding more messages from this conversation can be achieved via a MAM query using <tt>with</tt> to specify the
      conversation required.</p>
  </section2>
</section1>

  <section1 topic="Protocol Elements">
    <section2 topic="Querying">
      <p>An &lt;iq/&gt; of type "get" is used, containing a single element <tt>&lt;inbox/&gt;</tt>, containing an optional RSM
        filter as specified by <span class="ref"><link url="https://xmpp.org/extensions/xep-0059.html">Result Set Management (XEP-0059)</link></span> <note>XEP-0059: Result Set Management &lt;<link url="https://xmpp.org/extensions/xep-0059.html">https://xmpp.org/extensions/xep-0059.html</link>&gt;.</note>. This will typically be sent only to the user's own bare jid. If a client
        requests the inbox without RSM, the server MAY limit the number of conversations arbitrarily by either time or number. This element has a number of attributes:</p>
      <ul>
        <li><tt>unread-only</tt> - Defaults to false. If true, the server will list only conversations with at least one unread message.</li>
        <li><tt>messages</tt> - Defaults to true. If true, the server includes the last message; if false, this is elided.</li>
      </ul>
      <p>The server
        responds with a sequence of &lt;message/&gt; stanzas, each containing an <tt>&lt;entry/&gt;</tt> element qualified by the
        <tt>urn:xmpp:inbox:1</tt> namespace with a number of attributes:</p>
      <ul>
        <li><tt>jid</tt> - contains the Jid of the conversation for this entry.</li>
        <li><tt>unread</tt> - contains a count of messages which are deemed to be unread by the server. Clients may use this to indicate unread messages to the user.</li>
        <li><tt>id</tt> - contains the last id in the MAM archive for this conversation. Clients may use this as a marker to fetch additional messages (or collated fastenings, see <span class="ref"><link url="https://xmpp.org/extensions/xep-0427.html">MAM Fastening Collation (XEP-0427)</link></span> <note>XEP-0427: MAM Fastening Collation &lt;<link url="https://xmpp.org/extensions/xep-0427.html">https://xmpp.org/extensions/xep-0427.html</link>&gt;.</note>) about the conversation via MAM.</li>
      </ul>
      <p>If the <tt>messages</tt> attribute is missing or set to <tt>true</tt>, the <tt>&lt;entry/&gt;</tt> element is followed by the latest instant message, if any, which is encapsulated as a
        <tt>&lt;result/&gt;</tt> element as defined by <span class="ref"><link url="https://xmpp.org/extensions/xep-0313.html">Message Archive Management (XEP-0313)</link></span> <note>XEP-0313: Message Archive Management &lt;<link url="https://xmpp.org/extensions/xep-0313.html">https://xmpp.org/extensions/xep-0313.html</link>&gt;.</note>. This contains collated fastenings if supported by the
        server.</p>
      <p>After all entries required have been returned, the server then responds with an &lt;iq/&gt; result containing a
        <tt>&lt;fin/&gt;</tt> element qualified by <tt>urn:xmpp:inbox:1</tt>. This contains the RSM data, a total count of conversation
        entries within the inbox, a count of conversations with unread messages, and a total count of unread messages.</p>
    </section2>
  </section1>

  <section1 topic="Unread Messages">
    <p>Servers MUST track which instant messages sent to clients remain unread.</p>
    <ul>
      <li>An instant message is always read if it is followed by an instant message which is read.</li>
      <li>An instant message always starts unread.</li>
      <li>A Chat Marker (see <span class="ref"><link url="https://xmpp.org/extensions/xep-0333.html">Displayed Markers (XEP-0333)</link></span> <note>XEP-0333: Displayed Markers &lt;<link url="https://xmpp.org/extensions/xep-0333.html">https://xmpp.org/extensions/xep-0333.html</link>&gt;.</note>) of "displayed" or "acknowledged" causes the message to be read (and also causes
      all prior messages to be read by implication).</li>
      <li>A Message Receipt (see <span class="ref"><link url="https://xmpp.org/extensions/xep-0184.html">Message Delivery Receipts  (XEP-0184)</link></span> <note>XEP-0184: Message Delivery Receipts &lt;<link url="https://xmpp.org/extensions/xep-0184.html">https://xmpp.org/extensions/xep-0184.html</link>&gt;.</note>) does not cause messages to be considered unread.</li>
      <li>Unmarking a conversation always sets the unread counter to zero, and by implication sets all messages to be
        read.</li>
    </ul>
  </section1>

  <section1 topic="Examples">
    <p>Let us assume a user has only three jids they have exchanged messages with. Asking for their inbox is simple:</p>
    <example><![CDATA[
    <iq type='get' id='iq_stanza_id'>
      <inbox xmlns=']]>urn:xmpp:inbox:1<![CDATA['/>
    </iq>
    ]]></example>
    <p>The server responds with a list of conversations:</p>
    <example><![CDATA[
    <message>
      <entry xmlns=']]>urn:xmpp:inbox:1<![CDATA[' unread='5' jid='first_contact@example.net' id='uuid-1'/>
      <result xmlns='urn:xmpp:mam:2' queryid='iq_stanza_id' id='uuid-1'>
        <forwarded xmlns='urn:xmpp:forward:0'>
          <message xmlns='jabber:client' from='first_contact@example.net' to='user@example.org' type='chat'>
            <body>Greetings from Alpha Centauri!</body>
          </message>
        </forwarded>
      </result>
    </message>

    <message>
      <entry xmlns=']]>urn:xmpp:inbox:1<![CDATA[' unread='0' jid='second_contact@example.net' id='uuid-5'/>
      <result xmlns='urn:xmpp:mam:2' queryid='iq_stanza_id' id='uuid-5'>
        <forwarded xmlns='urn:xmpp:forward:0'>
          <message xmlns='jabber:client' from='second_contact@example.net' to='user@example.org' type='chat'>
            <body>Greetings from Mars!</body>
          </message>
        </forwarded>
      </result>
    </message>

    <message>
      <entry xmlns=']]>urn:xmpp:inbox:1<![CDATA[' unread='1' jid='third_contact@example.net' id='uuid-8'/>
      <result xmlns='urn:xmpp:mam:2' queryid='iq_stanza_id' id='uuid-8'>
        <forwarded xmlns='urn:xmpp:forward:0'>
          <message xmlns='jabber:client' from='third_contact@example.net' to='user@example.org' type='chat'>
            <body>Greetings from Somewhere Else!</body>
          </message>
        </forwarded>
      </result>
    </message>
    ]]></example>
    <p>If the <tt>id</tt> of a conversation has changed, a client might fetch the missing messages and metadata by requesting the MAM archive <tt>with</tt> the <tt>jid</tt> of the entry, and <tt>after</tt> the previous known <tt>id</tt> for the conversation.</p>
    <p>After the list of conversations, the server completes its response with a the reply to the original IQ.</p>
    <example><![CDATA[
      <iq type='result' id='iq_stanza_id'>
        <fin xmlns=']]>urn:xmpp:inbox:1<![CDATA[' total='3' unread='2' all-unread='6'>
          <!-- RSM -->
        </fin>
    ]]></example>
  </section1>

  <section1 topic="Schema">
    <p>TODO - Hopefully roughly given by the examples.</p>
  </section1>

<section1 topic="Security Considerations" anchor="security">
  <p>TODO</p>
</section1>

<section1 topic="IANA Considerations" anchor="iana">
  <p>This XEP requires no interaction with the <span class="ref"><link url="http://www.iana.org/">Internet Assigned Numbers Authority (IANA)</link></span> <note>The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see &lt;<link url="http://www.iana.org/">http://www.iana.org/</link>&gt;.</note>. </p>
</section1>

<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <p>None.</p>
</section1>

<section1 topic="Acknowledgements" anchor="ack">
  <p>The author notes that this protocol is heavily based on the <tt>mod_inbox</tt> system of MongooseIM. In addition, Kevin Smith and several others at the XMPP Summit 24 provided useful feedback which has shaped this specification.</p>
</section1>

</xep>
