How do I limit the parts of a message I get? I'd like to avoid fetching attachments until a user wants it.
John Zukowski The JavaMail API supports a FetchProfile that allows you to limit the contents retrieved. The FetchProfile.Item class specifies three pre-defined items that can be fetched: ENVELOPE, FLAGS, and/or CONTENT_INFO. For instance, if all you want is the From, To, Subject, and Date (or message Envelope info), you could do something like the following:
Messages msgs = folder.getMessages(); FetchProfile profile = new FetchProfile(); profile.add(FetchProfile.Item.ENVELOPE); folder.fetch(msgs, profile);You can also add specific headers to the fetch profile with: