Example usage for org.springframework.integration.mail AbstractMailReceiver setSession

List of usage examples for org.springframework.integration.mail AbstractMailReceiver setSession

Introduction

In this page you can find the example usage for org.springframework.integration.mail AbstractMailReceiver setSession.

Prototype

public void setSession(Session session) 

Source Link

Document

Set the Session .

Usage

From source file:org.springframework.integration.mail.config.MailReceiverFactoryBean.java

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 provied.");
        receiver.setSession(this.session);
    }/*from w  ww  .  j a  v a2 s .com*/
    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(selectorExpression);

    if (isPop3) {
        if (this.isShouldMarkMessagesAsRead() && this.logger.isWarnEnabled()) {
            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);
    }
    receiver.afterPropertiesSet();
    return receiver;
}