com.sun.mail.mbox
Class SunV3BodyPart

java.lang.Object
  extended by javax.mail.BodyPart
      extended by javax.mail.internet.MimeBodyPart
          extended by com.sun.mail.mbox.SunV3BodyPart
All Implemented Interfaces:
javax.mail.internet.MimePart, javax.mail.Part

public class SunV3BodyPart
extends javax.mail.internet.MimeBodyPart

This class represents a SunV3 BodyPart.

See Also:
Part, MimePart, MimeBodyPart

Field Summary
 
Fields inherited from class javax.mail.internet.MimeBodyPart
content, contentStream, dh, headers
 
Fields inherited from class javax.mail.BodyPart
parent
 
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE
 
Constructor Summary
SunV3BodyPart(javax.mail.internet.InternetHeaders headers, byte[] content)
          Constructs a SunV3BodyPart using the given header and content bytes.
 
Method Summary
 java.lang.String getContentType()
          Returns the value of the RFC822 "Content-Type" header field.
 java.lang.String getDescription()
          Returns the "Content-Description" header field of this BodyPart.
 java.lang.String getEncoding()
          Returns the value of the "Content-Transfer-Encoding" header field.
 java.lang.String getFileName()
          Get the filename associated with this BodyPart.
 int getLineCount()
          Return the number of lines for the content of this Part.
 int getSize()
          Return the size of the content of this BodyPart in bytes.
 void setDataHandler(javax.activation.DataHandler dh)
          This method provides the mechanism to set this BodyPart's content.
 void setDescription(java.lang.String description)
          Set the "Content-Description" header field for this BodyPart.
 void setDescription(java.lang.String description, java.lang.String charset)
          Set the "Content-Description" header field for this BodyPart.
 void setFileName(java.lang.String filename)
          Set the filename associated with this BodyPart, if possible.
protected  void updateHeaders()
          This is the method that has the 'smarts' to query the 'content' and update the appropriate headers.
 void writeTo(java.io.OutputStream os)
          Output the BodyPart as a RFC822 format stream.
 
Methods inherited from class javax.mail.internet.MimeBodyPart
addHeader, addHeaderLine, attachFile, attachFile, getAllHeaderLines, getAllHeaders, getContent, getContentID, getContentLanguage, getContentMD5, getContentStream, getDataHandler, getDisposition, getHeader, getHeader, getInputStream, getMatchingHeaderLines, getMatchingHeaders, getNonMatchingHeaderLines, getNonMatchingHeaders, getRawInputStream, isMimeType, removeHeader, saveFile, saveFile, setContent, setContent, setContentID, setContentLanguage, setContentMD5, setDisposition, setHeader, setText, setText, setText
 
Methods inherited from class javax.mail.BodyPart
getParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SunV3BodyPart

public SunV3BodyPart(javax.mail.internet.InternetHeaders headers,
                     byte[] content)
              throws javax.mail.MessagingException
Constructs a SunV3BodyPart using the given header and content bytes.

Used by providers.

Parameters:
headers - The header of this part
content - bytes representing the body of this part.
Throws:
javax.mail.MessagingException
Method Detail

getSize

public int getSize()
            throws javax.mail.MessagingException
Return the size of the content of this BodyPart in bytes. Return -1 if the size cannot be determined.

Note that this number may not be an exact measure of the content size and may or may not account for any transfer encoding of the content.

Specified by:
getSize in interface javax.mail.Part
Overrides:
getSize in class javax.mail.internet.MimeBodyPart
Returns:
size in bytes
Throws:
javax.mail.MessagingException

getLineCount

public int getLineCount()
                 throws javax.mail.MessagingException
Return the number of lines for the content of this Part. Return -1 if this number cannot be determined.

Note that this number may not be an exact measure of the content length and may or may not account for any transfer encoding of the content.

Specified by:
getLineCount in interface javax.mail.Part
Overrides:
getLineCount in class javax.mail.internet.MimeBodyPart
Returns:
number of lines, or -1 if not known
Throws:
javax.mail.MessagingException

getContentType

public java.lang.String getContentType()
                                throws javax.mail.MessagingException
Returns the value of the RFC822 "Content-Type" header field. This represents the content-type of the content of this BodyPart. This value must not be null. If this field is unavailable, "text/plain" should be returned.

This implementation uses getHeader(name) to obtain the requisite header field.

Specified by:
getContentType in interface javax.mail.Part
Overrides:
getContentType in class javax.mail.internet.MimeBodyPart
Returns:
Content-Type of this BodyPart
Throws:
javax.mail.MessagingException
See Also:
DataHandler

getEncoding

public java.lang.String getEncoding()
                             throws javax.mail.MessagingException
Returns the value of the "Content-Transfer-Encoding" header field. Returns null if the header is unavailable or its value is absent.

This implementation uses getHeader(name) to obtain the requisite header field.

Specified by:
getEncoding in interface javax.mail.internet.MimePart
Overrides:
getEncoding in class javax.mail.internet.MimeBodyPart
Returns:
content-transfer-encoding
Throws:
javax.mail.MessagingException
See Also:
MimeBodyPart.headers

getDescription

public java.lang.String getDescription()
                                throws javax.mail.MessagingException
Returns the "Content-Description" header field of this BodyPart. This typically associates some descriptive information with this part. Returns null if this field is unavailable or its value is absent.

If the Content-Description field is encoded as per RFC 2047, it is decoded and converted into Unicode. If the decoding or conversion fails, the raw data is returned as-is

This implementation uses getHeader(name) to obtain the requisite header field.

Specified by:
getDescription in interface javax.mail.Part
Overrides:
getDescription in class javax.mail.internet.MimeBodyPart
Returns:
content-description
Throws:
javax.mail.MessagingException

setDescription

public void setDescription(java.lang.String description)
                    throws javax.mail.MessagingException
Set the "Content-Description" header field for this BodyPart. If the description parameter is null, then any existing "Content-Description" fields are removed.

If the description contains non US-ASCII characters, it will be encoded using the platform's default charset. If the description contains only US-ASCII characters, no encoding is done and it is used as-is.

Specified by:
setDescription in interface javax.mail.Part
Overrides:
setDescription in class javax.mail.internet.MimeBodyPart
Parameters:
description - content-description
Throws:
javax.mail.IllegalWriteException - if the underlying implementation does not support modification
java.lang.IllegalStateException - if this BodyPart is obtained from a READ_ONLY folder.
javax.mail.MessagingException - otherwise; an UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.

setDescription

public void setDescription(java.lang.String description,
                           java.lang.String charset)
                    throws javax.mail.MessagingException
Set the "Content-Description" header field for this BodyPart. If the description parameter is null, then any existing "Content-Description" fields are removed.

If the description contains non US-ASCII characters, it will be encoded using the specified charset. If the description contains only US-ASCII characters, no encoding is done and it is used as-is

Overrides:
setDescription in class javax.mail.internet.MimeBodyPart
Parameters:
description - Description
charset - Charset for encoding
Throws:
javax.mail.IllegalWriteException - if the underlying implementation does not support modification
java.lang.IllegalStateException - if this BodyPart is obtained from a READ_ONLY folder.
javax.mail.MessagingException - otherwise; an UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.

getFileName

public java.lang.String getFileName()
                             throws javax.mail.MessagingException
Get the filename associated with this BodyPart.

Returns the value of the "filename" parameter from the "Content-Disposition" header field of this BodyPart. If its not available, returns the value of the "name" parameter from the "Content-Type" header field of this BodyPart. Returns null if both are absent.

Specified by:
getFileName in interface javax.mail.Part
Overrides:
getFileName in class javax.mail.internet.MimeBodyPart
Returns:
filename
Throws:
javax.mail.MessagingException

setFileName

public void setFileName(java.lang.String filename)
                 throws javax.mail.MessagingException
Set the filename associated with this BodyPart, if possible.

Sets the "filename" parameter of the "Content-Disposition" header field of this BodyPart.

Specified by:
setFileName in interface javax.mail.Part
Overrides:
setFileName in class javax.mail.internet.MimeBodyPart
Parameters:
filename - Filename to associate with this part
Throws:
javax.mail.IllegalWriteException - if the underlying implementation does not support modification
java.lang.IllegalStateException - if this BodyPart is obtained from a READ_ONLY folder.
javax.mail.MessagingException

setDataHandler

public void setDataHandler(javax.activation.DataHandler dh)
                    throws javax.mail.MessagingException
This method provides the mechanism to set this BodyPart's content. The given DataHandler object should wrap the actual content.

Specified by:
setDataHandler in interface javax.mail.Part
Overrides:
setDataHandler in class javax.mail.internet.MimeBodyPart
Parameters:
dh - The DataHandler for the content
Throws:
javax.mail.IllegalWriteException - if the underlying implementation does not support modification
java.lang.IllegalStateException - if this BodyPart is obtained from a READ_ONLY folder.
javax.mail.MessagingException

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException,
                    javax.mail.MessagingException
Output the BodyPart as a RFC822 format stream.

Specified by:
writeTo in interface javax.mail.Part
Overrides:
writeTo in class javax.mail.internet.MimeBodyPart
Throws:
javax.mail.MessagingException
java.io.IOException - if an error occurs writing to the stream or if an error is generated by the javax.activation layer.
See Also:
javax.activation.DataHandler#writeTo()

updateHeaders

protected void updateHeaders()
                      throws javax.mail.MessagingException
This is the method that has the 'smarts' to query the 'content' and update the appropriate headers. Typical headers that get set here are: Content-Type, Content-Encoding, boundary (for multipart). Now, the tricky part here is when to actually activate this method: - A Message being crafted by a mail-application will certainly need to activate this method at some point to fill up its internal headers. Typically this is triggered off by our writeTo() method. - A message read-in from a MessageStore will have obtained all its headers from the store, and so does'nt need this. However, if this message is editable and if any edits have been made to either the content or message-structure, we might need to resync our headers. Typically this is triggered off by the Message.saveChanges() methods.

Overrides:
updateHeaders in class javax.mail.internet.MimeBodyPart
Throws:
javax.mail.MessagingException