BrightSide Workbench Full Report + Source Code
org.turro.mail.impl.MailPool Class Reference
Inheritance diagram for org.turro.mail.impl.MailPool:
Collaboration diagram for org.turro.mail.impl.MailPool:

Public Member Functions

 MailPool ()
 
void setEncoding (String encoding)
 
String getTemplateString (String attribute)
 
void addToPool (String from, String to, String cc, String subject, String message, String content)
 
void sendPool ()
 
void addCssFile (String cssFile)
 
- Public Member Functions inherited from org.turro.elephant.impl.abstracts.AbstractImplementation
 AbstractImplementation ()
 
void setElement (IElement element)
 
void setConstructor (IConstructor constructor)
 
void setConfiguration (Element configuration)
 
KeyValueMap getAttributes ()
 
Long getLongAttribute (String key)
 

Static Public Member Functions

static void sendMailToAssistants (String path, String subject, String message, Object data)
 
static void sendMailToAdmin (String subject, String message)
 
static void sendMailToRole (String role, String subject, String message, Object data)
 
static void sendMailToAssistantsAndAdmin (String path, String subject, String message, Object data)
 
static void sendMailToRoleAndAdmin (String role, String subject, String message, Object data)
 

Protected Member Functions

Session getMailSession () throws MessagingException
 

Protected Attributes

Session session = null
 
- Protected Attributes inherited from org.turro.elephant.impl.abstracts.AbstractImplementation
IElement iel
 
IConstructor constructor
 
Element configuration
 
Map attributes
 

Detailed Description

Constructor & Destructor Documentation

◆ MailPool()

org.turro.mail.impl.MailPool.MailPool ( )

Creates a new instance of MailPool

Definition at line 63 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

63  {
64  }

Member Function Documentation

◆ addCssFile()

void org.turro.mail.impl.MailPool.addCssFile ( String  cssFile)

Definition at line 175 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

175  {
176  if(cssFiles.isEmpty()) {
177  String cssS = (String) getAttributes().get("cssS");
178  if(!Strings.isBlank(cssS)) {
179  String[] cssA = cssS.split(",");
180  for(String css1 : cssA) {
181  cssFiles.add(ElephantContext.getRealPath(css1));
182  }
183  }
184  }
185  cssFiles.add(cssFile);
186  }
Here is the call graph for this function:

◆ addToPool()

void org.turro.mail.impl.MailPool.addToPool ( String  from,
String  to,
String  cc,
String  subject,
String  message,
String  content 
)

Definition at line 74 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

74  {
75  String poolFrom = (String) getAttributes().get("from");
76  String poolTo = (String) getAttributes().get("to");
77  String template = getTemplateString("template");
78 
79  if(to == null) {
80  to = poolTo;
81  }
82  if(to == null) {
83  return;
84  }
85  try {
86 
87  if (session == null) {
89  }
90 
91  MimeMessage msg = new MimeMessage(session);
92 
93  if (from != null) {
94  msg.setFrom(new InternetAddress(from));
95  } else if (poolFrom != null) {
96  msg.setFrom(new InternetAddress(poolFrom));
97  } else {
98  msg.setFrom();
99  }
100  msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
101 
102  if (cc != null) {
103  msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false));
104  }
105  msg.setSubject(cleanSubject(subject), encoding);
106 
107  message = template == null ? message : template.replaceAll("\\#body", Parser.escapeGrouping(message));
108 
109  if (content == null) {
110  msg.setText(addStyles(message), encoding);
111  } else {
112  msg.setContent(addStyles(message), content + ";charset=\"" + encoding + "\"");
113  }
114  msg.setHeader("X-Mailer", "Elephant Mail System");
115  msg.setHeader("Content-Transfer-Encoding", "quoted-printable");
116  msg.setSentDate(date);
117 
118  pool.add(msg);
119 
120  Logger.getLogger(MailPool.class.getName()).log(Level.INFO, "Added mail from {0} to {1}. Subject: {2}",
121  new Object[]{InternetAddress.toString(msg.getFrom()),
122  InternetAddress.toString(msg.getAllRecipients()), msg.getSubject()});
123 
124  } catch (MessagingException mex) {
125  Logger.getLogger(MailPool.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), mex);
126  }
127  }

◆ getMailSession()

Session org.turro.mail.impl.MailPool.getMailSession ( ) throws MessagingException
protected

Definition at line 145 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

145  {
146  String mailhost = (String) getAttributes().get("mailhost");
147  String user = (String) getAttributes().get("user");
148 
149  Session tmpSession = null;
150 
151  if (mailhost.startsWith("java:")) {
152  try {
153  InitialContext ic = new InitialContext();
154  tmpSession = (Session) ic.lookup(mailhost);
155  } catch (NamingException ex) {
156  Logger.getLogger(MailPool.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
157  throw new MessagingException("Naming problem with: " + mailhost + "\n\n" + ex.getExplanation());
158  }
159  } else {
160  Properties props = System.getProperties();
161  tmpSession = Session.getDefaultInstance(props, null);
162  if (mailhost != null) {
163  props.put("mail.smtp.host", mailhost);
164  }
165  if (user != null) {
166  props.put("mail.smtp.auth", "true");
167  } else {
168  props.put("mail.smtp.auth", "false");
169  }
170  }
171 
172  return tmpSession;
173  }
Here is the call graph for this function:

◆ getTemplateString()

String org.turro.mail.impl.MailPool.getTemplateString ( String  attribute)

Definition at line 70 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

70  {
71  return loadFromFile((String) getAttributes().get(attribute));
72  }
Here is the call graph for this function:

◆ sendMailToAdmin()

static void org.turro.mail.impl.MailPool.sendMailToAdmin ( String  subject,
String  message 
)
static

Definition at line 247 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

247  {
248  MailPool mp = (MailPool) ContextFactory.getImplementation(HeadlessApplication.getInstance().getConstructor(), "IMailPool");
249  mp.setEncoding(ElephantContext.getEncoding());
250  mp.addCssFile(ElephantContext.getRealPath("/_internal/css/mail.css"));
251  mp.addToPool(null, null, null, subject + " : " + ElephantContext.getSiteName(),
252  StringParser.toHTML(message), "text/html");
253  mp.sendPool();
254  }

◆ sendMailToAssistants()

static void org.turro.mail.impl.MailPool.sendMailToAssistants ( String  path,
String  subject,
String  message,
Object  data 
)
static

Definition at line 232 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

232  {
233  AssistantSet al = new AssistantSet();
234  Assistants.addAssistants(path, true, al, data);
235  if(!al.isEmpty()) {
236  MailPool mp = (MailPool) ContextFactory.getImplementation(HeadlessApplication.getInstance().getConstructor(), "IMailPool");
237  mp.setEncoding(ElephantContext.getEncoding());
238  mp.addCssFile(ElephantContext.getRealPath("/_internal/css/mail.css"));
239  for(Assistant a : al) {
240  mp.addToPool(null, a.email, null, subject + " : " + ElephantContext.getSiteName(),
241  StringParser.toHTML(al.getSubject() + "\n\n" + message), "text/html");
242  }
243  mp.sendPool();
244  }
245  }

◆ sendMailToAssistantsAndAdmin()

static void org.turro.mail.impl.MailPool.sendMailToAssistantsAndAdmin ( String  path,
String  subject,
String  message,
Object  data 
)
static

Definition at line 271 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

271  {
272  MailPool mp = (MailPool) ContextFactory.getImplementation(HeadlessApplication.getInstance().getConstructor(), "IMailPool");
273  mp.setEncoding(ElephantContext.getEncoding());
274  mp.addCssFile(ElephantContext.getRealPath("/_internal/css/mail.css"));
275  AssistantSet al = new AssistantSet();
276  Assistants.addAssistants(path, true, al, data);
277  String to = (String) mp.getAttributes().get("to");
278  if(to != null) {
279  al.add(new Assistant(null, to, null, null));
280  }
281  if(!al.isEmpty()) {
282  for(Assistant a : al) {
283  mp.addToPool(null, a.email, null, subject + " : " + ElephantContext.getSiteName(),
284  StringParser.toHTML(al.getSubject() + "\n\n" + message), "text/html");
285  }
286  mp.sendPool();
287  }
288  }

◆ sendMailToRole()

static void org.turro.mail.impl.MailPool.sendMailToRole ( String  role,
String  subject,
String  message,
Object  data 
)
static

Definition at line 256 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

256  {
257  AssistantSet al = new AssistantSet();
258  Assistants.addAssistants(role, al, data);
259  if(!al.isEmpty()) {
260  MailPool mp = (MailPool) ContextFactory.getImplementation(HeadlessApplication.getInstance().getConstructor(), "IMailPool");
261  mp.setEncoding(ElephantContext.getEncoding());
262  mp.addCssFile(ElephantContext.getRealPath("/_internal/css/mail.css"));
263  for(Assistant a : al) {
264  mp.addToPool(null, a.email, null, subject + " : " + ElephantContext.getSiteName(),
265  StringParser.toHTML(al.getSubject() + "\n\n" + message), "text/html");
266  }
267  mp.sendPool();
268  }
269  }

◆ sendMailToRoleAndAdmin()

static void org.turro.mail.impl.MailPool.sendMailToRoleAndAdmin ( String  role,
String  subject,
String  message,
Object  data 
)
static

Definition at line 290 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

290  {
291  MailPool mp = (MailPool) ContextFactory.getImplementation(HeadlessApplication.getInstance().getConstructor(), "IMailPool");
292  mp.setEncoding(ElephantContext.getEncoding());
293  mp.addCssFile(ElephantContext.getRealPath("/_internal/css/mail.css"));
294  AssistantSet al = new AssistantSet();
295  Assistants.addAssistants(role, al, data);
296  String to = (String) mp.getAttributes().get("to");
297  if(to != null) {
298  al.add(new Assistant(null, to, null, null));
299  }
300  if(!al.isEmpty()) {
301  for(Assistant a : al) {
302  mp.addToPool(null, a.email, null, subject + " : " + ElephantContext.getSiteName(),
303  StringParser.toHTML(al.getSubject() + "\n\n" + message), "text/html");
304  }
305  mp.sendPool();
306  }
307  }

◆ sendPool()

void org.turro.mail.impl.MailPool.sendPool ( )

Definition at line 129 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

129  {
130  String mailhost = (String) getAttributes().get("mailhost");
131  String user = (String) getAttributes().get("user");
132  String password = (String) getAttributes().get("password");
133 
134  if(password == null) {
135  try {
136  password = ElephantContext.decrypt((String) getAttributes().get("cryptpass"));
137  } catch (Exception ex) {
138  Logger.getLogger(MailPool.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
139  }
140  }
141 
142  //new MailPoolSender(session, pool, mailhost, user, password).send();
143  }
Here is the call graph for this function:

◆ setEncoding()

void org.turro.mail.impl.MailPool.setEncoding ( String  encoding)

Definition at line 66 of file elephant/src/main/java/org/turro/mail/impl/MailPool.java.

66  {
67  this.encoding = encoding;
68  }

Member Data Documentation

◆ session

Session org.turro.mail.impl.MailPool.session = null
protected

The documentation for this class was generated from the following file: