• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Multiple Attachments from MIMEMessage

 
pk anoop
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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 :

BodyPart bodyPart = multipart.getBodyPart(0);

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.

happy Coding,

Anoop
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anoop, please read your private messages.

Can you show us the code that is reading the email?

Also, moving to Other JEE APIs.
 
pk anoop
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

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 :



Am i doing anything wrong here???

Also please find my reply in your Private Messages.

Happy Coding
Thanks,
Anoop
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pk anoop
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Rob,

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

Please help.

Regards,
Anoop
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Perhaps this can help you.
 
pk anoop
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anyway that we can check whether its a HTML Text?
Or is HTML's content type is text/plain type??

Regards,
Anoop
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!