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.
If you prefetch the UIDs for all messages (using the Folder.fetch method) you should be able to get the UID of a message using the Folder.getUID(Message) after it's been deleted/expunged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With