Move multiple messages to a folder using Javamail

Asked

Viewed 327 times

2

I’m looking to refactor an email manipulation code, I know you can remove multiple messages in one operation, but and to move multiple messages to a certain folder, have as?

I use the IMAP protocol.

1 answer

2


Yes. I implemented a function for this, it is very 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();
   }
  • Man, cool, I didn’t know that you could pass several messages to a printer at once, to delete yes. Thank you

  • could please post the code of findFolder.

  • Look man, I came from C++ and I don’t know much about Java no... Check there and see if there is a way to find folders and then I edit the question! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.