use of org.nhindirect.stagent.NHINDAddress in project nhin-d by DirectProject.
the class TrackIncomingNotification method service.
/**
* {@inheritDoc}
*/
@Override
public void service(Mail mail) throws MessagingException {
LOGGER.debug("Calling track incoming notification service");
final MimeMessage msg = mail.getMessage();
final NHINDAddressCollection recipients = getMailRecipients(mail);
final NHINDAddress sender = getMailSender(mail);
final Tx txToMonitor = getTxToTrack(msg, sender, recipients);
// track message
if (txToMonitor != null && (txToMonitor.getMsgType() == TxMessageType.DSN || txToMonitor.getMsgType() == TxMessageType.MDN)) {
try {
txService.trackMessage(txToMonitor);
}///CLOVER:OFF
catch (ServiceException ex) {
LOGGER.warn("Failed to submit message to monitoring service.", ex);
}
///CLOVER:ON
}
LOGGER.debug("Exiting track incoming notification service");
}
use of org.nhindirect.stagent.NHINDAddress in project nhin-d by DirectProject.
the class NotificationProducerTest method testProduceMDN_MultipleRecipients.
public void testProduceMDN_MultipleRecipients() throws Exception {
NotificationSettings setting = new NotificationSettings(true, "", "");
NotificationProducer prod = new NotificationProducer(setting);
IncomingMessage msg = getMessageFromFile("MultipleRecipientsIncomingMessage.txt", Arrays.asList("cerner.com", "securehealthemail.com"));
Collection<NotificationMessage> notes = prod.produce(msg);
assertNotNull(notes);
assertEquals(2, notes.size());
boolean foundCernerCom = false;
boolean foundSecureHealth = false;
for (NHINDAddress noteMsg : msg.getDomainRecipients()) {
if (noteMsg.toString().contains("cerner.com"))
foundCernerCom = true;
else if (noteMsg.toString().contains("securehealthemail.com"))
foundSecureHealth = true;
}
assertTrue(foundCernerCom);
assertTrue(foundSecureHealth);
}
use of org.nhindirect.stagent.NHINDAddress in project nhin-d by DirectProject.
the class AbstractNotificationAwareMailet method getMailRecipients.
/**
* Get the recipients of Mail message by retrieving the recipient list from the SMTP envelope first, then falling back to the recipients
* in the message if the recipients cannot be retrieved from the SMTP envelope.
* @param mail The mail object that contains information from the SMTP envelope.
* @return Collection of message recipients.
* @throws MessagingException
*/
@SuppressWarnings("unchecked")
protected NHINDAddressCollection getMailRecipients(Mail mail) throws MessagingException {
final NHINDAddressCollection recipients = new NHINDAddressCollection();
// uses the RCPT TO commands
final Collection<MailAddress> recips = mail.getRecipients();
if (recips == null || recips.size() == 0) {
// fall back to the mime message list of recipients
final Address[] recipsAddr = mail.getMessage().getAllRecipients();
for (Address addr : recipsAddr) {
recipients.add(new NHINDAddress(addr.toString(), (AddressSource) null));
}
} else {
for (MailAddress addr : recips) {
recipients.add(new NHINDAddress(addr.toString(), (AddressSource) null));
}
}
return recipients;
}
use of org.nhindirect.stagent.NHINDAddress in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_service_Test method testService_UseRcpt_AssertRecipientsUsed.
public void testService_UseRcpt_AssertRecipientsUsed() throws Exception {
final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
final SmtpAgent mockAgent = mock(SmtpAgent.class);
when(mockAgent.processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any())).thenAnswer(new Answer<MessageProcessResult>() {
public MessageProcessResult answer(InvocationOnMock invocation) throws Throwable {
usedRecipients = (NHINDAddressCollection) invocation.getArguments()[1];
usedSender = (NHINDAddress) invocation.getArguments()[2];
return new MessageProcessResult(new DefaultMessageEnvelope(new Message(mimeMsg), usedRecipients, usedSender), null);
}
});
final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com")));
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
mockMail.setMessage(mimeMsg);
NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
mailet.agent = mockAgent;
mailet.service(mockMail);
assertNotNull(usedRecipients);
assertEquals(1, usedRecipients.size());
assertEquals("you@cerner.com", usedRecipients.iterator().next().toString());
}
use of org.nhindirect.stagent.NHINDAddress in project nhin-d by DirectProject.
the class TimelyAndReliableLocalDelivery_serviceTest method testService_failedDelivery_assertDSNCreated.
public void testService_failedDelivery_assertDSNCreated() throws Exception {
new TestPlan() {
@Override
protected void setupMocks() {
theMailet = new TimelyAndReliableLocalDelivery() {
protected Object createLocalDeliveryClass() throws Exception {
Mailet mailet = mock(Mailet.class);
doThrow(new RuntimeException()).when(mailet).service((Mail) any());
return mailet;
}
};
try {
MailetConfig config = getMailetConfig();
theMailet.init(config);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
protected void doAssertions(MockMailetContext context) throws Exception {
assertEquals(1, context.getSentMessages().size());
MimeMessage dsnMessage = context.getSentMessages().iterator().next().getMessage();
assertEquals(TxMessageType.DSN, TxUtil.getMessageType(dsnMessage));
String originalMessageString = TestUtils.readMessageResource(getMessageToSend());
MimeMessage originalMsg = EntitySerializer.Default.deserialize(originalMessageString);
NHINDAddress originalRecipAddress = new NHINDAddress(MailStandard.getHeader(originalMsg, MailStandard.Headers.To));
NHINDAddress dsnFromAddress = new NHINDAddress(MailStandard.getHeader(dsnMessage, MailStandard.Headers.From));
assertTrue(dsnFromAddress.getHost().toLowerCase(Locale.getDefault()).contains(originalRecipAddress.getHost().toLowerCase(Locale.getDefault())));
}
}.perform();
}
Aggregations