GMAIL IMAP: Getting only Unread/Fresh Email Messages

View: New views
3 Messages — Rating Filter:   Alert me  

GMAIL IMAP: Getting only Unread/Fresh Email Messages

by gopchandani :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 listserv@... and include in the body of the message "signoff JAVAMAIL-INTEREST". For general help, send email to listserv@... and include in the body of the message "help".


Re: GMAIL IMAP: Getting only Unread/Fresh Email Messages

by Bill Shannon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Rakesh Kumar wrote:

> 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 listserv@... and include in the body
of the message "signoff JAVAMAIL-INTEREST".  For general help, send email to
listserv@... and include in the body of the message "help".

Re: GMAIL IMAP: Getting only Unread/Fresh Email Messages

by gopchandani :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

On Tue, Dec 2, 2008 at 4:36 PM, Bill Shannon <bill.shannon@...> wrote:
Rakesh Kumar wrote:
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 listserv@... and include in the body of the message "signoff JAVAMAIL-INTEREST". For general help, send email to listserv@... and include in the body of the message "help".