I have configured the following imap-inbound-adapter to receive already seen mails from an inbox. The mails should be deleted after they were received, so I set the "should be deleted" flag to "true". I am using the spring-boot-starter-integration with version 1.4.1.
@Configuration
public class MailDeleteAdapterConfiguration {
@Bean
public IntegrationFlow deleteMailFlow(MailNotifierProperties properties,
SeenSearchTermStrategy seenSearchTermStrategy,
DeleteMailHandler deleteMailHandler
) {
return IntegrationFlows
.from(Mail.imapInboundAdapter(properties.getImapUrl())
.javaMailProperties(p -> p
.put("mail.imap.starttls.enable", "true")
.put("mail.imap.ssl.trust", "*"))
.searchTermStrategy(seenSearchTermStrategy)
.shouldDeleteMessages(true)
)
.handle(deleteMailHandler)
.get();
}
@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata poller() {
return Pollers.fixedRate(10000).maxMessagesPerPoll(100).get();
}
}
The mails are deleted, but there is also a exception thrown by the framework:
org.springframework.messaging.MessageHandlingException: nested exception is java.lang.NullPointerException
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:96) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.router.AbstractMessageProcessingRouter.getChannelKeys(AbstractMessageProcessingRouter.java:80) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.router.AbstractMappingMessageRouter.determineTargetChannels(AbstractMappingMessageRouter.java:185) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:182) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.dispatcher.BroadcastingDispatcher.invokeHandler(BroadcastingDispatcher.java:236) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.dispatcher.BroadcastingDispatcher.dispatch(BroadcastingDispatcher.java:185) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.channel.MessagePublishingErrorHandler.handleError(MessagePublishingErrorHandler.java:95) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:58) [spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51) [spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:344) [spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: java.lang.NullPointerException: null
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:113) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:129) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:347) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:330) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:169) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.util.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:317) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.util.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:155) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:93) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 22 common frames omitted
2018-01-22 15:29:02.223 ERROR 25726 --- [ask-scheduler-4] o.s.i.c.MessagePublishingErrorHandler : failure occurred in messaging task
org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is javax.mail.MessagingException: IOException while copying message;
nested exception is:
com.sun.mail.util.MessageRemovedIOException
at org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:131) ~[spring-integration-mail-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:209) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:245) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:58) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:190) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:186) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:353) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55) ~[spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51) [spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:344) [spring-integration-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: javax.mail.MessagingException: IOException while copying message
at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:254) ~[javax.mail-api-1.5.5.jar:1.5.5]
at org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage.<init>(AbstractMailReceiver.java:557) ~[spring-integration-mail-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage.<init>(AbstractMailReceiver.java:552) ~[spring-integration-mail-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.mail.AbstractMailReceiver.postProcessFilteredMessages(AbstractMailReceiver.java:415) ~[spring-integration-mail-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:342) ~[spring-integration-mail-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:112) ~[spring-integration-mail-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 19 common frames omitted
Caused by: com.sun.mail.util.MessageRemovedIOException: null
at com.sun.mail.imap.IMAPInputStream.forceCheckExpunged(IMAPInputStream.java:113) ~[javax.mail-1.5.5.jar:1.5.5]
at com.sun.mail.imap.IMAPInputStream.fill(IMAPInputStream.java:166) ~[javax.mail-1.5.5.jar:1.5.5]
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:218) ~[javax.mail-1.5.5.jar:1.5.5]
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:244) ~[javax.mail-1.5.5.jar:1.5.5]
at com.sun.mail.imap.IMAPMessage.writeTo(IMAPMessage.java:849) ~[javax.mail-1.5.5.jar:1.5.5]
at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:245) ~[javax.mail-api-1.5.5.jar:1.5.5]
... 24 common frames omitted
I had the mail.debug property set to "true", but I did not receive any hint for an error:
2018-01-22 15:54:24.702 INFO 27337 --- [ask-scheduler-1] o.s.integration.mail.ImapMailReceiver : attempting to receive mail from folder [INBOX]
A32 SEARCH SEEN ALL
* SEARCH 1
A32 OK SEARCH completed in 0.00 s
A33 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE FLAGS BODYSTRUCTURE)
* 1 FETCH (ENVELOPE (CONTENT......))
A33 OK FETCH completed
A34 STORE 1 +FLAGS (\Flagged)
* 1 FETCH (FLAGS (\Seen \Flagged))
A34 OK STORE completed
A35 STORE 1 +FLAGS (\Seen)
* 1 FETCH (FLAGS (\Seen \Flagged))
A35 OK STORE completed
A36 STORE 1 +FLAGS (\Deleted)
* 1 FETCH (FLAGS (\Seen \Flagged \Deleted))
A36 OK STORE completed
A37 FETCH 1 (BODY.PEEK[]<0.16384>)
A37 NO FETCH Some of the requested messages no longer exist
DEBUG IMAP: IMAPProtocol noop
A38 NOOP
* 1 EXPUNGE
* 0 EXISTS
A38 OK NOOP completed
A39 CLOSE
A39 OK CLOSE completed
DEBUG IMAP: added an Authenticated connection -- size: 1
Mayby anyone has used the inbound adapter with the delete flag set to true successfully and can share a solution.