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

MimeBodyPart

public class MimeBodyPart extends com.android.email.mail.BodyPart
TODO this is a close approximation of Message, need to update along with Message.

Fields Summary
protected MimeHeader
mHeader
protected com.android.email.mail.Body
mBody
protected int
mSize
private static final Pattern
REMOVE_OPTIONAL_BRACKETS
Constructors Summary
public MimeBodyPart()


        
        this(null);
    
public MimeBodyPart(com.android.email.mail.Body body)

        this(body, null);
    
public MimeBodyPart(com.android.email.mail.Body body, String mimeType)

        if (mimeType != null) {
            setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeType);
        }
        setBody(body);
    
Methods Summary
public voidaddHeader(java.lang.String name, java.lang.String value)

        mHeader.addHeader(name, value);
    
public com.android.email.mail.BodygetBody()

        return mBody;
    
public java.lang.StringgetContentId()

        String contentId = getFirstHeader(MimeHeader.HEADER_CONTENT_ID);
        if (contentId == null) {
            return null;
        } else {
            // remove optionally surrounding brackets.
            return REMOVE_OPTIONAL_BRACKETS.matcher(contentId).replaceAll("$1");
        }
    
public java.lang.StringgetContentType()

        String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE);
        if (contentType == null) {
            return "text/plain";
        } else {
            return contentType;
        }
    
public java.lang.StringgetDisposition()

        String contentDisposition = getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION);
        if (contentDisposition == null) {
            return null;
        } else {
            return contentDisposition;
        }
    
protected java.lang.StringgetFirstHeader(java.lang.String name)

        return mHeader.getFirstHeader(name);
    
public java.lang.String[]getHeader(java.lang.String name)

        return mHeader.getHeader(name);
    
public java.lang.StringgetMimeType()

        return MimeUtility.getHeaderParameter(getContentType(), null);
    
public intgetSize()

        return mSize;
    
public booleanisMimeType(java.lang.String mimeType)

        return getMimeType().equals(mimeType);
    
public voidremoveHeader(java.lang.String name)

        mHeader.removeHeader(name);
    
public voidsetBody(com.android.email.mail.Body body)

        this.mBody = body;
        if (body instanceof com.android.email.mail.Multipart) {
            com.android.email.mail.Multipart multipart = ((com.android.email.mail.Multipart)body);
            multipart.setParent(this);
            setHeader(MimeHeader.HEADER_CONTENT_TYPE, multipart.getContentType());
        }
        else if (body instanceof TextBody) {
            String contentType = String.format("%s;\n charset=utf-8", getMimeType());
            String name = MimeUtility.getHeaderParameter(getContentType(), "name");
            if (name != null) {
                contentType += String.format(";\n name=\"%s\"", name);
            }
            setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
            setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
        }
    
public voidsetHeader(java.lang.String name, java.lang.String value)

        mHeader.setHeader(name, value);
    
public voidwriteTo(java.io.OutputStream out)
Write the MimeMessage out in MIME format.

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
        mHeader.writeTo(out);
        writer.write("\r\n");
        writer.flush();
        if (mBody != null) {
            mBody.writeTo(out);
        }