Class Part

  • Direct Known Subclasses:
    Message

    public class Part
    extends java.lang.Object
    This class represents a MIME body part, which are contained by Multipart objects.
    Since:
    TotalCross 1.13
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ATTACHMENT  
      static java.lang.String BINARY  
      protected java.lang.Object content  
      protected DataContentHandler contentHandler  
      java.lang.String disposition
      Defines if this part's content should be inlined in the body of the message, or attached as a file.
      Its value MUST be set to either INLINE (default value) or ATTACHMENT, using the constants defined by the class Part.
      java.lang.String fileName
      File name of the attachment represented by this part (if any).
      If assigned with a non-null value, the field disposition value is ignored and the part treated as ATTACHMENT.
      protected totalcross.net.mail.PartHeaders headers  
      static java.lang.String HTML  
      static java.lang.String INLINE  
      protected java.lang.String mimeType  
      static java.lang.String PLAIN  
    • Constructor Summary

      Constructors 
      Constructor Description
      Part()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addHeader​(java.lang.String name, java.lang.String value)
      Add this value to the existing values for this header name.
      java.lang.Object getContent()
      Returns the content of this part.
      java.lang.String getContentType()
      Returns the Content-Type of the content of this part.
      void setContent​(java.lang.Object content)
      A convenience method for setting this part's content based on the type of the passed object.
      If the given object type is Multipart, it's MIME type is set to "multipart/mixed".
      If the given object type is String, it's MIME type is set to "text/plain".
      Otherwise, the given object will be handled as "application/octet-stream" by the BinaryContentHandler.
      void setContent​(java.lang.Object content, java.lang.String mimeType)
      A convenience method for setting this part's content.
      Note that a DataContentHandler class for the specified type should be available, otherwise the content will be handled by the BinaryContentHandler, which writes the content as a base 64 encoded String.
      void setContent​(Multipart multipart)
      This method sets the given Multipart object as this part's content.
      void setText​(java.lang.String text)
      A convenience method that sets the given String as this part's content with a MIME type of "text/plain".
      void writeTo​(Stream stream)
      Writes this part to the given Stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • disposition

        public java.lang.String disposition
        Defines if this part's content should be inlined in the body of the message, or attached as a file.
        Its value MUST be set to either INLINE (default value) or ATTACHMENT, using the constants defined by the class Part.
      • fileName

        public java.lang.String fileName
        File name of the attachment represented by this part (if any).
        If assigned with a non-null value, the field disposition value is ignored and the part treated as ATTACHMENT.
      • content

        protected java.lang.Object content
      • mimeType

        protected java.lang.String mimeType
      • headers

        protected totalcross.net.mail.PartHeaders headers
    • Constructor Detail

      • Part

        public Part()
    • Method Detail

      • addHeader

        public void addHeader​(java.lang.String name,
                              java.lang.String value)
        Add this value to the existing values for this header name.
        Parameters:
        name - the name of this header
        value - the value for this header
        Since:
        TotalCross 1.22
      • getContentType

        public java.lang.String getContentType()
        Returns the Content-Type of the content of this part. Returns null if the Content-Type could not be determined.
        The MIME typing system is used to name Content-types.
        Returns:
        The ContentType of this part, or null if it could not be determined
        Since:
        TotalCross 1.22
      • setContent

        public void setContent​(java.lang.Object content,
                               java.lang.String mimeType)
        A convenience method for setting this part's content.
        Note that a DataContentHandler class for the specified type should be available, otherwise the content will be handled by the BinaryContentHandler, which writes the content as a base 64 encoded String.
        Parameters:
        content - this part's content
        mimeType - content's MIME type
        Throws:
        java.lang.IllegalArgumentException - if the given content is a Part object
        Since:
        TotalCross 1.13
        See Also:
        BinaryContentHandler
      • setContent

        public void setContent​(Multipart multipart)
        This method sets the given Multipart object as this part's content.
        Parameters:
        multipart - the multipart object that is the part's content
        Since:
        TotalCross 1.13
      • setContent

        public void setContent​(java.lang.Object content)
        A convenience method for setting this part's content based on the type of the passed object.
        If the given object type is Multipart, it's MIME type is set to "multipart/mixed".
        If the given object type is String, it's MIME type is set to "text/plain".
        Otherwise, the given object will be handled as "application/octet-stream" by the BinaryContentHandler.
        Parameters:
        content - this part's content
        Throws:
        java.lang.IllegalArgumentException - if the given content is a Part object
        Since:
        TotalCross 1.13
      • setText

        public void setText​(java.lang.String text)
        A convenience method that sets the given String as this part's content with a MIME type of "text/plain".
        Parameters:
        text - the text that is this part's content.
        Since:
        TotalCross 1.13
      • writeTo

        public void writeTo​(Stream stream)
                     throws IOException,
                            MessagingException
        Writes this part to the given Stream. The output is typically an aggregation of the Part attributes and an appropriately encoded byte stream from its 'content'. Classes that extends the Part class decide on the appropriate encoding algorithm to be used. The received Stream is typically used for sending.
        Parameters:
        stream - the output stream that will receive this part's encoded representation
        Throws:
        IOException - if an error occurs writing to the stream
        MessagingException - if an error occurs fetching the data to be written
        Since:
        TotalCross 1.13
      • getContent

        public java.lang.Object getContent()
        Returns the content of this part.
        Returns:
        the content of this part.
        Since:
        TotalCross 1.13