<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Message Attaching</title>
  <abstract>
    This specification defines a method for indicating that a message contains
    content which describes an earlier message in the conversation and should
    be grouped with the earlier message.
  </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>0367</number>
  <status>Deferred</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0359</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>message-attaching</shortname>
  
  <author>
    <firstname>Sam</firstname>
    <surname>Whited</surname>
    <email>sam@samwhited.com</email>
    <jid>sam@samwhited.com</jid>
    <uri>https://blog.samwhited.com/</uri>
  </author>

  <author>
    <firstname>Craig</firstname>
    <surname>Petchell</surname>
    <email>cpetchell@atlassian.com</email>
  </author>
  
  <author>
    <firstname>Matthew</firstname>
    <surname>Wild</surname>
    <email>mwild1@gmail.com</email>
    <jid>me@matthewwild.co.uk</jid>
  </author>

  <revision>
    <version>0.3</version>
    <date>2018-08-18</date>
    <initials>mw</initials>
    <remark>Update to use unique stanza ids.</remark>
  </revision>
  <revision>
    <version>0.2</version>
    <date>2017-09-11</date>
    <initials>XEP Editor (jwi)</initials>
    <remark>Defer due to lack of activity.</remark>
  </revision>
  <revision>
    <version>0.1</version>
    <date>2015-12-15</date>
    <initials>XEP Editor (asw)</initials>
    <remark><p>Initial published version approved by the XMPP Council.</p></remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2015-10-16</date>
    <initials>ssw</initials>
    <remark><p>First draft.</p></remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p>
    Many messaging applications send special messages which include more
    information about a previous message. For example, when sending a link the
    service may display the description or an image off the page, or users may
    respond to a message with a "sticker" or an "emotion" which they wish to
    display alongside the message, even though the conversation has moved on.
  </p>
  <p>
    This specification defines a way by which one can indicate that a message
    is logically (and visibly) "attached" to an earlier message in the
    conversation.
  </p>
</section1>
<section1 topic="Discovering support" anchor="disco">
  <p>
    If a client implements message attaching, it MUST specify the
    'urn:xmpp:message-attaching:1' feature in its service discovery information
    features as specified 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> and the Entity Capabilities profile
    specified in <span class="ref"><link url="https://xmpp.org/extensions/xep-0115.html">Entity Capabilities (XEP-0115)</link></span> <note>XEP-0115: Entity Capabilities &lt;<link url="https://xmpp.org/extensions/xep-0115.html">https://xmpp.org/extensions/xep-0115.html</link>&gt;.</note>.
  </p>
  <example caption="Client requests information about a chat partner's client"><![CDATA[
<iq type='get'
    from='alonso@naples.lit/ship'
    id='miuARo9V'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>]]></example>
  <example caption="Partner's client advertises support for attaching"><![CDATA[
<iq type='result'
    to='alonso@naples.lit/ship'
    from='naples.lit'
    id='miuARo9V'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
…
    <feature var='urn:xmpp:message-attaching:1'/>
…
  </query>
</iq>]]></example>
</section1>
<section1 topic="Usage" anchor="usage">
  <p>
    Messages that are attached to other messages MUST contain an
    &lt;attach-to/&gt; element qualified by the 'urn:xmpp:message-attaching:1'
    namespace and with an 'id' attribute set to the ID of the message that we
    want to attach to (important note: the correct ID to use depends on the context,
    see the business rules below). Messages MAY be attached to any
    other message, including those sent by other clients, but clients MAY choose
    to ignore the attach-to directive and display the message normally.
  </p>
  <example caption="User attaches a message"><![CDATA[
<message to='antonio@milan.lit/ship' from='prospero@milan.lit/island' id='RgEGnjqy'>
  <body>storm.png</body>
  <attach-to id='SD24VCzSYQ' xmlns='urn:xmpp:message-attaching:1'/>
</message>]]></example>
  <p>
    Note that indicating that a message should be "attached" to an earlier
    message in the conversation is merely a suggestion to the client to display
    the message next to or below the old message.
  </p>
</section1>
<section1 topic="Business Rules" anchor="rules">
  <section2 topic="Using the correct ID" anchor="business-id">
    <p>
      For messages of type 'groupchat', the stanza's 'id' attribute MUST NOT be
      used for attachments. Instead, in group chat situations, the ID assigned to
      the stanza by the group chat itself must be used. This is discovered in a
      &lt;stanza-id&gt; element with a 'by' attribute that matches the bare JID of
      the group chat, as defined in <span class="ref"><link url="https://xmpp.org/extensions/xep-0359.html">Unique and Stable Stanza IDs (XEP-0359)</link></span> <note>XEP-0359: Unique and Stable Stanza IDs &lt;<link url="https://xmpp.org/extensions/xep-0359.html">https://xmpp.org/extensions/xep-0359.html</link>&gt;.</note>.
    </p>
    <p>
      This implies that group chat messages without a <span class="ref"><link url="https://xmpp.org/extensions/xep-0359.html">Unique and Stable Stanza IDs (XEP-0359)</link></span> <note>XEP-0359: Unique and Stable Stanza IDs &lt;<link url="https://xmpp.org/extensions/xep-0359.html">https://xmpp.org/extensions/xep-0359.html</link>&gt;.</note> stanza-id cannot
      be attached-to.
    </p>
    <p>
      For other message types the attacher should use the 'id' from a XEP-0359
      &lt;origin-id&gt; if present, or the value of the 'id' attribute on the
      &lt;message&gt; otherwise.
    </p>
  </section2>
  <section2 topic="Display of attached messages" anchor="business-display">
    <p>
      A receiving client MAY choose to show the attached message next to or below
      the indicated message in whatever display is used for messages or can
      choose to display the attachment in another way (including as a normal
      message, completely ignoring the attach-to element).
    </p>
    <p>
      A receiving client SHOULD indicate that the message is an attachment, and
      not a part of the original message to prevent confusion.
    </p>
  </section2>
  <section2 topic="General" anchor="business-general">
    <p>
      &lt;attach-to/&gt; elements MUST NOT be put on any stanza type other than
      messages.
    </p>
    <p>
      A server may choose to strip some &lt;attach-to/&gt; messages based on
      local policy (eg. a server might have a policy that only it can create
      message attachments).
    </p>
    <p>Clients MUST send ids on messages if they support attachments.</p>
    <p>
      Messages MUST NOT contain more than one &lt;attach-to/&gt; element.
    </p>
    <p>
      Clients and servers MUST NOT include an &lt;attach-to/&gt; element on
      messages with a non-messaging payload unless they are including it on an
      error which may be attached to the message that caused the error to be
      generated.
    </p>
   </section2>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>
    Clients that implement message attachments MUST display the attachments
    in such a way that they could not be confused with the original message
    and cause someone viewing the conversation to assume they were sent by
    the sender of the message being attached to.
  </p>
  <p>
    When matching a received attachment to the original message, clients must
    ensure they match using the correct ID, as described in the business rules
    section, e.g. within a group chat only the XEP-0359 stanza-id should be
    matched against. If this is not available, the message SHOULD be displayed
    as a normal unattached message.
  </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>This specification defines the following XML namespaces:</p>
	<ul>
		<li>urn:xmpp:message-attaching:1</li>
	</ul>
	<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> shall include the foregoing namespaces in its disco
    features registry as 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>.
	</p>
	<code caption="Registry Submission"><![CDATA[
<var>
	<name>urn:xmpp:message-attaching:1</name>
	<desc>Indicates support for attaching one message to another.</desc>
	<doc>XEP-xxxx</doc>
</var>
]]></code>
</section1>
<section1 topic="XML Schema" anchor="schema">
  <code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:xmpp:message-attaching:1'
    xmlns='urn:xmpp:message-attaching:1'
    elementFormDefault='qualified'>

  <xs:element name='attach-to'>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base='xs:string'>
          <xs:attribute name='id' type='xs:string' use='required'/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

</xs:schema>
]]></code>
</section1>
</xep>
