How do I delete a folder with IMAP4? Must I get the folder with getFolder() before deleting?

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

public abstract boolean delete(boolean recurse)
                        throws MessagingException