<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<!--
© XMPP Standards Foundation, 2016
Author: Peter Waher
-->
<xep xmlns="">
    <header>
        <title>Content Types in Messages</title>
        <abstract>This specification describes a generic method whereby content in messages can be tagged as having a specific Internet Content Type. It also provides a method for sending the same content using different content types, as a fall-back mechanism when communicating between clients having different content type support.</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>0481</number>
        <status>Experimental</status>
        <type>Standards Track</type>
        <sig>Standards</sig>
        <approver>Council</approver>
        <dependencies>
            <spec>XMPP Core</spec>
            <spec>XEP-0030</spec>
        </dependencies>
        <supersedes/>
        <supersededby/>
        <shortname>content</shortname>
        
  <author>
    <firstname>Peter</firstname>
    <surname>Waher</surname>
    <email>peterwaher@hotmail.com</email>
    <jid>peter.waher@jabber.org</jid>
    <uri>http://www.linkedin.com/in/peterwaher</uri>
  </author>

        <revision>
            <version>0.1.0</version>
            <date>2023-05-04</date>
            <initials>XEP Editor: ks</initials>
            <remark>
                <p>Promoting to Experimental.</p>
            </remark>
        </revision>
        <revision>
            <version>0.0.1</version>
            <date>2016-01-15</date>
            <initials>pw</initials>
            <remark>
                <p>First draft.</p>
            </remark>
        </revision>
    </header>
    <section1 topic="Introduction" anchor="intro">
        <p>
            Sometimes it is desirable for clients to communicate, or to send messages between each other, using a well defined Internet Content Type.
            Reasons can vary between the purely esthetic to funcional data-exchange. While there are XEPs, such as <span class="ref"><link url="https://xmpp.org/extensions/xep-0071.html">XHTML-IM (XEP-0071)</link></span> <note>XEP-0071: XHTML-IM &lt;<link url="https://xmpp.org/extensions/xep-0071.html">https://xmpp.org/extensions/xep-0071.html</link>&gt;.</note> that provides means for
            sending richer content using a specific type, this extensions provides a similar mechanism, but for the general case of any content having
            a defined Internet Content Type.
        </p>
        <p>
            <strong>Note:</strong> While the examples in this extensions uses Markdown as an example, any other text-based content type can be used.
        </p>
    </section1>
    <section1 topic="Use Cases" anchor="usecases">
        <section2 topic="Content type hint" anchor="hint">
            <p>
                The simplest use case is hinting at the content type of the textual content presented in the message body. This is done by aggregating
                a <strong>content</strong> element of namespace <strong>urn:xmpp:content</strong> to the message, with the attribute <strong>type</strong>
                specifying the content type. If the element does not provide a value, it is understood that the body contains the textual body of the
                content. This method should only be used if there's no risk of misunderstanding the message if the content type is not understood by
                the receiver, and the textual representation is readable. Example:
            </p>
            <example caption="Hinting at a content type">
                <![CDATA[
    <message
        from='person1@example.org/34892374'
        to='person2@example.org/938089023'
        type='chat'>
       <body>**Note:** This message is very important.</body>
       <content type='text/markdown' xmlns='urn:xmpp:content'/>
    </message>]]>
            </example>
        </section2>
        <section2 topic="Alternate encoding" anchor="encoding">
            <p>
                If there is a risk of misunderstanding the message if it's content type is not recognized, or the presentation of the message
                is done in an undesireable fashion, you can provide an alternate encoding of the message in the <strong>content</strong> element
                itself. If the <strong>content</strong> element contains a message, and the content type is recognized, the message should be
                taken from the <strong>content</strong> element instead of the <strong>body</strong> element. The <strong>body</strong> element
                in turn, should contain the <strong>plain text</strong> version of the same message. Example:
            </p>
            <example caption="Alternate encoding">
                <![CDATA[
    <message
        from='person1@example.org/34892374'
        to='person2@example.org/938089023'
        type='chat'>
       <body>Note: Go to Google and search for it.</body>
       <content type='text/markdown' xmlns='urn:xmpp:content'>
          **Note:** Go to [Google](http://www.google.com/) and search for it.
       </content>
    </message>]]>
            </example>
        </section2>
        <section2 topic="Alternate encodings" anchor="encodings">
            <p>
                By providing multiple <strong>content</strong> elements in the same message, you can allow the receiver to choose the encoding
                best suited for its purpose. It also makes it possible to interchange messages that are understood by both humans and machines
                in the same message. If an empty <strong>content</strong> element is found, it is interpreted as above, i.e. providing a hint
                as to the content type of the message in the <strong>body</strong> element. Example:
            </p>
            <example caption="Alternate encodings">
                <![CDATA[
    <message
        from='person1@example.org/34892374'
        to='person2@example.org/938089023'
        type='chat'>
       <body>
          Your energy consumption this month is 5000 kWh.
          That is very much. It will cost you 200 USD.
          You can find current tariffs at our web page.
       </body>
       <content type='text/markdown' xmlns='urn:xmpp:content'>
          Your energy consumption this month is **5000 kWh**.
          That is *very much*. It will cost you **200 USD**.
          You can find current tariffs at our [web page](http://www.example.com/Energy).
       </content>
       <content type='text/xml' xmlns='urn:xmpp:content'>
          &lt;Quote xmlns='somenamespace'&gt;
             &lt;Consumption unit='kWh'&gt5000&lt;/Consumption&gt;
             &lt;Cost unit='USD'&gt200&lt;/Cost&gt;
          &lt;/Quote&gt;
       </content>
    </message>]]>
            </example>
        </section2>
    </section1>
    <section1 topic="Determining Support" anchor="support">
        <p>
            If an entity supports content types as specified herein, it MUST advertise that fact by returning a feature of
            "urn:xmpp:content" 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="Service discovery information request">
            <![CDATA[
    <iq type='get'
        from='example.org'
        to='device@example.org'
        id='disco1'>
      <query xmlns='http://jabber.org/protocol/disco#info'/>
    </iq>]]>
        </example>
        <example caption="Service discovery information response">
            <![CDATA[
    <iq type='result'
        from='device@example.org'
        to='example.org'
        id='disco1'>
      <query xmlns='http://jabber.org/protocol/disco#info'>
        ...
        <feature var='urn:xmpp:content'/>
        ...
      </query>
    </iq>]]>
        </example>
        <p>
            In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic,
            presence-based profile of service discovery defined 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>. However, if an application has not received entity capabilities
            information from an entity, it SHOULD use explicit service discovery instead.
        </p>
    </section1>
    <section1 topic="Implementation Notes" anchor="impl">
        <section2 topic="Content Types" anchor="contentTypes">
            <p>
                This document does not specify how content types are to be interpreted, or if content types are valid or well defined.
                It does not specify which content types are to be understood, or when. It only provides a means to hint or include different
                encodings in the same message.
            </p>
        </section2>
        <section2 topic="Custom Content Types" anchor="customTypes">
            <p>
                It is possible to use custom or vendor-specific content types. These types are marked by prefixing the subtype with
                <strong>x.</strong> for custom unregistered types, and with <strong>vnd.</strong> for registered vendor specific types.
            </p>
        </section2>
        <section2 topic="Stanza size" anchor="stanzaSize">
            <p>
                Care has to be taken when sending multiple encodings of the same message, as to not reach the smallest allowed
                maximum stanza size used by client and server software.
            </p>
        </section2>
    </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 <link url="#schema">protocol schema</link> needs to be added to the list of <link url="http://xmpp.org/resources/schemas/">XMPP protocol schemas</link>.
        </p>
    </section1>
    <section1 topic="XML Schema" anchor="schema">
        <code>
            <![CDATA[
<?xml version='1.0' encoding='UTF-8'?>
<!--
© XMPP Standards Foundation, 2016
Author: Peter Waher
-->
<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:xmpp:content'
    xmlns='urn:xmpp:content'
    elementFormDefault='qualified'>

    <xs:element name='content'>
        <xs:complexType mixed='true'>
            <xs:attribute name='type' use='required'/>
        </xs:complexType>
    </xs:element>

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