<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Best Practices for Handling Offline Messages</title>
  <abstract>This document specifies best practices to be followed by Jabber/XMPP servers in handling messages sent to recipients who are offline.</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>0160</number>
  <status>Active</status>
  <type>Informational</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XMPP IM</spec>
    <spec>XEP-0030</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>msgoffline</shortname>
  
  <author>
    <firstname>Peter</firstname>
    <surname>Saint-Andre</surname>
    <email>stpeter@stpeter.im</email>
    <jid>stpeter@jabber.org</jid>
    <uri>https://stpeter.im/</uri>
  </author>

  <revision>
    <version>1.0.1</version>
    <date>2016-10-07</date>
    <initials>egp</initials>
    <remark><p>Use the correct namespace in the Service Discovery examples; fix some formatting.</p></remark>
  </revision>
  <revision>
    <version>1.0</version>
    <date>2006-01-24</date>
    <initials>psa</initials>
    <remark>Per a vote of the Jabber Council, advanced status to Active.</remark>
  </revision>
  <revision>
    <version>0.2</version>
    <date>2005-11-15</date>
    <initials>psa</initials>
    <remark>Added section on handling of each message type.</remark>
  </revision>
  <revision>
    <version>0.1</version>
    <date>2005-10-05</date>
    <initials>psa</initials>
    <remark>Initial version.</remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2005-09-27</date>
    <initials>psa</initials>
    <remark>First draft.</remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p><span class="ref"><link url="http://tools.ietf.org/html/rfc6120">XMPP Core</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note> and <span class="ref"><link url="http://tools.ietf.org/html/rfc6121">XMPP IM</link></span> <note>RFC 6121: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence &lt;<link url="http://tools.ietf.org/html/rfc6121">http://tools.ietf.org/html/rfc6121</link>&gt;.</note> specify general rules for handling XML stanzas, but explicitly do not address how to handle message stanzas sent to recipients (e.g., IM users or other nodes) that are offline, except to say that a server MUST return a &lt;service-unavailable/&gt; error if offline message storage or message forwarding is not enabled (see <span class="ref"><link url="http://tools.ietf.org/html/rfc6121">RFC 6121</link></span> <note>RFC 6121: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence &lt;<link url="http://tools.ietf.org/html/rfc6121">http://tools.ietf.org/html/rfc6121</link>&gt;.</note>). This document fills the gap by specifying best practices for storage and delivery of so-called "offline messages".</p>
</section1>
<section1 topic="Process Flow" anchor="flow">
  <p>The RECOMMENDED process flow is as follows:</p>
  <ol>
    <li>Sender generates XMPP message stanza <note>This document does not discuss IQ or presence stanzas, handling of which is described in <span class="ref"><link url="http://tools.ietf.org/html/rfc6120">RFC 6120</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note> and <cite>RFC 6121</cite>.</note> for delivery to a recipient such as an IM user or other node, where the 'to' address is of the form &lt;node@domain&gt; or &lt;node@domain/resource&gt; (see <cite>RFC 6121</cite> for rules regarding server handling of such XMPP message stanzas).</li>
    <li>Recipient's server determines that the intended recipient has no available resources that have specified non-negative presence priority. <note>As specified in <span class="ref"><link url="http://tools.ietf.org/html/rfc6121">RFC 6121</link></span> <note>RFC 6121: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence &lt;<link url="http://tools.ietf.org/html/rfc6121">http://tools.ietf.org/html/rfc6121</link>&gt;.</note>, available resources that have specified a negative presence priority shall never receive message stanzas addressed to &lt;node@domain&gt;.</note></li>
    <li>Recipient's server determines that if the server can store offline messages on behalf of the intended recipient; if not (e.g., because the recipient's offline message queue is full), the server returns a &lt;service-unavailable/&gt; error to the sender.</li>
    <li>Recipient's server does not return a &lt;service-unavailable/&gt; error but instead stores the message stanza for later delivery.</li>
    <li>When the recipient next sends non-negative available presence to the server, the server delivers the message to the resource that has sent that presence. (Alternatively, the server may support <span class="ref"><link url="https://xmpp.org/extensions/xep-0013.html">Flexible Offline Message Retrieval (XEP-0013)</link></span> <note>XEP-0013: Flexible Offline Message Retrieval &lt;<link url="https://xmpp.org/extensions/xep-0013.html">https://xmpp.org/extensions/xep-0013.html</link>&gt;.</note>, although that functionality is not described herein.)</li>
  </ol>
  <p>This flow is described more fully below.</p>
  <p>First, the sender (in this example, romeo@montague.net) sends a message to an intended recipient (juliet@capulet.com).</p>
  <example caption="Sender Generates Message to Recipient"><![CDATA[
<message from='romeo@montague.net/orchard' to='juliet@capulet.com'>
  <body>
    O blessed, blessed night! I am afeard.
    Being in night, all this is but a dream,
    Too flattering-sweet to be substantial.
  </body>
</message>
]]></example>
  <p>Next, the recipient's server determines if there are any available resources that have sent non-negative presence priority. If there are, the server immediately delivers the message stanza to the resource that it determines to be most available (based on its own algorithm).</p>
  <p>Next, the recipient's server determines if offline messages can be stored on behalf of the intended recipient. If not (e.g., because the recipient's offline message queue is full), the server returns a &lt;service-unavailable/&gt; error to the sender. If so, the server stores the message for later delivery.</p>
  <p>Now the recipient authenticates with the server and sends initial presence (with a non-negative priority) to the server.</p>
  <example caption="Recipient Becomes Available"><![CDATA[
<presence from='juliet@capulet.com/balcony'>
  <priority>1</priority>
</presence>
]]></example>
  <p>The recipient's server now delivers the offline message to that resource (it is RECOMMENDED for the server to add a <span class="ref"><link url="https://xmpp.org/extensions/xep-0203.html">Delayed Delivery (XEP-0203)</link></span> <note>XEP-0203: Delayed Delivery &lt;<link url="https://xmpp.org/extensions/xep-0203.html">https://xmpp.org/extensions/xep-0203.html</link>&gt;.</note> extension to indicate that the message was stored offline).</p>
  <example caption="Recipient's Server Delivers Message"><![CDATA[
<message from='romeo@montague.net/orchard' to='juliet@capulet.com'>
  <body>
    O blessed, blessed night! I am afeard.
    Being in night, all this is but a dream,
    Too flattering-sweet to be substantial.
  </body>
  <delay xmlns='urn:xmpp:delay'
     from='capulet.com'
     stamp='2002-09-10T23:08:25Z'>Offline Storage</delay>
</message>
]]></example>
</section1>
<section1 topic="Handling of Message Types" anchor="types">
  <p>Message stanzas SHOULD be handled by a server as follows (based on the values of the 'type' attribute specified in <span class="ref"><link url="http://tools.ietf.org/html/rfc6121">RFC 6121</link></span> <note>RFC 6121: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence &lt;<link url="http://tools.ietf.org/html/rfc6121">http://tools.ietf.org/html/rfc6121</link>&gt;.</note>):</p>
  <ul>
    <li><p><strong>normal</strong> -- Messages with a 'type' attribute whose value is "normal" (or messages with no 'type' attribute) SHOULD be stored offline.</p></li>
    <li><p><strong>chat</strong> -- Messages with a 'type' attribute whose value is "chat" SHOULD be stored offline, with the exception of messages that contain only <span class="ref"><link url="https://xmpp.org/extensions/xep-0085.html">Chat State Notifications (XEP-0085)</link></span> <note>XEP-0085: Chat State Notifications &lt;<link url="https://xmpp.org/extensions/xep-0085.html">https://xmpp.org/extensions/xep-0085.html</link>&gt;.</note> content (such messages SHOULD NOT be stored offline).</p></li>
    <li><p><strong>groupchat</strong> -- Messages with a 'type' attribute whose value is "groupchat" SHOULD NOT be stored offline, since by definition a user without online presence cannot be in a <span class="ref"><link url="https://xmpp.org/extensions/xep-0045.html">Multi-User Chat (XEP-0045)</link></span> <note>XEP-0045: Multi-User Chat &lt;<link url="https://xmpp.org/extensions/xep-0045.html">https://xmpp.org/extensions/xep-0045.html</link>&gt;.</note> room.</p></li>
    <li><p><strong>headline</strong> -- Messages with a 'type' attribute whose value is "headline" SHOULD NOT be stored offline, since such messages are usually time-sensitive.</p></li>
    <li><p><strong>error</strong> -- Messages with a 'type' attribute whose value is "error" SHOULD NOT be stored offline, although a server MAY store <span class="ref"><link url="https://xmpp.org/extensions/xep-0079.html">Advanced Message Processing (XEP-0079)</link></span> <note>XEP-0079: Advanced Message Processing &lt;<link url="https://xmpp.org/extensions/xep-0079.html">https://xmpp.org/extensions/xep-0079.html</link>&gt;.</note> error messages offline.</p></li>
  </ul>
</section1>
<section1 topic="Service Discovery" anchor="disco">
  <p>If a server supports offline message handling as described herein, it SHOULD return a "msgoffline" feature in response to <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> information requests:</p>
  <example caption="Recipient Queries Server About Support"><![CDATA[
<iq from='juliet@capulet.com/chamber' to='capulet.com'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
]]></example>
  <example caption="Server Returns Information About Support"><![CDATA[
<iq from='capulet.com' to='juliet@capulet.com/chamber'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    ...
    <feature var='msgoffline'/>
    ...
  </query>
</iq>
]]></example>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>A message stored offline may not be readable by the recipient if the message was encrypted using a session-based encryption method such as <span class="ref"><link url="https://xmpp.org/extensions/xep-0116.html">Encrypted Session Negotiation (XEP-0116)</link></span> <note>XEP-0116: Encrypted Session Negotiation &lt;<link url="https://xmpp.org/extensions/xep-0116.html">https://xmpp.org/extensions/xep-0116.html</link>&gt;.</note> or if the key used in object encryption is revoked after the message was sent but before it is read.</p>
  <p>In certain countries, offline storage of message stanzas may introduce legal requirements or privacy vulnerabilities that do not apply to messages that are delivered immediately and never stored on an intermediate server.</p>
  <p>See <span class="ref"><link url="https://xmpp.org/extensions/xep-0203.html">Delayed Delivery (XEP-0203)</link></span> <note>XEP-0203: Delayed Delivery &lt;<link url="https://xmpp.org/extensions/xep-0203.html">https://xmpp.org/extensions/xep-0203.html</link>&gt;.</note> for security considerations regarding the inclusion and processing of delayed delivery notations.</p>
</section1>
<section1 topic="IANA Considerations" anchor="iana">
  <p>This document 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>The <span class="ref"><link url="https://xmpp.org/registrar/">XMPP Registrar</link></span> <note>The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see &lt;<link url="https://xmpp.org/registrar/">https://xmpp.org/registrar/</link>&gt;.</note> includes "msgoffline" in its registry of service discovery features (see &lt;<link url="https://xmpp.org/registrar/disco-features.html">https://xmpp.org/registrar/disco-features.html</link>&gt;).</p>
</section1>
</xep>
