Search in sources :

Example 6 with NHINDAddress

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");
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) Tx(org.nhindirect.common.tx.model.Tx) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection)

Example 7 with NHINDAddress

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);
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) IncomingMessage(org.nhindirect.stagent.IncomingMessage)

Example 8 with NHINDAddress

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;
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) MailAddress(org.apache.mailet.MailAddress) AddressSource(org.nhindirect.stagent.AddressSource) Address(javax.mail.Address) MailAddress(org.apache.mailet.MailAddress) InternetAddress(javax.mail.internet.InternetAddress) NHINDAddress(org.nhindirect.stagent.NHINDAddress) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection)

Example 9 with NHINDAddress

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());
}
Also used : MailAddress(org.apache.mailet.MailAddress) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) DefaultMessageEnvelope(org.nhindirect.stagent.DefaultMessageEnvelope) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent) MessageProcessResult(org.nhindirect.gateway.smtp.MessageProcessResult) NHINDAddress(org.nhindirect.stagent.NHINDAddress) Mail(org.apache.mailet.Mail) MimeMessage(javax.mail.internet.MimeMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 10 with NHINDAddress

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();
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) BaseTestPlan(org.nhindirect.gateway.testutils.BaseTestPlan) MimeMessage(javax.mail.internet.MimeMessage) MailetConfig(org.apache.mailet.MailetConfig) Mailet(org.apache.mailet.Mailet)

Aggregations

NHINDAddress (org.nhindirect.stagent.NHINDAddress)22 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)15 MimeMessage (javax.mail.internet.MimeMessage)11 ArrayList (java.util.ArrayList)6 Tx (org.nhindirect.common.tx.model.Tx)6 Address (javax.mail.Address)5 InternetAddress (javax.mail.internet.InternetAddress)5 MailAddress (org.apache.mailet.MailAddress)5 Message (org.nhindirect.stagent.mail.Message)5 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)5 Collection (java.util.Collection)4 MessagingException (javax.mail.MessagingException)4 DefaultMessageSignatureImpl (org.nhindirect.stagent.DefaultMessageSignatureImpl)4 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)3 TxDetail (org.nhindirect.common.tx.model.TxDetail)3 MessageProcessResult (org.nhindirect.gateway.smtp.MessageProcessResult)3 Header (javax.mail.Header)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 Mail (org.apache.mailet.Mail)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2