Search in sources :

Example 1 with Pop3MailReceiver

use of org.springframework.integration.mail.Pop3MailReceiver in project nifi by apache.

the class ConsumePOP3 method buildMessageReceiver.

/**
 */
@Override
protected Pop3MailReceiver buildMessageReceiver(ProcessContext context) {
    final Pop3MailReceiver receiver = new Pop3MailReceiver(this.buildUrl(context));
    receiver.setShouldDeleteMessages(context.getProperty(AbstractEmailProcessor.SHOULD_DELETE_MESSAGES).asBoolean());
    return receiver;
}
Also used : Pop3MailReceiver(org.springframework.integration.mail.Pop3MailReceiver)

Example 2 with Pop3MailReceiver

use of org.springframework.integration.mail.Pop3MailReceiver in project lavagna by digitalfondue.

the class MailTicketService method getPop3MailReceiver.

private MailReceiver getPop3MailReceiver(ProjectMailTicketConfigData config) {
    String sanitizedUsername = sanitizeUsername(config.getInboundUser());
    String inboxFolder = getInboxFolder(config);
    String url = "pop3://" + sanitizedUsername + ":" + config.getInboundPassword() + "@" + config.getInboundServer() + "/" + inboxFolder.toUpperCase();
    Pop3MailReceiver receiver = new Pop3MailReceiver(url);
    Properties mailProperties = new Properties();
    mailProperties.setProperty("mail.pop3.port", Integer.toString(config.getInboundPort()));
    if (config.getInboundProtocol().equals("pop3s")) {
        mailProperties.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        mailProperties.setProperty("mail.pop3.socketFactory.fallback", "false");
        mailProperties.setProperty("mail.pop3.socketFactory.port", Integer.toString(config.getInboundPort()));
    }
    mailProperties.putAll(config.generateInboundProperties());
    receiver.setJavaMailProperties(mailProperties);
    return receiver;
}
Also used : Pop3MailReceiver(org.springframework.integration.mail.Pop3MailReceiver)

Example 3 with Pop3MailReceiver

use of org.springframework.integration.mail.Pop3MailReceiver 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 4 with Pop3MailReceiver

use of org.springframework.integration.mail.Pop3MailReceiver 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

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