Reputation: 3261
I'm trying to use addMessageCountListener (for POP3 protocol) in a small project, but it doesn't work.
This is code where I added listener:
protected void openFolder() {
try {
this.inbox = this.store.getFolder("INBOX");
if (inbox == null) {
throw new Exception("No POP3 INBOX");
}
this.inbox.open(Folder.READ_WRITE);
this.inbox.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
System.out.println("Event");
Message [] msgs = ev.getMessages();
for (Message msg : msgs) {
System.out.println("msg");
System.out.println(AbstractReceiverClient.getTextFromMsg("email", "subject", msg));
}
}
public void messagesRemoved(MessageCountEvent ev) {}
});
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
Here, I ask server for count of messages per 5 seconds.
public void worker() {
try {
while(true){
java.lang.Thread.sleep(5000);
System.out.println(this.inbox.getMessageCount());
}
}
catch(Exception e){}
}
As the result, I just see only count of messages (g.e. 18), but I've sent a message after programm was run.
PS. Thanks for help
Upvotes: 0
Views: 1744
Reputation: 1
yeah.... when I use the imap protocol, the addMessageCountListenner method do not work.I did not find the way to resolve this problem. So I give up the way which monitor the event, instead of polling method.
Upvotes: -1
Reputation: 29971
That's because the POP3 protocol doesn't allow new messages to appear in your INBOX while it's open.
Upvotes: 0