FileDocCategorySizeDatePackage
MimeMultipart.javaAPI DocAndroid 1.5 API3459Wed May 06 22:42:46 BST 2009com.android.email.mail.internet

MimeMultipart

public class MimeMultipart extends com.android.email.mail.Multipart

Fields Summary
protected String
mPreamble
protected String
mContentType
protected String
mBoundary
protected String
mSubType
Constructors Summary
public MimeMultipart()

        mBoundary = generateBoundary();
        setSubType("mixed");
    
public MimeMultipart(String contentType)

        this.mContentType = contentType;
        try {
            mSubType = MimeUtility.getHeaderParameter(contentType, null).split("/")[1];
            mBoundary = MimeUtility.getHeaderParameter(contentType, "boundary");
            if (mBoundary == null) {
                throw new MessagingException("MultiPart does not contain boundary: " + contentType);
            }
        } catch (Exception e) {
            throw new MessagingException(
                    "Invalid MultiPart Content-Type; must contain subtype and boundary. ("
                            + contentType + ")", e);
        }
    
Methods Summary
public java.lang.StringgenerateBoundary()

        StringBuffer sb = new StringBuffer();
        sb.append("----");
        for (int i = 0; i < 30; i++) {
            sb.append(Integer.toString((int)(Math.random() * 35), 36));
        }
        return sb.toString().toUpperCase();
    
public java.lang.StringgetContentType()

        return mContentType;
    
public java.io.InputStreamgetInputStream()

        return null;
    
public java.lang.StringgetPreamble()

        return mPreamble;
    
public voidsetPreamble(java.lang.String preamble)

        this.mPreamble = preamble;
    
public voidsetSubType(java.lang.String subType)

        this.mSubType = subType;
        mContentType = String.format("multipart/%s; boundary=\"%s\"", subType, mBoundary);
    
public voidwriteTo(java.io.OutputStream out)

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);

        if (mPreamble != null) {
            writer.write(mPreamble + "\r\n");
        }

        for (int i = 0, count = mParts.size(); i < count; i++) {
            BodyPart bodyPart = (BodyPart)mParts.get(i);
            writer.write("--" + mBoundary + "\r\n");
            writer.flush();
            bodyPart.writeTo(out);
            writer.write("\r\n");
        }

        writer.write("--" + mBoundary + "--\r\n");
        writer.flush();