Package javax.mail
Interface Part
-
- All Known Subinterfaces:
MimePart
- All Known Implementing Classes:
BodyPart,IMAPBodyPart,IMAPMessage,MaildirMessage,MboxMessage,Message,MimeBodyPart,MimeMessage,NNTPMessage,POP3Message,gnu.mail.providers.ReadOnlyMessage
public interface PartA 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:
- As a data handler, using the
getDataHandlermethod. - As an input stream, using the
getInputStreammethod. - As a Java object, using the
getContentmethod.
writeTomethod 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
Fields Modifier and Type Field Description static java.lang.StringATTACHMENTThis part should be presented as an attachment.static java.lang.StringINLINEThis part should be presented inline.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.String value)Adds the specified value to the existing values for this header name.java.util.EnumerationgetAllHeaders()Returns all the headers from this part.java.lang.ObjectgetContent()Returns the content of this part as a Java object.java.lang.StringgetContentType()Returns the content-type of the content of this part, ornullif the content-type could not be determined.javax.activation.DataHandlergetDataHandler()Returns a data handler for the content of this part.java.lang.StringgetDescription()Returns the description of this part.java.lang.StringgetDisposition()Returns the disposition of this part.java.lang.StringgetFileName()Returns the filename associated with this part, if available.java.lang.String[]getHeader(java.lang.String name)Returns all the values for the specified header name, ornullif no such headers are available.java.io.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.java.util.EnumerationgetMatchingHeaders(java.lang.String[] names)Returns the matching headers from this part.java.util.EnumerationgetNonMatchingHeaders(java.lang.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(java.lang.String mimeType)Is this part of the specified MIME type? This method compares only the primary type and subtype.voidremoveHeader(java.lang.String name)Removes all headers of the specified name.voidsetContent(java.lang.Object obj, java.lang.String type)Sets the content of this part using the specified object.voidsetContent(Multipart mp)Sets the multipart content of this part.voidsetDataHandler(javax.activation.DataHandler dh)Sets the content of this part using the specified data handler.voidsetDescription(java.lang.String description)Sets the description of this part.voidsetDisposition(java.lang.String disposition)Sets the disposition of this part.voidsetFileName(java.lang.String filename)Sets the filename associated with this part.voidsetHeader(java.lang.String name, java.lang.String value)Sets the value for the specified header name.voidsetText(java.lang.String text)Sets the textual content of this part, using a MIME type oftext/plain.voidwriteTo(java.io.OutputStream os)Writes this part to the specified byte stream.
-
-
-
Field Detail
-
ATTACHMENT
static final java.lang.String ATTACHMENT
This part should be presented as an attachment.- See Also:
- Constant Field Values
-
INLINE
static final java.lang.String INLINE
This part should be presented inline.- See Also:
- Constant Field Values
-
-
Method Detail
-
getSize
int getSize() throws MessagingExceptionReturns 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.
- Throws:
MessagingException
-
getLineCount
int getLineCount() throws MessagingExceptionReturns 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.- Throws:
MessagingException
-
getContentType
java.lang.String getContentType() throws MessagingExceptionReturns the content-type of the content of this part, ornullif the content-type could not be determined.The MIME typing system is used to name content-types.
- Throws:
MessagingException
-
isMimeType
boolean isMimeType(java.lang.String mimeType) throws MessagingExceptionIs 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
mimeTypeis the special character '*', then the subtype is ignored during the comparison.- Throws:
MessagingException
-
getDisposition
java.lang.String getDisposition() throws MessagingExceptionReturns 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.- Throws:
MessagingException
-
setDisposition
void setDisposition(java.lang.String disposition) throws MessagingExceptionSets the disposition of this part.- Parameters:
disposition- the disposition of this part- Throws:
IllegalWriteException- if the underlying implementation does not support modification of this headerjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
getDescription
java.lang.String getDescription() throws MessagingExceptionReturns the description of this part.- Throws:
MessagingException
-
setDescription
void setDescription(java.lang.String description) throws MessagingExceptionSets the description of this part.- Parameters:
description- the description of this part- Throws:
IllegalWriteException- if the underlying implementation does not support modification of this headerjava.lang.IllegalStateException- if this Part is obtained from a READ_ONLY folderMessagingException
-
getFileName
java.lang.String getFileName() throws MessagingExceptionReturns the filename associated with this part, if available.- Throws:
MessagingException
-
setFileName
void setFileName(java.lang.String filename) throws MessagingExceptionSets 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 headerjava.lang.IllegalStateException- if this Part is obtained from a READ_ONLY folderMessagingException
-
getInputStream
java.io.InputStream getInputStream() throws java.io.IOException, MessagingExceptionReturns an input stream for reading the content of this part. Any mail-specific transfer encodings will be decoded by the implementation.- Throws:
java.io.IOException- when a data handler error occursMessagingException
-
getDataHandler
javax.activation.DataHandler getDataHandler() throws MessagingExceptionReturns a data handler for the content of this part.- Throws:
MessagingException
-
getContent
java.lang.Object getContent() throws java.io.IOException, MessagingExceptionReturns 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:
java.io.IOException- when a data handler error occursMessagingException
-
setDataHandler
void setDataHandler(javax.activation.DataHandler dh) throws MessagingExceptionSets 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 modificationjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
setContent
void setContent(java.lang.Object obj, java.lang.String type) throws MessagingExceptionSets 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 objecttype- the MIME content-type of this object- Throws:
IllegalWriteException- if the underlying implementation does not support modificationjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
setText
void setText(java.lang.String text) throws MessagingExceptionSets the textual content of this part, using a MIME type oftext/plain.- Parameters:
text- the textual content- Throws:
IllegalWriteException- if the underlying implementation does not support modificationjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
setContent
void setContent(Multipart mp) throws MessagingException
Sets the multipart content of this part.- Parameters:
mp- the multipart content- Throws:
IllegalWriteException- if the underlying implementation does not support modificationjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
writeTo
void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingExceptionWrites this part to the specified byte stream.- Throws:
java.io.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
-
getHeader
java.lang.String[] getHeader(java.lang.String name) throws MessagingExceptionReturns all the values for the specified header name, ornullif no such headers are available.- Parameters:
name- the header name- Throws:
MessagingException
-
setHeader
void setHeader(java.lang.String name, java.lang.String value) throws MessagingExceptionSets the value for the specified header name.- Parameters:
name- the header namevalue- the new value- Throws:
IllegalWriteException- if the underlying implementation does not support modification of this headerjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
addHeader
void addHeader(java.lang.String name, java.lang.String value) throws MessagingExceptionAdds the specified value to the existing values for this header name.- Parameters:
name- the header namevalue- the value to add- Throws:
IllegalWriteException- if the underlying implementation does not support modification of this headerjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
removeHeader
void removeHeader(java.lang.String name) throws MessagingExceptionRemoves all headers of the specified name.- Parameters:
name- the header name- Throws:
IllegalWriteException- if the underlying implementation does not support modification of this headerjava.lang.IllegalStateException- if this part is obtained from a READ_ONLY folderMessagingException
-
getAllHeaders
java.util.Enumeration getAllHeaders() throws MessagingExceptionReturns all the headers from this part.- Returns:
- an enumeration of Header
- Throws:
MessagingException
-
getMatchingHeaders
java.util.Enumeration getMatchingHeaders(java.lang.String[] names) throws MessagingExceptionReturns the matching headers from this part.- Parameters:
names- the header names to match- Returns:
- an enumeration of Header
- Throws:
MessagingException
-
getNonMatchingHeaders
java.util.Enumeration getNonMatchingHeaders(java.lang.String[] names) throws MessagingExceptionReturns the non-matching headers from this part.- Parameters:
names- the header names to ignore- Returns:
- an enumeration of Header
- Throws:
MessagingException
-
-