use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class ContentFilterPlugin method createServerMessage.
private Message createServerMessage(String subject, String body) {
Message message = new Message();
message.setTo(violationContact + "@" + violationNotificationFrom.getDomain());
message.setFrom(violationNotificationFrom);
message.setSubject(subject);
message.setBody(body);
return message;
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class ContentFilterTest method testFilterMessageSubjectWithMask.
@Test
public void testFilterMessageSubjectWithMask() {
// filter on the word fox
filter.setPatterns("fox");
// set a content mask
filter.setMask("**");
// test message
Message message = new Message();
message.setSubject("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has changed
assertEquals("the quick brown ** jumped over the lazy dog", message.getSubject());
assertNull(message.getBody());
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class ContentFilterTest method testFilterWholeWords.
@Test
public void testFilterWholeWords() {
//match every instance of "at" in string
filter.setPatterns("at");
filter.setMask("**");
Message message = new Message();
message.setBody("At noon the fat cats ate lunch at Rizzos");
boolean matched = filter.filter(message);
assertTrue(matched);
assertEquals("At noon the f** c**s **e lunch ** Rizzos", message.getBody());
//match only whole word instances of "at" ignoring case
filter.setPatterns("(?i)\\bat\\b");
message.setBody("At noon the fat cats ate lunch at Rizzos");
matched = filter.filter(message);
assertTrue(matched);
assertEquals("** noon the fat cats ate lunch ** Rizzos", message.getBody());
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class ContentFilterTest method testFilterMessageSubject.
@Test
public void testFilterMessageSubject() {
// filter on the word fox
filter.setPatterns("fox");
// test message
Message message = new Message();
message.setSubject("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has not changed as there is no content mask
assertEquals("the quick brown fox jumped over the lazy dog", message.getSubject());
assertNull(message.getBody());
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class Workgroup method rejectPacket.
public void rejectPacket(Packet packet, PacketRejectedException e) {
if (packet instanceof IQ) {
IQ reply = new IQ();
reply.setChildElement(((IQ) packet).getChildElement().createCopy());
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
send(reply);
} else if (packet instanceof Presence) {
Presence reply = new Presence();
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
send(reply);
}
// Check if a message notifying the rejection should be sent
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message notification = new Message();
notification.setTo(packet.getFrom());
notification.setFrom(packet.getTo());
notification.setBody(e.getRejectionMessage());
send(notification);
}
Log.warn("Packet was REJECTED " + "by interceptor: " + packet.toXML(), e);
}
Aggregations