How do I delete a folder with IMAP4? Must I get the folder with getFolder() before deleting?
Created May 4, 2012
Dieter Wimberger Yes, you have to get the folder first. Here a small code snippet:
//I suppose some existing reference to the store private Store myStore; [...] String path="mail/aFolder"; Folder afolder=myStore.getFolder(path); if(afolder.exists() && !afolder.isOpen()) { //the true will recurse afolder.delete(true); } [...]You should be sure the folder exists, and the operation performs only on a closed folder. However, I suggest anyway to consult the API docs about the implications of the delete().
javax.mail.Folder public abstract boolean delete(boolean recurse) throws MessagingException