com.mirrorworlds.lifestreams.mail.tnef.internet
Class TnefMultipart

com.mirrorworlds.lifestreams.mail.tnef.internet.TnefMultipart

public class TnefMultipart

The TnefMultipart class is an implementation of the abstract Multipart class (in the Java MAIL api) that uses MIME conventions for the multipart data.

Note: This package is still at a very early stage. Requires the Java Mail API and the Java Activation Framework API.

Sample usage (hack) with Java Mail API:

  // assume you have Java Mail API MultiPart object that has text/plain message
  // as well as an application/ms-tnef attachment (bodypart).
  // The solution (hack) described here basically removes this bodypart from the
  // multipart, then obtains the tnef attachments from this application/ms-tnef
  // bodypart and adds these attachments back into the original multipart object.

  // (ideally, all of these should be transparent to the Java Mail API user,
  //  probably by associating a DataContentHandler etc.(JAF) for the tnef content-type).

  // mp is of type Multipart that has the application/ms-tnef attachment.
  // loop thru and get the tnef part.
  int size = mp.getCount();
  boolean done = false;
  for (int i = 0; i < size; i++) {
      BodyPart bp = mp.getBodyPart(i);
      // ct is content-type of the body part.
      String ct = bp.getContentType();
      //if this is a tnef, then process it.
       if (ct.indexOf("application/ms-tnef") != -1) {
           // create tnef data source.
           TnefMultipartDataSource tnefDS = new TnefMultipartDataSource((MimePart)bp);
           // create Tnef multipart
           MimeMultipart tnefMP = new TnefMultipart(tnefDS);
           // get num of tnef attachments
           int partCount = tnefMP.getCount();
           // loop thru and add the attachment into the original multipart.
           for (int k = 0; k < partCount; k++) {
               BodyPart tnefBodyPart = tnefMP.getBodyPart(k);
               mp.addBodyPart(tnefBodyPart);                    
           }
           //remove the original application/ms-tnef part.
           mp.removeBodyPart(bp);
           bp = null;
           done = true;
           break;
       }// if
  }//for           
 

Version:
Feb 22, 2000 Lifestreams 1.5

Constructor Summary
TnefMultipart()
          Default constructor.
TnefMultipart(TnefMultipartDataSource ds)
          Constructs a TnefMultipart object and its bodyparts from the given DataSource.
 

Constructor Detail

TnefMultipart

public TnefMultipart()
Default constructor. An empty TnefMultipart object is created. Its contentType is set to "multipart/tnef". A unique boundary string is generated and this string is setup as the "boundary" parameter for the contentType field.

MimeBodyParts may be added later.


TnefMultipart

public TnefMultipart(TnefMultipartDataSource ds)
              throws com.mirrorworlds.lifestreams.mail.tnef.internet.MessagingException
Constructs a TnefMultipart object and its bodyparts from the given DataSource.

Parameters:
ds - TnefMultipartDataSource.