Package totalcross.net.mail
Class Part
- java.lang.Object
-
- totalcross.net.mail.Part
-
- Direct Known Subclasses:
Message
public class Part extends java.lang.ObjectThis 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.StringATTACHMENTstatic java.lang.StringBINARYprotected java.lang.Objectcontentprotected DataContentHandlercontentHandlerjava.lang.StringdispositionDefines 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.StringfileNameFile 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.PartHeadersheadersstatic java.lang.StringHTMLstatic java.lang.StringINLINEprotected java.lang.StringmimeTypestatic java.lang.StringPLAIN
-
Constructor Summary
Constructors Constructor Description Part()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.String value)Add this value to the existing values for this header name.java.lang.ObjectgetContent()Returns the content of this part.java.lang.StringgetContentType()Returns the Content-Type of the content of this part.voidsetContent(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.voidsetContent(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.voidsetContent(Multipart multipart)This method sets the given Multipart object as this part's content.voidsetText(java.lang.String text)A convenience method that sets the given String as this part's content with a MIME type of "text/plain".voidwriteTo(Stream stream)Writes this part to the given Stream.
-
-
-
Field Detail
-
INLINE
public static final java.lang.String INLINE
- See Also:
- Constant Field Values
-
ATTACHMENT
public static final java.lang.String ATTACHMENT
- See Also:
- Constant Field Values
-
PLAIN
public static final java.lang.String PLAIN
- See Also:
- Constant Field Values
-
HTML
public static final java.lang.String HTML
- See Also:
- Constant Field Values
-
BINARY
public static final java.lang.String BINARY
- See Also:
- Constant Field Values
-
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
-
contentHandler
protected DataContentHandler contentHandler
-
headers
protected totalcross.net.mail.PartHeaders headers
-
-
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 headervalue- 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 contentmimeType- 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 streamMessagingException- 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
-
-