I’m playing around with java’s default pop3 implementation and having trouble getting it to read the actual state of flags (i think).
Here’s the (abbreviated) code:
Store store = null;
Folder folder = null;
try
{
Session mailSession = Session.getInstance(new Properties(), null);
store = mailSession.getStore("pop3");
store.connect(host, addr, pwd);
folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
for (Message msg : folder.getMessages())
{
if (msg.isSet(Flag.SEEN))
continue;
LOG.debug("processing email titled '" + msg.getSubject()
+ "' from '" + msg.getFrom()[0] + "'");
... do some stuff
msg.setFlag(Flag.SEEN, true);
}
}
finally
{
if (folder != null)
folder.close(true);
if (store != null)
store.close();
}
The problem is that each time the above code is executed, the same messages (all of them) are processed because the call to msg.isSet(Flag.SEEN) always returns false, even though I have set it to true in the previous iteration.
The webmail client even reflects the flag being set (title changes from bold to normal font).
Does anyone know what I’m doing wrong?
thanks, p.
further reading tells me that pop3 doesn’t support setting/getting these flags, only deleting messages.
it does seem that pop3 supports setting the flag (since i could see the flag had been set successfully in the webmail program) but could not subsequently read the flags state.
thankfully my mail server supports imap which does everything as expected. I just had to change my code from
mailSession.getStore("pop3")tomailSession.getStore("imap").