public void sendHistory(MUCOccupant occupant, MUCRoomHistory roomHistory) {
        if (!isConfigured()) {
            Iterator<Message> history = roomHistory.getMessageHistory();
            while (history.hasNext()) {
                // OF-2163: Create a defensive copy of the message, to prevent the address that it is sent to to leak back into the archive.
                occupant.send(history.next().createCopy());
            }
        }
        else {
            if (getMaxChars() == 0) {
                // The user requested to receive no history
                return;
            }
            int accumulatedChars = 0;
            int accumulatedStanzas = 0;
            Element delayInformation;
            LinkedList<Message> historyToSend = new LinkedList<>();
            ListIterator<Message> iterator = roomHistory.getReverseMessageHistory();
            while (iterator.hasPrevious()) {
                Message message = iterator.previous();
                // Update number of characters to send
                String text = message.getBody() == null ? message.getSubject() : message.getBody();
                if (text == null) {
                    // Skip this message since it has no body and no subject  
                    continue;
                }
                accumulatedChars += text.length();
                if (getMaxChars() > -1 && accumulatedChars > getMaxChars()) {
                    // Stop collecting history since we have exceded a limit
                    break;
                }
                // Update number of messages to send
                accumulatedStanzas ++;
                if (getMaxStanzas() > -1 && accumulatedStanzas > getMaxStanzas()) {
                    // Stop collecting history since we have exceded a limit
                    break;
                }

                if (getSeconds() > -1 || getSince() != null) {
                    delayInformation = message.getChildElement("delay", "urn:xmpp:delay");
                    try {
                        // Get the date when the historic message was sent
                        Date delayedDate = xmppDateTime.parseString(delayInformation.attributeValue("stamp"));
                        if (getSince() != null && delayedDate != null && delayedDate.before(getSince())) {
                            // Stop collecting history since we have exceded a limit
                            break;
                        }
                        if (getSeconds() > -1) {
                            Date current = new Date();
                            long diff = (current.getTime() - delayedDate.getTime()) / 1000;
                            if (getSeconds() <= diff) {
                                // Stop collecting history since we have exceded a limit
                                break;
                            }
                        }
                    }
                    catch (Exception e) {
                        Log.error("Error parsing date from historic message", e);
                    }

                }

                historyToSend.addFirst(message);
            }
            // Send the smallest amount of traffic to the user
            for (final Message aHistoryToSend : historyToSend) {
                // OF-2163: Create a defensive copy of the message, to prevent the address that it is sent to to leak back into the archive.
                occupant.send(aHistoryToSend.createCopy());
            }
        }
    }
Sends the smallest amount of traffic that meets any combination of the requested criteria.

@param occupant the user that will receive the history.
@param roomHistory the history of the room.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/HistoryRequest.java