Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get the whole attachment as a MimeMessage?

843830Sep 1 2003 — edited Sep 1 2003
I'm finding a way to deal with base64 encoded .eml attachment. I need to parse it to MimeMessage for further process
        
   for (i=0; i<part.getCount(); i++) { 
        currentPart = (MimePart) part.getBodyPart(i);
        
        if ( file extension is .eml ) {
            InputStream input = currentPart.getInputStream();
            currentPart = new MimeMessage(null, input);
        }
with the above code, I would only get the decoded body of the email content, all header information are missing.
From JavaMail API, getInputStream() and writeTo() would only get/write the content part, so I've tried to use:
   for(Enumeration enum = currentPart.getAllHeaderLines(); enum.hasMoreElements();)	{
        currentPart.addHeaderLine((String)enum.nextElement());
   }		
I suppose currentPart is a MimeMessage now, but when I try this:
   request.setAttribute("part", (MimeMessage) currentPart.getContent());
I would get a ClassCastException

Would anyone give me some suggestion?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 29 2003
Added on Sep 1 2003
1 comment
513 views