Search in sources :

Example 21 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class MockMail method getSender.

public MailAddress getSender() {
    MailAddress retVal = null;
    try {
        Address addr = mimeMessage.getSender();
        if (addr == null) {
            Address[] addrs = mimeMessage.getFrom();
            addr = addrs[0];
        }
        retVal = new MailAddress(addr.toString());
    } catch (Exception e) {
    }
    return retVal;
}
Also used : MailAddress(org.apache.mailet.MailAddress) Address(javax.mail.Address) MailAddress(org.apache.mailet.MailAddress) MessagingException(javax.mail.MessagingException)

Example 22 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_service_Test method testService_ProcessIsNull_AssertGhostState.

public void testService_ProcessIsNull_AssertGhostState() throws Exception {
    final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
    final SmtpAgent mockAgent = mock(SmtpAgent.class);
    final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
    when(mockMail.getRecipients()).thenReturn(null);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    mockMail.setMessage(mimeMsg);
    NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
    mailet.agent = mockAgent;
    mailet.service(mockMail);
    assertEquals(Mail.GHOST, mockMail.getState());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent)

Example 23 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class RecipAndSenderIsNotLocalTest method testMatch_LocalSender_LocalAndRemoteRcpt_AssertRemoteRcptReturned.

public void testMatch_LocalSender_LocalAndRemoteRcpt_AssertRemoteRcptReturned() throws Exception {
    final Mail mockMail = mock(Mail.class);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com"), new MailAddress("someone@remoteMail.com")));
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn("cerner.com");
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    matcher.init(newConfig);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(1, matchAddresses.size());
    assertEquals("someone@remoteMail.com", matchAddresses.iterator().next().toString());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MatcherConfig(org.apache.mailet.MatcherConfig)

Example 24 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class RecipAndSenderIsNotLocalTest method testMatch_LocalSender_LocalRcpt_AssertNoneReturned.

public void testMatch_LocalSender_LocalRcpt_AssertNoneReturned() throws Exception {
    final Mail mockMail = mock(Mail.class);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com")));
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn("cerner.com");
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    matcher.init(newConfig);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(0, matchAddresses.size());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MatcherConfig(org.apache.mailet.MatcherConfig)

Example 25 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class RecipAndSenderIsNotLocalTest method testMatch_RemoteSender_AssertRecipeintReturned.

public void testMatch_RemoteSender_AssertRecipeintReturned() throws Exception {
    final Mail mockMail = mock(Mail.class);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@remoteMail.com"));
    when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com")));
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn("cerner.com");
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    matcher.init(newConfig);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(1, matchAddresses.size());
    assertEquals("you@cerner.com", matchAddresses.iterator().next().toString());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MatcherConfig(org.apache.mailet.MatcherConfig)

Aggregations

MailAddress (org.apache.mailet.MailAddress)28 MimeMessage (javax.mail.internet.MimeMessage)17 ArrayList (java.util.ArrayList)11 Mail (org.apache.mailet.Mail)11 InternetAddress (javax.mail.internet.InternetAddress)8 MockMail (org.nhindirect.gateway.smtp.james.mailet.MockMail)8 SmtpAgent (org.nhindirect.gateway.smtp.SmtpAgent)7 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)7 NHINDAddress (org.nhindirect.stagent.NHINDAddress)6 Collection (java.util.Collection)5 MessageProcessResult (org.nhindirect.gateway.smtp.MessageProcessResult)5 Address (javax.mail.Address)4 MessagingException (javax.mail.MessagingException)4 MatcherConfig (org.apache.mailet.MatcherConfig)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Message (org.nhindirect.stagent.mail.Message)4 Tx (org.nhindirect.common.tx.model.Tx)2 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)2 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)2 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)2