--


I gave up trying to cons a MimeMultipart directly, and tried a different
approach.

This approach is quite clean.  The trick is to use the MimeMessage interface
that takes an InputStream.  But to use this interface you need to dummy up a
message header that contains at a minimum the content type:

                        import javax.mail.*;
                        import javax.mail.internet.*;

                        // ...

                        Properties props = System.getProperties();
                        Session session = Session.getDefaultInstance(props, null);

                        // Dummy up a message header.
                        String headers
                                = "Content-Type: " + request.getContentType() +
                                  "\r\n\r\n";

                        InputStream messageIS =
                                new SequenceInputStream(new 
StringBufferInputStream(headers),
                                                                
request.getInputStream());

                        MimeMessage message = new MimeMessage(session, messageIS);

                        Object content = message.getContent();
                        if (content instanceof MimeMultipart) {
                                MimeMultipart mm = (MimeMultipart) content;

                                int nBodyParts = mm.getCount();
                                for (int i = 0; i < nBodyParts; i++) {
                                        BodyPart part = mm.getBodyPart(i);
                                        ...
                                }
                        }

Ciao!
-ch

------
Christopher Hoover
mailto:[EMAIL PROTECTED]
http://www.murgatroid.com
+1-408-348-0304, +1-209-315-6378 fax


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Christopher
> Hoover
> Sent: Wednesday, July 07, 1999 4:10 PM
> To: [EMAIL PROTECTED]
> Subject: Using javax.mail.internet for parsing multipart/form-data
>
>
> --
>
>
> [Slightly off topic ... ]
>
> Has anyone had any success using the Java Mail framework
> (javax.mail.internet) to parse multipart/form-data POST responses?
>
> All my attempts thus far have yielded a javax.mail.internet.ParseException
> when I try to create a MimeMultipart from a DataSource that reads from the
> request input stream.
>
> The Java Mail framework isn't Open Source, so it is difficult to
> figure out
> what is going wrong.  :-(
>
> Ciao!
> -ch
>
> ------
> Christopher Hoover
> mailto:[EMAIL PROTECTED]
> http://www.murgatroid.com
> +1-408-348-0304, +1-209-315-6378 fax
>
>
>
>
> --
> --------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> READ THE FAQ!!!!     <http://java.apache.org/faq/>
> Archives and Other:  <http://java.apache.org/main/mail.html/>
> Problems?:           [EMAIL PROTECTED]
>



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
READ THE FAQ!!!!     <http://java.apache.org/faq/>
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to