Search in sources :

Example 1 with DefaultMailHeaderMapper

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

the class ImapMailReceiverTests method testIdleWithMessageMapping.

@Test
public void testIdleWithMessageMapping() throws Exception {
    ImapMailReceiver receiver = new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getPort() + "/INBOX");
    receiver.setHeaderMapper(new DefaultMailHeaderMapper());
    testIdleWithServerGuts(receiver, true);
}
Also used : DefaultMailHeaderMapper(org.springframework.integration.mail.support.DefaultMailHeaderMapper) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 2 with DefaultMailHeaderMapper

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

the class ImapMailReceiverTests method testAttachmentsWithMappingMultiAsBytes.

@Test
public void testAttachmentsWithMappingMultiAsBytes() throws Exception {
    final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
    receiver.setHeaderMapper(new DefaultMailHeaderMapper());
    testAttachmentsGuts(receiver);
    org.springframework.messaging.Message<?>[] messages = (org.springframework.messaging.Message<?>[]) receiver.receive();
    org.springframework.messaging.Message<?> received = messages[0];
    Object content = received.getPayload();
    assertThat(content, instanceOf(byte[].class));
    assertThat((String) received.getHeaders().get(MailHeaders.CONTENT_TYPE), equalTo("multipart/mixed;\r\n boundary=\"------------040903000701040401040200\""));
    assertThat((String) received.getHeaders().get(MessageHeaders.CONTENT_TYPE), equalTo("application/octet-stream"));
}
Also used : DefaultMailHeaderMapper(org.springframework.integration.mail.support.DefaultMailHeaderMapper) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 3 with DefaultMailHeaderMapper

use of org.springframework.integration.mail.support.DefaultMailHeaderMapper 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)

Example 4 with DefaultMailHeaderMapper

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

the class ImapMailReceiverTests method testIdleWithMessageMappingSimple.

@Test
public void testIdleWithMessageMappingSimple() throws Exception {
    ImapMailReceiver receiver = new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getPort() + "/INBOX");
    receiver.setSimpleContent(true);
    receiver.setHeaderMapper(new DefaultMailHeaderMapper());
    testIdleWithServerGuts(receiver, true, true);
}
Also used : DefaultMailHeaderMapper(org.springframework.integration.mail.support.DefaultMailHeaderMapper) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 5 with DefaultMailHeaderMapper

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

the class ImapMailReceiverTests method testAttachmentsWithMapping.

@Test
public void testAttachmentsWithMapping() throws Exception {
    final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
    receiver.setHeaderMapper(new DefaultMailHeaderMapper());
    receiver.setEmbeddedPartsAsBytes(false);
    testAttachmentsGuts(receiver);
    org.springframework.messaging.Message<?>[] messages = (org.springframework.messaging.Message<?>[]) receiver.receive();
    Object content = messages[0].getPayload();
    assertThat(content, instanceOf(Multipart.class));
    assertEquals("bar", ((Multipart) content).getBodyPart(0).getContent().toString().trim());
    assertEquals("foo", ((Multipart) content).getBodyPart(1).getContent().toString().trim());
}
Also used : Multipart(javax.mail.Multipart) DefaultMailHeaderMapper(org.springframework.integration.mail.support.DefaultMailHeaderMapper) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 DefaultMailHeaderMapper (org.springframework.integration.mail.support.DefaultMailHeaderMapper)5 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)4 Message (javax.mail.Message)2 MimeMessage (javax.mail.internet.MimeMessage)2 Multipart (javax.mail.Multipart)1 MailReceivingMessageSource (org.springframework.integration.mail.MailReceivingMessageSource)1 Pop3MailReceiver (org.springframework.integration.mail.Pop3MailReceiver)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1