IntelliJ Java IDE
The moose likes Other JSE/JEE APIs and the fly likes folder.Expunge() not supported exception. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "folder.Expunge() not supported exception." Watch "folder.Expunge() not supported exception." New topic
Author

folder.Expunge() not supported exception.

vikas tarade
Greenhorn

Joined: Oct 06, 2001
Posts: 5
I want to delete some messages in my mailbox.
When a message is read the DELETED flag was set as,
message.setFlag(Flags.Flag.DELETED,true);
folder.Expunge();
As per the documentation,folder.Expunge() method will look for all the messages in the folder whose DELETED flag is set.
But with the above code Exception was thrown as
method folder.Expunge() not supported by the implementation.
How should I delete the messages I want,or get through this problem?
Thanks
Vikas
Lewin Chan
Ranch Hand

Joined: Oct 10, 2001
Posts: 214
Assuming you are using the Sun POP3 implementation, and you read the sundocs, you will find that Folder.expunge is not supported...
You should do Message.setFlag(Flags.Flag.DELETED), and then do a folder.close(true) to delete the messages

I have no java certifications. <br />This makes me a bad programmer.<br />Ignore my post.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11862
I just tried this:
msg[i].setFlag( Flags.Flag.DELETED ,true );// could mark flag?
msg[i].saveChanges(); // will delete when folder closed
and got the following :
javax.mail.IllegalWriteException: POP3 messages are read-only
at com.sun.mail.pop3.POP3Message.saveChanges(POP3Message.java:380)
at com.lanw.clients.TestMailRead.main(TestMailRead.java:48)
The folder was opened like this:
folder.open(Folder.READ_WRITE);
So - now I am mystified, how can I delete a Message from a Folder?
Bill

Java Resources at www.wbrogden.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11862
Aha - get to answer my own question.
if I remove the line: msg[i].saveChanges();
But use the following on the folder:
folder.close(true) ;
Then the POP3 messages are deleted.
Somehow that does not seem "instinctive"!
Bill
 
 
subject: folder.Expunge() not supported exception.
 
Threads others viewed
IO Exception while checking for deleted record
delete in B&S
unlock a deleted record, how to?
Gaps in JTable for deleted records?
B&S: DuplicateKeyException?
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com