private void populate(Element copy, Date delay, JID delayFrom) {

        copy.setQName(QName.get("message", "jabber:client"));

        for (Object element : copy.elements()) {
            if (element instanceof Element) {
                Element el = (Element) element;
                // Only set the "jabber:client" namespace if the namespace is empty (otherwise the resulting xml would look like <body xmlns=""/>)
                if ("".equals(el.getNamespace().getStringValue())) {
                    el.setQName(QName.get(el.getName(), "jabber:client"));
                }
            }
        }
        if (delay != null) {
            Element delayInfo = element.addElement("delay", "urn:xmpp:delay");
            delayInfo.addAttribute("stamp", XMPPDateTimeFormat.format(delay));
            if (delayFrom != null) {
                // Set the Full JID as the "from" attribute
                delayInfo.addAttribute("from", delayFrom.toString());
            }
        }
        element.add(copy);
    }
@author Christian Schudt
@author Guus der Kinderen, guus@goodbytes.nl
xmppserver/src/main/java/org/jivesoftware/openfire/forward/Forwarded.java