Search code examples
javamavenjakarta-mailprefetch

Cache Message body using FetchProfile in JavaMail


I am stuck using an older version of JavaMail - it comes packaged inside of another maven dependency and I believe it is 1.4.7.

I have a Fetch Profile set up where I am attempting to download certain parts of the email including the body/content. This is possible beginning JavaMail 1.5.2 using IMAPFolder.FetchProfileItem.MESSAGE. Unfortunately, this is not available to me.

Does anybody have any ideas on how one can fetch the message content prior to 1.5.2? The ultimate goal is to reduce server round-trips - all other aspects fit the profile including partialFetch set to false, size of emails are small, etc.

Thanks in advance!


Solution

  • Use Message.writeTo to write the data to a local file or ByteArrayOutputStream. You can then reconstruct a MimeMessage object for the data by using the MimeMessage constructor that takes an InputStream.