1 43 package net.jforum.util.ajax; 44 45 import java.util.ArrayList ; 46 import java.util.Date ; 47 48 import net.jforum.entities.Post; 49 import net.jforum.util.SafeHtml; 50 import net.jforum.util.mail.Spammer; 51 import net.jforum.util.preferences.ConfigKeys; 52 import net.jforum.util.preferences.SystemGlobals; 53 import net.jforum.view.forum.common.PostCommon; 54 import freemarker.template.SimpleHash; 55 56 62 public class AjaxUtils 63 { 64 74 public static String sendTestMail(String sender, String host, String auth, 75 String username, String password, String to) 76 { 77 String originalHost = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_HOST); 79 String originalAuth = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_AUTH); 80 String originalUsername = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_USERNAME); 81 String originalPassword = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_PASSWORD); 82 String originalSender = SystemGlobals.getValue(ConfigKeys.MAIL_SENDER); 83 84 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_HOST, host); 86 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_AUTH, auth); 87 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_USERNAME, username); 88 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_PASSWORD, password); 89 SystemGlobals.setValue(ConfigKeys.MAIL_SENDER, sender); 90 91 class TestSpammer extends Spammer { 93 public TestSpammer(final String to) { 94 super.prepareMessage(new ArrayList () {{ add(to); }}, null, "JForum Test Mail", null); 95 } 96 97 protected String getMessageText(SimpleHash params, String messageFile) throws Exception { 98 return ("Test mail from JForum Admin Panel. Sent at " + new Date ()); 99 } 100 } 101 102 Spammer s = new TestSpammer(to); 103 104 try { 105 s.dispatchMessages(); 106 } 107 catch (Exception e) { 108 return e.toString(); 109 } 110 finally { 111 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_HOST, originalHost); 113 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_AUTH, originalAuth); 114 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_USERNAME, originalUsername); 115 SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_PASSWORD, originalPassword); 116 SystemGlobals.setValue(ConfigKeys.MAIL_SENDER, originalSender); 117 } 118 119 return "OK"; 120 } 121 122 127 public static Post previewPost(Post p) 128 { 129 p = PostCommon.preparePostForDisplay(p); 130 131 if (p.isHtmlEnabled()) { 132 p.setText(SafeHtml.makeSafe(p.getText())); 133 } 134 135 return p; 136 } 137 } 138 | Popular Tags |