The Part
interface is the common base interface for
Messages and BodyParts.
Part consists of a set of attributes and a "Content".
Attributes:
The JavaMail API defines a set of standard Part attributes that are considered to be common to most existing Mail systems. These attributes have their own settor and gettor methods. Mail systems may support other Part attributes as well, these are represented as name-value pairs where both the name and value are Strings.
Content:
The data type of the "content" is returned by
the getContentType()
method. The MIME typing system
is used to name data types.
The "content" of a Part is available in various formats:
getDataHandler()
method.
The "content" of a Part is also available through a
javax.activation.DataHandler
object. The DataHandler
object allows clients to discover the operations available on the
content, and to instantiate the appropriate component to perform
those operations.
getInputStream()
method.
Any mail-specific encodings are decoded before this stream is returned
getContent()
method.
This method returns the "content" as a Java object.
The returned object is of course dependent on the content
itself. In particular, a "multipart" Part's content is always a
Multipart or subclass thereof. ie getContent()
on a
"multipart" type Part will always return a Multipart (or subclass) object.
writeTo()
method that streams
out its bytestream in mail-safe form suitable for transmission.
This bytestream is typically an aggregation of the Part attributes
and its content's bytestream. Message and BodyPart implement the Part interface. Note that in MIME parlance, Part models an Entity (RFC2045, Section 2.4)
void
addHeader(java.lang.String header_name,
java.lang.String header_value)
java.util.Enumeration
getAllHeaders()
java.lang.String[]
getHeader(java.lang.String header_name)
java.util.Enumeration
getMatchingHeaders(java.lang.String[] header_names)
java.util.Enumeration
getNonMatchingHeaders(java.lang.String[] header_names)
boolean
isMimeType(java.lang.String mimeType)
primaryType
and
subType
.
void
setContent(Multipart mp)
void
setContent(java.lang.Object obj,
java.lang.String type)
void
setFileName(java.lang.String filename)
void
setHeader(java.lang.String header_name,
java.lang.String header_value)
void
setText(java.lang.String text)
public static final java.lang.String ATTACHMENT
getDisposition()
,
setDisposition(java.lang.String)
public static final java.lang.String INLINE
getDisposition()
,
setDisposition(java.lang.String)
public int getSize() throws MessagingException
Note that the size may not be an exact measure of the content size and may or may not account for any transfer encoding of the content. The size is appropriate for display in a user interface to give the user a rough idea of the size of this part.
MessagingException
- public int getLineCount() throws MessagingException
MessagingException
- public java.lang.String getContentType() throws MessagingException
The MIME typing system is used to name Content-types.
MessagingException
- DataHandler
public boolean isMimeType(java.lang.String mimeType) throws MessagingException
primaryType
and
subType
.
The parameters of the content types are ignored.
For example, this method will return true
when
comparing a Part of content type "text/plain"
with "text/plain; charset=foobar".
If the subType
of mimeType
is the
special character '*', then the subtype is ignored during the
comparison.
public java.lang.String getDisposition() throws MessagingException
MessagingException
- ATTACHMENT
,
INLINE
,
getFileName()
public void setDisposition(java.lang.String disposition) throws MessagingException
disposition
- disposition of this partMessagingException
- IllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this Part is obtained
from a READ_ONLY folderATTACHMENT
,
INLINE
,
setFileName(java.lang.String)
public java.lang.String getDescription() throws MessagingException
MessagingException
- public void setDescription(java.lang.String description) throws MessagingException
description
- description of this partMessagingException
- IllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this Part is obtained
from a READ_ONLY folderpublic java.lang.String getFileName() throws MessagingException
public void setFileName(java.lang.String filename) throws MessagingException
filename
- Filename to associate with this partIllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this Part is obtained
from a READ_ONLY folderpublic java.io.InputStream getInputStream() throws java.io.IOException, MessagingException
This is typically a convenience method that just invokes
the DataHandler's getInputStream()
method.
java.io.IOException
- this is typically thrown by the
DataHandler. Refer to the documentation for
javax.activation.DataHandler for more details.MessagingException
- getDataHandler()
,
DataHandler.getInputStream()
public DataHandler getDataHandler() throws MessagingException
MessagingException
- public java.lang.Object getContent() throws java.io.IOException, MessagingException
This is a convenience method that just invokes the DataHandler's getContent() method
MessagingException
- java.io.IOException
- this is typically thrown by the
DataHandler. Refer to the documentation for
javax.activation.DataHandler for more details.DataHandler.getContent()
public void setDataHandler(DataHandler dh) throws MessagingException
dh
- The DataHandler for the content.MessagingException
- IllegalWriteException
- if the underlying implementation
does not support modification of existing valuesjava.lang.IllegalStateException
- if this Part is obtained
from a READ_ONLY folderpublic void setContent(java.lang.Object obj, java.lang.String type) throws MessagingException
Note that a DataContentHandler class for the specified type should
be available to the JavaMail implementation for this to work right.
i.e., to do setContent(foobar, "application/x-foobar")
,
a DataContentHandler for "application/x-foobar" should be installed.
Refer to the Java Activation Framework for more information.
obj
- A java object.type
- MIME type of this object.IllegalWriteException
- if the underlying implementation
does not support modification of existing valuesjava.lang.IllegalStateException
- if this Part is obtained
from a READ_ONLY folderpublic void setText(java.lang.String text) throws MessagingException
text
- The text that is the Message's content.IllegalWriteException
- if the underlying
implementation does not support modification of
existing valuesjava.lang.IllegalStateException
- if this Part is obtained
from a READ_ONLY folderpublic void setContent(Multipart mp) throws MessagingException
mp
- The multipart object that is the Message's contentIllegalWriteException
- if the underlying
implementation does not support modification of
existing valuesjava.lang.IllegalStateException
- if this Part is obtained
from a READ_ONLY folderpublic void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingException
Classes that implement the Part interface decide on the appropriate encoding algorithm to be used.
The bytestream is typically used for sending.
java.io.IOException
- if an error occurs writing to the
stream or if an error is generated
by the javax.activation layer.MessagingException
- if an error occurs fetching the
data to be writtenDataHandler.writeTo(java.io.OutputStream)
public java.lang.String[] getHeader(java.lang.String header_name) throws MessagingException
null
if no headers for this header name are available.header_name
- the name of this headerMessagingException
- public void setHeader(java.lang.String header_name, java.lang.String header_value) throws MessagingException
header_name
- the name of this headerheader_value
- the value for this headerMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this Part is
obtained from a READ_ONLY folderpublic void addHeader(java.lang.String header_name, java.lang.String header_value) throws MessagingException
header_name
- the name of this headerheader_value
- the value for this headerMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this Part is
obtained from a READ_ONLY folderpublic void removeHeader(java.lang.String header_name) throws MessagingException
header_name
- the name of this headerMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this Part is
obtained from a READ_ONLY folderpublic java.util.Enumeration getAllHeaders() throws MessagingException
MessagingException
- public java.util.Enumeration getMatchingHeaders(java.lang.String[] header_names) throws MessagingException
MessagingException
- public java.util.Enumeration getNonMatchingHeaders(java.lang.String[] header_names) throws MessagingException
MessagingException
-