<p>Since the XMPP routing rules were originally defined, formalised in RFC 3920/3921 and refreshed in RFC 6120/6121, people's expectations of the behaviour of instant messaging systems has progressed. While the original rules encouraging routing to specific devices via full-JID routing is still very suited for some applications (particularly machine to machine communications) they are becoming less useful for IM, as the popularity of XEPs such as Carbons to adjust them and the workarounds needed for XEP-0045 have shown. Here a simpler opt-in model is proposed, whereby IM messages are sent to a bare JID, and all clients opting in to this new routing (referred to here as IM-NG) will receive them. Conversely, messages sent to a full-JID are no longer used for IM cases.</p>
</section1>
<section1topic='Requirements'anchor='reqs'>
<p>Clients, both those online and offline, receive a consistent set of messages, such that it is possible to start conversations one device and continue them on another device without inconsistent delivery of messages (no client should receive only a subset of the conversation).</p>
<p>Interoperate with contacts using non-IM-NG routing.</p>
<p>A server advertises support for this protocol by including the "urn:xmpp:im-ng:0" feature in its service discovery information features as specified in &xep0030; or section 6.3 of &xep0115;.</p>
<examplecaption='Client requests information about its own server'><![CDATA[
<p>When a client wants to participate in the IM-NG protocol, it enables the protocol by sending an IQ-set containing a child element <enable/> qualified by the namespace "urn:xmpp:im-ng:0":</p>
<examplecaption='Client enables IM-NG'><![CDATA[
<iqxmlns='jabber:client'
from='romeo@montague.example/garden'
id='enable1'
type='set'>
<enablexmlns='urn:xmpp:im-ng:0'/>
</iq>]]></example>
<p>The server will respond with an IQ-result when IM-NG is enabled:</p>
<p>When an entity wants to send a non-error message to be handled by all a user's IM-NG clients they will send it to the user's bare JID, which the receiving server then MUST send to all the contact's IM-NG resources, and the sending server must reflect to all the user's IM-NG resources.</p>
<examplecaption='Client sends a message that IM-NG will route to all resources'><![CDATA[
<messagexmlns='jabber:client'
from='montague@montague.example/bas149a'
to='benvolio@shakespeare.example'
id='342'
type='chat'>
<body>I neither know it nor can learn of him</body>
</message>]]></example>
<p>When an entity wants to send a non-error message to be received exclusively by a single resource, they include an <im-ng xmlns='urn:xmpp:im-ng:0'> element in the message. An IM-NG server receiving this MUST then send it to only the specified resource, if available, or respond with an error consistent with RFC-6121 ("return an error stanza to the sender, which SHOULD be <service-unavailable/>").</p>
<examplecaption='Client sends a message that IM-NG will route to a single resource'><![CDATA[
<messagexmlns='jabber:client'
from='montague@montague.example/bas149a'
to='benvolio@shakespeare.example/csa003'
id='343'
type='chat'>
<im-ngxmlns='urn:xmpp:im-ng:0'/>
</message>]]></example>
</section2>
</section1>
<section1topic='Business Rules'anchor='rules'>
<p>Any message of normal type, or type 'chat', 'groupchat' or 'headline' sent to a bare JID is distributed to all IM-NG clients (error messages sent to the bare JID are in response to server-generated stanzas, and so are not routed to clients).</p>
<p>Any message that is routed to all IM-NG clients is stored in the MAM archive, where available, and any message that would not be routed to all IM-NG clients is not stored in the MAM archive</p>
<p>In order for interoperability with other entities (contacts, remote servers etc.) that don't support IM-NG, old-style full-JID messages also need to be handled. When a server receives a message with type other than than 'groupchat' or 'headline' that does not contain an <im-ng xmlns='urn:xmpp:im-ng:0'> element it is to be routed by the above rules as if they were sent to the bare JID</p>
<p>A client activating IM-NG MUST NOT also activate Carbons.</p>
<p>An IM-NG client SHOULD send all IM-related messages to bare JIDs (as full-JID messages would not be distributed appropriately).</p>
<p>An IM-NG client SHOULD ignore any IM-related messages that are sent to a full-JID with an <im-ng xmlns='urn:xmpp:im-ng:0'> element (see Security Considerations).</p>
<p>When reflecting an IM-NG client's outbound bare-JID messages, the server SHOULD reflect the archived version (i.e. after any transforms have taken place).</p>
<p>Malicious clients could attempt to avoid having messages archived by causing them to be routed only to individual resources - this is mitigated by ensuring that clients receiving such a message will not process them.</p>