Plan Repository (master)
Alexander Pinske <[email protected]> 07a6fb3a9a2215058f39737e7ffffdfdbef69d2f
Fix IMAP race condition around idle()
`IMAPFolder.idle()` by default keeps idle-ing after each response.
We don't need that, because we want to fetch the new mails immediately (over the same connection).
To make `idle()` not keep on going, we called
`folder.isOpen()` which in most cases makes `idle()` stop by calling `noop()`
internally (to keep the connection alive) which leads to the current
`idle()`-call being canceled.
The problem this commits addresses is that the call to `noop()` only
happens if there were no calls in the last second.
There is a check for that in `com.sun.mail.imap.IMAPFolder.keepConnectionAlive`.
So if a new message appears less then a second after idle started, we will miss it.
This new way interrupts `idle()` more often than before, e.g. when there
is an expunge-message (i.e. a message was deleted), which we don't care about.
But the subsequent `receive()` in IdleTask will simply get no
messages and then turn around and start idle-ing again.
**Cherry-pick to `5.3.x` & `master`**
- spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java (version 07a6fb3a9a2215058f39737e7ffffdfdbef69d2f)
- spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java (version 07a6fb3a9a2215058f39737e7ffffdfdbef69d2f)