本文介绍了addMessageCountListener在javamail中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在一个小项目中使用addMessageCountListener(用于POP3协议),但它不起作用。
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());
}
}
在这里,我要求服务器每5个消息的数量秒。
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){}
}
结果,我只看到了消息的数量(ge 18),但是我在programm运行后发送了一条消息。
As the result, I just see only count of messages (g.e. 18), but I've sent a message after programm was run.
PS。感谢您的帮助
推荐答案
这是因为POP3协议不允许新邮件在打开时显示在您的INBOX中。
That's because the POP3 protocol doesn't allow new messages to appear in your INBOX while it's open.
这篇关于addMessageCountListener在javamail中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!