Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Correct Messages troubles for #39
Browse files Browse the repository at this point in the history
  • Loading branch information
hdsdi3g committed Apr 26, 2014
1 parent f391abd commit 950e6b3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
7 changes: 6 additions & 1 deletion app/hd3gtv/mydmam/mail/EndUserBaseMail.java
Expand Up @@ -6,6 +6,7 @@

import java.util.HashMap;
import java.util.Locale;
import java.util.Map.Entry;

import javax.mail.internet.InternetAddress;

Expand Down Expand Up @@ -80,7 +81,11 @@ public void send(HashMap<Object, Object> mail_vars) {
mail.setPlaintext(mte.getPlain_text());
mail.send();

Log2.log.info("Send an user mail", this);
Log2Dump dump = getLog2Dump();
for (Entry<Object, Object> entry : mail_vars.entrySet()) {
dump.add("mail_vars: " + (String) entry.getKey(), entry.getValue());
}
Log2.log.info("Send an user mail", dump);
} catch (Exception e) {
Log2.log.error("Fail to send an user mail", e, this);
}
Expand Down
19 changes: 9 additions & 10 deletions app/hd3gtv/mydmam/mail/MailTemplateEngine.java
Expand Up @@ -203,12 +203,7 @@ public void process(HashMap<Object, Object> variables) throws CompilationFailedE
/**
* Prepare template variables and messages
*/
HashMap<Object, Object> real_variables;
if (variables != null) {
real_variables = (HashMap<Object, Object>) variables.clone();
} else {
real_variables = new HashMap<Object, Object>();
}
HashMap<Object, Object> all_variables = new HashMap<Object, Object>();

File message_file = new File(template_directory.getAbsolutePath() + File.separator + BASE_TEMPLATE_MESSAGES + "." + locale.getLanguage());
if (message_file.exists() == false) {
Expand All @@ -231,13 +226,17 @@ public boolean accept(File dir, String name) {
Properties message = new OrderSafeProperties();
message.load(message_fis);
message_fis.close();
real_variables.putAll(message);

all_variables.putAll(message);
if (variables != null) {
all_variables.putAll(variables);
}

/**
* Process templates
*/
html_text = process(template_engine.createTemplate(new File(template_directory.getAbsolutePath() + File.separator + TEMPLATE_HTML_FILE)), real_variables);
ArrayList<String> plain_text_list = process(template_engine.createTemplate(new File(template_directory.getAbsolutePath() + File.separator + TEMPLATE_TXT_FILE)), real_variables);
html_text = process(template_engine.createTemplate(new File(template_directory.getAbsolutePath() + File.separator + TEMPLATE_HTML_FILE)), all_variables);
ArrayList<String> plain_text_list = process(template_engine.createTemplate(new File(template_directory.getAbsolutePath() + File.separator + TEMPLATE_TXT_FILE)), all_variables);

StringBuffer sb = new StringBuffer();
for (int pos = 0; pos < plain_text_list.size(); pos++) {
Expand All @@ -246,7 +245,7 @@ public boolean accept(File dir, String name) {
}
plain_text = sb.toString();

ArrayList<String> subject_text_list = process(template_engine.createTemplate(new File(template_directory.getAbsolutePath() + File.separator + TEMPLATE_SUBJECT_FILE)), real_variables);
ArrayList<String> subject_text_list = process(template_engine.createTemplate(new File(template_directory.getAbsolutePath() + File.separator + TEMPLATE_SUBJECT_FILE)), all_variables);
sb = new StringBuffer();
for (int pos = 0; pos < subject_text_list.size(); pos++) {
sb.append(subject_text_list.get(pos));
Expand Down
5 changes: 1 addition & 4 deletions app/models/UserProfile.java
Expand Up @@ -39,7 +39,6 @@
import play.data.validation.Required;
import play.i18n.Lang;
import play.i18n.Messages;
import play.mvc.Router;

@AuthorisedForAdminController
public class UserProfile extends CrudOrmModel {
Expand Down Expand Up @@ -69,11 +68,10 @@ public void sendTestMail() throws Exception {
HashMap<Object, Object> variables = new HashMap<Object, Object>();
try {
if (Play.initialized) {
Properties messages = Messages.all(Lang.get());
Properties messages = Messages.all(language);
String real_message = messages.getProperty("crud.field.userprofile.sendTestMail.by", "");
variables.put("me_has_sent_this_message", String.format(real_message, longname));
variables.put("sitename", messages.getProperty("site.name", "[MyDMAM]"));
variables.put("sitefooter", messages.getProperty("site.name", "[MyDMAM]") + " :: " + Router.getFullUrl("Application.index"));
} else {
throw new Exception();
}
Expand All @@ -82,7 +80,6 @@ public void sendTestMail() throws Exception {
* Outside Play scope
*/
variables.put("sitename", "[MyDMAM]");
variables.put("sitefooter", "");
}
mail.send(variables);
}
Expand Down
2 changes: 1 addition & 1 deletion conf/mail-templates/usertestmail/messages.en
@@ -1,4 +1,4 @@
mailtest=Send test mail
testmessage=This email was sent to check the proper functioning of the mail engine, as well as your ability to receive and read this email.
please_not_respond=This email is automatically sent, thank you not to answer.
please_not_respond=Thank you not to answer to this email.
me_has_sent_this_message=You should normally have caused the sending of this email.
2 changes: 1 addition & 1 deletion conf/mail-templates/usertestmail/messages.fr
@@ -1,4 +1,4 @@
mailtest=Test d'envoi de mail
testmessage=Ce mail a été envoyé pour vérifier le bon fonctionnement du moteur de mail, ainsi que votre capacité à pouvoir recevoir et lire ce mail.
please_not_respond=Ce mail étant envoyé automatiquement, merci de ne pas y répondre.
please_not_respond=Merci de ne pas y répondre à ce mail.
me_has_sent_this_message=Vous devez avoir normalement provoqué l'envoi de ce mail.
5 changes: 2 additions & 3 deletions conf/mail-templates/usertestmail/template.html
Expand Up @@ -29,7 +29,7 @@
</style>
</head>
<body>
<span class="title">${sitename} <span style="color:#0E6900">:: ${mailtest}</span></span><br>
<span class="title">${mailtest}</span></span><br>
<hr style="height:3px; background-color:#992626">
<p style="padding:7pt;">
${testmessage}
Expand All @@ -40,7 +40,6 @@
<i>${please_not_respond}</i>
</p>
</div>
<br>
<span style="font-size:0.9em;">${sitefooter}</span>
<span style="font-size:0.9em;">${sitename}</span>
</body>
</html>
1 change: 0 additions & 1 deletion conf/mail-templates/usertestmail/template.txt
Expand Up @@ -21,5 +21,4 @@ ${testmessage}
###
## ${me_has_sent_this_message}
## ${please_not_respond}
## ${sitefooter}
###

0 comments on commit 950e6b3

Please sign in to comment.