Search in sources :

Example 1 with MailReceivingMessageSource

use of org.springframework.integration.mail.MailReceivingMessageSource in project spring-integration by spring-projects.

the class Pop3Tests method testPop3.

@Test
public void testPop3() throws Exception {
    Pop3MailReceiver receiver = new Pop3MailReceiver("localhost", pop3Server.getPort(), "user", "pw");
    receiver.setHeaderMapper(new DefaultMailHeaderMapper());
    MailReceivingMessageSource source = new MailReceivingMessageSource(receiver);
    Message<?> message = source.receive();
    assertNotNull(message);
    MessageHeaders headers = message.getHeaders();
    assertEquals("Foo <foo@bar>", headers.get(MailHeaders.TO, String[].class)[0]);
    assertEquals("[a@b, c@d]", Arrays.toString(headers.get(MailHeaders.CC, String[].class)));
    assertEquals("[e@f, g@h]", Arrays.toString(headers.get(MailHeaders.BCC, String[].class)));
    assertEquals("Bar <bar@baz>", headers.get(MailHeaders.FROM));
    assertEquals("Test Email", headers.get(MailHeaders.SUBJECT));
    assertEquals("foo\r\n\r\n", message.getPayload());
}
Also used : DefaultMailHeaderMapper(org.springframework.integration.mail.support.DefaultMailHeaderMapper) MailReceivingMessageSource(org.springframework.integration.mail.MailReceivingMessageSource) MessageHeaders(org.springframework.messaging.MessageHeaders) Pop3MailReceiver(org.springframework.integration.mail.Pop3MailReceiver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MailReceivingMessageSource (org.springframework.integration.mail.MailReceivingMessageSource)1 Pop3MailReceiver (org.springframework.integration.mail.Pop3MailReceiver)1 DefaultMailHeaderMapper (org.springframework.integration.mail.support.DefaultMailHeaderMapper)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1