I am trying to read a MIME Message which is having multiple attachments. I was in a feeling that using multipart i can traverse through each attachment. But it failed.
Can anyone please guide me how to get more than one attachments. I am able to get one attachment like this :
But it doesn't seems to work for multiple. Because all the time i am getting the multipart.count as '1'. Please help. I am getting screwed up because of stucking up with this for last 3-4 days.
Thanks for the reply. I am reading mails using javax.mail from Unix Mail Box using maildir protocol. I am succesfully getting the mails. After getting the mails am parsing it like this :
A body part's content does not necessarily have to be an InputStream instance; from experience I've seen that it can be (at least) a String, InputStream, or even another Message or MultiPart.
This is how I usually read email bodies:
As you can see this is a recursive call.
thanks for the reply man. I had followed your approach and right now am stuck up at some place.
I have little knowledge about the MIME Message and am working on it for the first type.
My doubt is, if the mail contains both body and attachments, how should I read the mails.
Means, how can I know that which part is the body and which are all attachments.
I think I may be asked to handle the HTML/RichText bodies as well
The bodies are usually Strings and the attachments either other Message objects (messages forwarded as attachments) or InputStreams (regular attachments).
That still leaves the problem when you have multiple String bodies. Usually the first is the "real" body (plain text for multipart). How we handled this a short while back is as follows:
- take the first String body as the real body
- if that is plain text, take the first String HTML body if present