javax.mail

Class Multipart

  • Direct Known Subclasses:
    MimeMultipart

    public abstract class Multipart
    extends Object
    Multipart is a container that holds multiple body parts. Multipart provides methods to retrieve and set its subparts.

    Multipart also acts as the base class for the content object returned by most Multipart DataContentHandlers. For example, invoking getContent() on a DataHandler whose source is a "multipart/signed" data source may return an appropriate subclass of Multipart.

    Some messaging systems provide different subtypes of Multiparts. For example, MIME specifies a set of subtypes that include "alternative", "mixed", "related", "parallel", "signed", etc.

    Multipart is an abstract class. Subclasses provide actual implementations.

    Author:
    John Mani
    • Field Detail

      • parts

        protected Vector parts
        Vector of BodyPart objects.
      • contentType

        protected String contentType
        This field specifies the content-type of this multipart object. It defaults to "multipart/mixed".
      • parent

        protected Part parent
        The Part containing this Multipart, if known.
        Since:
        JavaMail 1.1
    • Constructor Detail

      • Multipart

        protected Multipart()
        Default constructor. An empty Multipart object is created.
    • Method Detail

      • setMultipartDataSource

        protected void setMultipartDataSource(MultipartDataSource mp)
                                       throws MessagingException
        Setup this Multipart object from the given MultipartDataSource.

        The method adds the MultipartDataSource's BodyPart objects into this Multipart. This Multipart's contentType is set to that of the MultipartDataSource.

        This method is typically used in those cases where one has a multipart data source that has already been pre-parsed into the individual body parts (for example, an IMAP datasource), but needs to create an appropriate Multipart subclass that represents a specific multipart subtype.

        Parameters:
        mp - Multipart datasource
        Throws:
        MessagingException
      • getContentType

        public String getContentType()
        Return the content-type of this Multipart.

        This implementation just returns the value of the contentType field.

        Returns:
        content-type
        See Also:
        contentType
      • removeBodyPart

        public boolean removeBodyPart(BodyPart part)
                               throws MessagingException
        Remove the specified part from the multipart message. Shifts all the parts after the removed part down one.
        Parameters:
        part - The part to remove
        Returns:
        true if part removed, false otherwise
        Throws:
        MessagingException - if no such Part exists
        IllegalWriteException - if the underlying implementation does not support modification of existing values
      • removeBodyPart

        public void removeBodyPart(int index)
                            throws MessagingException
        Remove the part at specified location (starting from 0). Shifts all the parts after the removed part down one.
        Parameters:
        index - Index of the part to remove
        Throws:
        MessagingException
        IndexOutOfBoundsException - if the given index is out of range.
        IllegalWriteException - if the underlying implementation does not support modification of existing values
      • addBodyPart

        public void addBodyPart(BodyPart part)
                         throws MessagingException
        Adds a Part to the multipart. The BodyPart is appended to the list of existing Parts.
        Parameters:
        part - The Part to be appended
        Throws:
        MessagingException
        IllegalWriteException - if the underlying implementation does not support modification of existing values
      • addBodyPart

        public void addBodyPart(BodyPart part,
                                int index)
                         throws 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.
        Parameters:
        part - The BodyPart to be inserted
        index - Location where to insert the part
        Throws:
        MessagingException
        IllegalWriteException - if the underlying implementation does not support modification of existing values
      • writeTo

        public abstract void writeTo(OutputStream os)
                              throws IOException,
                                     MessagingException
        Output an appropriately encoded bytestream to the given OutputStream. The implementation subclass decides the appropriate encoding algorithm to be used. The bytestream is typically used for sending.
        Throws:
        IOException - if an IO related exception occurs
        MessagingException
      • getParent

        public Part getParent()
        Return the Part that contains this Multipart object, or null if not known.
        Since:
        JavaMail 1.1
      • setParent

        public void setParent(Part parent)
        Set the parent of this Multipart to be the specified Part. Normally called by the Message or BodyPart setContent(Multipart) method. parent may be null if the Multipart is being removed from its containing Part.
        Since:
        JavaMail 1.1

Document created the 11/06/2005, last modified the 18/08/2025
Source of the printed document:https://www.gaudry.be/en/java-api-javaee-rf-javax/mail/Multipart.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : https://docs.oracle.com, Multipart (Java(TM) EE 7 Specification APIs)

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.