Separate email preparation and email sending into separate classes

- SendMailSSL keeps on handling the technical details for sending mails, while EmailService offers methods to other classes and worries about generating the correct email content
This commit is contained in:
ljacqu
2017-02-25 20:14:58 +01:00
parent 72c5cfac68
commit a4b440bcca
11 changed files with 396 additions and 318 deletions
@@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme.debug;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.mail.EmailService;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -18,7 +18,7 @@ class TestEmailSender implements DebugSection {
private DataSource dataSource;
@Inject
private SendMailSSL sendMailSSL;
private EmailService emailService;
@Override
@@ -33,7 +33,7 @@ class TestEmailSender implements DebugSection {
@Override
public void execute(CommandSender sender, List<String> arguments) {
if (!sendMailSSL.hasAllInformation()) {
if (!emailService.hasAllInformation()) {
sender.sendMessage(ChatColor.RED + "You haven't set all required configurations in config.yml " +
"for sending emails. Please check your config.yml");
return;
@@ -43,7 +43,7 @@ class TestEmailSender implements DebugSection {
// getEmail() takes care of informing the sender of the error if email == null
if (email != null) {
boolean sendMail = sendMailSSL.sendTestEmail(email);
boolean sendMail = emailService.sendTestEmail(email);
if (sendMail) {
sender.sendMessage("Test email sent to " + email + " with success");
} else {
@@ -5,7 +5,7 @@ import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
@@ -37,7 +37,7 @@ public class RecoverEmailCommand extends PlayerCommand {
private PlayerCache playerCache;
@Inject
private SendMailSSL sendMailSsl;
private EmailService emailService;
@Inject
private RecoveryCodeService recoveryCodeService;
@@ -47,7 +47,7 @@ public class RecoverEmailCommand extends PlayerCommand {
final String playerMail = arguments.get(0);
final String playerName = player.getName();
if (!sendMailSsl.hasAllInformation()) {
if (!emailService.hasAllInformation()) {
ConsoleLogger.warning("Mail API is not set");
commonService.send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS);
return;
@@ -84,7 +84,7 @@ public class RecoverEmailCommand extends PlayerCommand {
private void createAndSendRecoveryCode(Player player, String email) {
String recoveryCode = recoveryCodeService.generateCode(player.getName());
boolean couldSendMail = sendMailSsl.sendRecoveryCode(player.getName(), email, recoveryCode);
boolean couldSendMail = emailService.sendRecoveryCode(player.getName(), email, recoveryCode);
if (couldSendMail) {
commonService.send(player, MessageKey.RECOVERY_CODE_SENT);
} else {
@@ -108,7 +108,7 @@ public class RecoverEmailCommand extends PlayerCommand {
HashedPassword hashNew = passwordSecurity.computeHash(thePass, name);
dataSource.updatePassword(name, hashNew);
boolean couldSendMail = sendMailSsl.sendPasswordMail(name, email, thePass);
boolean couldSendMail = emailService.sendPasswordMail(name, email, thePass);
if (couldSendMail) {
commonService.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
} else {
@@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.register;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
@@ -37,7 +37,7 @@ public class RegisterCommand extends PlayerCommand {
private CommonService commonService;
@Inject
private SendMailSSL sendMailSsl;
private EmailService emailService;
@Inject
private ValidationService validationService;
@@ -127,7 +127,7 @@ public class RegisterCommand extends PlayerCommand {
}
private void handleEmailRegistration(Player player, List<String> arguments) {
if (!sendMailSsl.hasAllInformation()) {
if (!emailService.hasAllInformation()) {
commonService.send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS);
ConsoleLogger.warning("Cannot register player '" + player.getName() + "': no email or password is set "
+ "to send emails from. Please adjust your config at " + EmailSettings.MAIL_ACCOUNT.getPath());