You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by Larry Reeder <lr...@freevoice.org> on 2002/07/11 01:46:57 UTC

Is this a bug? MIME headers sometimes misplaced with MimeMultipart.writeTo

I realize this is more of a JavaMail question, but I ran across it while
trying to populate a SOAPContext.  Maybe some of you JavaMail gurus can
see if I'm doing something wrong.
 
I'm getting some strange behavior with the MimeMultipart constructor that
takes an InputStream as an argument.  When I do this and call
MimeMultipart.writeTo, usually the content of the InputStream is first,
followed by the MIME headers.  Sometimes, if the content of the
InputStream is very large, like an image, the headers will be inserted in
the middle of the content.  Here's an example of the output with three
attachments in the Multipart:

------=_Part_0_41771.1026343706443
<bazz>
  This is bazz!
</bazz>
Content-Type: text/xml


------=_Part_0_41771.1026343706443
This is foo!
Content-Type: text/plain


------=_Part_0_41771.1026343706443
This is bar!
Content-Type: text/plain


------=_Part_0_41771.1026343706443--


If I use the MimeBodyPart(InternetHeaders, byte[]) constructor,
the Content-type is in the right place, above the content.   Before I
submit this to JDC, can any one tell me if I'm doing something wrong?

Here's my program that demonstrates the problem:

package com.fidelia.emerald.reportServer;

import java.io.*;
import javax.mail.internet.*;

public class MultipartTest {

  public static void main(String[] args) {
     MultipartTest mpt = new MultipartTest();
     try {
       mpt.createMessage();
     } catch(Exception exc) {
       exc.printStackTrace();
     }
  }

  public void createMessage() throws Exception {

    MimeMultipart multipart = new MimeMultipart("related");

    //This works right.
    //String bazz = "<bazz>\nThis is bazz!\n</bazz>\n";
    //MimeBodyPart bazzAttachment = new MimeBodyPart(new
InternetHeaders(), bazz.getBytes());
    //This does not.
    MimeBodyPart bazzAttachment = getAttachment("/tmp/report/bazz.xml");
    bazzAttachment.setHeader("Content-Type", "text/xml");
    multipart.addBodyPart(bazzAttachment, 0);

    //String foo = "This is foo!\n";
    //MimeBodyPart fooAttachment = new MimeBodyPart(new InternetHeaders(),
foo.getBytes());
    MimeBodyPart fooAttachment = getAttachment("/tmp/report/foo.txt");
    fooAttachment.setHeader("Content-Type", "text/plain");
    multipart.addBodyPart(fooAttachment, 1);

    //String bar = "This is bar!\n";
    //MimeBodyPart barAttachment = new MimeBodyPart(new InternetHeaders(),
bar.getBytes());
    MimeBodyPart barAttachment = getAttachment("/tmp/report/bar.txt");
    barAttachment.setHeader("Content-Type", "text/plain");
    multipart.addBodyPart(barAttachment, 2);

    multipart.writeTo(new FileOutputStream("/tmp/multipart"));
  }

  private MimeBodyPart getAttachment(String fileName) throws Exception {
    File attachmentFile = new File(fileName);
    InputStream is = new FileInputStream(attachmentFile);
    MimeBodyPart attachment = new MimeBodyPart(is);
    return attachment;
  }

}


I'm using JavaMail 1.3, and JAF 1.0.2.

Thanks..............             Larry



--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>