tetest, thank you, the complete working example would be then:

                        MimeMessage message = new MimeMessage(session,
request.getInputStream());

                        StringBuffer sb = new StringBuffer();

                        sb.append("From: ");
                        Address[] senders = message.getFrom();
                        for (int i = 0; i < senders.length; i++)
                                sb.append(senders[i].toString()).append("; ");
                        sb.append("\n");

                        sb.append("To: ");
                        Address[] receivers = message.getAllRecipients();
                        for (int i = 0; i < receivers.length; i++)
                                sb.append(receivers[i].toString()).append("; ");
                        sb.append("\n");

                        InputStream is = (InputStream) message.getContent();
                        String contentType = message.getContentType();
                        ByteArrayDataSource byteArrayDataSource = new 
ByteArrayDataSource
(is, contentType);
                        Multipart mmp = new MimeMultipart(byteArrayDataSource);

                        for (int i = 0; i < mmp.getCount(); i++) {
                                Part p = mmp.getBodyPart(i);
                                if ("text/plain".equals(p.getContentType())) {
                                        if (i > 0) sb.append("*******");
                                        ByteArrayInputStream bais = 
(ByteArrayInputStream) p.getContent
();
                                        byte[] buffer = new byte[1024];
                                        int length = 0;
                                        while ((length = bais.read(buffer)) != 
-1)
                                                sb.append(new String(buffer, 0, 
length));
                                }
                        }

Does not work reliably (java.io.IOException: Truncated quoted
printable data and java.lang.OutOfMemoryError: Java heap space) but
that is either other bug in GAE or my code.

On Dec 1, 4:38 am, tetest <[email protected]> wrote:
> Hi,
>
> Follow this thread:
>
> http://groups.google.com/group/google-appengine-java/browse_thread/th...http://groups.google.com/group/google-appengine-java/browse_thread/th...
>
> Though something only has to be able to be useful.
>
> thanks.
>
> On 11月30日, 午後11:34, Peter Ondruska <[email protected]> wrote:
>
>
>
> > I am following instructions 
> > onhttp://code.google.com/appengine/docs/java/mail/receiving.html
> > to process incoming mail but failing on retrieving content (headers
> > are fine).
>
> > "The getContent() method returns an object that implements the
> > Multipart interface. You can then call getCount() to determine the
> > number of parts and getBodyPart(int index) to return a particular body
> > part."
>
> > MimeMultipart mmp = (MimeMultipart) message.getContent();
>
> > Error:
> > java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be
> > cast to javax.mail.internet.MimeMultipart
>
> > And when I check at runtime what class is returned by getContent() it
> > really is java.io.ByteArrayInputStream.
>
> > Am I doing something wrong?

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to