<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Message Archive Management Preferences</title>
  <abstract>This document defines a protocol to control a user's archiving preferences.</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>0441</number>
  <status>Experimental</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0030</spec>
    <spec>XEP-0313</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>mamprefs</shortname>
  
  <author>
    <firstname>Matthew</firstname>
    <surname>Wild</surname>
    <email>mwild1@gmail.com</email>
    <jid>me@matthewwild.co.uk</jid>
  </author>

  
  <author>
    <firstname>Kevin</firstname>
    <surname>Smith</surname>
    <email>kevin@kismith.co.uk</email>
    <jid>kevin@doomsong.co.uk</jid>
  </author>

  <revision>
    <version>0.2.0</version>
    <date>2020-08-25</date>
    <initials>XEP Editor (jsc)</initials>
    <remark>Accepted by vote of Council on 2020-08-19.</remark>
  </revision>
  <revision>
    <version>0.1</version>
    <date>2020-04-03</date>
    <initials>mw</initials>
    <remark>
      <p>Split from XEP-0313, no protocol changes</p>
    </remark>
  </revision>
</header>

<section1 topic="Introduction" anchor="intro">
  <p>This specification describes a protocol for a server to allow a client to configure a user's
  message archiving preferences. It is intended to be used in conjunction with <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>.</p>

  <p>After observing XEP-0313 usage in the wild, it became apparent that preferences were not often
  used, and can interfere with clients that use the archive for synchronization of messages received
  by the user while disconnected. Therefore it is not actively encouraged for an implementation/deployment
  to offer this functionality.</p>
</section1>

<section1 topic="Archiving Preferences" anchor="prefs">
  <p>Depending on implementation and deployment policies, a server MAY allow the user to have control
  over the server's archiving behaviour. This specification defines a basic protocol for this, and
  also allows a server to offer more advanced configuration to a user.</p>
  <section2 topic="Simple configuration" anchor="config">
    <p>If the server supports and allows configuration of the preferences described below then it SHOULD implement the protocol defined
    in this section. This allows the user to retrieve and configure the following preferences:</p>
    <ul>
      <li>A list of JIDs that should always have messages to/from archived in the user's store.</li>
      <li>A list of JIDs that should never have messages to/from archived in the user's store.</li>
      <li>The default archiving behaviour (for JIDs in neither of the above lists).</li>
    </ul>
    <example caption="Retrieving archiving preferences"><![CDATA[
<iq type='get' id='juliet2'>
  <prefs xmlns='urn:xmpp:mam:2'/>
</iq>
]]></example>

    <p>The server replies with the user's current archiving preferences. The &lt;prefs&gt; element
    MUST be present and contain the current default archiving policy. The &lt;always&gt; and &lt;never&gt;
    MUST also be present (even if empty), and contain a list of JIDs enclosed in &lt;jid&gt; elements.</p>

    <example caption="Server responds with current preferences"><![CDATA[
<iq type='result' id='juliet2'>
  <prefs xmlns='urn:xmpp:mam:2' default='roster'>
    <always/>
    <never/>
  </prefs>
</iq>
]]></example>

    <p>It is also possible that the server may respond with a stanza error, for example the standard
    'feature-not-implemented' (server does not support MAM configuration) defined 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>.</p>

    <example caption="Server does not support archive configuration"><![CDATA[
<iq type='error' id='juliet2'>
  <error type='cancel'>
    <feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
]]></example>

    <p>To update the preferences, the client can simply send an iq stanza with a type of 'set':</p>

    <example caption="Updating archiving preferences"><![CDATA[
<iq type='set' id='juliet3'>
  <prefs xmlns='urn:xmpp:mam:2' default='roster'>
    <always>
      <jid>romeo@montague.lit</jid>
    </always>
    <never>
      <jid>montague@montague.lit</jid>
    </never>
  </prefs>
</iq>
]]></example>
  <p>The server then replies with the applied preferences (note that due to server policies these
  MAY be different to the preferences sent by the client):</p>
<example caption="Server responds with updated preferences"><![CDATA[
<iq type='result' id='juliet3'>
  <prefs xmlns='urn:xmpp:mam:2' default='roster'>
    <always>
      <jid>romeo@montague.lit</jid>
    </always>
    <never>
      <jid>montague@montague.lit</jid>
    </never>
  </prefs>
</iq>
]]></example>

  <p>It is also possible for the server to respond with an error, for example (but not limited to)
  the standard 'feature-not-implemented' (the server does not support configuration of preferences),
  'forbidden' (the user is not authorized to change their preferences) or 'not-allowed' (the server
  generally does not allow changing of configuration preferences).</p>

    <section3 topic="Default behaviour" anchor="config-default">
      <p>If a JID is in neither the 'always archive' nor the 'never archive' list then whether it
         is archived depends on this setting, the default.
      </p>
      <p>The 'default' attribute of the 'prefs' element MUST be one of the following values:</p>
      <ul>
        <li>'always' - all messages are archived by default.</li>
        <li>'never' - messages are never archived by default.</li>
        <li>'roster' - messages are archived only if the contact's bare JID is in the user's roster.</li>
      </ul>
    </section3>
    <section3 topic="Always archive" anchor="config-always">
      <p>The &lt;prefs/&gt; element MAY contain an &lt;always/&gt; child element. If present, it
         contains a list of &lt;jid/&gt; elements, each containing a single JID. The server SHOULD
         archive any messages to/from this JID (see 'JID matching').
      </p>
      <p>If missing from the preferences, &lt;always/&gt; SHOULD be assumed by the server to be an
         empty list.
      </p>
    </section3>
    <section3 topic="Never archive" anchor="config-never">
      <p>The &lt;prefs/&gt; element MAY contain an &lt;never/&gt; child element. If present, it
         contains a list of &lt;jid/&gt; elements, each containing a single JID. The server SHOULD
         NOT archive any messages to/from this JID (see 'JID matching').
      </p>
      <p>If missing from the preferences, &lt;never/&gt; SHOULD be assumed by the server to be an
         empty list.
      </p>
    </section3>
  </section2>
  <section2 topic="Advanced configuration" anchor="advanced-config">
    <p>In addition to this protocol, a server MAY offer more advanced configuration to the user
       through <span class="ref"><link url="https://xmpp.org/extensions/xep-0050.html">Ad-Hoc Commands (XEP-0050)</link></span> <note>XEP-0050: Ad-Hoc Commands &lt;<link url="https://xmpp.org/extensions/xep-0050.html">https://xmpp.org/extensions/xep-0050.html</link>&gt;.</note>. Such an interface might, for example, allow the user to configure what
       types of messages to store, or set a limit on how long messages should remain in the
       archive.</p>
    <p>If supported, such a configuration command SHOULD be presented on the well-defined
       command node of "urn:xmpp:mam#configure".</p>
  </section2>
  <section2 topic="JID matching" anchor="match">
    <section3 topic="General rules" anchor="match-rules">
      <p>When comparing the message target JID against the user's roster (ie. when the user has
         set default='roster') the comparison MUST use the bare target JID (that is, stripped of
         any resource).
      </p>
      <p>For matching against entries in either the 'allow' or 'never' lists, for each listed
         JID:
      </p>
      <ul>
        <li>If the listed JID contains a resource, compare against the target JID as-is.</li>
        <li>If the listed JID has no resource (it is a bare JID) then first strip any resource
            from the target JID prior to comparison.
        </li>
      </ul>
    </section3>
    <section3 topic="Outgoing messages" anchor="match-out">
      <p>For outgoing messages, the server MUST use the value of the 'to' attribute as the target JID.
      </p>
    </section3>
    <section3 topic="Incoming messages" anchor="match-in">
      <p>For incoming messages, the server MUST use the value of the 'from' attribute as the target JID.
      </p>
    </section3>
  </section2>
</section1>
</xep>
