Skip to content

Commit

Permalink
Change from mailText to a dedicated file email.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Xephi committed Dec 4, 2015
1 parent 8336dc8 commit e781115
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/fr/xephi/authme/SendMailSSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void main(final PlayerAuth auth, final String newPass) {
final String subject = Settings.getMailSubject;
final String smtp = Settings.getmailSMTP;
final String password = Settings.getmailPassword;
final String mailText = Settings.getMailText.replace("<playername>", auth.getNickname()).replace("<servername>", plugin.getServer().getServerName()).replace("<generatedpass>", newPass);
final String mailText = Settings.getMailText.replace("%playername%", auth.getNickname()).replace("%servername%", plugin.getServer().getServerName()).replace("%generatedpass%", newPass);
final String mail = auth.getEmail();
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

Expand Down Expand Up @@ -76,7 +76,7 @@ public void run() {
ImageIO.write(gen.generateImage(), "jpg", file);
DataSource source = new FileDataSource(file);
String tag = email.embed(source, auth.getNickname() + "_new_pass.jpg");
content = content.replace("<image>", "<img src=\"cid:" + tag + "\">");
content = content.replace("%image%", "<img src=\"cid:" + tag + "\">");
} catch (Exception e) {
ConsoleLogger.showError("Unable to send new password as image! Using normal text! Dest: " + mail);
}
Expand Down
48 changes: 46 additions & 2 deletions src/main/java/fr/xephi/authme/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import fr.xephi.authme.util.Wrapper;
import org.bukkit.configuration.file.YamlConfiguration;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand All @@ -23,6 +27,7 @@ public final class Settings {
public static final File MODULE_FOLDER = new File(PLUGIN_FOLDER, "modules");
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
public static final File EMAIL_FILE = new File(PLUGIN_FOLDER, "email.html");
public static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
public static final File LOG_FILE = new File(PLUGIN_FOLDER, "authme.log");
// This is not an option!
Expand Down Expand Up @@ -221,7 +226,7 @@ public static void loadVariables() {
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
getMailSubject = configFile.getString("Email.mailSubject", "Your new AuthMe Password");
getMailText = configFile.getString("Email.mailText", "Dear <playername>, <br /><br /> This is your new AuthMe password for the server <br /><br /> <servername> : <br /><br /> <generatedpass><br /><br />Do not forget to change password after login! <br /> /changepassword <generatedpass> newPassword");
getMailText = loadEmailText();
emailRegistration = configFile.getBoolean("settings.registration.enableEmailRegistrationSystem", false);
saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8);
getmaxRegPerEmail = configFile.getInt("Email.maxRegPerEmail", 1);
Expand Down Expand Up @@ -285,7 +290,40 @@ public static void loadVariables() {

}

public static void setValue(String key, Object value) {
private static String loadEmailText() {
if (!EMAIL_FILE.exists())
saveDefaultEmailText();
StringBuilder str = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new FileReader(EMAIL_FILE));
String s;
while ((s = in.readLine()) != null)
str.append(s);
in.close();
} catch(IOException e)
{
}
return str.toString();
}

private static void saveDefaultEmailText() {
InputStream file = plugin.getResource("email.html");
StringBuilder str = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(file, Charset.forName("utf-8")));
String s;
while ((s = in.readLine()) != null)
str.append(s);
in.close();
Files.touch(EMAIL_FILE);
Files.write(str.toString(), EMAIL_FILE, Charsets.UTF_8);
}
catch(Exception e)
{
}
}

public static void setValue(String key, Object value) {
instance.set(key, value);
save();
}
Expand Down Expand Up @@ -636,6 +674,12 @@ public void mergeConfig() {
changes = true;
}

if (contains("Email.mailText"))
{
set("Email.mailText", null);
ConsoleLogger.showError("Remove Email.mailText from config, we now use the email.html file");
}

if (changes) {
plugin.getLogger().warning("Merged new Config Options - I'm not an error, please don't report me");
plugin.getLogger().warning("Please check your config.yml file for new configs!");
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1>
Dear %playername%,
</h1>

<p>
This is your new AuthMe password for the server %servername%:

%generatedpass%

%image%

Do not forget to change password after login!
/changepassword %generatedpass% newPassword'

See you on %servername%!
</p>

0 comments on commit e781115

Please sign in to comment.