Move multiple messages to a folder using JavaMail

2

I want to refactor an email handling code, I know you can remove multiple messages in one operation, but to move multiple messages to a certain folder,

I use the IMAP protocol.

    
asked by anonymous 05.02.2014 / 14:44

1 answer

2

Yes, it does. I've implemented a function for this, it's quite easy!

public void saveMessages(Message[] mArray, String folderName) throws Exception{
      //Primeiro copiamos...
      Folder f = findFolder(folderName);
      currentFolder.copyMessages(mArray, f);

      // Depois removemos do diretório antigo!
      for ( int i = 0; i < mArray.length; i++){
          mArray[i].setFlag(Flags.Flag.DELETED, true);
      }
      currentFolder.expunge();
   }
    
05.02.2014 / 18:30