Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting UID of deleted message

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.

like image 848
Bart Platak Avatar asked Sep 30 '22 04:09

Bart Platak


1 Answers

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.

like image 70
Bill Shannon Avatar answered Oct 03 '22 03:10

Bill Shannon