use of javax.mail.internet.InternetAddress 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.InternetAddress 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.InternetAddress in project nhin-d by DirectProject.
the class AbstractNotificationAwareMailet method getSender.
/**
* Gets the sender attribute of a Mail message
* @param mail The message to retrive the sender from
* @return The message sender.
*/
public static InternetAddress getSender(Mail mail) {
InternetAddress retVal = null;
if (mail.getSender() != null)
retVal = mail.getSender().toInternetAddress();
else {
// try to get the sender from the message
Address[] senderAddr = null;
try {
if (mail.getMessage() == null)
return null;
senderAddr = mail.getMessage().getFrom();
if (senderAddr == null || senderAddr.length == 0)
return null;
} catch (MessagingException e) {
return null;
}
// not the best way to do this
retVal = (InternetAddress) senderAddr[0];
}
return retVal;
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class IsNotificationTest method testIsNotification_ecryptedMessage_assertNull.
@SuppressWarnings("unchecked")
public void testIsNotification_ecryptedMessage_assertNull() throws Exception {
MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("EncryptedMessage.txt")));
IsNotSMIMEEncrypted matcher = new IsNotSMIMEEncrypted();
final Collection<MailAddress> initialRecips = new ArrayList<MailAddress>();
for (InternetAddress addr : (InternetAddress[]) msg.getAllRecipients()) initialRecips.add(new MailAddress(addr.getAddress()));
final MockMail mockMail = new MockMail(msg);
mockMail.setRecipients(initialRecips);
Collection<MailAddress> matchAddresses = matcher.match(mockMail);
assertEquals(null, matchAddresses);
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class IsNotificationTest method testIsNotification_DSNMessage_assertAllRecips.
@SuppressWarnings("unchecked")
public void testIsNotification_DSNMessage_assertAllRecips() throws Exception {
MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("DSNMessage.txt")));
IsNotification matcher = new IsNotification();
final Collection<MailAddress> initialRecips = new ArrayList<MailAddress>();
for (InternetAddress addr : (InternetAddress[]) msg.getAllRecipients()) initialRecips.add(new MailAddress(addr.getAddress()));
final MockMail mockMail = new MockMail(msg);
mockMail.setRecipients(initialRecips);
Collection<MailAddress> matchAddresses = matcher.match(mockMail);
assertEquals(1, matchAddresses.size());
assertEquals(initialRecips.iterator().next().toString(), matchAddresses.iterator().next().toString());
}
Aggregations