Bulk Fetch Mail Bodies Using Javamail API and IMAP
Asked Answered
W

1

7

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?

Wagon answered 3/5, 2011 at 22:15 Comment(1)
See this answer: https://mcmap.net/q/587620/-javamail-performanceOringa
M
5

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

a1 fetch 1:* (rfc822.header rfc822.text)
Misrule answered 4/5, 2011 at 0:2 Comment(1)
Cocnerning this issue, if we get the response as an IMAPResponse object, how could I then get the body contents as a MultiPart object? I am trying to avoid to parse the responses manually...Pacha

© 2022 - 2024 — McMap. All rights reserved.