Secure iNet Factory

com.jscape.inet.mime
Class MimeMessage

java.lang.Object
  extended by com.jscape.inet.mime.MimeMessage
All Implemented Interfaces:
MimeConstants, java.io.Serializable
Direct Known Subclasses:
Attachment, EmailMessage, HttpRequest, HttpResponse, NntpArticleHeader

public class MimeMessage
extends java.lang.Object
implements MimeConstants, java.io.Serializable

Provides methods for building MIME message content and parsing existing MIME message content into its parts.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.jscape.inet.mime.MimeConstants
COLON, CR, CRLF, EQUALS, LF, QUESTION_MARK, SEMI_COLON, SPACE, TAB
 
Constructor Summary
MimeMessage()
          Constructs a new MimeMessage.
MimeMessage(byte[] message)
          Constructs a MimeMessage from existing content.
 
Method Summary
 void addHeader(MimeHeader header)
          Adds MIME header to this MimeMessage.
 void addHeader(java.lang.String name, java.lang.String value)
          Adds MIME header to this MimeMessage.
 void addPart(MimeMessage message)
          Adds part to multipart MimeMessage.
 void addReplaceHeader(MimeHeader header)
          Adds MIME header to this MimeMessage, replacing existing header if found.
 void addReplaceHeader(java.lang.String name, java.lang.String value)
          Adds MIME header to this MimeMessage, replacing existing header if found.
 java.lang.String getBody()
          Gets decoded message body using character encoding specified in charset attribute of Content-Type message header.
 java.io.File getBodyAsFile()
          Get the file body.
 byte[] getBodyData()
          Gets decoded message body as bytes.
 java.lang.String getBoundary()
          Gets boundary used in this MimeMessage.
 java.lang.String getContentTransferEncoding()
          Gets the value of the Content-Transfer-Encoding header for this MimeMessage.
 java.lang.String getContentType()
          Gets the content-type of this MimeMessage.
 MimeHeader getHeader(java.lang.String name)
          Returns named header specified by name.
 java.util.Enumeration getHeaders()
          Gets all mime headers for this MimeMessage.
 java.util.Enumeration getHeaders(java.lang.String name)
          Gets all MIME headers for this MimeMessage with specified name.
 java.lang.String getHeaderValue(java.lang.String name)
          Gets value for header specified by name If more than one header with specified name exists for this MimeMessage then the value of the last header added to this MimeMessage with specified name will be returned.
 byte[] getMessage()
          Gets contents of this MimeMessage.
 MimeMessage getPart(int index)
          Gets specified part from this MimeMessage.
 java.util.Enumeration getParts()
          Gets parts of this MimeMessage.
 byte[] getRawBodyData()
          Gets message body as bytes.
 void removeHeader(java.lang.String name)
          Removes specified header from this MimeMessage.
 void removePart(int index)
          Removes specified index from parts array.
 void removeParts()
          Removes all parts from this message.
 void setBody(byte[] contents)
          Sets body of this MimeMessage.
 void setBody(java.io.File file)
          Sets body of this MimeMessage.
 void setBody(java.lang.String body)
          Sets body of this MimeMessage.
 void setBody(java.lang.String body, java.lang.String characterSet)
          Sets body of this MimeMessage and sets the charset attribute of Content-Type header to provided character set.
 void setBodyAsFile(java.io.File body)
           
 void setContentType(java.lang.String contentType)
          Sets the content-type of this MimeMessage.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeMessage

public MimeMessage()
Constructs a new MimeMessage.


MimeMessage

public MimeMessage(byte[] message)
            throws MimeException
Constructs a MimeMessage from existing content.

Parameters:
message - the contents of mime message
Throws:
MimeException - a Mime parsing error occurs
Method Detail

getMessage

public byte[] getMessage()
                  throws MimeException
Gets contents of this MimeMessage. Contents include all MIME message headers, body and any parts.

Returns:
message contents
Throws:
MimeException - if a MIME related parsing error occurs

setContentType

public void setContentType(java.lang.String contentType)
                    throws MimeException
Sets the content-type of this MimeMessage.

Parameters:
contentType - the content-type
Throws:
MimeException - if a MIME related parsing error occurs

getContentType

public java.lang.String getContentType()
Gets the content-type of this MimeMessage.

Returns:
content-type

getContentTransferEncoding

public java.lang.String getContentTransferEncoding()
Gets the value of the Content-Transfer-Encoding header for this MimeMessage. The Content-Transfer-Encoding header indicates the encoding method used for the message body. Typical values are BASE64, UUENCODE, 7BIT, 8BIT and QUOTED-PRINTABLE

Returns:
content transfer encoding

setBodyAsFile

public void setBodyAsFile(java.io.File body)

getBodyAsFile

public java.io.File getBodyAsFile()
Get the file body. Intended to be used together with HttpFileUpload class.

Returns:
body

setBody

public void setBody(java.lang.String body)
Sets body of this MimeMessage. Default system character encoding is used to convert the body to bytes.

Parameters:
body - the body contents

setBody

public void setBody(java.lang.String body,
                    java.lang.String characterSet)
             throws MimeException
Sets body of this MimeMessage and sets the charset attribute of Content-Type header to provided character set. If Content-Type header is not found then a new Content-Type header will be created with a value of text/plain.

Parameters:
body - the body contents
characterSet - the character set the body it to be set with.
Throws:
MimeException - if a MIME related parsing error occurs

setBody

public void setBody(byte[] contents)
Sets body of this MimeMessage.

Parameters:
contents - the body contents

setBody

public void setBody(java.io.File file)
             throws java.io.IOException
Sets body of this MimeMessage.

Parameters:
file - the body contents
Throws:
java.io.IOException - if an I/O error occurs reading file

getHeaderValue

public java.lang.String getHeaderValue(java.lang.String name)
Gets value for header specified by name If more than one header with specified name exists for this MimeMessage then the value of the last header added to this MimeMessage with specified name will be returned. To get all header see the getHeaders method.

Parameters:
name - the name of the header to retrive
Returns:
the value of the header or null if header is not found
See Also:
getHeaders()

getHeader

public MimeHeader getHeader(java.lang.String name)
Returns named header specified by name. If more than one header with specified name exists for this MimeMessage then the last header added to this MimeMessage with specified name will be returned. To get all header see the getHeaders method.

Parameters:
name - the name of the header to retrieve
Returns:
a MimeHeader or null if header is not present
See Also:
getHeaders()

getBody

public java.lang.String getBody()
                         throws MimeException
Gets decoded message body using character encoding specified in charset attribute of Content-Type message header. If no character encoding is defined then US-ASCII character encoding is used.

Returns:
the body of the MIME message
Throws:
MimeException - if a MIME related parsing error occurs

getBodyData

public byte[] getBodyData()
                   throws MimeException
Gets decoded message body as bytes. If message body is encoded using Base64, Uuencode or Quoted-Printable codecs then message body will be decoded. If message body is in 7bit or 8bit form then body will be returned as is.

Returns:
body data
Throws:
MimeException - if a MIME related parsing error occurs

getRawBodyData

public byte[] getRawBodyData()
Gets message body as bytes. the body will be returned as is.

Returns:
body data

getBoundary

public java.lang.String getBoundary()
                             throws MimeException
Gets boundary used in this MimeMessage.

Returns:
boundary
Throws:
MimeException - if a MIME related parsing error occurs

addPart

public void addPart(MimeMessage message)
             throws MimeException
Adds part to multipart MimeMessage. If not previously set boundary string is generated. This method also sets Content-Type field for this MimeMessage to multipart/mixed to reflect multipart nature of the message.

Parameters:
message - the MimeMessage to add to this MimeMessage
Throws:
MimeException - if a MIME related parsing error occurs

getParts

public java.util.Enumeration getParts()
Gets parts of this MimeMessage. Returns an Enumeration of MimeMessage.

Returns:
a Enumeration

removePart

public void removePart(int index)
Removes specified index from parts array.

Parameters:
index - the index of part to remove

removeParts

public void removeParts()
Removes all parts from this message.


addHeader

public void addHeader(MimeHeader header)
Adds MIME header to this MimeMessage.

Parameters:
header - a MimeHeader

addReplaceHeader

public void addReplaceHeader(MimeHeader header)
Adds MIME header to this MimeMessage, replacing existing header if found.

Parameters:
header - a MimeHeader

addReplaceHeader

public void addReplaceHeader(java.lang.String name,
                             java.lang.String value)
                      throws MimeException
Adds MIME header to this MimeMessage, replacing existing header if found.

Parameters:
name - the header name
value - the header value
Throws:
MimeException - if a MIME related parsing error occurs

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
               throws MimeException
Adds MIME header to this MimeMessage.

Parameters:
name - the header name
value - the header value
Throws:
MimeException - if a MIME related parsing error occurs

removeHeader

public void removeHeader(java.lang.String name)
Removes specified header from this MimeMessage.

Parameters:
name - the name of the header to remove

getHeaders

public java.util.Enumeration getHeaders()
Gets all mime headers for this MimeMessage. Returns an Enumeration of MimeHeader.

Returns:
a Enumeration

getHeaders

public java.util.Enumeration getHeaders(java.lang.String name)
Gets all MIME headers for this MimeMessage with specified name. Returns an Enumeration of MimeHeader.

Parameters:
name - the header name
Returns:
a Enumeration

getPart

public MimeMessage getPart(int index)
Gets specified part from this MimeMessage.

Parameters:
index - the index of part
Returns:
a MimeMessage or null if not present

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved