2

调用以下代码后,我编写了代码片段:

Message message_in  = null;
inbox instanceof IMAPFolder
IMAPFolder f = (IMAPFolder)inbox;
f.idle();
System.out.println("IDLE done");                                              
message_in = inbox.getMessage(inbox.getMessageCount());
message_in.setFlag(Flags.Flag.DELETED, true);
inbox.expunge();

我收到错误消息:

Got 1 new messages
***********************************************************
------------ Message 1 ------------
DONE
A4 OK IDLE completed.
A5 FETCH 13 (ENVELOPE INTERNALDATE RFC822.SIZE)
IDLE done
* 13 FETCH (ENVELOPE ("Wed, 29 Aug 2012 13:25:15 -0500" "Doc Com: Voice msg from Outside caller 5555555555 Unread:2" (("Support" NIL "support" "example.com")) NIL NIL (("Support" NIL "support" "example.com")) NIL NIL "<94BA85B8-FC4D-4193-B386-7FD2C1DE1B1F@example.com>" "<873439BD-8640-47D9-BF88-5FD3521B8173@example.com>") INTERNALDATE "29-Aug-2012 13:25:17 -0500" RFC822.SIZE 967)
A5 OK FETCH completed.
A6 STORE 13 +FLAGS (\Deleted)
* 13 FETCH (FLAGS (\Deleted \Recent))
A6 OK STORE completed.
A7 EXPUNGE
* 13 EXPUNGE
* 12 EXPUNGE
* 11 EXPUNGE
* 10 EXPUNGE
* 9 EXPUNGE
* 8 EXISTS
A7 OK EXPUNGE completed.
javax.mail.MessageRemovedException
    at com.sun.mail.imap.IMAPMessage.checkExpunged(IMAPMessage.java:205)
    at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1305)
    at com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:450)
    at javax.mail.internet.MimeBodyPart.isMimeType(MimeBodyPart.java:1050)
    at javax.mail.internet.MimeMessage.isMimeType(MimeMessage.java:986)
    at com.example.vmmonitor.main.VMMonitor.getText(VMMonitor.java:211)
    at com.example.vmmonitor.main.VMMonitor.access$000(VMMonitor.java:27)
    at com.example.vmmonitor.main.VMMonitor$1.messagesAdded(VMMonitor.java:109)
    at javax.mail.event.MessageCountEvent.dispatch(MessageCountEvent.java:150)
    at javax.mail.EventQueue.run(EventQueue.java:134)
    at java.lang.Thread.run(Thread.java:680)
DEBUG IMAP: IMAPProtocol noop

我能够通过添加Thread.sleep()如下来修补问题:

问题是什么?为什么我可以将邮件标记为DELETED但无法删除邮箱?

Message message_in  = null;
inbox instanceof IMAPFolder
IMAPFolder f = (IMAPFolder)inbox;
f.idle();
System.out.println("IDLE done");                                              
message_in = inbox.getMessage(inbox.getMessageCount());
message_in.setFlag(Flags.Flag.DELETED, true);
Thread.sleep(2000);/*****************bug patch***********/
inbox.expunge();
4

1 回答 1

0

这个多线程程序没有inbox以非线程安全的方式访问资源。该程序是在庄园中定义的,inbox.expunge();因此附加功能正在相互访问邮箱,因此引发异常。

于 2012-09-07T19:26:05.857 回答