How do I uniquely identify a Java Mail Message using IMAP?

Look at the UIDFolder interface, which exposes the IMAP UID capability.


You can get a unique identifier for a message using the following code as an example

Folder folder = imapStore.getFolder("INBOX"); // get reference for inbox folder
UIDFolder uf = (UIDFolder)folder; // cast folder to UIDFolder interface
folder.open(Folder.READ_ONLY); // open folder
Message messages[] = folder.getMessages(); // get all messages
Long messageId = uf.getUID(messages[0]); // get message Id of first message in the inbox