How to move message from one folder to another?
Created May 7, 2012
Asif Sajjad Here is the code I am using to move the messages to another folder.
In findFolder method I search for the folder name and then open the folder to read-write. CurrentFolder is the folder from where the messages are copied to the destination folder.
public void saveMessages(Message[] mArray, String folderName) throws Exception{ Folder f = findFolder(folderName); currentFolder.copyMessages(mArray, f); // Now the delete the messages from Current Folder for ( int i = 0; i < mArray.length; i++){ mArray[i].setFlag(Flags.Flag.DELETED, true); } currentFolder.expunge(); }[Keep in mind this is for IMAP only. POP doesn't support folders.]