Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move (copy) IMAPMessage to another folder on the mail server

My application is checking the patterns of the subjects of the mails on the Inbox server folder and if some pattern is found, we should move the email (com.sun.mail.imap.IMAPMessage) to another folder - called 'test' for example (copy will do the job also).

I searched on the Internet for the solution but I could not find anything helpful.

Can you tell me how can I move / copy IMAPMessage from inbox to another folder on server?

Thank you

like image 264
gospodin Avatar asked Jul 22 '14 12:07

gospodin


1 Answers

It is a bad idea to move a message with methods like copyMessages(), addMessages() or appendMessage() and removing the old message, because these methods generates a new message. The new message have an different Message-ID in the header. If you response on the new message, the receiver cannot relate the response to his sent mail, because he does not know the new Message-ID. You have to cast the folder to a IMAPFolder. IMAPFolder has the method moveMessages(Message[] msgs, Folder targetFolder) to move messages without tampering the header Message-ID.

like image 176
Dieter Avatar answered Oct 06 '22 19:10

Dieter