Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to find if message is unread using java mail API?

Tags:

java

I was using java mail to read Gmail as following -

Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "mail", "password");

Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);

Message[] messages = folder.getMessages();

Now I wan to find out if message is unread, but could not find any API. I want to do something like -

 for(Message message:messages) {

    if(message.isUnread) {
    // Do Something here
    }
 }

While there is no such API - isUnred.

like image 397
Tarun Avatar asked Aug 01 '11 12:08

Tarun


1 Answers

Have you tried Message.isSet(Flags.Flag.SEEN)

http://javamail.kenai.com/nonav/javadocs/javax/mail/Flags.Flag.html#SEEN

This message is seen. This flag is implicitly set by the implementation when the this Message's content is returned to the client in some form

it's been a while since I used JavaMail, but I think that does what you want

like image 116
strmqm Avatar answered Sep 23 '22 17:09

strmqm