IP*Works! S/MIME V9

ipworkssmime
Class Mime

java.lang.Object
  extended by ipworkssmime.Mime

public class Mime
extends java.lang.Object

The MIME bean 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 formatting of messages containing non-text, multipart or non 'US' formatted text.

The bean 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 provided in Parts collection .

To decode a MIME message you should first assign either the whole message (headers and body) to Message or put the message headers into the MessageHeaders property and the message body or the filename holding it into the Message property. Calling DecodeFromFile or DecodeFromString directs the bean to start parsing the message: it will fill out the ContentType , ContentTypeAttr properties with message content type information, and enter information about message parts into the Parts collection , which includes: part sizes, part content types, part content type attributes, part content disposition, part content disposition attributes, part encoding, part name, part filename, part headers, or part content (part decoded string or part decoded file) for each decoded part.

Calling the DecodeFromString or DecodeFromFile to decode doesn't actually decode the message but only parses it. The real decoding is done when the part content in the Parts collection is first accessed.

To encode data into a MIME message you should first assign values for each part to either part decoded string or part decoded file in the Parts collection property, and optionally assign values to the other part attributes in the Parts collection . Assigning a value to the part decoded string or part decoded file through the Parts collection , fills out automatically the part headers into the Parts collection for the respective part. Calling EncodeToFile or EncodeToString directs the bean 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.


Constructor Summary
Mime()
          Creates an instance of Mime Bean.
Mime(java.lang.String runtimeLicense)
          Creates an instance of Mime Bean with specified run-time license.
 
Method Summary
 void addMimeEventListener(MimeEventListener l)
           
 java.lang.String config(java.lang.String configurationString)
          Sets or retrieves a configuration setting.
 void decodeFromFile()
          Decodes from file.
 void decodeFromStream(java.io.InputStream inputStream)
          Decodes from stream.
 void decodeFromString()
          Decodes from string.
 void encodeToFile()
          Encodes to file.
 void encodeToStream(java.io.OutputStream outputStream)
          Encodes to stream.
 void encodeToString()
          Encodes to string.
 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()
          Contains the encoded message text or a path to a file which contains the encoded message text.
 HeaderList getMessageHeaders()
          The headers of the MIME message.
 java.lang.String getMessageHeadersString()
          String version of the MIME message headers.
 MIMEPartList getParts()
          Contains information about all parts of a MIME message.
 void removeMimeEventListener(MimeEventListener l)
           
 void resetData()
          Resets the values of all headers and Part- properties.
 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)
          Contains the encoded message text or a path to a file which contains the encoded message text.
 void setMessageHeadersString(java.lang.String messageHeadersString)
          String version of the MIME message headers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mime

public Mime()
Creates an instance of Mime Bean.


Mime

public Mime(java.lang.String runtimeLicense)
Creates an instance of Mime Bean with specified run-time license.

Method Detail

getBoundary

public java.lang.String getBoundary()
The boundary separating the MIME parts. Maximum length of 80 bytes.

This property contains the boundary separating the MIME parts and has a maximum length of 80 bytes. The bean will automatically generate a random boundary value during encoding if no value is given. During decoding this property is filled with the boundary from the actual MIME message.

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


setBoundary

public void setBoundary(java.lang.String boundary)
                 throws IPWorksSMIMEException
The boundary separating the MIME parts. Maximum length of 80 bytes.

This property contains the boundary separating the MIME parts and has a maximum length of 80 bytes. The bean will automatically generate a random boundary value during encoding if no value is given. During decoding this property is filled with the boundary from the actual MIME message.

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

Throws:
IPWorksSMIMEException

getContentType

public java.lang.String getContentType()
The value of the content-type header of the message which was encoded/decoded.

This property contains the value of the content-type header of the message which was encoded/decoded. The bean 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 this property.


setContentType

public void setContentType(java.lang.String contentType)
                    throws IPWorksSMIMEException
The value of the content-type header of the message which was encoded/decoded.

This property contains the value of the content-type header of the message which was encoded/decoded. The bean 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 this property.

Throws:
IPWorksSMIMEException

getContentTypeAttr

public java.lang.String getContentTypeAttr()
The attributes for content-type header of the message which was encoded/decoded.

This property contains content-type attributes such as "filename", "boundary", "charset", etc.


setContentTypeAttr

public void setContentTypeAttr(java.lang.String contentTypeAttr)
                        throws IPWorksSMIMEException
The attributes for content-type header of the message which was encoded/decoded.

This property contains content-type attributes such as "filename", "boundary", "charset", etc.

Throws:
IPWorksSMIMEException

getMessage

public byte[] getMessage()
Contains the encoded message text or a path to a file which contains the encoded message text.

This property contains the encoded message text or a path to a file which contains the encoded message text. The bean fills out this property with the message body and MessageHeaders during encoding. The user may assign both the headers and the body to this property and leave MessageHeaders empty before decoding.


setMessage

public void setMessage(byte[] message)
                throws IPWorksSMIMEException
Contains the encoded message text or a path to a file which contains the encoded message text.

This property contains the encoded message text or a path to a file which contains the encoded message text. The bean fills out this property with the message body and MessageHeaders during encoding. The user may assign both the headers and the body to this property and leave MessageHeaders empty before decoding.

Throws:
IPWorksSMIMEException

getMessageHeaders

public HeaderList getMessageHeaders()
The headers of the MIME message.

This property contains the headers of the MIME message. The bean fills out this property upon encoding. The user should use them as additional headers when emailing the Message .

During decoding, if this property is empty the bean will try to find the headers in the beginning of the Message and will fill out this property accordingly.


getMessageHeadersString

public java.lang.String getMessageHeadersString()
String version of the MIME message headers.

The component fills out MessageHeadersString upon encoding. The user should use them as additional headers when emailing the Message .

This property contains a string version of the MIME message headers. During decoding, if this property is empty the bean will try to find the headers in the beginning of the Message and will fill out this property accordingly.


setMessageHeadersString

public void setMessageHeadersString(java.lang.String messageHeadersString)
                             throws IPWorksSMIMEException
String version of the MIME message headers.

The component fills out MessageHeadersString upon encoding. The user should use them as additional headers when emailing the Message .

This property contains a string version of the MIME message headers. During decoding, if this property is empty the bean will try to find the headers in the beginning of the Message and will fill out this property accordingly.

Throws:
IPWorksSMIMEException

getParts

public MIMEPartList getParts()
Contains information about all parts of a MIME message.

This property contains information about all parts of a MIME message. A MIME message consists of different parts, separated by either a user-specified or an auto-generated boundary. Each part has its own set of headers which are contained in the Headers field.

The MIMEPARTS collection is filled out by the bean when a call to either DecodeFromFile or DecodeFromString is made. However, when the EncodeToFile or EncodeToString methods are called, the bean encodes the data given in either DecodedFile or DecodedString into a MIME message.

This collection is indexed from 0 to size - 1.


config

public java.lang.String config(java.lang.String configurationString)
                        throws IPWorksSMIMEException
Sets or retrieves a configuration setting.

Config is a generic method available in every bean. It is used to set and retrieve configuration settings for the bean.

Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the bean, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY , you must call Config("PROPERTY=VALUE") , where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY") . The value will be returned as a string.

The bean accepts one or more of the following configuration settings . Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the bean, access to these internal properties is provided through the Config method.

MIME Configuration Settings

FoldHeaders
Tells the bean whether to fold the headers
If true, the bean will fold the headers if the headers are over a certain length. If false, the headers will be on one line regardless of length.
IncludeHeaders
Tells the bean whether to include the headers when encoding the message
If true, the bean will include the headers when EncodeToFile or EncodeToString are called. If false, only the message will be encoded.The default value for IncludeHeaders is false.

MaxParts
The maximum number of parts to be parsed from a mime message
This config should be set to limit the amount of parts that will be parsed by the component and saved into the collection . By default, this value is 100. Therefore up to 100 parts will be parsed from a mime message by default.
RequireVersionHeader
Specifies whether or not the bean should require the version header
If true, the bean will require that the "MIME-Version" header be included in the MessageHeaders . If the header is not present during decoding, the component throws an exception. This config is false by default.
TempFilePath
If set, the temporary files created during MIME decoding and encoding will be put in the path specified
The TempFilePath property sets the path at which the temporary files will be created.

Base Configuration Settings

GUIAvailable
Tells the bean whether or not a message loop is available for processing events
In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The bean will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.In some non-GUI applications an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GuiAvailable to false will ensure that the bean does not attempt to process external events.

Throws:
IPWorksSMIMEException

decodeFromFile

public void decodeFromFile()
                    throws IPWorksSMIMEException
Decodes from file.

This method decodes the data file given in Message and optionally MessageHeaders and fills out the Parts collection for each decoded part.

Example (Decoding From File)

 MIMEControl.Message = "C:\filename.txt"
 MIMEControl.DecodeFromFile 

Here, C:\filename.txt must contain the MIME headers and body. If not, the MessageHeaders property must also be set to the appropriate MIME headers.

Throws:
IPWorksSMIMEException

decodeFromStream

public void decodeFromStream(java.io.InputStream inputStream)
                      throws IPWorksSMIMEException
Decodes from stream.

This method decodes from stream. Same as DecodeFromString, but now the MIME message is passed to this method as a stream.

This method decodes the data given by the InputStream and optionally MessageHeaders and fills out the Parts collection .

Example (Decoding Mail Message)

 MIMEControl.MessageHeaders.AddRange(MailControl.MessageHeaders)
 MIMEControl.DecodeFromStream(InputStream) 

Throws:
IPWorksSMIMEException

decodeFromString

public void decodeFromString()
                      throws IPWorksSMIMEException
Decodes from string.

This method decodes from string. Same as DecodeFromFile, but now the Message denotes the real encoded message rather than a filename.

This method decodes the data given in Message and optionally MessageHeaders and fills out the Parts collection .

Example (Decoding Mail Message)

 MIMEControl.MessageHeaders.AddRange(MailControl.MessageHeaders)
 MIMEControl.Message = MailControl.MessageText
 MIMEControl.DecodeFromString 

Throws:
IPWorksSMIMEException

encodeToFile

public void encodeToFile()
                  throws IPWorksSMIMEException
Encodes to file.

This method encodes the data given in Parts collection (either decoded file or decoded string) into a MIME message at Message and MessageHeaders using the values optionally given in Parts collection . To encode several objects into a MIME envelope, the user should first clear any old values left in the Parts collection .

The bean will check for each item in Parts collection (first decoded file and then the decoded string) for the data to encode.

The encoded message will be saved in the file pointed to by Message ; the message headers will be held by MessageHeaders .

Example (Encoding Data)

 MIMEControl.ResetData()
 MIMEControl.Parts.Add(new MIMEPart())
 MIMEControl.Parts.Add(new MIMEPart())
 
 MIMEControl.Parts[0].DecodedString = "This is plain text data"
 MIMEControl.Parts[0].Encoding = peQuotedPrintable
 MIMEControl.Parts[0].ContentType = "text/plain"
 MIMEControl.Parts[1].DecodedFile = "C:\filename.txt"
 
 MIMEControl.Message = "temp.tmp"
 MIMEControl.EncodeToFile() 

Throws:
IPWorksSMIMEException

encodeToStream

public void encodeToStream(java.io.OutputStream outputStream)
                    throws IPWorksSMIMEException
Encodes to stream.

This method encodes to stream. Same as EncodeToString but the encoded data is written to a stream instead of to the Message property.

This method encodes the data given in Parts collection into a MIME message. The Message gets written to the specified OutputStream and MessageHeaders using the values optionally given in Parts collection. To encode several objects into a MIME envelope, the user should first clear any old values left in the Parts collection by calling ResetData .

The bean will check each item in Parts collection (first decoded file and then decoded string) for the data to encode.

The encoded message will be written to the specified OutputStream , and the message headers will be held by MessageHeaders .

Example (Encoding Data)

 MIMEControl.ResetData()
 MIMEControl.Parts.Add(new MIMEPart())
 MIMEControl.Parts.Add(new MIMEPart())
 
 MIMEControl.Parts[0].DecodedString = "This is plain text data"
 MIMEControl.Parts[0].Encoding = peQuotedPrintable
 MIMEControl.Parts[0].ContentType = "text/plain"
 MIMEControl.Parts[1].DecodedFile = "C:\filename.txt"
 
 MIMEControl.EncodeToStream(OutputStream) 

Throws:
IPWorksSMIMEException

encodeToString

public void encodeToString()
                    throws IPWorksSMIMEException
Encodes to string.

This method encodes to string. Same as EncodeToFile but the encoded data is held in the Message property rather than saved to a file.

This method encodes the data given in Parts collection into a MIME message. The Message gets stored in Message and MessageHeaders using the values optionally given in Parts collection . To encode several objects into a MIME envelope, the user should first clear any old values left in the Parts collection by calling ResetData .

The bean will check each item in Parts collection (first decoded file and then decoded string) for the data to encode.

The encoded message will be stored in the Message property; the message headers will be held by MessageHeaders .

Example (Encoding Data)

 MIMEControl.ResetData()
 MIMEControl.Parts.Add(new MIMEPart())
 MIMEControl.Parts.Add(new MIMEPart())
 
 MIMEControl.Parts[0].DecodedString = "This is plain text data"
 MIMEControl.Parts[0].Encoding = peQuotedPrintable
 MIMEControl.Parts[0].ContentType = "text/plain"
 MIMEControl.Parts[1].DecodedFile = "C:\filename.txt"
 
 MIMEControl.EncodeToString() 

Throws:
IPWorksSMIMEException

resetData

public void resetData()
               throws IPWorksSMIMEException
Resets the values of all headers and Part- properties.

This method resets the values of all headers and Part- properties. It is an easy way to reset the bean's properties before starting to populate the Part- properties with new values.

Throws:
IPWorksSMIMEException

addMimeEventListener

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

removeMimeEventListener

public void removeMimeEventListener(MimeEventListener l)

IP*Works! S/MIME V9

Copyright (c) 2013 /n software inc. - All rights reserved.