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;
import org.xmpp.packet.Packet;
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.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.PatternSyntaxException;
/**
......@@ -512,7 +506,6 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
}
private void sendViolationNotification(Packet originalPacket) {
String subject = "Content filter notification! ("
+ originalPacket.getFrom().getNode() + ")";
......@@ -580,36 +573,13 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
}
private void sendViolationNotificationEmail(String subject, String body) {
List<MimeMessage> messages = new ArrayList<MimeMessage>();
try {
EmailService emailService = EmailService.getInstance();
MimeMessage message = emailService.createMimeMessage();
String encoding = MimeUtility.mimeCharset("iso-8859-1");
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()));
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 e) {
// catch throwable in case email setup is invalid
Log.error("Content Filter: Failed to send email, please review Wildfire setup", e);
}
......
......@@ -33,10 +33,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
/**
* Registration plugin.
*
......@@ -287,7 +283,7 @@ public class RegistrationPlugin implements Plugin {
}
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()) {
router.route(createServerMessage(contact + "@" + serverName,
......@@ -296,26 +292,19 @@ public class RegistrationPlugin implements Plugin {
}
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();
MimeMessage message = emailService.createMimeMessage();
String encoding = MimeUtility.mimeCharset("iso-8859-1");
for (String toAddress : emailContacts) {
try {
message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(toAddress));
message.setFrom(new InternetAddress("no_reply@" + serverName, "Wildfire", encoding));
message.setText(msg);
message.setSubject("User Registration");
messages.add(message);
} catch (Exception e) {
emailService.sendMessage(null, toAddress, "Wildfire", "no_reply@" + serverName,
subject, body, null);
}
catch (Exception e) {
Log.error(e);
}
}
emailService.sendMessages(messages);
}
private void sendWelcomeMessage(User user) {
......@@ -365,11 +354,7 @@ public class RegistrationPlugin implements Plugin {
return false;
}
//must at least match x@x.xx
if (!address.matches(".{1,}[@].{1,}[.].{2,}")) {
return false;
}
return true;
// Must at least match x@x.xx.
return address.matches(".{1,}[@].{1,}[.].{2,}");
}
}
\ 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