This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes JavaMail IMAP And GMail Unread Messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail IMAP And GMail Unread Messages" Watch "JavaMail IMAP And GMail Unread Messages" New topic
Author

JavaMail IMAP And GMail Unread Messages

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I've spent quite a bit of time this evening messing around the JavaMail's IMAP support and GMail. The problem I am having is trying to simply check for new messages. It would seem that for whatever reason GMail doesn't implement the Flags.Flag.RECENT flag. The only way I can seem to reliably determine if there is a new message after authenticating to the server is by checking each messages system flags like so:



Most of the time the user flags are also zero in length, but not all the time. So I can't rely on that. While this works the problem with it is that I am really bad about archiving my email. So I have 2000+ messages under the "Inbox" label. It takes a long time for JavaMail to go through all 2000+ messages and check the flags. Does anyone know of a better way, upon initial authentication, to get just messages that are unread?
[ May 11, 2008: Message edited by: Gregg Bolinger ]

GenRocket - Experts at Building Test Data
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3702
    
    5

Not really but I can attest to the fact that GMail is 'funny' about recent mail. Every once in awhile GMail will have trouble syncing and start downloading all messages over again. One thing I suggest trying is you can access your mail by putting the prefix "recent:" as part of your account login. See if this helps: https://mail.google.com/support/bin/answer.py?answer=47948

If I understand it correctly, without the "recent:" flag, GMail automates the synchronization and causes problems similar to what you're describing. With this flag, the clients handle synchronization. But as with anything useful, there is a catch: with the recent flag, the client also downloads all sent mail from you. I have a filter on my computer to move sent mail from me to the "Sent" folder, of course this ends up with duplicate messages in my sent folder (one I sent from the client, and the one downloaded from GMail).
[ May 11, 2008: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thanks Scott. I use Thunderbird for accessing GMail via IMAP and have never noticed this issue. With this JavaMail stuff I am leaning more towards a notifier than a full fledged client. It looks like the issue you linked to is a POP issue, not IMAP, but I might give it a shot anyway.

Update: doesn't work. Authentication fails.
[ May 11, 2008: Message edited by: Gregg Bolinger ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaMail IMAP And GMail Unread Messages
 
Similar Threads
Java Mail listener not being invoked
JavaMail API for Unread yahoo messages not working.
problem debugging an IMAP email listener
JavaMail: Working with Flags
JavaMail Flags, IMAP and Gmail Problem