Top Description Fields Constructors Methods
com.sun.mail.imap

public Class IMAPBodyPart

extends MimeBodyPart
implements ReadableMime
Class Inheritance
All Implemented Interfaces
com.sun.mail.util.ReadableMime
Imports
java.io.*, java.util.Enumeration, javax.mail.*, javax.mail.internet.*, javax.activation.*, com.sun.mail.util.PropUtil, .ReadableMime, .LineOutputStream, .SharedByteArrayOutputStream, com.sun.mail.iap.*, com.sun.mail.imap.protocol.*

An IMAP body part.
Authors
John Mani, Bill Shannon

Field Summary

Modifier and TypeField and Description
private BODYSTRUCTURE
private static final boolean
private String
private boolean
private IMAPMessage
private String
private String
Inherited from javax.mail.internet.MimeBodyPart:
cachedContentcontentcontentStreamdhheaders

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
addHeader(String
header name
name
,
String
header value
value
)

Overrides javax.mail.internet.MimeBodyPart.addHeader.

Implements javax.mail.Part.addHeader.

Add this value to the existing values for this header_name.
public void
addHeaderLine(String
the line to add
line
)

Overrides javax.mail.internet.MimeBodyPart.addHeaderLine.

Implements javax.mail.internet.MimePart.addHeaderLine.

Add a header line to this body part
public Enumeration<String>
getAllHeaderLines()

Overrides javax.mail.internet.MimeBodyPart.getAllHeaderLines.

Implements javax.mail.internet.MimePart.getAllHeaderLines.

Get all header lines as an Enumeration of Strings.
public Enumeration<Header>
getAllHeaders()

Overrides javax.mail.internet.MimeBodyPart.getAllHeaders.

Implements javax.mail.Part.getAllHeaders.

Return all the headers from this Message as an Enumeration of Header objects.
public String
getContentID()

Overrides javax.mail.internet.MimeBodyPart.getContentID.

Implements javax.mail.internet.MimePart.getContentID.

Returns the value of the "Content-ID" header field.
public String
getContentMD5()

Overrides javax.mail.internet.MimeBodyPart.getContentMD5.

Implements javax.mail.internet.MimePart.getContentMD5.

Return the value of the "Content-MD5" header field.
protected InputStream
getContentStream()

Overrides javax.mail.internet.MimeBodyPart.getContentStream.

Produce the raw bytes of the content.
public String
getContentType()

Overrides javax.mail.internet.MimeBodyPart.getContentType.

Implements javax.mail.Part.getContentType.

Returns the value of the RFC 822 "Content-Type" header field.
public synchronized DataHandler
getDataHandler()

Overrides javax.mail.internet.MimeBodyPart.getDataHandler.

Implements javax.mail.Part.getDataHandler.

Return a DataHandler for this body part's content.
public String
getDescription()

Overrides javax.mail.internet.MimeBodyPart.getDescription.

Implements javax.mail.Part.getDescription.

Returns the "Content-Description" header field of this body part.
public String
getDisposition()

Overrides javax.mail.internet.MimeBodyPart.getDisposition.

Implements javax.mail.Part.getDisposition.

Returns the disposition from the "Content-Disposition" header field.
public String
getEncoding()

Overrides javax.mail.internet.MimeBodyPart.getEncoding.

Implements javax.mail.internet.MimePart.getEncoding.

Returns the content transfer encoding from the "Content-Transfer-Encoding" header field.
public String
getFileName()

Overrides javax.mail.internet.MimeBodyPart.getFileName.

Implements javax.mail.Part.getFileName.

Get the filename associated with this body part.
public String[]
getHeader(String
name of header
name
)

Overrides javax.mail.internet.MimeBodyPart.getHeader.

Implements javax.mail.Part.getHeader.

Get all the headers for this header_name.
private InputStream
getHeaderStream()

Return the MIME format stream of headers for this body part.

public int
getLineCount()

Overrides javax.mail.internet.MimeBodyPart.getLineCount.

Implements javax.mail.Part.getLineCount.

Return the number of lines for the content of this Part.
public Enumeration<String>
getMatchingHeaderLines(String[]
the headers to return
names
)

Overrides javax.mail.internet.MimeBodyPart.getMatchingHeaderLines.

Implements javax.mail.internet.MimePart.getMatchingHeaderLines.

Get matching header lines as an Enumeration of Strings.
public Enumeration<Header>
getMatchingHeaders(String[]
the headers to match
names
)

Overrides javax.mail.internet.MimeBodyPart.getMatchingHeaders.

Implements javax.mail.Part.getMatchingHeaders.

Return matching headers from this Message as an Enumeration of Header objects.
public InputStream

Returns:

the MIME format stream
getMimeStream
()

Implements com.sun.mail.util.ReadableMime.getMimeStream.

Return the MIME format stream corresponding to this message part.
public Enumeration<String>
getNonMatchingHeaderLines(String[]
the headers to not return
names
)

Overrides javax.mail.internet.MimeBodyPart.getNonMatchingHeaderLines.

Implements javax.mail.internet.MimePart.getNonMatchingHeaderLines.

Get non-matching header lines as an Enumeration of Strings.
public Enumeration<Header>
getNonMatchingHeaders(String[]
the headers to not match
names
)

Overrides javax.mail.internet.MimeBodyPart.getNonMatchingHeaders.

Implements javax.mail.Part.getNonMatchingHeaders.

Return non-matching headers from this Message as an Enumeration of Header objects.
public int
getSize()

Overrides javax.mail.internet.MimeBodyPart.getSize.

Implements javax.mail.Part.getSize.

Return the size of the content of this body part in bytes.
private synchronized void
public void
removeHeader(String
the name of this header
name
)

Overrides javax.mail.internet.MimeBodyPart.removeHeader.

Implements javax.mail.Part.removeHeader.

Remove all headers with this name.
public void
setContent(Object
the content object
o
,
String
Mime type of the object
type
)

Overrides javax.mail.internet.MimeBodyPart.setContent.

Implements javax.mail.Part.setContent.

A convenience method for setting this body part's content.
public void
setContent(Multipart
The multipart object that is the Message's content
mp
)

Overrides javax.mail.internet.MimeBodyPart.setContent.

Implements javax.mail.Part.setContent.

This method sets the body part's content to a Multipart object.
public void
setContentMD5(String
the MD5 value
md5
)

Overrides javax.mail.internet.MimeBodyPart.setContentMD5.

Implements javax.mail.internet.MimePart.setContentMD5.

Set the "Content-MD5" header field of this body part.
public void
setDataHandler(DataHandler
The DataHandler for the content
content
)

Overrides javax.mail.internet.MimeBodyPart.setDataHandler.

Implements javax.mail.Part.setDataHandler.

This method provides the mechanism to set this body part's content.
public void
setDescription(String
Description
description
,
String
Charset for encoding
charset
)

Overrides javax.mail.internet.MimeBodyPart.setDescription.

Set the "Content-Description" header field for this body part.
public void
setDisposition(String
disposition of this part
disposition
)

Overrides javax.mail.internet.MimeBodyPart.setDisposition.

Implements javax.mail.Part.setDisposition.

Set the disposition in the "Content-Disposition" header field of this body part.
public void
setFileName(String
the file name
filename
)

Overrides javax.mail.internet.MimeBodyPart.setFileName.

Implements javax.mail.Part.setFileName.

Set the filename associated with this body part, if possible.
public void
setHeader(String
header name
name
,
String
header value
value
)

Overrides javax.mail.internet.MimeBodyPart.setHeader.

Implements javax.mail.Part.setHeader.

Set the value for this header_name.
protected void
updateHeaders()

Overrides javax.mail.internet.MimeBodyPart.updateHeaders.

Examine the content of this body part and update the appropriate MIME headers.
Inherited from javax.mail.internet.MimeBodyPart:
attachFileattachFileattachFileattachFilegetContentgetContentLanguagegetHeadergetInputStreamgetRawInputStreamisMimeTypesaveFilesaveFilesetContentIDsetContentLanguagesetDescriptionsetTextsetTextsetTextwriteTo

Field Detail

bsback to summary
private BODYSTRUCTURE bs
decodeFileNameback to summary
private static final boolean decodeFileName

Hides javax.mail.internet.MimeBodyPart.decodeFileName.

descriptionback to summary
private String description
headersLoadedback to summary
private boolean headersLoaded
messageback to summary
private IMAPMessage message
sectionIdback to summary
private String sectionId
typeback to summary
private String type

Constructor Detail

IMAPBodyPartback to summary
protected IMAPBodyPart(BODYSTRUCTURE bs, String sid, IMAPMessage message)

Method Detail

addHeaderback to summary
public void addHeader(String name, String value) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.addHeader.

Implements javax.mail.Part.addHeader.

Doc from javax.mail.internet.MimeBodyPart.addHeader.

Add this value to the existing values for this header_name. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must be encoded as per the rules of RFC 2047.

Parameters
name:String

header name

value:String

header value

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.addHeader.

for other failures

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

Overrides javax.mail.internet.MimeBodyPart.addHeaderLine.

Implements javax.mail.internet.MimePart.addHeaderLine.

Doc from javax.mail.internet.MimeBodyPart.addHeaderLine.

Add a header line to this body part

Parameters
line:String

Doc from javax.mail.internet.MimePart.addHeaderLine.

the line to add

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.internet.MimePart.addHeaderLine.

for other failures

getAllHeaderLinesback to summary
public Enumeration<String> getAllHeaderLines() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getAllHeaderLines.

Implements javax.mail.internet.MimePart.getAllHeaderLines.

Doc from javax.mail.internet.MimeBodyPart.getAllHeaderLines.

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

Returns:Enumeration<String>

Doc from javax.mail.internet.MimePart.getAllHeaderLines.

an Enumeration of Strings

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.internet.MimePart.getAllHeaderLines.

for failures

getAllHeadersback to summary
public Enumeration<Header> getAllHeaders() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getAllHeaders.

Implements javax.mail.Part.getAllHeaders.

Doc from javax.mail.internet.MimeBodyPart.getAllHeaders.

Return all the headers from this Message as an Enumeration of Header objects.

Returns:Enumeration<Header>

Doc from javax.mail.Part.getAllHeaders.

enumeration of Header objects

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getAllHeaders.

for failures

getContentIDback to summary
public String getContentID() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getContentID.

Implements javax.mail.internet.MimePart.getContentID.

Doc from javax.mail.internet.MimeBodyPart.getContentID.

Returns the value of the "Content-ID" header field. Returns null if the field is unavailable or its value is absent.

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

Returns:String

Doc from javax.mail.internet.MimePart.getContentID.

content-ID

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.internet.MimePart.getContentID.

for failures

getContentMD5back to summary
public String getContentMD5() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getContentMD5.

Implements javax.mail.internet.MimePart.getContentMD5.

Doc from javax.mail.internet.MimeBodyPart.getContentMD5.

Return the value of the "Content-MD5" header field. Returns null if this field is unavailable or its value is absent.

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

Returns:String

Doc from javax.mail.internet.MimePart.getContentMD5.

content-MD5

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.internet.MimePart.getContentMD5.

for failures

getContentStreamback to summary
protected InputStream getContentStream() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getContentStream.

Doc from javax.mail.internet.MimeBodyPart.getContentStream.

Produce the raw bytes of the content. This method is used when creating a DataHandler object for the content. Subclasses that can provide a separate input stream for just the Part content might want to override this method.

Returns:InputStream

an InputStream containing the raw bytes

Annotations
@Override
Exceptions
MessagingException:
for failures
getContentTypeback to summary
public String getContentType() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getContentType.

Implements javax.mail.Part.getContentType.

Doc from javax.mail.internet.MimeBodyPart.getContentType.

Returns the value of the RFC 822 "Content-Type" header field. This represents the content type of the content of this body part. 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.

Returns:String

Content-Type of this body part

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getContentType.

for failures

getDataHandlerback to summary
public synchronized DataHandler getDataHandler() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getDataHandler.

Implements javax.mail.Part.getDataHandler.

Doc from javax.mail.internet.MimeBodyPart.getDataHandler.

Return a DataHandler for this body part's content.

The implementation provided here works just like the the implementation in MimeMessage.

Returns:DataHandler

Doc from javax.mail.Part.getDataHandler.

DataHandler for the content

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getDataHandler.

for failures

getDescriptionback to summary
public String getDescription() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getDescription.

Implements javax.mail.Part.getDescription.

Doc from javax.mail.internet.MimeBodyPart.getDescription.

Returns the "Content-Description" header field of this body part. 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.

Returns:String

content description

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getDescription.

for failures

getDispositionback to summary
public String getDisposition() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getDisposition.

Implements javax.mail.Part.getDisposition.

Doc from javax.mail.internet.MimeBodyPart.getDisposition.

Returns the disposition from the "Content-Disposition" header field. This represents the disposition of this part. The disposition describes how the part should be presented to the user.

If the Content-Disposition field is unavailable, null is returned.

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

Returns:String

Doc from javax.mail.Part.getDisposition.

disposition of this part, or null if unknown

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

Overrides javax.mail.internet.MimeBodyPart.getEncoding.

Implements javax.mail.internet.MimePart.getEncoding.

Doc from javax.mail.internet.MimeBodyPart.getEncoding.

Returns the content transfer encoding from 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.

Returns:String

Doc from javax.mail.internet.MimePart.getEncoding.

content-transfer-encoding

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.internet.MimePart.getEncoding.

for failures

getFileNameback to summary
public String getFileName() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getFileName.

Implements javax.mail.Part.getFileName.

Doc from javax.mail.internet.MimeBodyPart.getFileName.

Get the filename associated with this body part.

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

If the mail.mime.decodefilename System property is set to true, the MimeUtility.decodeText method will be used to decode the filename. While such encoding is not supported by the MIME spec, many mailers use this technique to support non-ASCII characters in filenames. The default value of this property is false.

Returns:String

filename

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getFileName.

for failures

getHeaderback to summary
public String[] getHeader(String name) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getHeader.

Implements javax.mail.Part.getHeader.

Doc from javax.mail.internet.MimeBodyPart.getHeader.

Get all the headers for this header_name. Note that certain headers may be encoded as per RFC 2047 if they contain non US-ASCII characters and these should be decoded.

Parameters
name:String

name of header

Returns:String[]

array of headers

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getHeader.

for failures

getHeaderStreamback to summary
private InputStream getHeaderStream() throws MessagingException

Return the MIME format stream of headers for this body part.

getLineCountback to summary
public int getLineCount() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getLineCount.

Implements javax.mail.Part.getLineCount.

Doc from javax.mail.internet.MimeBodyPart.getLineCount.

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.

This implementation returns -1.

Returns:int

number of lines, or -1 if not known

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getLineCount.

for failures

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

Overrides javax.mail.internet.MimeBodyPart.getMatchingHeaderLines.

Implements javax.mail.internet.MimePart.getMatchingHeaderLines.

Doc from javax.mail.internet.MimeBodyPart.getMatchingHeaderLines.

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

Parameters
names:String[]

Doc from javax.mail.internet.MimePart.getMatchingHeaderLines.

the headers to return

Returns:Enumeration<String>

Doc from javax.mail.internet.MimePart.getMatchingHeaderLines.

an Enumeration of Strings

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.internet.MimePart.getMatchingHeaderLines.

for failures

getMatchingHeadersback to summary
public Enumeration<Header> getMatchingHeaders(String[] names) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getMatchingHeaders.

Implements javax.mail.Part.getMatchingHeaders.

Doc from javax.mail.internet.MimeBodyPart.getMatchingHeaders.

Return matching headers from this Message as an Enumeration of Header objects.

Parameters
names:String[]

Doc from javax.mail.Part.getMatchingHeaders.

the headers to match

Returns:Enumeration<Header>

Doc from javax.mail.Part.getMatchingHeaders.

enumeration of Header objects

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getMatchingHeaders.

for failures

getMimeStreamback to summary
public InputStream getMimeStream() throws MessagingException

Implements com.sun.mail.util.ReadableMime.getMimeStream.

Return the MIME format stream corresponding to this message part.

Returns:InputStream

the MIME format stream

Annotations
@Override
Exceptions
MessagingException:

Doc from com.sun.mail.util.ReadableMime.getMimeStream.

for failures

Since
JavaMail 1.4.5
getNonMatchingHeaderLinesback to summary
public Enumeration<String> getNonMatchingHeaderLines(String[] names) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getNonMatchingHeaderLines.

Implements javax.mail.internet.MimePart.getNonMatchingHeaderLines.

Doc from javax.mail.internet.MimeBodyPart.getNonMatchingHeaderLines.

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

Parameters
names:String[]

Doc from javax.mail.internet.MimePart.getNonMatchingHeaderLines.

the headers to not return

Returns:Enumeration<String>

Doc from javax.mail.internet.MimePart.getNonMatchingHeaderLines.

an Enumeration of Strings

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.internet.MimePart.getNonMatchingHeaderLines.

for failures

getNonMatchingHeadersback to summary
public Enumeration<Header> getNonMatchingHeaders(String[] names) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getNonMatchingHeaders.

Implements javax.mail.Part.getNonMatchingHeaders.

Doc from javax.mail.internet.MimeBodyPart.getNonMatchingHeaders.

Return non-matching headers from this Message as an Enumeration of Header objects.

Parameters
names:String[]

Doc from javax.mail.Part.getNonMatchingHeaders.

the headers to not match

Returns:Enumeration<Header>

Doc from javax.mail.Part.getNonMatchingHeaders.

enumeration of Header objects

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getNonMatchingHeaders.

for failures

getSizeback to summary
public int getSize() throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.getSize.

Implements javax.mail.Part.getSize.

Doc from javax.mail.internet.MimeBodyPart.getSize.

Return the size of the content of this body part 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.

This implementation returns the size of the content array (if not null), or, if contentStream is not null, and the available method returns a positive number, it returns that number as the size. Otherwise, it returns -1.

Returns:int

size in bytes, or -1 if not known

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.getSize.

for failures

loadHeadersback to summary
private synchronized void loadHeaders() throws MessagingException
removeHeaderback to summary
public void removeHeader(String name) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.removeHeader.

Implements javax.mail.Part.removeHeader.

Doc from javax.mail.internet.MimeBodyPart.removeHeader.

Remove all headers with this name.

Parameters
name:String

Doc from javax.mail.Part.removeHeader.

the name of this header

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.removeHeader.

for other failures

setContentback to summary
public void setContent(Object o, String type) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setContent.

Implements javax.mail.Part.setContent.

Doc from javax.mail.internet.MimeBodyPart.setContent.

A convenience method for setting this body part's content.

The content is wrapped in a DataHandler object. Note that a DataContentHandler class for the specified type should be available to the JavaMail implementation for this to work right. That is, 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.

Parameters
o:Object

the content object

type:String

Mime type of the object

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.setContent.

for other failures

setContentback to summary
public void setContent(Multipart mp) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setContent.

Implements javax.mail.Part.setContent.

Doc from javax.mail.internet.MimeBodyPart.setContent.

This method sets the body part's content to a Multipart object.

Parameters
mp:Multipart

The multipart object that is the Message's content

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.setContent.

for other failures

setContentMD5back to summary
public void setContentMD5(String md5) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setContentMD5.

Implements javax.mail.internet.MimePart.setContentMD5.

Doc from javax.mail.internet.MimeBodyPart.setContentMD5.

Set the "Content-MD5" header field of this body part.

Parameters
md5:String

Doc from javax.mail.internet.MimePart.setContentMD5.

the MD5 value

Annotations
@Override
setDataHandlerback to summary
public void setDataHandler(DataHandler content) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setDataHandler.

Implements javax.mail.Part.setDataHandler.

Doc from javax.mail.internet.MimeBodyPart.setDataHandler.

This method provides the mechanism to set this body part's content. The given DataHandler object should wrap the actual content.

Parameters
content:DataHandler

The DataHandler for the content

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.setDataHandler.

for other failures

setDescriptionback to summary
public void setDescription(String description, String charset) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setDescription.

Doc from javax.mail.internet.MimeBodyPart.setDescription.

Set the "Content-Description" header field for this body part. 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.

Note that if the charset encoding process fails, a MessagingException is thrown, and an UnsupportedEncodingException is included in the chain of nested exceptions within the MessagingException.

Parameters
description:String

Description

charset:String

Charset for encoding

Annotations
@Override
Exceptions
MessagingException:
otherwise; an UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.
setDispositionback to summary
public void setDisposition(String disposition) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setDisposition.

Implements javax.mail.Part.setDisposition.

Doc from javax.mail.internet.MimeBodyPart.setDisposition.

Set the disposition in the "Content-Disposition" header field of this body part. If the disposition is null, any existing "Content-Disposition" header field is removed.

Parameters
disposition:String

Doc from javax.mail.Part.setDisposition.

disposition of this part

Annotations
@Override
Exceptions
MessagingException:
for other failures
setFileNameback to summary
public void setFileName(String filename) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setFileName.

Implements javax.mail.Part.setFileName.

Doc from javax.mail.internet.MimeBodyPart.setFileName.

Set the filename associated with this body part, if possible.

Sets the "filename" parameter of the "Content-Disposition" header field of this body part. For compatibility with older mailers, the "name" parameter of the "Content-Type" header is also set.

If the mail.mime.encodefilename System property is set to true, the MimeUtility.encodeText method will be used to encode the filename. While such encoding is not supported by the MIME spec, many mailers use this technique to support non-ASCII characters in filenames. The default value of this property is false.

Parameters
filename:String

the file name

Annotations
@Override
Exceptions
MessagingException:
for other failures
setHeaderback to summary
public void setHeader(String name, String value) throws MessagingException

Overrides javax.mail.internet.MimeBodyPart.setHeader.

Implements javax.mail.Part.setHeader.

Doc from javax.mail.internet.MimeBodyPart.setHeader.

Set the value for this header_name. Replaces all existing header values with this new value. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must be encoded as per the rules of RFC 2047.

Parameters
name:String

header name

value:String

header value

Annotations
@Override
Exceptions
MessagingException:

Doc from javax.mail.Part.setHeader.

for other failures

updateHeadersback to summary
protected void updateHeaders()

Overrides javax.mail.internet.MimeBodyPart.updateHeaders.

Doc from javax.mail.internet.MimeBodyPart.updateHeaders.

Examine the content of this body part and update the appropriate MIME headers. Typical headers that get set here are Content-Type and Content-Transfer-Encoding. Headers might need to be updated in two cases:
- A message being crafted by a mail application will certainly need to activate this method at some point to fill up its internal headers.
- A message read in from a Store will have obtained all its headers from the store, and so doesn't 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.
In both cases this method is typically called by the Message.saveChanges method.

If the cachedContent field is not null (that is, it references a Multipart or Message object), then that object is used to set a new DataHandler, any stream data used to create this object is discarded, and the cachedContent field is cleared.

Annotations
@Override