Receive UID of a remote message

I have IMAPFolderwith MessageCountListenerthat is listening posts that are added / deleted from the folder. Inside mine, messageRemoved(MessageCountEvent ...)I need to get the UID of the message that was just deleted so that I can reflect these changes in my local cache.

The problem is that if I try to execute IMAPFolder.getUID(Message ...)in a remote 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 to determine the identifier of a deleted message? I could look at all cached messages and check which ones still exist, however this is a too resource-intensive process that needs to be done every time a message is deleted.

+4
source share
3 answers

UID ( Folder.fetch), UID Folder.getUID(Message) /.

+2

UID - , . .

- UID , - . , , , , .

+1

IMAPFolder. , getUID.

API Doc :

The exception thrown when an invalid method is invoked on an expunged Message. The only valid methods on an expunged Message are isExpunged() and getMessageNumber().

I think you should cache the message UIDs, while deleting in your MessageCounterListener may be, after when you need it, you can check and receive the UIDs.

+1
source

Source: https://habr.com/ru/post/1568309/


All Articles