use of javax.mail.internet.AddressException in project oozie by apache.
the class SLAEmailEventListener method parseAddress.
private Address[] parseAddress(String str) {
Address[] addrs = null;
List<InternetAddress> addrList = new ArrayList<InternetAddress>();
String[] emails = str.split(ADDRESS_SEPARATOR, -1);
for (String email : emails) {
boolean isBlackListed = false;
AtomicInteger val = blackList.getIfPresent(email);
if (val != null) {
isBlackListed = (val.get() >= blacklistFailCount);
}
if (!isBlackListed) {
try {
// turn on strict syntax check by setting 2nd argument true
addrList.add(new InternetAddress(email, true));
} catch (AddressException ae) {
// simply skip bad address but do not throw exception
LOG.error("Skipping bad destination address: " + email, ae);
}
}
}
if (addrList.size() > 0) {
addrs = (Address[]) addrList.toArray(new InternetAddress[addrList.size()]);
}
return addrs;
}
use of javax.mail.internet.AddressException in project acs-aem-commons by Adobe-Consulting-Services.
the class EmailServiceImpl method sendEmail.
@Override
public List<String> sendEmail(String templatePath, Map<String, String> emailParams, Map<String, DataSource> attachments, String... recipients) {
List<String> failureList = new ArrayList<String>();
if (recipients == null || recipients.length <= 0) {
throw new IllegalArgumentException(MSG_INVALID_RECIPIENTS);
}
List<InternetAddress> addresses = new ArrayList<InternetAddress>(recipients.length);
for (String recipient : recipients) {
try {
addresses.add(new InternetAddress(recipient));
} catch (AddressException e) {
log.warn("Invalid email address {} passed to sendEmail(). Skipping.", recipient);
}
}
InternetAddress[] iAddressRecipients = addresses.toArray(new InternetAddress[addresses.size()]);
List<InternetAddress> failureInternetAddresses = sendEmail(templatePath, emailParams, attachments, iAddressRecipients);
for (InternetAddress address : failureInternetAddresses) {
failureList.add(address.toString());
}
return failureList;
}
use of javax.mail.internet.AddressException in project spring-integration by spring-projects.
the class ImapMailReceiverTests method testIdleWithServerCustomSearch.
@Test
public void testIdleWithServerCustomSearch() throws Exception {
ImapMailReceiver receiver = new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getPort() + "/INBOX");
receiver.setSearchTermStrategy((supportedFlags, folder) -> {
try {
FromTerm fromTerm = new FromTerm(new InternetAddress("bar@baz"));
return new AndTerm(fromTerm, new FlagTerm(new Flags(Flag.SEEN), false));
} catch (AddressException e) {
throw new RuntimeException(e);
}
});
testIdleWithServerGuts(receiver, false);
}
use of javax.mail.internet.AddressException in project hudson-2.x by hudson.
the class BaseBuildResultMail method createEmptyMail.
/**
* Creates empty mail.
*
* @param build build.
* @param listener listener.
* @return empty mail.
* @throws MessagingException exception if any.
*/
protected MimeMessage createEmptyMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException {
MimeMessage msg = new HudsonMimeMessage(Mailer.descriptor().createSession());
// TODO: I'd like to put the URL to the page in here,
// but how do I obtain that?
msg.setContent("", "text/plain");
msg.setFrom(new InternetAddress(Mailer.descriptor().getAdminAddress()));
msg.setSentDate(new Date());
Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>();
StringTokenizer tokens = new StringTokenizer(getRecipients());
while (tokens.hasMoreTokens()) {
String address = tokens.nextToken();
if (address.startsWith("upstream-individuals:")) {
// people who made a change in the upstream
String projectName = address.substring("upstream-individuals:".length());
AbstractProject up = Hudson.getInstance().getItemByFullName(projectName, AbstractProject.class);
if (up == null) {
listener.getLogger().println("No such project exist: " + projectName);
continue;
}
includeCulpritsOf(up, build, listener, rcp);
} else {
// ordinary address
try {
rcp.add(new InternetAddress(address));
} catch (AddressException e) {
// report bad address, but try to send to other addresses
e.printStackTrace(listener.error(e.getMessage()));
}
}
}
if (CollectionUtils.isNotEmpty(upstreamProjects)) {
for (AbstractProject project : upstreamProjects) {
includeCulpritsOf(project, build, listener, rcp);
}
}
if (sendToIndividuals) {
Set<User> culprits = build.getCulprits();
if (debug)
listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(culprits)==" + culprits.size());
rcp.addAll(buildCulpritList(listener, culprits));
}
msg.setRecipients(Message.RecipientType.TO, rcp.toArray(new InternetAddress[rcp.size()]));
AbstractBuild<?, ?> pb = build.getPreviousBuild();
if (pb != null) {
MailMessageIdAction b = pb.getAction(MailMessageIdAction.class);
if (b != null) {
msg.setHeader("In-Reply-To", b.messageId);
msg.setHeader("References", b.messageId);
}
}
return msg;
}
use of javax.mail.internet.AddressException in project stanbol by apache.
the class SimpleMailExtractor method extract.
public void extract(URI id, InputStream stream, Charset charset, String mimeType, RDFContainer result) throws ExtractorException {
try {
// parse the stream
MimeMessage message = new MimeMessage(null, stream);
result.add(RDF.type, NMO.Email);
// extract the full-text
StringBuilder buffer = new StringBuilder(10000);
processMessage(message, buffer, result);
String text = buffer.toString().trim();
if (text.length() > 0) {
result.add(NMO.plainTextMessageContent, text);
result.add(NIE.plainTextContent, text);
}
// extract other metadata
String title = message.getSubject();
if (title != null) {
title = title.trim();
if (title.length() > 0) {
result.add(NMO.messageSubject, title);
}
}
try {
copyAddress(message.getFrom(), NMO.from, result);
} catch (AddressException e) {
// ignore
}
copyAddress(getRecipients(message, RecipientType.TO), NMO.to, result);
copyAddress(getRecipients(message, RecipientType.CC), NMO.cc, result);
copyAddress(getRecipients(message, RecipientType.BCC), NMO.bcc, result);
MailUtil.getDates(message, result);
} catch (MessagingException e) {
throw new ExtractorException(e);
} catch (IOException e) {
throw new ExtractorException(e);
}
}
Aggregations