Skip to main content

Gmail Flags update

  3 posts   Feedicon  
Replies: 2 - Last Post: January 10, 2014 08:25
by: tneff
showing 1 - 3 of 3
Posted: January 03, 2014 13:23 by tneff
Hi,

I wrote an own imap email client by using javamail.
I fetch each minute for new messages or message flag updates on the current selected folder.
This works fine expected for gmail accounts. I only get the "real flags" of a message the first time I'm fetching on the ImapFolder.
This means if a message is unread when I fetch the first time, I never get a flag-update when I mark the message as read by using the gmail web client.

If the user doesn't select another folder I do not close the ImapFolder. This means I use the same folder instance
and connection each time I fetch for new messages. If I use a new folder instance it would work with gmail accounts as well.

No my question, is this a known gmail behaviour (It's not listed here: https://support.google.com/mail/answer/78761?hl=en).
Or do I wrong by caching the ImapFolder instances?
Would it be the right way to create and open an ImapFolder each time before fetching and close it at the end?
The idea why I cache the folder instances is to get performance improvements.

I create the FetchProfile like this:
fetchProfile = new FetchProfile();
fetchProfile.add(FetchProfile.Item.ENVELOPE);
fetchProfile.add(FetchProfile.Item.FLAGS);
fetchProfile.add(/*NlsIgnore*/"X-Priority");

and use:
IMAPFolder#fetch(Message[] msgs, FetchProfile fp)
to get the messages.

I tested it with the latest javamail release 1.5.1.

Thanks.
Thomas
Posted: January 03, 2014 22:21 by Bill Shannon
I suspect it's a limitation in Gmail. It's probably not sending flag updates to other IMAP client sessions. You might need to close and reopen the folder to detect flag changes.

How are you checking for flag updates?

You can turn on session debugging and the protocol trace will show if Gmail is sending any flag updates.
Posted: January 10, 2014 08:25 by tneff
I do the following steps to update message flags:

1. IMAPFolder#getMessagesByUID(1, UIDFolder.LASTUID)
IMAPFolder#fetch(messages, fetchProfile) ( fetchProfile contains: FetchProfile.Item.FLAGS);

2. Flags flags = message.getFlags();
boolean isSeen = flags.contains(Flags.Flag.SEEN);

I enabled session debugging and the result is as you expected it. Gmail only sends the first time flag states:

First fetch:
A9 UID FETCH 1:* (UID)
* 1 FETCH (UID 1)
A9 OK Success
A10 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (X-Priority)])
* 1 FETCH (RFC822.SIZE 2124 INTERNALDATE "10-Jan-2014 07:56:19 +0000" FLAGS (\Seen) ENVELOPE ("Fri, 10 Jan 2014 08:56:18 +0100" "testflag" (("Thomas n" NIL "Thomas.n" "sender.ch")) (("Thomas n" NIL "Thomas.n" "sender.ch")) (("Thomas n" NIL "Thomas.n" "sender.ch")) ((NIL NIL "t.n" "gmail.com")) NIL NIL NIL "<52CFB5B2020000DE0005245C@mail.sender.ch>") BODY[HEADER.FIELDS (X-Priority)] {4}

Any further fetch:
DEBUG IMAPS: IMAPProtocol noop
A16 NOOP
A16 OK Success
A17 UID FETCH 1:* (UID)
* 1 FETCH (UID 1)
A17 OK Success
A18 SEARCH UNSEEN ALL
* SEARCH
A18 OK SEARCH completed (Success)

It seems i only can handle this problem by close and reopen the folder.
Replies: 2 - Last Post: January 10, 2014 08:25
by: tneff
 
 
Close
loading
Please Confirm
Close