diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java index 68d0029596..8f90cc6462 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java @@ -51,6 +51,7 @@ public class MailInboundChannelAdapterParser extends AbstractPollingInboundChann Object source = parserContext.extractSource(element); IntegrationNamespaceUtils.setValueIfAttributeDefined(receiverBuilder, element, "store-uri"); IntegrationNamespaceUtils.setValueIfAttributeDefined(receiverBuilder, element, "protocol"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(receiverBuilder, element, "search-term-strategy"); String session = element.getAttribute("session"); if (StringUtils.hasText(session)) { if (element.hasAttribute("java-mail-properties") || element.hasAttribute("authenticator")) { @@ -74,9 +75,6 @@ public class MailInboundChannelAdapterParser extends AbstractPollingInboundChann if (StringUtils.hasText(mmpp)) { receiverBuilder.addPropertyValue("maxFetchSize", mmpp); } - if (StringUtils.hasText(pollerElement.getAttribute("synchronized"))) { - receiverBuilder.addPropertyValue("synchronized", true); - } } } receiverBuilder.addPropertyValue("shouldDeleteMessages", element.getAttribute("should-delete-messages")); diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java index 0a355c87fd..36296fcd11 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/MailReceiverFactoryBean.java @@ -31,6 +31,7 @@ import org.springframework.integration.mail.AbstractMailReceiver; import org.springframework.integration.mail.ImapMailReceiver; import org.springframework.integration.mail.MailReceiver; import org.springframework.integration.mail.Pop3MailReceiver; +import org.springframework.integration.mail.SearchTermStrategy; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -55,8 +56,6 @@ public class MailReceiverFactoryBean implements FactoryBean, Dispo private volatile Authenticator authenticator; - private volatile boolean synchronizedTx; - /** * Indicates whether retrieved messages should be deleted from the server. * This value will be null unless explicitly configured. @@ -69,6 +68,8 @@ public class MailReceiverFactoryBean implements FactoryBean, Dispo private volatile Expression selectorExpression; + private volatile SearchTermStrategy searchTermStrategy; + public void setStoreUri(String storeUri) { this.storeUri = storeUri; @@ -110,8 +111,8 @@ public class MailReceiverFactoryBean implements FactoryBean, Dispo this.selectorExpression = selectorExpression; } - public void setSynchronized(boolean synchronizedTx) { - this.synchronizedTx = synchronizedTx; + public void setSearchTermStrategy(SearchTermStrategy searchTermStrategy) { + this.searchTermStrategy = searchTermStrategy; } public MailReceiver getObject() throws Exception { @@ -157,6 +158,10 @@ public class MailReceiverFactoryBean implements FactoryBean, Dispo Assert.isNull(this.authenticator, "A JavaMail Authenticator is not allowed when a Session has been provied."); 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); } @@ -168,12 +173,6 @@ public class MailReceiverFactoryBean implements FactoryBean, Dispo // otherwise, the default is true for POP3 but false for IMAP receiver.setShouldDeleteMessages(this.shouldDeleteMessages); } - if (this.synchronizedTx && this.maxFetchSize != 1) { - if (logger.isWarnEnabled()) { - logger.warn("Max Fetch Size is set to 1 because the poller is synchronized; was " + this.maxFetchSize); - } - this.maxFetchSize = 1; - } receiver.setMaxFetchSize(this.maxFetchSize); receiver.setSelectorExpression(selectorExpression); diff --git a/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.2.xsd b/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.2.xsd index 7490351374..99e55eb465 100644 --- a/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.2.xsd +++ b/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.2.xsd @@ -94,6 +94,23 @@ ]]> + + + + + + + + + Reference to a custom implementation of org.springframework.integration.mail.SearchTermStrategy + to use when retrieving email. Only permitted with 'imap' protocol or an 'imap' uri. + By default, the ImapMailReceiver will search for Messages based on the default SearchTerm + which is "All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not + been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported)". + + + @@ -137,9 +154,9 @@ Reference to a custom implementation of org.springframework.integration.mail.SearchTermStrategy to use when retrieving email. - By default ImapMailReceiver will search for Messages based in the default SearchTerm - which is "All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not - been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported)". + By default, the ImapMailReceiver will search for Messages based on the default SearchTerm + which is "All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not + been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported)". diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml index f02d36a6da..e68d951233 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml @@ -104,6 +104,15 @@ + + + + + + + + diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml new file mode 100644 index 0000000000..e413289731 --- /dev/null +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java index a7a8d1e89a..ce84e30728 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java @@ -29,6 +29,7 @@ import javax.mail.Authenticator; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; +import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -40,6 +41,7 @@ import org.springframework.integration.mail.AbstractMailReceiver; import org.springframework.integration.mail.ImapIdleChannelAdapter; import org.springframework.integration.mail.ImapMailReceiver; import org.springframework.integration.mail.Pop3MailReceiver; +import org.springframework.integration.mail.SearchTermStrategy; import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -72,7 +74,7 @@ public class InboundChannelAdapterParserTests { Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages"); assertTrue(value); } - + @Test public void imapShouldMarkMessagesAsRead() { AbstractMailReceiver receiver = this.getReceiver("imapShouldMarkAsReadTrue"); @@ -283,6 +285,30 @@ public class InboundChannelAdapterParserTests { } + //==================== INT-2800 ==================== + + @Test + public void imapWithSearchTermStrategy() { + AbstractMailReceiver receiver = this.getReceiver("imapWithSearch"); + assertEquals(ImapMailReceiver.class, receiver.getClass()); + Object sts = new DirectFieldAccessor(receiver).getPropertyValue("searchTermStrategy"); + assertNotNull(sts); + assertSame(context.getBean(SearchTermStrategy.class), sts); + } + + @Test + public void pop3WithSearchTermStrategy() { + try { + new ClassPathXmlApplicationContext( + "org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml"); + fail("expected a parser error"); + } + catch(BeanCreationException e) { + assertTrue(e.getMessage().contains("searchTermStrategy is only allowed with imap")); + } + } + + //===================== COMMON ===================== private AbstractMailReceiver getReceiver(String name) {