private static <S extends Packet> S enrichWithFMUCElement( @Nonnull S stanza, @Nonnull MUCOccupant sender )
    {
        // Defensive copy - ensure that the original stanza (that might be routed locally) is not modified).
        final S result = (S) stanza.createCopy();

        final Element fmuc = result.getElement().element(FMUC);
        if ( fmuc != null ) {
            return result;
        }

        final JID from;
        if ( sender.getOccupantJID().getResource() == null ) {
            // This role represents the room itself as the sender. Rooms do not have a 'user' address.
            from = sender.getOccupantJID();
        } else {
            from = sender.getUserAddress();
        }
        result.getElement().addElement( FMUC ).addAttribute( "from", from.toString() );

        return result;
    }
Adds an FMUC child element to the stanza, if such an element does not yet exist.

This method provides the functionally opposite implementation of {@link #createCopyWithoutFMUC(Packet)}.

@param stanza The stanza to which an FMUC child element is to be added.
@param sender Representation of the originator of the stanza.
@param <S> Type of stanza
@return A copy of the stanza, with an added FMUC child element.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/FMUCHandler.java