How can I get date and time for archived messages using MamManager in Smack 4.4.6

I am getting the messages, but I don’t see a way to get the timestamp for it:

val mamQueryArgs = MamManager.MamQueryArgs.builder()
val mamQuery = mamManager.queryArchive(mamQueryArgs)
val messageList = mamQuery.messages

Every message should have a delay element extension, as described in XEP-0313: Message Archive Management

Try using the getExtension method on the Message class, to see if the message contains XEP-0203: Delayed Delivery information.

I have been trying to do so btw, but getExtension returns null. There is message.extensions method that returns all available extensions and I get only 1 - the message body. So I thought I should add/register this delay extension somehow, but it is not working still:

ProviderManager.addExtensionProvider(DelayInformation.ELEMENT, DelayInformation.NAMESPACE,
            object: ExtensionElementProvider<DelayInformation>() {
                override fun parse(
                    parser: XmlPullParser?,
                    initialDepth: Int,
                    xmlEnvironment: XmlEnvironment?
                ): DelayInformation {
                    val stampString = parser?.getAttributeValue(DelayInformation.NAMESPACE, "stamp")
                    val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault())
                    val date = stampString?.let { dateFormat.parse(it) }
                    return DelayInformation(date)


That’s curious. I’d expect that to work out of the box (although I have not tested this myself).

I would not expect it to be needed to create your own extension provider. Smack seems to include providers for this XEP: org.jivesoftware.smackx.delay.provider (smack-extensions 4.4.6 API)

Typically, Smack will automatically register extension providers when they’re on the classpath. Are they?

The <delay/> extension is not part of the message but part of the message envelope <forwarded/>. And MamQuery.getMessages() returns the “forwarded” messages, not the message envolope <forwarded/> that carries them.

You want to use MamQuery.getMamResultsExtensions().

1 Like

Much appreciated help! I have the date now. Cheers!

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.