Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.mail.BodyPart
javax.mail.internet.MimeBodyPart
MimeUtility
to ensure that header
values are correctly encoded.
Field Summary | |
protected byte[] |
|
protected InputStream |
|
protected DataHandler |
|
protected InternetHeaders |
|
Fields inherited from interface javax.mail.Part | |
ATTACHMENT , INLINE |
Constructor Summary | |
| |
| |
|
Method Summary | |
void |
|
void |
|
void |
|
void |
|
Enumeration |
|
Enumeration |
|
Object |
|
String |
|
String[] |
|
String |
|
protected InputStream |
|
String |
|
DataHandler |
|
String |
|
String |
|
String |
|
String |
|
String[] |
|
String |
|
InputStream |
|
int |
|
Enumeration |
|
Enumeration |
|
Enumeration |
|
Enumeration |
|
InputStream |
|
int |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
protected void |
|
void |
|
protected byte[] content
The bytes of the content of this part, if the part can be stored in memory.
protected InputStream contentStream
A SharedInputStream containing the bytes of this part, if it cannot be stored in memory.
protected DataHandler dh
The data handler managing this part's content.
public MimeBodyPart()
Constructor for an empty MIME body part.
public MimeBodyPart(InputStream is) throws MessagingException
Constructor with an input stream. The stream must be positioned at the start of a valid MIME body part and terminate at the end of that body part: the boundary string must not be included in the stream.
- Parameters:
is
- the input stream
public MimeBodyPart(InternetHeaders headers, byte[] content) throws MessagingException
Constructor with headers and byte content.
- Parameters:
headers
- the headercontent
- the byte content of this part
public void addHeader(String name, String value) throws MessagingException
Adds the specified header.
- Parameters:
name
- the header namevalue
- the header value
public void addHeaderLine(String line) throws MessagingException
Adds an RFC 822 header-line to this part.
- Specified by:
- addHeaderLine in interface MimePart
public void attachFile(File file) throws IOException, MessagingException
Use the specified file as the content for this part.
- Parameters:
file
- the file
- Since:
- JavaMail 1.4
public void attachFile(String file) throws IOException, MessagingException
Use the specified file as the content for this part.
- Parameters:
file
- the file
- Since:
- JavaMail 1.4
public Enumeration getAllHeaderLines() throws MessagingException
Returns all the header-lines.
- Specified by:
- getAllHeaderLines in interface MimePart
- Returns:
- an Enumeration of Strings
public Enumeration getAllHeaders() throws MessagingException
Returns all the headers.
- Specified by:
- getAllHeaders in interface Part
- Returns:
- an Enumeration of Header objects
public Object getContent() throws IOException, MessagingException
Returns this part's content as a Java object.
- Specified by:
- getContent in interface Part
public String getContentID() throws MessagingException
Returns the value of the Content-ID header field.
- Specified by:
- getContentID in interface MimePart
public String[] getContentLanguage() throws MessagingException
Returns the languages specified in the Content-Language header of this part, as defined by RFC 1766. This method returnsnull
if this header is not available.
- Specified by:
- getContentLanguage in interface MimePart
public String getContentMD5() throws MessagingException
Returns the value of the Content-MD5 header field.
- Specified by:
- getContentMD5 in interface MimePart
protected InputStream getContentStream() throws MessagingException
Returns the unencoded bytes of the content.
public String getContentType() throws MessagingException
Returns the value of the RFC 822 Content-Type header field, or "text/plain" if the header is not available.
- Specified by:
- getContentType in interface Part
public DataHandler getDataHandler() throws MessagingException
Returns a data handler for accessing this part's content.
- Specified by:
- getDataHandler in interface Part
public String getDescription() throws MessagingException
Returns the Content-Description header field of this part. If the Content-Description field is encoded as per RFC 2047, it is decoded and converted into Unicode.
- Specified by:
- getDescription in interface Part
public String getDisposition() throws MessagingException
Returns the value of the RFC 822 Content-Disposition header field, ornull
if the header is not available.
- Specified by:
- getDisposition in interface Part
public String getEncoding() throws MessagingException
Returns the value of the Content-Transfer-Encoding header field.
- Specified by:
- getEncoding in interface MimePart
public String getFileName() throws MessagingException
Returns the filename associated with this body part. This method returns the value of the "filename" parameter from the Content-Disposition header field. If the latter is not available, it returns the value of the "name" parameter from the Content-Type header field.
- Specified by:
- getFileName in interface Part
public String[] getHeader(String name) throws MessagingException
Returns all the values for the specified header name. Note that headers may be encoded as per RFC 2047 if they contain non-US-ASCII characters: these should be decoded.
- Parameters:
name
- the header name
public String getHeader(String name, String delimiter) throws MessagingException
Returns all the values for the specified header name as a single string, with headers separated by the given delimiter. If the delimiter isnull
, only the first header is returned.
- Parameters:
name
- the header namedelimiter
- the delimiter
public InputStream getInputStream() throws IOException, MessagingException
Returns a decoded input stream for this part's content.
- Specified by:
- getInputStream in interface Part
public int getLineCount() throws MessagingException
Returns the number of lines in the content of this body part, or -1 if this number cannot be determined. Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.
- Specified by:
- getLineCount in interface Part
public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException
Returns all the header-lines with any of the given names.
- Specified by:
- getMatchingHeaderLines in interface MimePart
- Returns:
- an Enumeration of Strings
public Enumeration getMatchingHeaders(String[] names) throws MessagingException
Returns all the headers with any of the given names.
- Specified by:
- getMatchingHeaders in interface Part
- Returns:
- an Enumeration of Header objects
public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException
Returns all the header-lines without any of the given names.
- Specified by:
- getNonMatchingHeaderLines in interface MimePart
- Returns:
- an Enumeration of Strings
public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException
Returns all the headers without any of the given names.
- Specified by:
- getNonMatchingHeaders in interface Part
- Returns:
- an Enumeration of Header objects
public InputStream getRawInputStream() throws MessagingException
Returns the unencoded bytes of the content without applying any content transfer decoding.
public int getSize() throws MessagingException
Returns the size of the content of this body part in bytes, or -1 if the size cannot be determined. Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.
public boolean isMimeType(String mimeType) throws MessagingException
Indicates whether this part is of the specified MIME type. If the subtype ofmimeType
is the special character '*', the subtype is ignored during the comparison.
- Specified by:
- isMimeType in interface Part
public void removeHeader(String name) throws MessagingException
Removes all headers with the specified name.
- Specified by:
- removeHeader in interface Part
- Parameters:
name
- the header name
public void saveFile(File file) throws IOException, MessagingException
Saves the content of this part to the specified file.
- Parameters:
file
- the file
- Since:
- JavaMail 1.4
public void saveFile(String file) throws IOException, MessagingException
Saves the content of this part to the specified file.
- Parameters:
file
- the file
- Since:
- JavaMail 1.4
public void setContent(Object o, String type) throws MessagingException
Sets the content of this part using the specified Java object and MIME type. Note that a data content handler for the MIME type must be installed and accept objects of the type given.
- Specified by:
- setContent in interface Part
- Parameters:
o
- the content objecttype
- the MIME type of the object
public void setContent(Multipart mp) throws MessagingException
Sets the content of this part to be the specified multipart.
- Specified by:
- setContent in interface Part
- Parameters:
mp
- the multipart content
public void setContentID(String cid) throws MessagingException
Sets the Content-ID header field of this part.
- Since:
- JavaMail 1.3
public void setContentLanguage(String[] languages) throws MessagingException
Sets the Content-Language header of this part.
- Specified by:
- setContentLanguage in interface MimePart
- Parameters:
languages
- the array of language tags
public void setContentMD5(String md5) throws MessagingException
Sets the Content-MD5 header field of this part.
- Specified by:
- setContentMD5 in interface MimePart
public void setDataHandler(DataHandler dh) throws MessagingException
Sets the content of this part using the specified data handler.
- Specified by:
- setDataHandler in interface Part
public void setDescription(String description) throws MessagingException
Sets the Content-Description header field for this part. Ifdescription
contains non US-ASCII characters, it will be encoded using the platform default charset.
- Specified by:
- setDescription in interface Part
- Parameters:
description
- the content description
public void setDescription(String description, String charset) throws MessagingException
Sets the Content-Description header field for this part. Ifdescription
contains non US-ASCII characters, it will be encoded using the specified charset.
- Parameters:
description
- the content descriptioncharset
- the charset used for encoding
public void setDisposition(String disposition) throws MessagingException
Sets the Content-Disposition header field of this part.
- Specified by:
- setDisposition in interface Part
public void setFileName(String filename) throws MessagingException
Sets the filename associated with this body part.
- Specified by:
- setFileName in interface Part
public void setHeader(String name, String value) throws MessagingException
Sets the specified header.
- Parameters:
name
- the header namevalue
- the header value
public void setText(String text) throws MessagingException
Sets the content of this part using the specified text, and with a MIME type of "text/plain". If the text contains non US-ASCII characters, it will be encoded using the platform default charset.
- Parameters:
text
- the text content
public void setText(String text, String charset) throws MessagingException
Sets the content of this part using the specified text, and with a MIME type of "text/plain". If the text contains non US-ASCII characters, it will be encoded using the specified charset.
- Parameters:
text
- the text contentcharset
- the charset used for any encoding
public void setText(String text, String charset, String subtype) throws MessagingException
Sets the content of this part using the specified text, and with a text MIME type of the specified subtype. If the text contains non US-ASCII characters, it will be encoded using the specified charset.
- Parameters:
text
- the text contentcharset
- the charset used for any encodingsubtype
- the MIME text subtype (e.g. "plain", "html")
- Since:
- JavaMail 1.4
protected void updateHeaders() throws MessagingException
Updates the headers of this part, based on the content.
public void writeTo(OutputStream os) throws IOException, MessagingException
Writes this body part to the specified stream in RFC 822 format.