GreenMail atomic getReceivedMessages() and purgeEmailFromAllMailboxes()

621 views Asked by At

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.

1

There are 1 answers