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!

print contents of mimemultipart message

843834Nov 10 2007 — edited Nov 10 2007
Hi,
i have tried various ways of printing the contents of a mime message, but i usually get to print only the signature. Is the MimeMessage structure a tree structure? Can you post a tip/link, etc?
Here is some sample code, that i am currently experimenting with:
...
       MimeMessage msg=getMIMEMessage(new File(filename));

        Object o=msg.getContent();

        

        if (o instanceof MimeMultipart)

        {

            System.err.print("Multipart instance ");

            MimeMultipart mm=(MimeMultipart)o;

            System.err.println("containg "+mm.getCount()+" parts");

            Part p1=mm.getBodyPart(0);

            System.err.println("content type: "+p1.getContentType());



            

            Part p2=mm.getBodyPart(1);

            System.err.println("content type: "+p2.getContentType());  

            InputStreamReader isr=new InputStreamReader(p2.getInputStream());

            BufferedReader br=new BufferedReader(isr);

            String line=br.readLine();

            String txt=line;

            while (line!=null)

            {

                line=br.readLine();

                txt+=line+"\n";

            }

            System.out.println(txt);            

            if (p2 instanceof Part)

            {

                System.err.println("p2 is of Part interface");                

                if (p2 instanceof Multipart)

                {

                    System.err.println("p2 is of Multipart interface");    

                }

            }            
....
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2007
Added on Nov 10 2007
1 comment
776 views