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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With