0
成功打開Pop3Folder
並從中檢索消息後,我有時會回到這一點,當folder.isOpen
返回false
。同時,在調試模式下查看Pop3Folder
的字段時,我看到字段opened
設置爲true
。JavaMail - Pop3Folder意外關閉
有人能給我一個提示,這裏可能會出錯嗎?
下面是代碼:
public void popMail(MessageProcessor messageProcessor) throws MessagingException {
Folder inboxFolder = null;
Store store = null;
try {
store = mailSession.getStore();
store.connect(mailSession.getProperty("mail.user"),
mailSession.getProperty("mail.password"));
// OK. Connected to POP3 Store.
inboxFolder = store.getFolder("inbox");
inboxFolder.open(Folder.READ_WRITE);
// The folder is successfully opened.
Message[] msgs = inboxFolder.getMessages();
// Messages are successfully retrieved.
if (msgs != null && msgs.length > 0) {
for (Message msg : msgs) {
if (messageProcessor != null) {
// Calling custom listener to process message
messageProcessor.processMessage(msg);
}
msg.setFlag(Flag.DELETED, true);
}
}
} finally {
// Oops, inboxFolder.isOpen returns false.
// Meanwhile I see in debug mode that inboxFolder#opened is set to true
if (inboxFolder != null && inboxFolder.isOpen()) {
try {
inboxFolder.close(true);
} catch (MessagingException e) {
log.warn("Error while closing folder");
}
} if (store != null) {
try {
store.close();
} catch (MessagingException e) {
log.warn("Error while closing store");
}
}
}
}
謝謝,我會看看這個。 – jFrenetic
我沒有打開調試,但我可以肯定地說,在處理消息大約2分鐘後,文件夾最終會被關閉。所以是的,這很可能是服務器超時連接。再次感謝! – jFrenetic