简体   繁体   中英

Exception immediately after Expunging mailbox Java Email

Upon calling the following I code snipit:

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();

I receive the error message:

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

I was able to patch the issues by adding a Thread.sleep() as follows:

What is the issue? Why am I able to flag a message as DELETED but I am not able to expunge the mailbox?

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();

This multithreaded program is not accessing the inbox resource in a non-thread safe manor. The program is defined in a manor such that inbox.expunge(); and an additional functioning are mutually accessing the mailbox and hence the exception is thrown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM