Commit 7d9b8735 authored by conor's avatar conor

extended catch to handle Throwable when sending emails

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3299 b35dd754-fafc-0310-a699-88a17e54d16e
parent cfac3014
...@@ -40,58 +40,52 @@ import org.xmpp.packet.Presence; ...@@ -40,58 +40,52 @@ import org.xmpp.packet.Presence;
/** /**
* Content filter plugin. * Content filter plugin.
* *
* @author Conor Hayes * @author Conor Hayes
*/ */
public class ContentFilterPlugin implements Plugin, PacketInterceptor { public class ContentFilterPlugin implements Plugin, PacketInterceptor {
/** /**
* The expected value is a boolean, if true the user identified by the value * The expected value is a boolean, if true the user identified by the value
* of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY will be notified * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY will be notified
* every time there is a content match, otherwise no notification will be * every time there is a content match, otherwise no notification will be
* sent. Then default value is false. * sent. Then default value is false.
*/ */
public static final String VIOLATION_NOTIFICATION_ENABLED_PROPERTY = public static final String VIOLATION_NOTIFICATION_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.enabled";
"plugin.contentFilter.violation.notification.enabled";
/** /**
* The expected value is a user name. The default value is "admin". * The expected value is a user name. The default value is "admin".
*/ */
public static final String VIOLATION_NOTIFICATION_CONTACT_PROPERTY = public static final String VIOLATION_NOTIFICATION_CONTACT_PROPERTY = "plugin.contentFilter.violation.notification.contact";
"plugin.contentFilter.violation.notification.contact";
/** /**
* The expected value is a boolean, if true the user identified by the value * The expected value is a boolean, if true the user identified by the value
* of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will also receive * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will also
* a copy of the offending packet. The default value is false. * receive a copy of the offending packet. The default value is false.
*/ */
public static final String VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY = public static final String VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.include.original.enabled";
"plugin.contentFilter.violation.notification.include.original.enabled";
/** /**
* The expected value is a boolean, if true the user identified by the value * The expected value is a boolean, if true the user identified by the value
* of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive
* notification by IM. The default value is true. * notification by IM. The default value is true.
*/ */
public static final String VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY = public static final String VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.by.im.enabled";
"plugin.contentFilter.violation.notification.by.im.enabled";
/** /**
* The expected value is a boolean, if true the user identified by the value * The expected value is a boolean, if true the user identified by the value
* of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive * of the property #VIOLATION_NOTIFICATION_CONTACT_PROPERTY, will receive
* notification by email. The default value is false. * notification by email. The default value is false.
*/ */
public static final String VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY = public static final String VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY = "plugin.contentFilter.violation.notification.by.email.enabled";
"plugin.contentFilter.violation.notification.by.email.enabled";
/** /**
* The expected value is a boolean, if true the sender will be notified when a * The expected value is a boolean, if true the sender will be notified when
* message is rejected, otherwise the message will be silently rejected,i.e. the * a message is rejected, otherwise the message will be silently
* sender will not know that the message was rejected and the receiver will * rejected,i.e. the sender will not know that the message was rejected and
* not get the message. The default value is false. * the receiver will not get the message. The default value is false.
*/ */
public static final String REJECTION_NOTIFICATION_ENABLED_PROPERTY = public static final String REJECTION_NOTIFICATION_ENABLED_PROPERTY = "plugin.contentFilter.rejection.notification.enabled";
"plugin.contentFilter.rejection.notification.enabled";
/** /**
* The expected value is a string, containing the desired message for the * The expected value is a string, containing the desired message for the
...@@ -109,10 +103,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -109,10 +103,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
* The expected value is a comma separated string of regular expressions. * The expected value is a comma separated string of regular expressions.
*/ */
public static final String PATTERNS_PROPERTY = "plugin.contentFilter.patterns"; public static final String PATTERNS_PROPERTY = "plugin.contentFilter.patterns";
/** /**
* The expected value is a boolean, if true Presence packets will * The expected value is a boolean, if true Presence packets will be
* be filtered * filtered
*/ */
public static final String FILTER_STATUS_ENABLED_PROPERTY = "plugin.contentFilter.filter.status.enabled"; public static final String FILTER_STATUS_ENABLED_PROPERTY = "plugin.contentFilter.filter.status.enabled";
...@@ -123,10 +117,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -123,10 +117,10 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public static final String MASK_ENABLED_PROPERTY = "plugin.contentFilter.mask.enabled"; public static final String MASK_ENABLED_PROPERTY = "plugin.contentFilter.mask.enabled";
/** /**
* The expected value is a string. If this property is set any * The expected value is a string. If this property is set any matching
* matching content will not be rejected but masked with the given value. * content will not be rejected but masked with the given value. Setting a
* Setting a content mask means that property #SENDER_NOTIFICATION_ENABLED_PROPERTY * content mask means that property #SENDER_NOTIFICATION_ENABLED_PROPERTY is
* is ignored. The default value is "**". * ignored. The default value is "**".
*/ */
public static final String MASK_PROPERTY = "plugin.contentFilter.mask"; public static final String MASK_PROPERTY = "plugin.contentFilter.mask";
...@@ -164,13 +158,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -164,13 +158,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
* the admin user to send violation notifications to * the admin user to send violation notifications to
*/ */
private String violationContact; private String violationContact;
/** /**
* flags if original packet should be included in the message * flags if original packet should be included in the message to the
* to the violation contact. * violation contact.
*/ */
private boolean violationIncludeOriginalPacketEnabled; private boolean violationIncludeOriginalPacketEnabled;
/** /**
* flags if violation contact should be notified by IM. * flags if violation contact should be notified by IM.
*/ */
...@@ -180,7 +174,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -180,7 +174,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
* flags if violation contact should be notified by email. * flags if violation contact should be notified by email.
*/ */
private boolean violationNotificationByEmailEnabled; private boolean violationNotificationByEmailEnabled;
/** /**
* flag if patterns should be used * flag if patterns should be used
*/ */
...@@ -190,7 +184,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -190,7 +184,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
* the patterns to use * the patterns to use
*/ */
private String patterns; private String patterns;
/** /**
* flag if Presence packets should be filtered. * flag if Presence packets should be filtered.
*/ */
...@@ -225,7 +219,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -225,7 +219,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setMaskEnabled(boolean enabled) { public void setMaskEnabled(boolean enabled) {
maskEnabled = enabled; maskEnabled = enabled;
JiveGlobals.setProperty(MASK_ENABLED_PROPERTY, enabled ? "true" : "false"); JiveGlobals.setProperty(MASK_ENABLED_PROPERTY, enabled ? "true"
: "false");
changeContentFilterMask(); changeContentFilterMask();
} }
...@@ -240,8 +235,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -240,8 +235,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
private void changeContentFilterMask() { private void changeContentFilterMask() {
if (maskEnabled) { if (maskEnabled) {
contentFilter.setMask(mask); contentFilter.setMask(mask);
} } else {
else {
contentFilter.clearMask(); contentFilter.clearMask();
} }
} }
...@@ -268,22 +262,21 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -268,22 +262,21 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
changeContentFilterPatterns(); changeContentFilterPatterns();
} }
public boolean isFilterStatusEnabled() { public boolean isFilterStatusEnabled() {
return filterStatusEnabled; return filterStatusEnabled;
} }
public void setFilterStatusEnabled(boolean enabled) { public void setFilterStatusEnabled(boolean enabled) {
filterStatusEnabled = enabled; filterStatusEnabled = enabled;
JiveGlobals.setProperty(FILTER_STATUS_ENABLED_PROPERTY, enabled ? "true" JiveGlobals.setProperty(FILTER_STATUS_ENABLED_PROPERTY,
: "false"); enabled ? "true" : "false");
} }
private void changeContentFilterPatterns() { private void changeContentFilterPatterns() {
if (patternsEnabled) { if (patternsEnabled) {
contentFilter.setPatterns(patterns); contentFilter.setPatterns(patterns);
} } else {
else {
contentFilter.clearPatterns(); contentFilter.clearPatterns();
} }
} }
...@@ -323,23 +316,25 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -323,23 +316,25 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
public void setViolationContact(String contact) { public void setViolationContact(String contact) {
violationContact = contact; violationContact = contact;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY, contact); JiveGlobals.setProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY,
contact);
} }
public String getViolationContact() { public String getViolationContact() {
return violationContact; return violationContact;
} }
public boolean isViolationIncludeOriginalPacketEnabled() { public boolean isViolationIncludeOriginalPacketEnabled() {
return violationIncludeOriginalPacketEnabled; return violationIncludeOriginalPacketEnabled;
} }
public void setViolationIncludeOriginalPacketEnabled(boolean enabled) { public void setViolationIncludeOriginalPacketEnabled(boolean enabled) {
violationIncludeOriginalPacketEnabled = enabled; violationIncludeOriginalPacketEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY, JiveGlobals.setProperty(
VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY,
enabled ? "true" : "false"); enabled ? "true" : "false");
} }
public boolean isViolationNotificationByIMEnabled() { public boolean isViolationNotificationByIMEnabled() {
return violationNotificationByIMEnabled; return violationNotificationByIMEnabled;
} }
...@@ -349,14 +344,15 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -349,14 +344,15 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY, JiveGlobals.setProperty(VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY,
enabled ? "true" : "false"); enabled ? "true" : "false");
} }
public boolean isViolationNotificationByEmailEnabled() { public boolean isViolationNotificationByEmailEnabled() {
return violationNotificationByEmailEnabled; return violationNotificationByEmailEnabled;
} }
public void setViolationNotificationByEmailEnabled(boolean enabled) { public void setViolationNotificationByEmailEnabled(boolean enabled) {
violationNotificationByEmailEnabled = enabled; violationNotificationByEmailEnabled = enabled;
JiveGlobals.setProperty(VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY, JiveGlobals.setProperty(
VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY,
enabled ? "true" : "false"); enabled ? "true" : "false");
} }
...@@ -374,17 +370,17 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -374,17 +370,17 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
VIOLATION_NOTIFICATION_ENABLED_PROPERTY, false); VIOLATION_NOTIFICATION_ENABLED_PROPERTY, false);
// default to "admin" // default to "admin"
violationContact = JiveGlobals.getProperty(VIOLATION_NOTIFICATION_CONTACT_PROPERTY, violationContact = JiveGlobals.getProperty(
"admin"); VIOLATION_NOTIFICATION_CONTACT_PROPERTY, "admin");
// default to true // default to true
violationNotificationByIMEnabled = JiveGlobals.getBooleanProperty( violationNotificationByIMEnabled = JiveGlobals.getBooleanProperty(
VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY, true); VIOLATION_NOTIFICATION_BY_IM_ENABLED_PROPERTY, true);
// default to false // default to false
violationNotificationByEmailEnabled = JiveGlobals.getBooleanProperty( violationNotificationByEmailEnabled = JiveGlobals.getBooleanProperty(
VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY, false); VIOLATION_NOTIFICATION_BY_EMAIL_ENABLED_PROPERTY, false);
// default to false // default to false
violationIncludeOriginalPacketEnabled = JiveGlobals.getBooleanProperty( violationIncludeOriginalPacketEnabled = JiveGlobals.getBooleanProperty(
VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY, false); VIOLATION_INCLUDE_ORIGNAL_PACKET_ENABLED_PROPERTY, false);
...@@ -398,22 +394,23 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -398,22 +394,23 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
"Message rejected. This is an automated server response"); "Message rejected. This is an automated server response");
// default to false // default to false
patternsEnabled = JiveGlobals.getBooleanProperty(PATTERNS_ENABLED_PROPERTY, patternsEnabled = JiveGlobals.getBooleanProperty(
false); PATTERNS_ENABLED_PROPERTY, false);
//default to "fox,dog" // default to "fox,dog"
patterns = JiveGlobals.getProperty(PATTERNS_PROPERTY, "fox,dog"); patterns = JiveGlobals.getProperty(PATTERNS_PROPERTY, "fox,dog");
changeContentFilterPatterns(); changeContentFilterPatterns();
// default to false // default to false
filterStatusEnabled = JiveGlobals.getBooleanProperty(FILTER_STATUS_ENABLED_PROPERTY, filterStatusEnabled = JiveGlobals.getBooleanProperty(
false); FILTER_STATUS_ENABLED_PROPERTY, false);
// default to false // default to false
maskEnabled = JiveGlobals.getBooleanProperty(MASK_ENABLED_PROPERTY, false); maskEnabled = JiveGlobals.getBooleanProperty(MASK_ENABLED_PROPERTY,
false);
//default to "***" // default to "***"
mask = JiveGlobals.getProperty(MASK_PROPERTY, "***"); mask = JiveGlobals.getProperty(MASK_PROPERTY, "***");
changeContentFilterMask(); changeContentFilterMask();
...@@ -426,130 +423,145 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -426,130 +423,145 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
// unregister with interceptor manager // unregister with interceptor manager
interceptorManager.removeInterceptor(this); interceptorManager.removeInterceptor(this);
} }
public void interceptPacket(Packet packet, Session session, boolean read, public void interceptPacket(Packet packet, Session session, boolean read,
boolean processed) throws PacketRejectedException { boolean processed) throws PacketRejectedException {
if (isValidTargetPacket(packet, read, processed)) { if (isValidTargetPacket(packet, read, processed)) {
Packet original = packet; Packet original = packet;
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: intercepted packet:" + original.toString()); Log.debug("Content filter: intercepted packet:"
+ original.toString());
} }
// make a copy of the original packet only if required, // make a copy of the original packet only if required,
// as it's an expensive operation // as it's an expensive operation
if (violationNotificationEnabled && violationIncludeOriginalPacketEnabled && maskEnabled) { if (violationNotificationEnabled
&& violationIncludeOriginalPacketEnabled && maskEnabled) {
original = packet.createCopy(); original = packet.createCopy();
} }
// filter the packet // filter the packet
boolean contentMatched = contentFilter.filter(packet); boolean contentMatched = contentFilter.filter(packet);
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: content matched? " + contentMatched); Log.debug("Content filter: content matched? " + contentMatched);
} }
// notify admin of violations // notify admin of violations
if (contentMatched && violationNotificationEnabled) { if (contentMatched && violationNotificationEnabled) {
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending violation notification"); Log.debug("Content filter: sending violation notification");
Log.debug("Content filter: include original msg? " + Log.debug("Content filter: include original msg? "
this.violationIncludeOriginalPacketEnabled); + this.violationIncludeOriginalPacketEnabled);
} }
//TODO consider spining off a separate thread here, // TODO consider spining off a separate thread here,
//in high volume situations, it will result in // in high volume situations, it will result in
//in faster response and notification is not required // in faster response and notification is not required
//to be real time. // to be real time.
sendViolationNotification(original); sendViolationNotification(original);
} }
// msg will either be rejected silently, rejected with // msg will either be rejected silently, rejected with
// some notification to sender, or masked. // some notification to sender, or masked.
if (contentMatched) { if (contentMatched) {
if (maskEnabled) { if (maskEnabled) {
//masking enabled, no further action required // masking enabled, no further action required
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: masked content:" + packet.toString()); Log.debug("Content filter: masked content:"
+ packet.toString());
} }
} else { } else {
//no masking, msg must be rejected // no masking, msg must be rejected
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: rejecting packet"); Log.debug("Content filter: rejecting packet");
} }
PacketRejectedException rejected = new PacketRejectedException( PacketRejectedException rejected = new PacketRejectedException(
"Packet rejected with disallowed content!"); "Packet rejected with disallowed content!");
if (rejectionNotificationEnabled) { if (rejectionNotificationEnabled) {
// let the sender know about the rejection, this is // let the sender know about the rejection, this is
// only possible/useful if the content is not masked // only possible/useful if the content is not masked
rejected.setRejectionMessage(rejectionMessage); rejected.setRejectionMessage(rejectionMessage);
} }
throw rejected; throw rejected;
} }
} }
} }
} }
private boolean isValidTargetPacket(Packet packet, boolean read, boolean processed) { private boolean isValidTargetPacket(Packet packet, boolean read,
return patternsEnabled && !processed && read && boolean processed) {
(packet instanceof Message || return patternsEnabled
(filterStatusEnabled && packet instanceof Presence)); && !processed
&& read
&& (packet instanceof Message || (filterStatusEnabled && packet instanceof Presence));
} }
private void sendViolationNotification(Packet originalPacket) { private void sendViolationNotification(Packet originalPacket) {
String subject = "Content filter notification! (" + originalPacket.getFrom().getNode() + ")"; String subject = "Content filter notification! ("
+ originalPacket.getFrom().getNode() + ")";
String body = null; String body = null;
if (originalPacket instanceof Message) { if (originalPacket instanceof Message) {
Message originalMsg = (Message) originalPacket; Message originalMsg = (Message) originalPacket;
body = "Disallowed content detected in message from:" body = "Disallowed content detected in message from:"
+ originalMsg.getFrom() + " to:" + originalMsg.getTo() + originalMsg.getFrom()
+ ", message was " + " to:"
+ (contentFilter.isMaskingContent() ? "altered." : "rejected.") + originalMsg.getTo()
+ (violationIncludeOriginalPacketEnabled ? + ", message was "
"\nOriginal subject:" + (originalMsg.getSubject() != null ? originalMsg.getSubject() : "") + (contentFilter.isMaskingContent() ? "altered."
+ "\nOriginal content:" + (originalMsg.getBody() != null ? originalMsg.getBody() : "") : ""); : "rejected.")
+ (violationIncludeOriginalPacketEnabled ? "\nOriginal subject:"
+ (originalMsg.getSubject() != null ? originalMsg
.getSubject() : "")
+ "\nOriginal content:"
+ (originalMsg.getBody() != null ? originalMsg
.getBody() : "")
: "");
} else { } else {
//presence // presence
Presence originalPresence = (Presence) originalPacket; Presence originalPresence = (Presence) originalPacket;
body = "Disallowed status detected in presence from:" body = "Disallowed status detected in presence from:"
+ originalPresence.getFrom() + originalPresence.getFrom()
+ ", status was " + ", status was "
+ (contentFilter.isMaskingContent() ? "altered." : "rejected.") + (contentFilter.isMaskingContent() ? "altered."
+ (violationIncludeOriginalPacketEnabled ? : "rejected.")
"\nOriginal status:" + originalPresence.getStatus() : ""); + (violationIncludeOriginalPacketEnabled ? "\nOriginal status:"
+ originalPresence.getStatus()
: "");
} }
if (violationNotificationByIMEnabled) { if (violationNotificationByIMEnabled) {
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending IM notification"); Log.debug("Content filter: sending IM notification");
} }
sendViolationNotificationIM(subject, body); sendViolationNotificationIM(subject, body);
} }
if (violationNotificationByEmailEnabled) { if (violationNotificationByEmailEnabled) {
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending email notification"); Log.debug("Content filter: sending email notification");
} }
sendViolationNotificationEmail(subject, body); sendViolationNotificationEmail(subject, body);
} }
}
private void sendViolationNotificationIM(String subject, String body) {
Message message = createServerMessage(subject, body);
messageRouter.route(message);
} }
private void sendViolationNotificationIM(String subject, String body) {
Message message = createServerMessage(subject, body);
messageRouter.route(message);
}
private Message createServerMessage(String subject, String body) { private Message createServerMessage(String subject, String body) {
Message message = new Message(); Message message = new Message();
message.setTo(violationContact + "@" message.setTo(violationContact + "@"
...@@ -559,36 +571,40 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -559,36 +571,40 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
message.setBody(body); message.setBody(body);
return message; return message;
} }
private void sendViolationNotificationEmail(String subject, String body) { private void sendViolationNotificationEmail(String subject, String body) {
List<MimeMessage> messages = new ArrayList<MimeMessage>(); List<MimeMessage> messages = new ArrayList<MimeMessage>();
EmailService emailService = EmailService.getInstance(); try {
MimeMessage message = emailService.createMimeMessage(); EmailService emailService = EmailService.getInstance();
String encoding = MimeUtility.mimeCharset("iso-8859-1"); MimeMessage message = emailService.createMimeMessage();
try { String encoding = MimeUtility.mimeCharset("iso-8859-1");
User user = UserManager.getInstance().getUser(violationContact);
User user = UserManager.getInstance().getUser(violationContact);
message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(user.getEmail()));
message.setRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(user.getEmail()));
message.setFrom(new InternetAddress("no_reply@"
+ violationNotificationFrom, "Wildfire", encoding));
message.setText(body);
message.setFrom(new InternetAddress("no_reply@" + violationNotificationFrom, "Wildfire", encoding)); message.setSubject(subject);
message.setText(body); message.setSentDate(new Date());
message.setSubject(subject); messages.add(message);
message.setSentDate(new Date());
messages.add(message); emailService.sendMessages(messages);
} catch (Exception e) { } catch (Throwable e) {
Log.error(e); // catch throwable in case email setup is invalid
Log.error("Content Filter: Failed to send email, please review Wildfire setup", e);
} }
emailService.sendMessages(messages);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment