I have an IMAPFolder
with MessageCountListener
that listens to messages being added / removed from the folder. Inside my messageRemoved(MessageCountEvent ...)
I need to get the UID of the message that was just removed so that I can reflect those changes in my local cache.
The issue is that if i try to execute IMAPFolder.getUID(Message ...)
on a deleted message I get
javax.mail.MessageRemovedException
at com.sun.mail.imap.IMAPMessage.checkExpunged(IMAPMessage.java:220)
at com.sun.mail.imap.IMAPFolder.getUID(IMAPFolder.java:1949)
at (...).IdleWatcher$1.messagesRemoved(IdleWatcher.java:64)
at javax.mail.event.MessageCountEvent.dispatch(MessageCountEvent.java:152)
at javax.mail.EventQueue.run(EventQueue.java:134)
at java.lang.Thread.run(Thread.java:856)
How can I determine the UID of the deleted message? I could go through all cached messages and check which ones still exist, however this is too resource intensive to be doing each time a message is deleted.