Is there a way how to atomically receive messages from GreenMail and then purge those messages? I don't want to receive any message more than once. Something like getReceivedMessagesAndPurge()
.
In my code, I want to write any email received by GreenMail to disk. My plan is to call GreenMail.getReceivedMessages()
let say every second and write received messages to disk. And after that I need to call GreenMail.purgeEmailFromAllMailboxes()
in order to write any message to disk only once. However there is a race condition which I don't know, how to avoid.
You could write your own MessageDeliveryHandler to do that.
Example: https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/test/java/com/icegreen/greenmail/examples/ExampleUndeliverableTest.java