XEP-0313: Message Archive Management#

class slixmpp.plugins.xep_0313.XEP_0313(xmpp, config=None)[source]#

XEP-0313 Message Archive Management

get_archive_metadata(jid=None, **iqkwargs)[source]#

Get the archive metadata from a JID.

Parameters

jid (Optional[JID]) – JID to get the metadata from.

Return type

Future

async get_configuration_commands(jid, **discokwargs)[source]#

Get the list of MAM advanced configuration commands.

Changed in version 1.8.0.

Parameters

jid (Optional[JID]) – JID to get the commands from.

Return type

Future

async get_fields(jid=None, **iqkwargs)[source]#

Get MAM query fields.

New in version 1.8.0.

Parameters

jid (Optional[JID]) – JID to retrieve the policy from.

Return type

Form

Returns

The Form of allowed options

async iterate(jid=None, start=None, end=None, with_jid=None, ifrom=None, reverse=False, rsm=None, total=None)[source]#

Iterate over each message of MAM query.

New in version 1.8.0.

Parameters
  • jid (Optional[JID]) – Entity holding the MAM records

  • start (Optional[datetime]) – MAM query start time

  • end (Optional[datetime]) – MAM query end time

  • with_jid (Optional[JID]) – Filter results on this JID

  • ifrom (Optional[JID]) – To change the from address of the query

  • reverse (bool) – Get the results in reverse order

  • rsm (Optional[Dict[str, Any]]) – RSM custom options

  • total (Optional[int]) – A number of messages received after which the query should stop.

Return type

AsyncGenerator

retrieve(jid=None, start=None, end=None, with_jid=None, ifrom=None, reverse=False, timeout=None, callback=None, iterator=False, rsm=None)[source]#

Send a MAM query and retrieve the results.

Parameters
  • jid (JID) – Entity holding the MAM records

  • start,end (datetime) – MAM query temporal boundaries

  • with_jid (JID) – Filter results on this JID

  • ifrom (JID) – To change the from address of the query

  • reverse (bool) – Get the results in reverse order

  • timeout (int) – IQ timeout

  • callback (func) – Custom callback for handling results

  • iterator (bool) – Use RSM and iterate over a paginated query

  • rsm (dict) – RSM custom options

Return type

Awaitable

Stanza elements#

class slixmpp.plugins.xep_0313.stanza.MAM(xml=None, parent=None)[source]#

A MAM Query element.

<iq type='set' id='juliet1'>
  <query xmlns='urn:xmpp:mam:2'>
    <x xmlns='jabber:x:data' type='submit'>
      <field var='FORM_TYPE' type='hidden'>
        <value>urn:xmpp:mam:2</value>
      </field>
      <field var='with'>
        <value>juliet@capulet.lit</value>
      </field>
    </x>
  </query>
</iq>
name: ClassVar[str] = 'query'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'urn:xmpp:mam:2'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

plugin_attrib: ClassVar[str] = 'mam'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
interfaces: ClassVar[Set[str]] = {'after_id', 'before_id', 'end', 'ids', 'queryid', 'results', 'start', 'with'}#

Available interfaces:

  • queryid: The MAM query id

  • start and end: Temporal boundaries of the query

  • with: JID of the other entity the conversation is with

  • after_id: Fetch stanzas after this specific ID

  • before_id: Fetch stanzas before this specific ID

  • ids: Fetch the stanzas matching those IDs

  • results: pseudo-interface used to accumulate MAM results during fetch, not relevant for the stanza itself.

sub_interfaces: ClassVar[Set[str]] = {'after_id', 'before_id', 'end', 'ids', 'start', 'with'}#

A subset of interfaces which maps interfaces to direct subelements of the underlying XML object. Using this set, the text of these subelements may be set, retrieved, or removed without needing to define custom methods.

setup(xml=None)[source]#

Initialize the stanza’s XML contents.

Will return True if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.

Parameters

xml – An existing XML object to use for the stanza’s content instead of generating new XML.

get_fields()[source]#
get_start()[source]#
Return type

Optional[datetime]

set_start(value)[source]#
get_end()[source]#
Return type

Optional[datetime]

set_end(value)[source]#
get_with()[source]#
Return type

Optional[JID]

set_with(value)[source]#
set_custom_field(fieldname, value)[source]#
get_custom_field(fieldname)[source]#
Return type

Optional[str]

set_before_id(value)[source]#
get_before_id()[source]#
set_after_id(value)[source]#
get_after_id()[source]#
set_ids(value)[source]#
get_ids()[source]#
get_results()[source]#
Return type

List[Message]

set_results(values)[source]#
del_results()[source]#
plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

loaded_plugins: Set[str]#
iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

class slixmpp.plugins.xep_0313.stanza.Fin(xml=None, parent=None)[source]#

A MAM fin element (end of query).

<iq type='result' id='juliet1'>
  <fin xmlns='urn:xmpp:mam:2'>
    <set xmlns='http://jabber.org/protocol/rsm'>
      <first index='0'>28482-98726-73623</first>
      <last>09af3-cc343-b409f</last>
    </set>
  </fin>
</iq>
name: ClassVar[str] = 'fin'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'urn:xmpp:mam:2'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

plugin_attrib: ClassVar[str] = 'mam_fin'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
interfaces: ClassVar[Set[str]] = {'results'}#

The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the plugin_attrib value of any registered stanza plugins.

setup(xml=None)[source]#

Initialize the stanza’s XML contents.

Will return True if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.

Parameters

xml – An existing XML object to use for the stanza’s content instead of generating new XML.

get_results()[source]#
Return type

List[Message]

set_results(values)[source]#
del_results()[source]#
plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

loaded_plugins: Set[str]#
iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

class slixmpp.plugins.xep_0313.stanza.Result(xml=None, parent=None)[source]#

A MAM result payload.

<message id='aeb213' to='juliet@capulet.lit/chamber'>
  <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
    <forwarded xmlns='urn:xmpp:forward:0'>
      <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
      <message xmlns='jabber:client' from="witch@shakespeare.lit"
               to="macbeth@shakespeare.lit">
        <body>Hail to thee</body>
      </message>
    </forwarded>
  </result>
</message>
name: ClassVar[str] = 'result'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'urn:xmpp:mam:2'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

plugin_attrib: ClassVar[str] = 'mam_result'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
interfaces: ClassVar[Set[str]] = {'id', 'queryid'}#

Available interfaces:

  • queryid: MAM queryid

  • id: ID of the result

plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

loaded_plugins: Set[str]#
iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

class slixmpp.plugins.xep_0313.stanza.Metadata(xml=None, parent=None)[source]#

Element containing archive metadata

<iq type='result' id='jui8921rr9'>
  <metadata xmlns='urn:xmpp:mam:2'>
    <start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
    <end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
  </metadata>
</iq>
name: ClassVar[str] = 'metadata'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'urn:xmpp:mam:2'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

plugin_attrib: ClassVar[str] = 'mam_metadata'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

loaded_plugins: Set[str]#
iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

class slixmpp.plugins.xep_0313.stanza.Start(xml=None, parent=None)[source]#

Metadata about the start of an archive.

<iq type='result' id='jui8921rr9'>
  <metadata xmlns='urn:xmpp:mam:2'>
    <start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
    <end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
  </metadata>
</iq>
name: ClassVar[str] = 'start'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'urn:xmpp:mam:2'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

plugin_attrib: ClassVar[str] = 'start'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
interfaces: ClassVar[Set[str]] = {'id', 'timestamp'}#

Available interfaces:

  • id: ID of the first message of the archive

  • timestamp (datetime): timestamp of the first message of the archive

get_timestamp()[source]#

Get the timestamp.

Return type

Optional[datetime]

Returns

The timestamp.

set_timestamp(value)[source]#

Set the timestamp.

Parameters

value (Union[datetime, str]) – Value of the timestamp (either a datetime or a XEP-0082 timestamp string.

plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

loaded_plugins: Set[str]#
iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

class slixmpp.plugins.xep_0313.stanza.End(xml=None, parent=None)[source]#

Metadata about the end of an archive.

<iq type='result' id='jui8921rr9'>
  <metadata xmlns='urn:xmpp:mam:2'>
    <start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' />
    <end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' />
  </metadata>
</iq>
name: ClassVar[str] = 'end'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'urn:xmpp:mam:2'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

plugin_attrib: ClassVar[str] = 'end'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
interfaces: ClassVar[Set[str]] = {'id', 'timestamp'}#

Available interfaces:

  • id: ID of the first message of the archive

  • timestamp (datetime): timestamp of the first message of the archive

get_timestamp()[source]#

Get the timestamp.

Return type

Optional[datetime]

Returns

The timestamp.

set_timestamp(value)[source]#

Set the timestamp.

Parameters

value (Union[datetime, str]) – Value of the timestamp (either a datetime or a XEP-0082 timestamp string.

plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

loaded_plugins: Set[str]#
iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.