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();
folder.fetch(msgs, profile);
You can also add specific headers to the fetch profile with:
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact