FileDocCategorySizeDatePackage
IMAPBodyPart.javaAPI DocJavaMail 1.4.310222Tue Nov 17 10:38:10 GMT 2009com.sun.mail.imap

IMAPBodyPart

public class IMAPBodyPart extends MimeBodyPart
This class
author
John Mani

Fields Summary
private IMAPMessage
message
private BODYSTRUCTURE
bs
private String
sectionId
private String
type
private String
description
private boolean
headersLoaded
Constructors Summary
protected IMAPBodyPart(BODYSTRUCTURE bs, String sid, IMAPMessage message)


           
	super();
	this.bs = bs;
	this.sectionId = sid;
	this.message = message;
	// generate content-type
	ContentType ct = new ContentType(bs.type, bs.subtype, bs.cParams);
	type = ct.toString();
    
Methods Summary
public voidaddHeader(java.lang.String name, java.lang.String value)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidaddHeaderLine(java.lang.String line)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public java.util.EnumerationgetAllHeaderLines()

	loadHeaders();
	return super.getAllHeaderLines();
    
public java.util.EnumerationgetAllHeaders()

	loadHeaders();
	return super.getAllHeaders();
    
public java.lang.StringgetContentID()

	return bs.id;
    
public java.lang.StringgetContentMD5()

	return bs.md5;
    
protected java.io.InputStreamgetContentStream()

	InputStream is = null;
	boolean pk = message.getPeek();	// acquire outisde of message cache lock

        // Acquire MessageCacheLock, to freeze seqnum.
        synchronized(message.getMessageCacheLock()) {
	    try {
		IMAPProtocol p = message.getProtocol();

		// Check whether this message is expunged
		message.checkExpunged();

		if (p.isREV1() && (message.getFetchBlockSize() != -1))
		    return new IMAPInputStream(message, sectionId, bs.size, pk);

		// Else, vanila IMAP4, no partial fetch 

		int seqnum = message.getSequenceNumber();
		BODY b;
		if (pk)
		    b = p.peekBody(seqnum, sectionId);
		else
		    b = p.fetchBody(seqnum, sectionId);
		if (b != null)
		    is = b.getByteArrayInputStream();
	    } catch (ConnectionException cex) {
		throw new FolderClosedException(
			message.getFolder(), cex.getMessage());
	    } catch (ProtocolException pex) { 
		throw new MessagingException(pex.getMessage(), pex);
	    }
	}

	if (is == null)
	    throw new MessagingException("No content");
	else
	    return is;
    
public java.lang.StringgetContentType()

	return type;
    
public synchronized javax.activation.DataHandlergetDataHandler()

	if (dh == null) {
	   if (bs.isMulti())
		dh = new DataHandler(
			new IMAPMultipartDataSource(
				this, bs.bodies, sectionId, message)
		     );
	    else if (bs.isNested() && message.isREV1())
		dh = new DataHandler(
			new IMAPNestedMessage(message, 
					      bs.bodies[0],
					      bs.envelope,
					      sectionId),
			type
		     );
	}

	return super.getDataHandler();
    
public java.lang.StringgetDescription()

	if (description != null) // cached value ?
	    return description;

	if (bs.description == null)
	    return null;
	
	try {
	    description = MimeUtility.decodeText(bs.description);
	} catch (UnsupportedEncodingException ex) {
	    description = bs.description;
	}

	return description;
    
public java.lang.StringgetDisposition()

	return bs.disposition;
    
public java.lang.StringgetEncoding()

	return bs.encoding;
    
public java.lang.StringgetFileName()

	String filename = null;
	if (bs.dParams != null)
	    filename = bs.dParams.get("filename");
	if (filename == null && bs.cParams != null)
	    filename = bs.cParams.get("name");
	return filename;
    
public java.lang.String[]getHeader(java.lang.String name)

	loadHeaders();
	return super.getHeader(name);
    
public intgetLineCount()

	return bs.lines;
    
public java.util.EnumerationgetMatchingHeaderLines(java.lang.String[] names)

	loadHeaders();
	return super.getMatchingHeaderLines(names);
    
public java.util.EnumerationgetMatchingHeaders(java.lang.String[] names)

	loadHeaders();
	return super.getMatchingHeaders(names);
    
public java.util.EnumerationgetNonMatchingHeaderLines(java.lang.String[] names)

	loadHeaders();
	return super.getNonMatchingHeaderLines(names);
    
public java.util.EnumerationgetNonMatchingHeaders(java.lang.String[] names)

	loadHeaders();
	return super.getNonMatchingHeaders(names);
    
public intgetSize()

	return bs.size;
    
private synchronized voidloadHeaders()

	if (headersLoaded)
	    return;

	if (headers == null)
	    headers = new InternetHeaders();

	// load headers

	// Acquire MessageCacheLock, to freeze seqnum.
	synchronized(message.getMessageCacheLock()) {
	    try {
		IMAPProtocol p = message.getProtocol();

		// Check whether this message got expunged
		message.checkExpunged();

		if (p.isREV1()) {
		    int seqnum = message.getSequenceNumber();
		    BODY b = p.peekBody(seqnum, sectionId + ".MIME");

		    if (b == null)
			throw new MessagingException("Failed to fetch headers");

		    ByteArrayInputStream bis = b.getByteArrayInputStream();
		    if (bis == null)
			throw new MessagingException("Failed to fetch headers");

		    headers.load(bis);

		} else {

		    // RFC 1730 does not provide for fetching BodyPart headers
		    // So, just dump the RFC1730 BODYSTRUCTURE into the
		    // headerStore
		    
		    // Content-Type
		    headers.addHeader("Content-Type", type);
		    // Content-Transfer-Encoding
		    headers.addHeader("Content-Transfer-Encoding", bs.encoding);
		    // Content-Description
		    if (bs.description != null)
			headers.addHeader("Content-Description",
							    bs.description);
		    // Content-ID
		    if (bs.id != null)
			headers.addHeader("Content-ID", bs.id);
		    // Content-MD5
		    if (bs.md5 != null)
			headers.addHeader("Content-MD5", bs.md5);
		}
	    } catch (ConnectionException cex) {
		throw new FolderClosedException(
			    message.getFolder(), cex.getMessage());
	    } catch (ProtocolException pex) {
		throw new MessagingException(pex.getMessage(), pex);
	    }
	}
	headersLoaded = true;
    
public voidremoveHeader(java.lang.String name)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetContent(java.lang.Object o, java.lang.String type)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetContent(javax.mail.Multipart mp)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetContentMD5(java.lang.String md5)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetDataHandler(javax.activation.DataHandler content)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetDescription(java.lang.String description, java.lang.String charset)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetDisposition(java.lang.String disposition)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetFileName(java.lang.String filename)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
public voidsetHeader(java.lang.String name, java.lang.String value)

	throw new IllegalWriteException("IMAPBodyPart is read-only");
    
protected voidupdateHeaders()

	return;