Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk Fetch Mail Bodies Using Javamail API and IMAP

Is there a way to fetch the mail bodies of multiple emails with a single call to an IMAP server using the Javamail API?

I know I can get to the body of a given message using the Message.getContent() call, but this ends up doing a call to the imap server for each individual message.

Is it possible to use the FetchProfile and Folder.fetch call to bulk fetch bodies? The documentation implies that the FetchProfile is only for header data. I tried the following, but that didn't do the trick:

FetchProfile fp = new FetchProfile();
fp.add("rfc822.text");
inbox.fetch(messages, fp);

If it is not possible to do this using Javamail, is it due to a constraint in the Javamail API or does the IMAP protocol simply not support this?

like image 447
Canned Avatar asked May 03 '11 22:05

Canned


1 Answers

Limitation of JavaMail. The IMAP protocol allows fetching the bodies of several messages at once:

a1 fetch 1:* (rfc822.header rfc822.text)
like image 150
dnault Avatar answered Sep 23 '22 06:09

dnault