1

I am attempting to write a Java class which will retrieve messages from GMail via POP3. So far, I have copied this code: http://www.java-tips.org/other-api-tips/javamail/connecting-gmail-using-pop3-connection-with-ssl-6.html

It does actually retrieve the messages, but I need to make it fetch only the unread messages. I have a GMail account I'm using for test purposes, with 3 messages: 1 read, 2 unread. The code correctly says there are 3 messages, but says there are 0 new messages.

When I add a line

folder.getUnreadMessageCount();

it returns 3. I would expect it to return 2, as one of the messages has been read (via Gamil web access)

What's going on? Is there any way I can retrieve only unread messages?

NickJ
  • 9,380
  • 9
  • 51
  • 74

1 Answers1

2

This is a limitation of the protocol. POP3 simply downloads all messages available at the server, but it does not make the read/unread status of the mail at the server side available. If you want to be able to query that kind of status, you'll have to use IMAP, instead.

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • 1
    Thanks! I originally thought that IMAP was for sending, POP was for receiving (shows how little I know about email) and your answer led me to further research, including this: http://stackoverflow.com/questions/5366767/retrieve-unread-emails-from-gmail-javamail-api-imap – NickJ Feb 25 '13 at 20:51