public Message parseHistoricMessage(String senderJID, String nickname, Date sentDate, String subject,
                                        String body, String stanza)
    {
        Message message = new Message();
        message.setType(Message.Type.groupchat);
        if (stanza != null) {
            // payload initialized as XML string from DB
            try {
                Element element = SAXReaderUtil.readRootElement(stanza);
                for (Element child : element.elements()) {
                    Namespace ns = child.getNamespace();
                    if (ns == null || ns.getURI().equals("jabber:client") || ns.getURI().equals("jabber:server")) {
                        continue;
                    }
                    Element added = message.addChildElement(child.getName(), child.getNamespaceURI());
                    if (!child.getText().isEmpty()) {
                        added.setText(child.getText());
                    }
                    for (Attribute attr : child.attributes()) {
                        added.addAttribute(attr.getQName(), attr.getValue());
                    }
                    for (Element el : child.elements()) {
                        added.add(el.createCopy());
                    }
                }
                if (element.attribute("id") != null) {
                    message.setID(element.attributeValue("id"));
                }
            } catch (Exception ex) {
                Log.error("Failed to parse payload XML", ex);
                if (ex instanceof InterruptedException) {
                    Thread.currentThread().interrupt();
                }
            }
        }
        message.setSubject(subject);
        message.setBody(body);
        // Set the sender of the message
        if (nickname != null && !nickname.trim().isEmpty()) {
            JID roomJID = getRoom().getSelfRepresentation().getOccupantJID();
            // Recreate the sender address based on the nickname and room's JID
            message.setFrom(new JID(roomJID.getNode(), roomJID.getDomain(), nickname, true));
        }
        else {
            // Set the room as the sender of the message
            message.setFrom(getRoom().getSelfRepresentation().getOccupantJID());
        }

        // Add the delay information to the message
        Element delayInformation = message.addChildElement("delay", "urn:xmpp:delay");
        delayInformation.addAttribute("stamp", XMPPDateTimeFormat.format(sentDate));
        if (getRoom().canAnyoneDiscoverJID()) {
            // Set the Full JID as the "from" attribute
            delayInformation.addAttribute("from", senderJID);
        }
        else {
            // Set the Room JID as the "from" attribute
            delayInformation.addAttribute("from", getRoom().getSelfRepresentation().getOccupantJID().toString());
        }
        return message;
    }
Creates a new message, representing a message that was exchanged in a chat room in the past, based on the
provided information.

This information will likely come from the database when loading the room history from the database.

@param senderJID the sender's JID of the message.
@param nickname the sender's nickname of the message.
@param sentDate the date when the message was sent to the room.
@param subject the subject included in the message.
@param body the body of the message.
@param stanza the stanza to add
@return A historic chat message.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCRoomHistory.java