use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DomainPolicyResolver_getPolicyTest method testGetPolicy_outgoingPolicyDoesNotExist_assertEmpty.
public void testGetPolicy_outgoingPolicyDoesNotExist_assertEmpty() throws Exception {
final PolicyExpression expression = mock(PolicyExpression.class);
final List<PolicyExpression> expressions = Arrays.asList(expression);
final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
policies.put("testdomain.com", expressions);
final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
Collection<PolicyExpression> retrievedExpressions = resolver.getOutgoingPolicy(new InternetAddress("me@testdomainother.com"));
assertNotNull(retrievedExpressions);
assertEquals(0, retrievedExpressions.size());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class UniversalPolicyResolver_getPolicyTest method testGetOutgoingPolicy_assertPolicyRetrieved.
public void testGetOutgoingPolicy_assertPolicyRetrieved() throws Exception {
final PolicyExpression expression = mock(PolicyExpression.class);
final UniversalPolicyResolver resolver = new UniversalPolicyResolver(expression);
final Collection<PolicyExpression> policies = resolver.getOutgoingPolicy(new InternetAddress("me@you.com"));
assertEquals(1, policies.size());
assertEquals(expression, policies.iterator().next());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class UniversalPolicyResolver_getPolicyTest method testGetIncomingPolicy_assertPolicyRetrieved.
public void testGetIncomingPolicy_assertPolicyRetrieved() throws Exception {
final PolicyExpression expression = mock(PolicyExpression.class);
final UniversalPolicyResolver resolver = new UniversalPolicyResolver(expression);
final Collection<PolicyExpression> policies = resolver.getIncomingPolicy(new InternetAddress("me@you.com"));
assertEquals(1, policies.size());
assertEquals(expression, policies.iterator().next());
}
use of javax.mail.internet.InternetAddress 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.InternetAddress in project nhin-d by DirectProject.
the class DSNMessageGenerator method generateDSNFailureMessage.
/**
* Generates the DSN message a replacing the existing exchange in body with the DSN message as a MimeMessage object.
* @param txs Collection of correlated Tx objects.
* @param ex The message exchange.
* @throws Exception
*/
@Handler
public void generateDSNFailureMessage(Collection<Tx> txs, Exchange ex) throws Exception {
// change the inbound message body to null
ex.getIn().setBody(null);
// get the message that is being tracked so we can generate an error message for it
Tx messageToTrack = AbstractCompletionCondition.getMessageToTrack(txs);
if (messageToTrack != null) {
// make sure we have incomplete recipients
final Collection<String> incompleteRecips = conditionChecker.getIncompleteRecipients(txs);
if (incompleteRecips != null && !incompleteRecips.isEmpty()) {
InternetAddress originalSender = null;
String originalSubject = "";
InternetAddress postmaster = null;
String originalMessageId = "";
Enumeration<Header> fullMessageHeaders = null;
final List<DSNRecipientHeaders> recipientDSNHeaders = new ArrayList<DSNRecipientHeaders>();
final List<Address> failedRecipAddresses = new ArrayList<Address>();
final TxDetail sender = messageToTrack.getDetail(TxDetailType.FROM);
if (sender != null) {
originalSender = new InternetAddress(sender.getDetailValue());
postmaster = new InternetAddress(postmasterMailbox + "@" + getAddressDomain(originalSender));
}
final TxDetail subject = messageToTrack.getDetail(TxDetailType.SUBJECT);
if (subject != null)
originalSubject = subject.getDetailValue();
for (String incompleteRecip : incompleteRecips) {
final Address failedRecipAddress = new InternetAddress(incompleteRecip);
DSNRecipientHeaders dsnRecipHeaders = new DSNRecipientHeaders(DSNAction.FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.UNDEFINED_STATUS), failedRecipAddress);
recipientDSNHeaders.add(dsnRecipHeaders);
failedRecipAddresses.add(failedRecipAddress);
}
///CLOVER:OFF
final TxDetail origMessId = messageToTrack.getDetail(TxDetailType.MSG_ID);
if (origMessId != null)
originalMessageId = origMessId.getDetailValue();
///CLOVER:ON
final DSNMessageHeaders messageDSNHeaders = new DSNMessageHeaders(reportingMta, originalMessageId, MtaNameType.DNS);
final TxDetail fullHeaders = messageToTrack.getDetail(TxDetailType.MSG_FULL_HEADERS);
if (fullHeaders != null)
fullMessageHeaders = this.convertStringToHeaders(fullHeaders.getDetailValue());
final MimeBodyPart textBodyPart = textGenerator.generate(originalSender, failedRecipAddresses, fullMessageHeaders);
final MimeMessage dnsMessage = generator.createDSNMessage(originalSender, originalSubject, postmaster, recipientDSNHeaders, messageDSNHeaders, textBodyPart);
ex.getIn().setBody(dnsMessage);
}
}
}
Aggregations