Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java mail - getting message by message ID

I'm developing Android mail client. I need to build a "conversation" structure for every email message. I use the

IMAPMessage.getInReplyTo()

method that returns the Message ID of message which the message is a reply to. Unfortunatelly there seems to be no easy way to obtain message from

IMAPFolder

using its message ID. It is only possible to get the message by its UID. Is there an easy way to get the IMAP message by its Message ID?

like image 251
cubesoft Avatar asked Dec 26 '22 05:12

cubesoft


1 Answers

You can use the IMAPFolder's search method like this:

SearchTerm searchTerm = new MessageIDTerm(messageId);
Message[] messages = imapFolder.search(searchTerm);

See the docs for the IMAPFolder's search method here: https://javaee.github.io/javamail/docs/api/com/sun/mail/imap/IMAPFolder.html#search-javax.mail.search.SearchTerm-

and for the MessageIDTerm class here: https://javaee.github.io/javamail/docs/api/javax/mail/search/MessageIDTerm.html

like image 194
Bartek Avatar answered Jan 05 '23 18:01

Bartek