Top Description Fields Methods
javax.mail.internet

public Interface MimePart

extends Part
Known Direct Implementers
javax.mail.internet.MimeMessage, javax.mail.internet.MimeBodyPart
Imports
javax.mail.*, java.io.*, java.util.Enumeration

The MimePart interface models an Entity as defined by MIME (RFC2045, Section 2.4).

MimePart extends the Part interface to add additional RFC822 and MIME specific semantics and attributes. It provides the base interface for the MimeMessage and MimeBodyPart classes


A note on RFC822 and MIME headers

RFC822 and MIME header fields must contain only US-ASCII characters. If a header contains non US-ASCII characters, it must be encoded as per the rules in RFC 2047. The MimeUtility class provided in this package can be used to to achieve this. Callers of the setHeader, addHeader, and addHeaderLine methods are responsible for enforcing the MIME requirements for the specified headers. In addition, these header fields must be folded (wrapped) before being sent if they exceed the line length limitation for the transport (1000 bytes for SMTP). Received headers may have been folded. The application is responsible for folding and unfolding headers as appropriate.

Author
John Mani
See Also
MimeUtility, javax.mail.Part

Field Summary

Inherited from javax.mail.Part:
ATTACHMENTINLINE

Method Summary

Modifier and TypeMethod and Description
public void
addHeaderLine(String
the line to add
line
)

Add a raw RFC822 header-line.

public Enumeration<String>

Returns:

an Enumeration of Strings
getAllHeaderLines
()

Get all header lines as an Enumeration of Strings.

public String

Returns:

content-ID
getContentID
()

Get the Content-ID of this part.

public String[]

Returns:

array of content language strings
getContentLanguage
()

Get the language tags specified in the Content-Language header of this MimePart.

public String

Returns:

content-MD5
getContentMD5
()

Get the Content-MD5 digest of this part.

public String

Returns:

content-transfer-encoding
getEncoding
()

Get the transfer encoding of this part.

public String

Returns:

the value fields for all headers with this name
getHeader
(String
the name of this header
name
,
String
delimiter between fields in returned string
delimiter
)

Get the values of all header fields available for this header, returned as a single String, with the values separated by the delimiter.

public Enumeration<String>

Returns:

an Enumeration of Strings
getMatchingHeaderLines
(String[]
the headers to return
names
)

Get matching header lines as an Enumeration of Strings.

public Enumeration<String>

Returns:

an Enumeration of Strings
getNonMatchingHeaderLines
(String[]
the headers to not return
names
)

Get non-matching header lines as an Enumeration of Strings.

public void
setContentLanguage(String[]
array of language tags
languages
)

Set the Content-Language header of this MimePart.

public void
setContentMD5(String
the MD5 value
md5
)

Set the Content-MD5 of this part.

public void
setText(String
the text content to set
text
)

Redeclares javax.mail.Part.setText.

Convenience method that sets the given String as this part's content, with a MIME type of "text/plain".
public void
setText(String
the text content to set
text
,
String
the charset to use for the text
charset
)

Convenience method that sets the given String as this part's content, with a MIME type of "text/plain" and the specified charset.

public void
setText(String
the text content to set
text
,
String
the charset to use for the text
charset
,
String
the MIME subtype to use (e.g., "html")
subtype
)

Convenience method that sets the given String as this part's content, with a primary MIME type of "text" and the specified MIME subtype.

Inherited from javax.mail.Part:
addHeadergetAllHeadersgetContentgetContentTypegetDataHandlergetDescriptiongetDispositiongetFileNamegetHeadergetInputStreamgetLineCountgetMatchingHeadersgetNonMatchingHeadersgetSizeisMimeTyperemoveHeadersetContentsetContentsetDataHandlersetDescriptionsetDispositionsetFileNamesetHeaderwriteTo

Method Detail

addHeaderLineback to summary
public void addHeaderLine(String line) throws MessagingException

Add a raw RFC822 header-line.

Parameters
line:String

the line to add

Exceptions
MessagingException:
for other failures
IllegalWriteException:
if the underlying implementation does not support modification
IllegalStateException:
if this Part is obtained from a READ_ONLY folder
getAllHeaderLinesback to summary
public Enumeration<String> getAllHeaderLines() throws MessagingException

Get all header lines as an Enumeration of Strings. A Header line is a raw RFC822 header-line, containing both the "name" and "value" field.

Returns:Enumeration<String>

an Enumeration of Strings

Exceptions
MessagingException:
for failures
getContentIDback to summary
public String getContentID() throws MessagingException

Get the Content-ID of this part. Returns null if none present.

Returns:String

content-ID

Exceptions
MessagingException:
for failures
getContentLanguageback to summary
public String[] getContentLanguage() throws MessagingException

Get the language tags specified in the Content-Language header of this MimePart. The Content-Language header is defined by RFC 1766. Returns null if this header is not available.

Returns:String[]

array of content language strings

Exceptions
MessagingException:
for failures
getContentMD5back to summary
public String getContentMD5() throws MessagingException

Get the Content-MD5 digest of this part. Returns null if none present.

Returns:String

content-MD5

Exceptions
MessagingException:
for failures
getEncodingback to summary
public String getEncoding() throws MessagingException

Get the transfer encoding of this part.

Returns:String

content-transfer-encoding

Exceptions
MessagingException:
for failures
getHeaderback to summary
public String getHeader(String name, String delimiter) throws MessagingException

Get the values of all header fields available for this header, returned as a single String, with the values separated by the delimiter. If the delimiter is null, only the first value is returned.

Parameters
name:String

the name of this header

delimiter:String

delimiter between fields in returned string

Returns:String

the value fields for all headers with this name

Exceptions
MessagingException:
for failures
getMatchingHeaderLinesback to summary
public Enumeration<String> getMatchingHeaderLines(String[] names) throws MessagingException

Get matching header lines as an Enumeration of Strings. A Header line is a raw RFC822 header-line, containing both the "name" and "value" field.

Parameters
names:String[]

the headers to return

Returns:Enumeration<String>

an Enumeration of Strings

Exceptions
MessagingException:
for failures
getNonMatchingHeaderLinesback to summary
public Enumeration<String> getNonMatchingHeaderLines(String[] names) throws MessagingException

Get non-matching header lines as an Enumeration of Strings. A Header line is a raw RFC822 header-line, containing both the "name" and "value" field.

Parameters
names:String[]

the headers to not return

Returns:Enumeration<String>

an Enumeration of Strings

Exceptions
MessagingException:
for failures
setContentLanguageback to summary
public void setContentLanguage(String[] languages) throws MessagingException

Set the Content-Language header of this MimePart. The Content-Language header is defined by RFC1766.

Parameters
languages:String[]

array of language tags

Exceptions
IllegalWriteException:
if the underlying implementation does not support modification
IllegalStateException:
if this Part is obtained from a READ_ONLY folder
setContentMD5back to summary
public void setContentMD5(String md5) throws MessagingException

Set the Content-MD5 of this part.

Parameters
md5:String

the MD5 value

Exceptions
IllegalWriteException:
if the underlying implementation does not support modification
IllegalStateException:
if this Part is obtained from a READ_ONLY folder
setTextback to summary
public void setText(String text) throws MessagingException

Redeclares javax.mail.Part.setText.

Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". If the string contains non US-ASCII characters. it will be encoded using the platform's default charset. The charset is also used to set the "charset" parameter.

Note that there may be a performance penalty if text is large, since this method may have to scan all the characters to determine what charset to use.

If the charset is already known, use the setText method that takes the charset parameter.

Parameters
text:String

the text content to set

Annotations
@Override
Exceptions
MessagingException:
if an error occurs
See Also
setText(String text, String charset)
setTextback to summary
public void setText(String text, String charset) throws MessagingException

Convenience method that sets the given String as this part's content, with a MIME type of "text/plain" and the specified charset. The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set "charset" parameter.

Parameters
text:String

the text content to set

charset:String

the charset to use for the text

Exceptions
MessagingException:
if an error occurs
setTextback to summary
public void setText(String text, String charset, String subtype) throws MessagingException

Convenience method that sets the given String as this part's content, with a primary MIME type of "text" and the specified MIME subtype. The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set the "charset" parameter.

Parameters
text:String

the text content to set

charset:String

the charset to use for the text

subtype:String

the MIME subtype to use (e.g., "html")

Exceptions
MessagingException:
if an error occurs
Since
JavaMail 1.4