| java.lang.Object | ||
| ↳ | com.google.code.javax.mail.Multipart | |
| ↳ | com.google.code.javax.mail.internet.MimeMultipart | |
The MimeMultipart class is an implementation of the abstract Multipart class that uses MIME conventions for the multipart data.
A MimeMultipart is obtained from a MimePart whose primary type
is "multipart" (by invoking the part's getContent() method)
or it can be created by a client as part of creating a new MimeMessage.
The default multipart subtype is "mixed". The other multipart subtypes, such as "alternative", "related", and so on, can be implemented as subclasses of MimeMultipart with additional methods to implement the additional semantics of that type of multipart content. The intent is that service providers, mail JavaBean writers and mail clients will write many such subclasses and their Command Beans, and will install them into the JavaBeans Activation Framework, so that any JavaMail implementation and its clients can transparently find and use these classes. Thus, a MIME multipart handler is treated just like any other type handler, thereby decoupling the process of providing multipart handlers from the JavaMail API. Lacking these additional MimeMultipart subclasses, all subtypes of MIME multipart data appear as MimeMultipart objects.
An application can directly construct a MIME multipart object of any
subtype by using the MimeMultipart(String subtype)
constructor. For example, to create a "multipart/alternative" object,
use new MimeMultipart("alternative").
The mail.mime.multipart.ignoremissingendboundary
property may be set to false to cause a
MessagingException to be thrown if the multipart
data does not end with the required end boundary line. If this
property is set to true or not set, missing end
boundaries are not considered an error and the final body part
ends at the end of the data.
The mail.mime.multipart.ignoremissingboundaryparameter
System property may be set to false to cause a
MessagingException to be thrown if the Content-Type
of the MimeMultipart does not include a boundary parameter.
If this property is set to true or not set, the multipart
parsing code will look for a line that looks like a bounary line and
use that as the boundary separating the parts.
The current implementation also supports the following properties:
The mail.mime.multipart.ignoreexistingboundaryparameter
System property may be set to true to cause any boundary
to be ignored and instead search for a boundary line in the message
as with mail.mime.multipart.ignoremissingboundaryparameter.
Normally, when writing out a MimeMultipart that contains no body
parts, or when trying to parse a multipart message with no body parts,
a MessagingException is thrown. The MIME spec does not allow
multipart content with no body parts. The
mail.mime.multipart.allowempty System property may be set to
true to override this behavior.
When writing out such a MimeMultipart, a single empty part will be
included. When reading such a multipart, a MimeMultipart will be created
with no body parts.
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| allowEmpty | |||||||||||
| bmparse | |||||||||||
| complete | Have we seen the final bounary line? | ||||||||||
| ds | The DataSource supplying our InputStream. | ||||||||||
| ignoreExistingBoundaryParameter | |||||||||||
| ignoreMissingBoundaryParameter | |||||||||||
| ignoreMissingEndBoundary | Flags to control parsing, initialized from System properties in the parse() method. | ||||||||||
| parsed | Have we parsed the data from our InputStream yet? Defaults to true; set to false when our constructor is given a DataSource with an InputStream that we need to parse. | ||||||||||
| preamble | The MIME multipart preamble text, the text that occurs before the first boundary line. | ||||||||||
|
[Expand]
Inherited Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.code.javax.mail.Multipart
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Default constructor.
| |||||||||||
Construct a MimeMultipart object of the given subtype.
| |||||||||||
Constructs a MimeMultipart object and its bodyparts from the
given DataSource.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds a Part to the multipart.
| |||||||||||
Adds a BodyPart at position
index. | |||||||||||
Get the specified BodyPart.
| |||||||||||
Get the MimeBodyPart referred to by the given ContentID (CID).
| |||||||||||
Return the number of enclosed BodyPart objects.
| |||||||||||
Get the preamble text, if any, that appears before the
first body part of this multipart.
| |||||||||||
Return true if the final boundary line for this
multipart was seen.
| |||||||||||
Remove the specified part from the multipart message.
| |||||||||||
Remove the part at specified location (starting from 0).
| |||||||||||
Set the preamble text to be included before the first
body part.
| |||||||||||
Set the subtype.
| |||||||||||
Iterates through all the parts and outputs each MIME part
separated by a boundary.
| |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Create and return an InternetHeaders object that loads the
headers from the given InputStream.
| |||||||||||
Create and return a MimeBodyPart object to represent a
body part parsed from the InputStream.
| |||||||||||
Create and return a MimeBodyPart object to represent a
body part parsed from the InputStream.
| |||||||||||
Parse the InputStream from our DataSource, constructing the
appropriate MimeBodyParts.
| |||||||||||
Update headers.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.code.javax.mail.Multipart
| |||||||||||
From class
java.lang.Object
| |||||||||||
Have we seen the final bounary line?
Flags to control parsing, initialized from System properties in the parse() method.
Have we parsed the data from our InputStream yet? Defaults to true; set to false when our constructor is given a DataSource with an InputStream that we need to parse.
The MIME multipart preamble text, the text that occurs before the first boundary line.
Default constructor. An empty MimeMultipart object
is created. Its content type is set to "multipart/mixed".
A unique boundary string is generated and this string is
setup as the "boundary" parameter for the
contentType field.
MimeBodyParts may be added later.
Construct a MimeMultipart object of the given subtype.
A unique boundary string is generated and this string is
setup as the "boundary" parameter for the
contentType field.
MimeBodyParts may be added later.
| subtype |
|---|
Constructs a MimeMultipart object and its bodyparts from the given DataSource.
This constructor handles as a special case the situation where the given DataSource is a MultipartDataSource object. In this case, this method just invokes the superclass (i.e., Multipart) constructor that takes a MultipartDataSource object.
Otherwise, the DataSource is assumed to provide a MIME multipart
byte stream. The parsed flag is set to false. When
the data for the body parts are needed, the parser extracts the
"boundary" parameter from the content type of this DataSource,
skips the 'preamble' and reads bytes till the terminating
boundary and creates MimeBodyParts for each part of the stream.
| ds | DataSource, can be a MultipartDataSource |
|---|
| MessagingException |
|---|
Adds a Part to the multipart. The BodyPart is appended to the list of existing Parts.
| part | The Part to be appended |
|---|
| IllegalWriteException | if the underlying implementation does not support modification of existing values |
|---|---|
| MessagingException |
Adds a BodyPart at position index.
If index is not the last one in the list,
the subsequent parts are shifted up. If index
is larger than the number of parts present, the
BodyPart is appended to the end.
| part | The BodyPart to be inserted |
|---|---|
| index | Location where to insert the part |
| IllegalWriteException | if the underlying implementation does not support modification of existing values |
|---|---|
| MessagingException |
Get the specified BodyPart. BodyParts are numbered starting at 0.
| index | The index of the desired BodyPart |
|---|
| MessagingException | if no such BodyPart exists |
|---|
Get the MimeBodyPart referred to by the given ContentID (CID). Returns null if the part is not found.
| CID | The ContentID of the desired part |
|---|
| MessagingException |
|---|
Get the preamble text, if any, that appears before the first body part of this multipart. Some protocols, such as IMAP, will not allow access to the preamble text.
| MessagingException |
|---|
Return true if the final boundary line for this multipart was seen. When parsing multipart content, this class will (by default) terminate parsing with no error if the end of input is reached before seeing the final multipart boundary line. In such a case, this method will return false. (If the System property "mail.mime.multipart.ignoremissingendboundary" is set to false, parsing such a message will instead throw a MessagingException.)
| MessagingException |
|---|
Remove the specified part from the multipart message. Shifts all the parts after the removed part down one.
| part | The part to remove |
|---|
| MessagingException | if no such Part exists |
|---|---|
| IllegalWriteException | if the underlying implementation does not support modification of existing values |
Remove the part at specified location (starting from 0). Shifts all the parts after the removed part down one.
| index | Index of the part to remove |
|---|
| IndexOutOfBoundsException | if the given index is out of range. |
|---|---|
| IllegalWriteException | if the underlying implementation does not support modification of existing values |
| MessagingException |
Set the preamble text to be included before the first body part. Applications should generally not include any preamble text. In some cases it may be helpful to include preamble text with instructions for users of pre-MIME software. The preamble text should be complete lines, including newlines.
| preamble | The preamble text |
|---|
| MessagingException |
|---|
Set the subtype. This method should be invoked only on a new MimeMultipart object created by the client. The default subtype of such a multipart object is "mixed".
| subtype | Subtype |
|---|
| MessagingException |
|---|
Iterates through all the parts and outputs each MIME part separated by a boundary.
| os |
|---|
| IOException | |
|---|---|
| MessagingException |
Create and return an InternetHeaders object that loads the headers from the given InputStream. Subclasses can override this method to return a subclass of InternetHeaders, if necessary. This implementation simply constructs and returns an InternetHeaders object.
| is | The InputStream to read the headers from |
|---|
| MessagingException |
|---|
Create and return a MimeBodyPart object to represent a body part parsed from the InputStream. Subclasses can override this method to return a subclass of MimeBodyPart, if necessary. This implementation simply constructs and returns a MimeBodyPart object.
| is | InputStream containing the body part |
|---|
| MessagingException |
|---|
Create and return a MimeBodyPart object to represent a body part parsed from the InputStream. Subclasses can override this method to return a subclass of MimeBodyPart, if necessary. This implementation simply constructs and returns a MimeBodyPart object.
| headers | The headers for the body part |
|---|---|
| content | The content of the body part |
| MessagingException |
|---|
Parse the InputStream from our DataSource, constructing the
appropriate MimeBodyParts. The parsed flag is
set to true, and if true on entry nothing is done. This
method is called by all other methods that need data for
the body parts, to make sure the data has been parsed.
| MessagingException |
|---|
Update headers. The default implementation here just
calls the updateHeaders method on each of its
children BodyParts.
Note that the boundary parameter is already set up when a new and empty MimeMultipart object is created.
This method is called when the saveChanges
method is invoked on the Message object containing this
Multipart. This is typically done as part of the Message
send process, however note that a client is free to call
it any number of times. So if the header updating process is
expensive for a specific MimeMultipart subclass, then it
might itself want to track whether its internal state actually
did change, and do the header updating only if necessary.
| MessagingException |
|---|