cubesoft
cubesoft

Reputation: 3550

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?

Upvotes: 4

Views: 8039

Answers (2)

Bartek
Bartek

Reputation: 1337

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

Upvotes: 12

Anshul
Anshul

Reputation: 1446

unfortunately there is no straight forward solution... May be what you can try is to maintain an internal structure with body structures of all the mail ids and then perform a one on one Message-ID check and obtain the UID of mail. Anyways you would be doing it, in order to show the Maillist. Add a new logic to map the message-ids as well.

Upvotes: 0

Related Questions