18 package org.turro.mail.impl;
20 import java.util.Date;
21 import java.util.HashSet;
24 import java.util.function.Consumer;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import javax.mail.internet.InternetAddress;
28 import org.apache.commons.mail.EmailException;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.impl.abstracts.AbstractImplementation;
31 import org.turro.marker.ElephantMarker;
40 private final Date date =
new Date();
41 private final Set<MailMessage> pool =
new HashSet<>();
42 private String encoding;
49 this.encoding = encoding;
53 String message, String
template, String name, String login) {
54 return addToPoolTemplate(from, to, cc, subject, message,
template, name, login,
null);
58 String message, String
template, String name, String login, Map args) {
73 em.
put(
"body", message);
79 }
catch (EmailException ex) {
100 }
catch (EmailException ex) {
108 mail.
addHeader(
"X-Mailer",
"Elephant Mail System");
109 mail.setSentDate(date);
116 if(password ==
null) {
119 mail.setPassword(password);
121 mail.setSubject(cleanSubject(mail.getSubject()));
125 Logger.getLogger(
MailMessagePool.class.getName()).log(Level.INFO,
"Added mail from {0} to {1}. Subject: {2}",
126 new Object[]{mail.getEmail().getFromAddress().getAddress(),
127 InternetAddress.toString((InternetAddress[]) mail.getEmail().getToAddresses().toArray(
new InternetAddress[0])), mail.getSubject()});
130 }
catch(Exception ex) {
146 private String cleanSubject(String subject) {
147 subject = subject.replaceAll(
"\\<\\/?[\\?a-zA-Z\\-\\:\\_0-9]+\\ ?.*?\\>",
"");
148 subject = subject.replaceAll(
"\\n|\\r",
" ");
static String logMsg(String msg)
static byte[] decrypt(byte[] value)
KeyValueMap getAttributes()
MailMessage addToPool(String from, String to, String cc, String subject, String message)
MailMessage addToPool(MailMessage mail)
void setEncoding(String encoding)
MailMessage addToPoolTemplate(String from, String to, String cc, String subject, String message, String template, String name, String login)
MailMessage addToPoolTemplate(String from, String to, String cc, String subject, String message, String template, String name, String login, Map args)
void sendPool(Consumer onFinish)
void setMessage(ElephantMarker marker, IContact contact)
void setSubject(String subject)
void addHeader(String name, String value)
void setCharset(String newCharset)
Email addCc(String email, String name)
Email setFrom(String email, String name)
void setMessage(String message)
Email addTo(String email, String name)
Object put(Object key, Object value)