javax.mail

Interface Part

public interface Part

A part consists of a set of attributes and a content. Some of the attributes provide metadata describing the content and its encoding, others may describe how to process the part. The Part interface is the common base interface for Messages and BodyParts.

The content of a part is available in various forms:

The writeTo method can be used to write the part to a byte stream in mail-safe form suitable for transmission.

In MIME terms, Part models an Entity (RFC 2045, Section 2.4).

Version: 1.4

Author: Chris Burdess

Field Summary
StringATTACHMENT
This part should be presented as an attachment.
StringINLINE
This part should be presented inline.
Method Summary
voidaddHeader(String name, String value)
Adds the specified value to the existing values for this header name.
EnumerationgetAllHeaders()
Returns all the headers from this part.
ObjectgetContent()
Returns the content of this part as a Java object.
StringgetContentType()
Returns the content-type of the content of this part, or null if the content-type could not be determined.
DataHandlergetDataHandler()
Returns a data handler for the content of this part.
StringgetDescription()
Returns the description of this part.
StringgetDisposition()
Returns the disposition of this part.
StringgetFileName()
Returns the filename associated with this part, if available.
String[]getHeader(String name)
Returns all the values for the specified header name, or null if no such headers are available.
InputStreamgetInputStream()
Returns an input stream for reading the content of this part.
intgetLineCount()
Returns the number of lines in the content of this part, or -1 if the number cannot be determined.
EnumerationgetMatchingHeaders(String[] names)
Returns the matching headers from this part.
EnumerationgetNonMatchingHeaders(String[] names)
Returns the non-matching headers from this part.
intgetSize()
Returns the size of the content of this part in bytes, or -1 if the size cannot be determined.
booleanisMimeType(String mimeType)
Is this part of the specified MIME type?
voidremoveHeader(String name)
Removes all headers of the specified name.
voidsetContent(Object obj, String type)
Sets the content of this part using the specified object.
voidsetContent(Multipart mp)
Sets the multipart content of this part.
voidsetDataHandler(DataHandler dh)
Sets the content of this part using the specified data handler.
voidsetDescription(String description)
Sets the description of this part.
voidsetDisposition(String disposition)
Sets the disposition of this part.
voidsetFileName(String filename)
Sets the filename associated with this part.
voidsetHeader(String name, String value)
Sets the value for the specified header name.
voidsetText(String text)
Sets the textual content of this part, using a MIME type of text/plain.
voidwriteTo(OutputStream os)
Writes this part to the specified byte stream.

Field Detail

ATTACHMENT

public String ATTACHMENT
This part should be presented as an attachment.

INLINE

public String INLINE
This part should be presented inline.

Method Detail

addHeader

public void addHeader(String name, String value)
Adds the specified value to the existing values for this header name.

Parameters: name the header name value the value to add

Throws: IllegalWriteException if the underlying implementation does not support modification of this header IllegalStateException if this part is obtained from a READ_ONLY folder

getAllHeaders

public Enumeration getAllHeaders()
Returns all the headers from this part.

Returns: an enumeration of Header

getContent

public Object getContent()
Returns the content of this part as a Java object. The type of the returned object is of course dependent on the content itself. For instance, the object returned for "text/plain" content is usually a String object. The object returned for a "multipart" content is always a Multipart subclass. For content-types that are unknown to the data handler system, an input stream is returned.

Throws: IOException when a data handler error occurs

getContentType

public String getContentType()
Returns the content-type of the content of this part, or null if the content-type could not be determined.

The MIME typing system is used to name content-types.

getDataHandler

public DataHandler getDataHandler()
Returns a data handler for the content of this part.

getDescription

public String getDescription()
Returns the description of this part.

getDisposition

public String getDisposition()
Returns the disposition of this part. The disposition describes how the part should be presented to the user (see RFC 2183). Return values are not case sensitive.

getFileName

public String getFileName()
Returns the filename associated with this part, if available.

getHeader

public String[] getHeader(String name)
Returns all the values for the specified header name, or null if no such headers are available.

Parameters: name the header name

getInputStream

public InputStream getInputStream()
Returns an input stream for reading the content of this part. Any mail-specific transfer encodings will be decoded by the implementation.

Throws: IOException when a data handler error occurs

getLineCount

public int getLineCount()
Returns the number of lines in the content of this part, or -1 if the number cannot be determined. Note that this number may not be an exact measure.

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
Returns the matching headers from this part.

Parameters: names the header names to match

Returns: an enumeration of Header

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
Returns the non-matching headers from this part.

Parameters: names the header names to ignore

Returns: an enumeration of Header

getSize

public int getSize()
Returns the size of the content of this part in bytes, or -1 if the size cannot be determined.

Note that the size may not be an exact measure of the content size, but will be suitable for display in a user interface to give the user an idea of the size of this part.

isMimeType

public boolean isMimeType(String mimeType)
Is this part of the specified MIME type? This method compares only the primary type and subtype. The parameters of the content types are ignored.

If the subtype of mimeType is the special character '*', then the subtype is ignored during the comparison.

removeHeader

public void removeHeader(String name)
Removes all headers of the specified name.

Parameters: name the header name

Throws: IllegalWriteException if the underlying implementation does not support modification of this header IllegalStateException if this part is obtained from a READ_ONLY folder

setContent

public void setContent(Object obj, String type)
Sets the content of this part using the specified object. The type of the supplied argument must be known to the data handler system.

Parameters: obj a Java object type the MIME content-type of this object

Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this part is obtained from a READ_ONLY folder

setContent

public void setContent(Multipart mp)
Sets the multipart content of this part.

Parameters: mp the multipart content

Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this part is obtained from a READ_ONLY folder

setDataHandler

public void setDataHandler(DataHandler dh)
Sets the content of this part using the specified data handler.

Parameters: dh the data handler for the content

Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this part is obtained from a READ_ONLY folder

setDescription

public void setDescription(String description)
Sets the description of this part.

Parameters: description the description of this part

Throws: IllegalWriteException if the underlying implementation does not support modification of this header IllegalStateException if this Part is obtained from a READ_ONLY folder

setDisposition

public void setDisposition(String disposition)
Sets the disposition of this part.

Parameters: disposition the disposition of this part

Throws: IllegalWriteException if the underlying implementation does not support modification of this header IllegalStateException if this part is obtained from a READ_ONLY folder

setFileName

public void setFileName(String filename)
Sets the filename associated with this part.

Parameters: filename the filename to associate with this part

Throws: IllegalWriteException if the underlying implementation does not support modification of this header IllegalStateException if this Part is obtained from a READ_ONLY folder

setHeader

public void setHeader(String name, String value)
Sets the value for the specified header name.

Parameters: name the header name value the new value

Throws: IllegalWriteException if the underlying implementation does not support modification of this header IllegalStateException if this part is obtained from a READ_ONLY folder

setText

public void setText(String text)
Sets the textual content of this part, using a MIME type of text/plain.

Parameters: text the textual content

Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this part is obtained from a READ_ONLY folder

writeTo

public void writeTo(OutputStream os)
Writes this part to the specified byte stream.

Throws: IOException if an error occurs writing to the stream or if an error occurs in the data handler system. MessagingException if an error occurs fetching the data to be written

© Copyright 2003, 2004 The Free Software Foundation, All rights reserved