Search in sources :

Example 1 with AbstractMailReceiver

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

the class MailReceiverFactoryBean method createReceiver.

private MailReceiver createReceiver() {
    this.verifyProtocol();
    boolean isPop3 = this.protocol.toLowerCase().startsWith("pop3");
    boolean isImap = this.protocol.toLowerCase().startsWith("imap");
    Assert.isTrue(isPop3 || isImap, "the store URI must begin with 'pop3' or 'imap'");
    AbstractMailReceiver receiver = isPop3 ? new Pop3MailReceiver(this.storeUri) : new ImapMailReceiver(this.storeUri);
    if (this.session != null) {
        Assert.isNull(this.javaMailProperties, "JavaMail Properties are not allowed when a Session has been provided.");
        Assert.isNull(this.authenticator, "A JavaMail Authenticator is not allowed when a Session has been provided.");
        receiver.setSession(this.session);
    }
    if (this.searchTermStrategy != null) {
        Assert.isTrue(isImap, "searchTermStrategy is only allowed with imap");
        ((ImapMailReceiver) receiver).setSearchTermStrategy(this.searchTermStrategy);
    }
    if (this.javaMailProperties != null) {
        receiver.setJavaMailProperties(this.javaMailProperties);
    }
    if (this.authenticator != null) {
        receiver.setJavaMailAuthenticator(this.authenticator);
    }
    if (this.shouldDeleteMessages != null) {
        // always set the value if configured explicitly
        // otherwise, the default is true for POP3 but false for IMAP
        receiver.setShouldDeleteMessages(this.shouldDeleteMessages);
    }
    receiver.setMaxFetchSize(this.maxFetchSize);
    receiver.setSelectorExpression(this.selectorExpression);
    if (StringUtils.hasText(this.userFlag)) {
        receiver.setUserFlag(this.userFlag);
    }
    if (isPop3) {
        if (this.isShouldMarkMessagesAsRead() && this.logger.isWarnEnabled()) {
            this.logger.warn("Setting 'should-mark-messages-as-read' to 'true' while using POP3 has no effect");
        }
    } else if (isImap) {
        ((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(this.shouldMarkMessagesAsRead);
    }
    if (this.beanFactory != null) {
        receiver.setBeanFactory(this.beanFactory);
    }
    if (this.headerMapper != null) {
        receiver.setHeaderMapper(this.headerMapper);
    }
    if (this.embeddedPartsAsBytes != null) {
        receiver.setEmbeddedPartsAsBytes(this.embeddedPartsAsBytes);
    }
    if (this.simpleContent != null) {
        receiver.setSimpleContent(this.simpleContent);
    }
    receiver.afterPropertiesSet();
    return receiver;
}
Also used : AbstractMailReceiver(org.springframework.integration.mail.AbstractMailReceiver) ImapMailReceiver(org.springframework.integration.mail.ImapMailReceiver) Pop3MailReceiver(org.springframework.integration.mail.Pop3MailReceiver)

Example 2 with AbstractMailReceiver

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

the class InboundChannelAdapterParserTests method imapIdleWithSession.

@Test
public void imapIdleWithSession() {
    AbstractMailReceiver receiver = this.getReceiver("imapIdleWithSession");
    assertEquals(ImapMailReceiver.class, receiver.getClass());
    Object session = new DirectFieldAccessor(receiver).getPropertyValue("session");
    assertNotNull(session);
    assertEquals(context.getBean("testSession"), session);
}
Also used : AbstractMailReceiver(org.springframework.integration.mail.AbstractMailReceiver) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 3 with AbstractMailReceiver

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

the class InboundChannelAdapterParserTests method pop3ShouldDeleteTrueProperty.

// ==================== INT-1158 ====================
@Test
public void pop3ShouldDeleteTrueProperty() {
    AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteTrueProperty");
    assertEquals(Pop3MailReceiver.class, receiver.getClass());
    Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
    assertTrue(value);
}
Also used : AbstractMailReceiver(org.springframework.integration.mail.AbstractMailReceiver) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 4 with AbstractMailReceiver

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

the class InboundChannelAdapterParserTests method imapShouldDeleteTrueProperty.

@Test
public void imapShouldDeleteTrueProperty() {
    AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteTrueProperty");
    assertEquals(ImapMailReceiver.class, receiver.getClass());
    Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
    assertTrue(value);
    assertNotNull(TestUtils.getPropertyValue(receiver, "evaluationContext.beanResolver"));
}
Also used : AbstractMailReceiver(org.springframework.integration.mail.AbstractMailReceiver) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 5 with AbstractMailReceiver

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

the class InboundChannelAdapterParserTests method imapShouldDeleteFalse.

@Test
public void imapShouldDeleteFalse() {
    AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteFalse");
    assertEquals(ImapMailReceiver.class, receiver.getClass());
    DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
    Boolean value = (Boolean) receiverAccessor.getPropertyValue("shouldDeleteMessages");
    assertFalse(value);
    assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("simpleContent"));
}
Also used : AbstractMailReceiver(org.springframework.integration.mail.AbstractMailReceiver) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

AbstractMailReceiver (org.springframework.integration.mail.AbstractMailReceiver)24 Test (org.junit.Test)23 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)23 ImapMailReceiver (org.springframework.integration.mail.ImapMailReceiver)1 Pop3MailReceiver (org.springframework.integration.mail.Pop3MailReceiver)1 SearchTermStrategy (org.springframework.integration.mail.SearchTermStrategy)1