Discussion:
GMAIL IMAP: Getting only Unread/Fresh Email Messages
Rakesh Kumar
2008-12-02 22:01:33 UTC
Permalink
Hello All,

I see that there is a method *folder.getMessages();* provided in API but
nothing that could pull only unread messages, however I can still see the
Unread messages count in a particular folder.

What I am trying to do is to pull email messages from my GMAIL folder *as
they arrive*. Previously I was thinking to do it by repeatedly checking for
new messages on server and pulling only unread messages but since this
feature is not directly available in API, Can you give me any tips on how to
implement this?




Rakesh.

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Bill Shannon
2008-12-02 22:36:30 UTC
Permalink
Post by Rakesh Kumar
Hello All,
I see that there is a method /folder.getMessages();/ provided in API but
nothing that could pull only unread messages, however I can still see
the Unread messages count in a particular folder.
What I am trying to do is to pull email messages from my GMAIL folder
/as they arrive/. Previously I was thinking to do it by repeatedly
checking for new messages on server and pulling only unread messages but
since this feature is not directly available in API, Can you give me any
tips on how to implement this?
In general, to get only unread messages, use Folder.search.

In your particular use case, you can probably just get all messages
with message numbers larger than the number of messages in the folder
the last time you checked. That is, if the folder has 10 messages,
you check for new messages and see that the folder now has 13 messages,
get messages 11, 12, and 13.

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Rakesh Kumar
2008-12-03 01:31:55 UTC
Permalink
Thanks for the pointer Bill.

GMAIL's implementation of Flag.RECENT is incomprehensible, i.e. I tried
logging out of my Gmail account and explicitly closed my JavaMail Session
and then sent an email to my account but it still would not recognize/return
the newly sent email message as RECENT message when searched even when the
unread email count was increasing by 1 during that period.

What proved to be worthwhile is Flag.SEEN. This sort of covers my purpose,
i.e. gives out all the messages for which getContent() hasn't been called,
when searched. I explicitly set Flag.SEEN to be true using setFlag when I
have seen the message, it was not being automatically set to false when
accessed using JavaMail.

-
Rakesh
Post by Bill Shannon
Post by Rakesh Kumar
Hello All,
I see that there is a method /folder.getMessages();/ provided in API but
nothing that could pull only unread messages, however I can still see the
Unread messages count in a particular folder.
What I am trying to do is to pull email messages from my GMAIL folder /as
they arrive/. Previously I was thinking to do it by repeatedly checking for
new messages on server and pulling only unread messages but since this
feature is not directly available in API, Can you give me any tips on how to
implement this?
In general, to get only unread messages, use Folder.search.
In your particular use case, you can probably just get all messages
with message numbers larger than the number of messages in the folder
the last time you checked. That is, if the folder has 10 messages,
you check for new messages and see that the folder now has 13 messages,
get messages 11, 12, and 13.
===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Loading...