Skip to content

Commit

Permalink
GH-119: Fix auto-wiring ambiguity in the MailSupplierConfiguration
Browse files Browse the repository at this point in the history
Fixes: #119
  • Loading branch information
artembilan committed Dec 19, 2024
1 parent eb64497 commit 6d4cb43
Showing 1 changed file with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public MailSupplierConfiguration(MailSupplierProperties properties) {
}

@Bean
public Publisher<Message<Object>> mailInboundFlow(MessageProducerSupport messageProducer) {
return IntegrationFlow.from(messageProducer)
public Publisher<Message<Object>> mailInboundFlow(MessageProducerSupport mailChannelAdapter) {
return IntegrationFlow.from(mailChannelAdapter)
.transform(Mail.toStringTransformer(this.properties.getCharset()))
.enrichHeaders((h) -> h.defaultOverwrite(true)
.header(MailHeaders.TO, arrayToListProcessor(MailHeaders.TO))
Expand All @@ -76,12 +76,7 @@ public Publisher<Message<Object>> mailInboundFlow(MessageProducerSupport message
.toReactivePublisher(true);
}

@Bean
public Supplier<Flux<Message<?>>> mailSupplier(Publisher<Message<Object>> messagePublisher) {
return () -> Flux.from(messagePublisher);
}

private HeaderValueMessageProcessor<?> arrayToListProcessor(String header) {
private static HeaderValueMessageProcessor<?> arrayToListProcessor(String header) {
return new AbstractHeaderValueMessageProcessor<List<String>>() {

@Override
Expand All @@ -92,6 +87,11 @@ public List<String> processMessage(Message<?> message) {
};
}

@Bean
public Supplier<Flux<Message<?>>> mailSupplier(Publisher<Message<Object>> mailInboundFlow) {
return () -> Flux.from(mailInboundFlow);
}

@Bean("mailChannelAdapter")
@ConditionalOnProperty("mail.supplier.idle-imap")
MessageProducerSpec<?, ?> imapIdleProducer(
Expand All @@ -103,8 +103,7 @@ public List<String> processMessage(Message<?> message) {
.userFlag(this.properties.getUserFlag())
.javaMailProperties(getJavaMailProperties(urlName))
.selectorExpression(this.properties.getExpression())
.shouldMarkMessagesAsRead(this.properties.isMarkAsRead())
.autoStartup(false);
.shouldMarkMessagesAsRead(this.properties.isMarkAsRead());

if (imapIdleChannelAdapterSpecCustomizer != null) {
imapIdleChannelAdapterSpecCustomizer.customize(imapIdleChannelAdapterSpec);
Expand Down Expand Up @@ -139,10 +138,7 @@ public List<String> processMessage(Message<?> message) {
@Bean("mailChannelAdapter")
@ConditionalOnProperty(value = "mail.supplier.idle-imap", matchIfMissing = true, havingValue = "false")
MessageProducerSupport mailMessageProducer(MessageSource<?> mailMessageSource) {
ReactiveMessageSourceProducer reactiveMessageSourceProducer = new ReactiveMessageSourceProducer(
mailMessageSource);
reactiveMessageSourceProducer.setAutoStartup(false);
return reactiveMessageSourceProducer;
return new ReactiveMessageSourceProducer(mailMessageSource);
}

private Pop3MailInboundChannelAdapterSpec getPop3ChannelAdapterSpec(URLName urlName) {
Expand Down

0 comments on commit 6d4cb43

Please sign in to comment.