IP*Works!

ipworks
Class Mime

java.lang.Object
  |
  +--ipworks.Mime

public class Mime
extends java.lang.Object

The MIME class allows for easy implementation of the Multipurpose Internet Mail Extensions or MIME as defined in RFC 1521 and updated in RFCs 2045-2049. Those standards provide for formating of messages containing non-text, multipart or non 'US' formated text.

The class's operation is controlled by the Action property. It may be used for decoding or encoding of messages. Message holds the content of the encoded message or the filename which holds the encoded data. The decoded data is put in PartDecodedString and/or PartDecodedFile depending on the user's query.

To decode a MIME message you should first assign either the whole message (headers and body) to Message or put the message headers to MessageHeaders and the message body or the filename holding it to Message . Setting Action property to decode directs the class to start parsing the message: it will fill out the ContentType , ContentTypeAttr and PartCount properties as well as the array properties PartSize , PartContentType , PartContentTypeAttr , PartContentDisposition , PartContentDispositionAttr , PartEncoding , PartName , PartFilename , PartHeaders , for each decoded part from 0 to PartCount -1.

For each part you may then get the content out of PartDecodedString or PartDecodedFile properties. Setting Action to decode doesn't actually decode the message but only parses it. The real decoding is done when the respective array property PartDecodedFile or PartDecodedString is first accessed for any particular index.

To encode data into a MIME message you should first assign values for each part to either PartDecodedString or PartDecodedFile , optionally assign values to the other Part- properties. Assiging a value to the PartDecodedString or PartDecodedFile properties fills out automatically the PartHeaders property for the respective part. Set Action property to encode directs the class to fill out the Message with the message body and the MessageHeaders with the headers.

The Progress event is fired as the message is parsed and the data is decoded/encoded.


Field Summary
static int a_DecodeFromFile
           
static int a_DecodeFromString
           
static int a_EncodeToFile
           
static int a_EncodeToString
           
static int a_Idle
           
static int a_ResetData
           
static int pe_7Bit
           
static int pe_8Bit
           
static int pe_Base64
           
static int pe_Binary
           
static int pe_QuotedPrintable
           
 
Constructor Summary
Mime()
           
 
Method Summary
 void addMimeEventListener(MimeEventListener l)
           
 void fireProgress(int percentDone)
          Shows the progress of decoding/encoding the input data.
 int getAction()
          Controls the operation of MIME component.
 java.lang.String getBoundary()
          The boundary separating the MIME parts.
 java.lang.String getContentType()
          The value of the content-type header of the message which was encoded/decoded.
 java.lang.String getContentTypeAttr()
          The attributes for content-type header of the message which was encoded/decoded.
 byte[] getMessage()
          Filename holding the encoded message or the encoded message itself.
 java.lang.String getMessageHeaders()
          The headers of the MIME message.
 java.lang.String getPartContentDisposition(int partIdx)
          Content Disposition for each part 0 to PartCount -1.
 java.lang.String getPartContentDispositionAttr(int partIdx)
          Array holding the content disposition's attributes, if any, for each part, numbered 0 to PartCount -1.
 java.lang.String getPartContentType(int partIdx)
          Content type for each part 0 to PartCount -1.
 java.lang.String getPartContentTypeAttr(int partIdx)
          Array holding the content type attributes, if any, for each part, numbered 0 to PartCount -1.
 int getPartCount()
          The number of MIME parts in the encoded message.
 java.lang.String getPartDecodedFile(int partIdx)
          Array holding the filenames with the decoded data numbered 0 to PartCount -1.
 byte[] getPartDecodedString(int partIdx)
          Array property.
 int getPartEncoding(int partIdx)
          The actual content encoding type for each part 0 to PartCount -1.
 java.lang.String getPartFilename(int partIdx)
          The filename attribute specified in the headers of the part.
 java.lang.String getPartHeaders(int partIdx)
          Headers for each MIME part, numbered 0 to PartCount -1.
 java.lang.String getPartName(int partIdx)
          The name given to a part, such as the filename.
 int getPartSize(int partIdx)
          The size of each PartDecodedFile or PartDecodedString .
 void removeMimeEventListener(MimeEventListener l)
           
 void setAction(int action)
          Controls the operation of MIME component.
 void setBoundary(java.lang.String boundary)
          The boundary separating the MIME parts.
 void setContentType(java.lang.String contentType)
          The value of the content-type header of the message which was encoded/decoded.
 void setContentTypeAttr(java.lang.String contentTypeAttr)
          The attributes for content-type header of the message which was encoded/decoded.
 void setMessage(byte[] message)
          Filename holding the encoded message or the encoded message itself.
 void setMessageHeaders(java.lang.String messageHeaders)
          The headers of the MIME message.
 void setPartContentDisposition(int partIdx, java.lang.String partContentDisposition)
          Content Disposition for each part 0 to PartCount -1.
 void setPartContentDispositionAttr(int partIdx, java.lang.String partContentDispositionAttr)
          Array holding the content disposition's attributes, if any, for each part, numbered 0 to PartCount -1.
 void setPartContentType(int partIdx, java.lang.String partContentType)
          Content type for each part 0 to PartCount -1.
 void setPartContentTypeAttr(int partIdx, java.lang.String partContentTypeAttr)
          Array holding the content type attributes, if any, for each part, numbered 0 to PartCount -1.
 void setPartCount(int partCount)
          The number of MIME parts in the encoded message.
 void setPartDecodedFile(int partIdx, java.lang.String partDecodedFile)
          Array holding the filenames with the decoded data numbered 0 to PartCount -1.
 void setPartDecodedString(int partIdx, byte[] partDecodedString)
          Array property.
 void setPartEncoding(int partIdx, int partEncoding)
          The actual content encoding type for each part 0 to PartCount -1.
 void setPartFilename(int partIdx, java.lang.String partFilename)
          The filename attribute specified in the headers of the part.
 void setPartHeaders(int partIdx, java.lang.String partHeaders)
          Headers for each MIME part, numbered 0 to PartCount -1.
 void setPartName(int partIdx, java.lang.String partName)
          The name given to a part, such as the filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

a_Idle

public static final int a_Idle

a_DecodeFromFile

public static final int a_DecodeFromFile

a_DecodeFromString

public static final int a_DecodeFromString

a_EncodeToFile

public static final int a_EncodeToFile

a_EncodeToString

public static final int a_EncodeToString

a_ResetData

public static final int a_ResetData

pe_7Bit

public static final int pe_7Bit

pe_QuotedPrintable

public static final int pe_QuotedPrintable

pe_Base64

public static final int pe_Base64

pe_8Bit

public static final int pe_8Bit

pe_Binary

public static final int pe_Binary
Constructor Detail

Mime

public Mime()
Method Detail

getAction

public int getAction()
Controls the operation of MIME component. Setting the Action property to a valid action code makes the class perform the associated action. If the action completes successfully, execution continues normally, and Action is reset to 0 (Idle). If an error happens, then an IPWorksException exception is raised.

The following are the possible values for the Action property and the corresponding descriptions:

a_Idle
Default.
a_DecodeFromFile
Decodes the data file given in Message and optionally MessageHeaders and fills out the PartCount , property and the array properties PartSize , PartContentType , PartContentTypeAttr , PartEncoding , PartName , PartHeaders , for each decoded part from 0 to PartCount -1. For each part you may get the content out of PartDecodedString or PartDecodedFile property. The decoded data will be held in PartDecodedString or otherwise saved in a temporary file given by PartDecodedFile when the user asks for the value of the respective property.
a_DecodeFromString
Same as a_DecodeFromFile but now the Message denotes the real encoded message rather than a filename.
a_EncodeToFile
Encode the data given in either PartDecodedFile or PartDecodedString into a MIME message at Message and MessageHeaders using the values optionally given in PartContentType , PartContentTypeAttr , PartEncoding , PartName , PartHeaders . To encode several objects into a MIME envelope, the user should first clear any old values left in the Part- properties and then assign values for all the indices starting with 1. The class will check for each index first the PartDecodedFile and then PartDecodedString for the data to encode. The encoded message will be saved in the file pointed by Message ; the message headers will be held by MessageHeaders .
a_EncodeToString
Same as a_EncodeToFile but the encoded data is hold in the Message property rather than saved to a file.
a_Reset
Resets the values of all headers and Part- properties. It is an easy way to reset the class's properties before starting to populate the Part- properties with new values.


setAction

public void setAction(int action)
               throws IPWorksException
Controls the operation of MIME component. Setting the Action property to a valid action code makes the class perform the associated action. If the action completes successfully, execution continues normally, and Action is reset to 0 (Idle). If an error happens, then an IPWorksException exception is raised.

The following are the possible values for the Action property and the corresponding descriptions:

a_Idle
Default.
a_DecodeFromFile
Decodes the data file given in Message and optionally MessageHeaders and fills out the PartCount , property and the array properties PartSize , PartContentType , PartContentTypeAttr , PartEncoding , PartName , PartHeaders , for each decoded part from 0 to PartCount -1. For each part you may get the content out of PartDecodedString or PartDecodedFile property. The decoded data will be held in PartDecodedString or otherwise saved in a temporary file given by PartDecodedFile when the user asks for the value of the respective property.
a_DecodeFromString
Same as a_DecodeFromFile but now the Message denotes the real encoded message rather than a filename.
a_EncodeToFile
Encode the data given in either PartDecodedFile or PartDecodedString into a MIME message at Message and MessageHeaders using the values optionally given in PartContentType , PartContentTypeAttr , PartEncoding , PartName , PartHeaders . To encode several objects into a MIME envelope, the user should first clear any old values left in the Part- properties and then assign values for all the indices starting with 1. The class will check for each index first the PartDecodedFile and then PartDecodedString for the data to encode. The encoded message will be saved in the file pointed by Message ; the message headers will be held by MessageHeaders .
a_EncodeToString
Same as a_EncodeToFile but the encoded data is hold in the Message property rather than saved to a file.
a_Reset
Resets the values of all headers and Part- properties. It is an easy way to reset the class's properties before starting to populate the Part- properties with new values.


getBoundary

public java.lang.String getBoundary()
The boundary separating the MIME parts. Maximum length of 80. The control will generate it during encoding if no value is given. During decoding it is filled out with the actual value.

The class will truncate any string longer than 80 if assigned to Boundary .


setBoundary

public void setBoundary(java.lang.String boundary)
                 throws IPWorksException
The boundary separating the MIME parts. Maximum length of 80. The control will generate it during encoding if no value is given. During decoding it is filled out with the actual value.

The class will truncate any string longer than 80 if assigned to Boundary .


getContentType

public java.lang.String getContentType()
The value of the content-type header of the message which was encoded/decoded. The class filters it out from the MessageHeaders . It shows the user about the type of the parts and their relation to each other.

The content-type attributes such as filename, boundary, charset etc are held in the ContentTypeAttr property.


setContentType

public void setContentType(java.lang.String contentType)
                    throws IPWorksException
The value of the content-type header of the message which was encoded/decoded. The class filters it out from the MessageHeaders . It shows the user about the type of the parts and their relation to each other.

The content-type attributes such as filename, boundary, charset etc are held in the ContentTypeAttr property.


getContentTypeAttr

public java.lang.String getContentTypeAttr()
The attributes for content-type header of the message which was encoded/decoded. The content-type attributes such as filename, boundary, charset etc are held in the ContentTypeAttr property. Its values and semantics on those of ContentType .


setContentTypeAttr

public void setContentTypeAttr(java.lang.String contentTypeAttr)
                        throws IPWorksException
The attributes for content-type header of the message which was encoded/decoded. The content-type attributes such as filename, boundary, charset etc are held in the ContentTypeAttr property. Its values and semantics on those of ContentType .


getMessage

public byte[] getMessage()
Filename holding the encoded message or the encoded message itself. The class fills out Message with the message body and MessageHeaders during encoding. The user may assign both the headers and the body to Message and leave MessageHeaders empty before decoding.


setMessage

public void setMessage(byte[] message)
                throws IPWorksException
Filename holding the encoded message or the encoded message itself. The class fills out Message with the message body and MessageHeaders during encoding. The user may assign both the headers and the body to Message and leave MessageHeaders empty before decoding.


getMessageHeaders

public java.lang.String getMessageHeaders()
The headers of the MIME message. The class fills out MessageHeaders upon encoding. The user should use them as additional headers when emailing the Message .

During decoding, if MessageHeaders is empty, the class will try to find the headers in the begining of the Message and will fill out MessageHeaders property accordingly.


setMessageHeaders

public void setMessageHeaders(java.lang.String messageHeaders)
                       throws IPWorksException
The headers of the MIME message. The class fills out MessageHeaders upon encoding. The user should use them as additional headers when emailing the Message .

During decoding, if MessageHeaders is empty, the class will try to find the headers in the begining of the Message and will fill out MessageHeaders property accordingly.


getPartContentType

public java.lang.String getPartContentType(int partIdx)
                                    throws IPWorksException
Content type for each part 0 to PartCount -1. This value is used in theContent-Typeheader. Typical values include "image/gif", "text/plain" etc. The class fills it out each time the PartDecodedFile property is changed. Changing PartContentType recalculates the PartHeaders property as well.

A valid PartIdx is 0 to PartCount -1.


setPartContentType

public void setPartContentType(int partIdx,
                               java.lang.String partContentType)
                        throws IPWorksException
Content type for each part 0 to PartCount -1. This value is used in theContent-Typeheader. Typical values include "image/gif", "text/plain" etc. The class fills it out each time the PartDecodedFile property is changed. Changing PartContentType recalculates the PartHeaders property as well.

A valid PartIdx is 0 to PartCount -1.


getPartContentTypeAttr

public java.lang.String getPartContentTypeAttr(int partIdx)
                                        throws IPWorksException
Array holding the content type attributes, if any, for each part, numbered 0 to PartCount -1. Setting this property recalculates the PartHeaders property.

A valid PartIdx is 0 to PartCount -1.


setPartContentTypeAttr

public void setPartContentTypeAttr(int partIdx,
                                   java.lang.String partContentTypeAttr)
                            throws IPWorksException
Array holding the content type attributes, if any, for each part, numbered 0 to PartCount -1. Setting this property recalculates the PartHeaders property.

A valid PartIdx is 0 to PartCount -1.


getPartContentDisposition

public java.lang.String getPartContentDisposition(int partIdx)
                                           throws IPWorksException
Content Disposition for each part 0 to PartCount -1. This value is used in theContent-Dispositionheader. Typical values include "form-data", "attachment" etc. The class fills it out each time the PartDecodedFile property is changed. Changing PartContentDisposition recalculates the PartHeaders property as well.

A valid PartIdx is 0 to PartCount -1.


setPartContentDisposition

public void setPartContentDisposition(int partIdx,
                                      java.lang.String partContentDisposition)
                               throws IPWorksException
Content Disposition for each part 0 to PartCount -1. This value is used in theContent-Dispositionheader. Typical values include "form-data", "attachment" etc. The class fills it out each time the PartDecodedFile property is changed. Changing PartContentDisposition recalculates the PartHeaders property as well.

A valid PartIdx is 0 to PartCount -1.


getPartContentDispositionAttr

public java.lang.String getPartContentDispositionAttr(int partIdx)
                                               throws IPWorksException
Array holding the content disposition's attributes, if any, for each part, numbered 0 to PartCount -1. Typical values for PartContentDispositionAttr are the names of the form-variables while creating an HTTP post, values for filenames etc.

Setting this property recalculates the PartHeaders property.

A valid PartIdx is 0 to PartCount -1.


setPartContentDispositionAttr

public void setPartContentDispositionAttr(int partIdx,
                                          java.lang.String partContentDispositionAttr)
                                   throws IPWorksException
Array holding the content disposition's attributes, if any, for each part, numbered 0 to PartCount -1. Typical values for PartContentDispositionAttr are the names of the form-variables while creating an HTTP post, values for filenames etc.

Setting this property recalculates the PartHeaders property.

A valid PartIdx is 0 to PartCount -1.


getPartEncoding

public int getPartEncoding(int partIdx)
                    throws IPWorksException
The actual content encoding type for each part 0 to PartCount -1. PartEncoding determines how to encode the data or how they were actually encoded in the Message as specified in theContent-Transfer-Encodingheader.

A valid PartIdx is 0 to PartCount -1.

Possible values for PartEncoding are:

0
7 Bit data, no encoding.
1
Quoted-Printable encoding of (typically) text.
2
Base64 encoding of binary data.
3
No encoding, 8 Bit characters may be contained as well.
4
Binary data without any encoding. Similar to 3 (8 Bit encoding).


setPartEncoding

public void setPartEncoding(int partIdx,
                            int partEncoding)
                     throws IPWorksException
The actual content encoding type for each part 0 to PartCount -1. PartEncoding determines how to encode the data or how they were actually encoded in the Message as specified in theContent-Transfer-Encodingheader.

A valid PartIdx is 0 to PartCount -1.

Possible values for PartEncoding are:

0
7 Bit data, no encoding.
1
Quoted-Printable encoding of (typically) text.
2
Base64 encoding of binary data.
3
No encoding, 8 Bit characters may be contained as well.
4
Binary data without any encoding. Similar to 3 (8 Bit encoding).


getPartDecodedFile

public java.lang.String getPartDecodedFile(int partIdx)
                                    throws IPWorksException
Array holding the filenames with the decoded data numbered 0 to PartCount -1. Accessing PartDecodedFile for the first time after setting Action to decode directs the class to actually decode the part and save the data in a temporary file. The user is responsible for deleting the temporary file.

Setting a value to PartDecodedFile directs the component to calculate the file size and fill out the respective PartSize property.

Valid PartIdx values are 0 to PartCount -1.


setPartDecodedFile

public void setPartDecodedFile(int partIdx,
                               java.lang.String partDecodedFile)
                        throws IPWorksException
Array holding the filenames with the decoded data numbered 0 to PartCount -1. Accessing PartDecodedFile for the first time after setting Action to decode directs the class to actually decode the part and save the data in a temporary file. The user is responsible for deleting the temporary file.

Setting a value to PartDecodedFile directs the component to calculate the file size and fill out the respective PartSize property.

Valid PartIdx values are 0 to PartCount -1.


getPartDecodedString

public byte[] getPartDecodedString(int partIdx)
                            throws IPWorksException
Array property. It holds the actual content of each part, numbered 0 to PartCount -1. The class decodes the actual part of Message to PartDecodedString property when PartDecodedString 's value is first queried.

Setting a value to PartDecodedString fills out the PartSize property with the string size if PartDecodedFile is empty. The class checks during encoding first PartDecodedFile : if it is empty then the class uses the value of PartDecodedString .

A valid PartIdx is 0 to PartCount -1.


setPartDecodedString

public void setPartDecodedString(int partIdx,
                                 byte[] partDecodedString)
                          throws IPWorksException
Array property. It holds the actual content of each part, numbered 0 to PartCount -1. The class decodes the actual part of Message to PartDecodedString property when PartDecodedString 's value is first queried.

Setting a value to PartDecodedString fills out the PartSize property with the string size if PartDecodedFile is empty. The class checks during encoding first PartDecodedFile : if it is empty then the class uses the value of PartDecodedString .

A valid PartIdx is 0 to PartCount -1.


getPartFilename

public java.lang.String getPartFilename(int partIdx)
                                 throws IPWorksException
The filename attribute specified in the headers of the part. Changing the value of PartDecodedFile sets automatically the PartFilename and consequently the PartHeaders property for the same PartIdx .

A valid PartIdx is 0 to PartCount -1.


setPartFilename

public void setPartFilename(int partIdx,
                            java.lang.String partFilename)
                     throws IPWorksException
The filename attribute specified in the headers of the part. Changing the value of PartDecodedFile sets automatically the PartFilename and consequently the PartHeaders property for the same PartIdx .

A valid PartIdx is 0 to PartCount -1.


getPartName

public java.lang.String getPartName(int partIdx)
                             throws IPWorksException
The name given to a part, such as the filename. Changing the value of PartDecodedFile sets automatically the PartName and consequently the PartHeaders property for the same PartIdx .

A valid PartIdx is 0 to PartCount -1.


setPartName

public void setPartName(int partIdx,
                        java.lang.String partName)
                 throws IPWorksException
The name given to a part, such as the filename. Changing the value of PartDecodedFile sets automatically the PartName and consequently the PartHeaders property for the same PartIdx .

A valid PartIdx is 0 to PartCount -1.


getPartHeaders

public java.lang.String getPartHeaders(int partIdx)
                                throws IPWorksException
Headers for each MIME part, numbered 0 to PartCount -1. The class fills out PartHeaders each time any of the other Part- properties for that PartIdx is changed. If additional headers are needed they should be appended after all the other Part- properties for that PartIdx are set.

Valid PartIdx values are 0 to PartCount -1.


setPartHeaders

public void setPartHeaders(int partIdx,
                           java.lang.String partHeaders)
                    throws IPWorksException
Headers for each MIME part, numbered 0 to PartCount -1. The class fills out PartHeaders each time any of the other Part- properties for that PartIdx is changed. If additional headers are needed they should be appended after all the other Part- properties for that PartIdx are set.

Valid PartIdx values are 0 to PartCount -1.


getPartSize

public int getPartSize(int partIdx)
                throws IPWorksException
The size of each PartDecodedFile or PartDecodedString . If a non empty value is assigned to PartDecodedFile then class fills out PartSize of the same PartIdx with the file size or an error occurrs if the file doesn't exist. If PartDecodedFile is empty and a value is assigned to PartDecodedString then PartSize will be equal to the string's size.

During decoding the PartSize is filled with the size of each part as soon as Action is set to decode.


getPartCount

public int getPartCount()
The number of MIME parts in the encoded message. The class fills out PartCount during decoding with the number of parts in the Message . All the Part- properties have valid indexes 0 to PartCount -1. The user may set PartCount before encoding to the number of parts she wants the class to encode.


setPartCount

public void setPartCount(int partCount)
                  throws IPWorksException
The number of MIME parts in the encoded message. The class fills out PartCount during decoding with the number of parts in the Message . All the Part- properties have valid indexes 0 to PartCount -1. The user may set PartCount before encoding to the number of parts she wants the class to encode.


fireProgress

public void fireProgress(int percentDone)
Shows the progress of decoding/encoding the input data. (Called internally to dispatch the event.)
See Also:
MimeProgressEvent

addMimeEventListener

public void addMimeEventListener(MimeEventListener l)
                          throws java.util.TooManyListenersException

removeMimeEventListener

public void removeMimeEventListener(MimeEventListener l)

IP*Works!

Copyright (c) 1995-2000 by /n software inc. - All rights reserved.