read spring-integration-mail I try to load the email's content including the attachments. As a result, I obviously set autoCloseFolder=false. Now, docs mention that the ClosableResource should be used to close it whenever it's required. I wonder though, how can I achieve such behaviour with integrationFlowContext? Is there any way to close determine the end of session and close the folder?
There is no session lifecycle management in Java Mail API. Therefore no way you can catch its closed state someway.
The close folder hook is for those use-cases where you'd like to re-fetch a fresh metadata on the next receive cycle. But in most cases there is no need to close it at all. Starting with Spring Integration 6.0
, the folder is closed automatically, when no new messages from the mail box to process:
finally {
if (this.autoCloseFolder || ObjectUtils.isEmpty(messagesToReturn)) {
closeFolder();
}
}