[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Other JSE/JEE APIs
 
RSS feed
 
New topic
Author

Getting Multiple Attachments from MIMEMessage

pk anoop
Greenhorn

Joined: Jun 11, 2009
Messages: 7

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 Prime
Bartender

Joined: Oct 27, 2005
Messages: 8689

Anoop, please read your private messages.

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

Also, moving to Other JEE APIs.

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
pk anoop
Greenhorn

Joined: Jun 11, 2009
Messages: 7

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 Prime
Bartender

Joined: Oct 27, 2005
Messages: 8689

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.

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
pk anoop
Greenhorn

Joined: Jun 11, 2009
Messages: 7

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 Prime
Bartender

Joined: Oct 27, 2005
Messages: 8689

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.

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
pk anoop
Greenhorn

Joined: Jun 11, 2009
Messages: 7

Is there anyway that we can check whether its a HTML Text?
Or is HTML's content type is text/plain type??

Regards,
Anoop
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Other JSE/JEE APIs
 
RSS feed
 
New topic
replay challenge