Commit dca7e8a7 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Fix email sending logic.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3393 b35dd754-fafc-0310-a699-88a17e54d16e
parent 14dea555
...@@ -29,13 +29,7 @@ import org.xmpp.packet.Message; ...@@ -29,13 +29,7 @@ import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
/** /**
...@@ -512,7 +506,6 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -512,7 +506,6 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
} }
private void sendViolationNotification(Packet originalPacket) { private void sendViolationNotification(Packet originalPacket) {
String subject = "Content filter notification! (" String subject = "Content filter notification! ("
+ originalPacket.getFrom().getNode() + ")"; + originalPacket.getFrom().getNode() + ")";
...@@ -580,36 +573,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor { ...@@ -580,36 +573,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
} }
private void sendViolationNotificationEmail(String subject, String body) { private void sendViolationNotificationEmail(String subject, String body) {
List<MimeMessage> messages = new ArrayList<MimeMessage>();
try { try {
EmailService emailService = EmailService.getInstance();
MimeMessage message = emailService.createMimeMessage();
String encoding = MimeUtility.mimeCharset("iso-8859-1");
User user = UserManager.getInstance().getUser(violationContact); User user = UserManager.getInstance().getUser(violationContact);
EmailService.getInstance().sendMessage(user.getName(), user.getEmail(), "Wildfire",
"no_reply@" + violationNotificationFrom.getDomain(), subject, body, null);
message.setRecipient(javax.mail.Message.RecipientType.TO, }
new InternetAddress(user.getEmail())); catch (Throwable e) {
message.setFrom(new InternetAddress("no_reply@"
+ violationNotificationFrom, "Wildfire", encoding));
message.setText(body);
message.setSubject(subject);
message.setSentDate(new Date());
messages.add(message);
emailService.sendMessages(messages);
} catch (Throwable e) {
// catch throwable in case email setup is invalid // catch throwable in case email setup is invalid
Log.error("Content Filter: Failed to send email, please review Wildfire setup", e); Log.error("Content Filter: Failed to send email, please review Wildfire setup", e);
} }
......
...@@ -33,10 +33,6 @@ import java.util.Iterator; ...@@ -33,10 +33,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
/** /**
* Registration plugin. * Registration plugin.
* *
...@@ -287,7 +283,7 @@ public class RegistrationPlugin implements Plugin { ...@@ -287,7 +283,7 @@ public class RegistrationPlugin implements Plugin {
} }
private void sendIMNotificatonMessage(User user) { private void sendIMNotificatonMessage(User user) {
String msg = " A new user with the username of '" + user.getUsername() + "' just registered"; String msg = " A new user with the username '" + user.getUsername() + "' just registered.";
for (String contact : getIMContacts()) { for (String contact : getIMContacts()) {
router.route(createServerMessage(contact + "@" + serverName, router.route(createServerMessage(contact + "@" + serverName,
...@@ -296,28 +292,21 @@ public class RegistrationPlugin implements Plugin { ...@@ -296,28 +292,21 @@ public class RegistrationPlugin implements Plugin {
} }
private void sendAlertEmail(User user) { private void sendAlertEmail(User user) {
String msg = " A new user with the username of '" + user.getUsername() + "' just registered"; String subject = "User Registration";
String body = " A new user with the username '" + user.getUsername() + "' just registered.";
List<MimeMessage> messages = new ArrayList<MimeMessage>();
EmailService emailService = EmailService.getInstance(); EmailService emailService = EmailService.getInstance();
MimeMessage message = emailService.createMimeMessage();
String encoding = MimeUtility.mimeCharset("iso-8859-1");
for (String toAddress : emailContacts) { for (String toAddress : emailContacts) {
try { try {
message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(toAddress)); emailService.sendMessage(null, toAddress, "Wildfire", "no_reply@" + serverName,
message.setFrom(new InternetAddress("no_reply@" + serverName, "Wildfire", encoding)); subject, body, null);
message.setText(msg); }
message.setSubject("User Registration"); catch (Exception e) {
messages.add(message);
} catch (Exception e) {
Log.error(e); Log.error(e);
} }
} }
emailService.sendMessages(messages);
} }
private void sendWelcomeMessage(User user) { private void sendWelcomeMessage(User user) {
router.route(createServerMessage(user.getUsername() + "@" + serverName, "Welcome", router.route(createServerMessage(user.getUsername() + "@" + serverName, "Welcome",
getWelcomeMessage())); getWelcomeMessage()));
...@@ -365,11 +354,7 @@ public class RegistrationPlugin implements Plugin { ...@@ -365,11 +354,7 @@ public class RegistrationPlugin implements Plugin {
return false; return false;
} }
//must at least match x@x.xx // Must at least match x@x.xx.
if (!address.matches(".{1,}[@].{1,}[.].{2,}")) { return address.matches(".{1,}[@].{1,}[.].{2,}");
return false;
}
return true;
} }
} }
\ 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