use of javax.mail.internet.AddressException in project nhin-d by DirectProject.
the class AbstractCompletionCondition method normalizeFinalRecip.
/**
* Final recipients may begin with something like rfc822;. This removes the prefix and just returns the final
* recipient as an address.
* @param recip The final recipient
* @return Normalized version of the final recipient that only contains the email address.
*/
public static String normalizeFinalRecip(String recip) {
String normalizedString = recip;
final int index = recip.indexOf(";");
if (index > -1) {
normalizedString = recip.substring(index + 1).trim();
}
// we need to just get the email address for comparison
try {
InternetAddress addr = new InternetAddress(normalizedString);
normalizedString = addr.getAddress();
} catch (AddressException e) {
/* noop */
}
return normalizedString;
}
use of javax.mail.internet.AddressException in project nhin-d by DirectProject.
the class WSSmtpAgentConfig method buildDomains.
protected void buildDomains() {
domains = new ArrayList<String>();
domainPostmasters = new HashMap<String, DomainPostmaster>();
// get the domain list first
try {
int domainCount = cfService.getDomainCount();
lookedupWSDomains = cfService.listDomains(null, domainCount);
} catch (Exception e) {
throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting domains list: " + e.getMessage(), e);
}
if (lookedupWSDomains != null) {
for (Domain dom : lookedupWSDomains) {
domains.add(dom.getDomainName());
try {
String configuredAddress = dom.getPostMasterEmail();
configuredAddress = (configuredAddress == null || configuredAddress.trim().isEmpty()) ? DomainPostmaster.getDefaultPostmaster(dom.getDomainName()) : configuredAddress;
domainPostmasters.put(dom.getDomainName().toUpperCase(Locale.getDefault()), new DomainPostmaster(dom.getDomainName(), new InternetAddress(configuredAddress)));
} catch (AddressException e) {
}
}
}
if (domains.size() == 0)
throw new SmtpAgentException(SmtpAgentError.MissingDomains);
// now get the trust anchors
buildTrustAnchorResolver();
}
use of javax.mail.internet.AddressException in project nhin-d by DirectProject.
the class XMLSmtpAgentConfig method buildDomains.
/*
* Builds the list of domains managed by the agent.
*/
private void buildDomains(Node domainsNode) {
domains = new ArrayList<String>();
domainPostmasters = new HashMap<String, DomainPostmaster>();
// get all domains
Node domainNode = domainsNode.getFirstChild();
Node anchorStoreNode = null;
Map<String, Collection<String>> incomingAnchorHolder = new HashMap<String, Collection<String>>();
Map<String, Collection<String>> outgoingAnchorHolder = new HashMap<String, Collection<String>>();
do {
// get an individual domain
String domain = "";
String postmasterAddr = "";
if (domainNode.getNodeType() == Node.ELEMENT_NODE) {
if (domainNode.getNodeName().equalsIgnoreCase("domain")) {
Element domainEl = (Element) domainNode;
domain = domainEl.getAttribute("name");
if (domain == null || domain.trim().length() == 0)
throw new SmtpAgentException(SmtpAgentError.MissingDomainName);
postmasterAddr = domainEl.getAttribute("postmaster");
if (postmasterAddr == null || postmasterAddr.trim().length() == 0)
postmasterAddr = DomainPostmaster.getDefaultPostmaster(domain);
domains.add(domain);
try {
domainPostmasters.put(domain.toUpperCase(Locale.getDefault()), new DomainPostmaster(domain, new InternetAddress(postmasterAddr)));
} catch (AddressException e) {
}
// get the trust anchors configured for this domain
Node anchorsNode = domainNode.getFirstChild();
do {
if (anchorsNode.getNodeType() == Node.ELEMENT_NODE) {
/*
* Incoming trust anchors
*/
if (anchorsNode.getNodeName().equalsIgnoreCase("incomingtrustanchors"))
incomingAnchorHolder.put(domain, getConfiguredTrustAnchorNames(anchorsNode));
else /*
* Outgoing trust anchors
*/
if (anchorsNode.getNodeName().equalsIgnoreCase("outgoingtrustanchors"))
outgoingAnchorHolder.put(domain, getConfiguredTrustAnchorNames(anchorsNode));
}
anchorsNode = anchorsNode.getNextSibling();
} while (anchorsNode != null);
} else if (domainNode.getNodeName().equalsIgnoreCase("anchorstore")) {
// save off for later configuration
anchorStoreNode = domainNode;
}
}
domainNode = domainNode.getNextSibling();
} while (domainNode != null);
if (domains.size() == 0)
throw new SmtpAgentException(SmtpAgentError.MissingDomains);
buildTrustAnchorResolver((Element) anchorStoreNode, incomingAnchorHolder, outgoingAnchorHolder);
}
use of javax.mail.internet.AddressException in project opennms by OpenNMS.
the class JavaMailAckReaderIT method workingWithSimpleTextMessages.
/**
* tests the ability to create acknowledgments from an email for plain text. This test
* creates a message from scratch rather than reading from an inbox.
*/
@Test
public void workingWithSimpleTextMessages() {
Properties props = new Properties();
Message msg = new MimeMessage(Session.getDefaultInstance(props));
try {
Address[] addrs = new Address[1];
addrs[0] = new InternetAddress("david@opennms.org");
msg.addFrom(addrs);
msg.addRecipient(javax.mail.internet.MimeMessage.RecipientType.TO, addrs[0]);
msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
msg.setText("ACK");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
List<Message> msgs = new ArrayList<Message>(1);
msgs.add(msg);
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertEquals(1, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
use of javax.mail.internet.AddressException in project zm-mailbox by Zimbra.
the class AttributeInfo method validEmailAddress.
public static void validEmailAddress(String addr, boolean personal) throws ServiceException {
if (addr.indexOf('@') == -1)
throw AccountServiceException.INVALID_ATTR_VALUE("address '" + addr + "' does not include domain", null);
try {
InternetAddress ia = new JavaMailInternetAddress(addr, true);
// is this even needed?
ia.validate();
if (!personal && ia.getPersonal() != null && !ia.getPersonal().equals(""))
throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, null);
} catch (AddressException e) {
throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, e);
}
}
Aggregations