From 731b238f1c2ed5c3e6abfa5a93f436bc0fe998d1 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 30 Oct 2008 21:23:13 +0000 Subject: [PATCH] Configuring the AbstractMailReceiver's maxFetchSize property to match the poller's max-messages-per-poll value if available. Otherwise, setting to 1 to avoid lost mails (since pre-fetched mail messages would be added to the mailQueue and deleted from the server). --- .../config/MailInboundChannelAdapterParser.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java index 2d7ebe7446..3cbd040b4d 100644 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java +++ b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailInboundChannelAdapterParser.java @@ -28,6 +28,7 @@ import org.springframework.integration.mail.MailReceivingMessageSource; import org.springframework.integration.mail.Pop3MailReceiver; import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; /** * Parser for the <inbound-channel-adapter> element of Spring @@ -59,6 +60,18 @@ public class MailInboundChannelAdapterParser extends AbstractPollingInboundChann if (StringUtils.hasText(propertiesRef)) { receiverBuilder.addPropertyReference("javaMailProperties", propertiesRef); } + boolean configuredFetchSize = false; + Element pollerElement = DomUtils.getChildElementByTagName(element, "poller"); + if (pollerElement != null) { + String mmpp = pollerElement.getAttribute("max-messages-per-poll"); + if (StringUtils.hasText(mmpp)) { + receiverBuilder.addPropertyValue("maxFetchSize", mmpp); + configuredFetchSize = true; + } + } + if (!configuredFetchSize) { + receiverBuilder.addPropertyValue("maxFetchSize", 1); + } return BeanDefinitionReaderUtils.registerWithGeneratedName( receiverBuilder.getBeanDefinition(), parserContext.getRegistry()); }