次の方法で共有


MIME Architecture

Topic Last Modified: 2007-06-18

The Microsoft.Exchange.Data.Mime namespace provides classes that enable you to create, access, and modify Multipurpose Internet Mail Extensions (MIME) documents. You can work with MIME documents by using either a stream-based or DOM-based method. This topic describes the document class used for DOM-based manipulation of MIME content and the reader and writer classes used for stream-based manipulation of MIME content.

MimeDocument Class and the MIME DOM

The MimeDocument class enables DOM access to a MIME document. Use objects of this type when you have the available memory to load a whole DOM and you must have random access to the headers and content of the message.

You load data into a MimeDocument object by using the GetLoadStream or Load methods. You can then walk the DOM hierarchy and create, modify, or remove MIME data. After you have modified the MIME data, you can write it to a stream by using one of the WriteTo methods.

The following diagram shows the structure of data within a MimeDocument object.

Figure 1   Structure of MimeDocument objects
MIME DOM Architecture

MimeReader and MimeWriter Classes and Stream-Based MIME Parsing

The MimeReader and MimeWriter classes enable forward-only access to MIME streams. Use these classes when you do not have to change the MIME data that would depend on data that has already been read or written. For example, if you want to print messages that fit a predefined format, the MimeWriter class may be ideal.

Where the MimeDocument class encapsulates a DOM, the MimeReader and MimeWriter classes represent state computers. Their states change based on the input received and the methods called. Figures 2 through 5 are simplified state transition diagrams that show, for the MimeReader object, which methods are valid to call from each state and the state that will result.

To use these diagrams, follow the arrows from one state to the next, noting the method calls or return values that cause the state to change. For example, in the first diagram, assume that you are at the start of the stream that belongs to the MimeReader that you have created. To get to the 'Part Headers' state, call one of ReadNextPart or ReadFirstChildPart, in that order. If there are headers (that is, if the MIME is well-formed), you will enter into the 'Part Headers' state. Otherwise, an exception will be thrown.

Figure 2   Simplified state transition diagram for MimeReader objects
MimeReader State Diagram

Note

Figures 3, 4, and 5 expand on states in the previous diagrams.

Figure 3   Expansion of 'Part Headers' state from Figure 1
Expansion of 'Part Headers' state

Figure 4   Expansion of 'Header' state from Figure 2 when a parameter has been encountered in a header
Expansion of 'Part Headers' state

Note

The state represented by Figure 5 is recursive in that, if an address group is encountered, you can use the GroupRecipientReader property to read the addresses in the group.

Figure 5   Expansion of 'Header' state from Figure 2 when an address or address group is encountered
Expansion of 'Header' state for address or group

Figures 6 and 7 show simplified state transition diagrams for the MimeWriter object.

Note

Figure 7 expands on the 'Part Headers' state found in Figure 6.

Figure 6   Simplified state transition diagram for MimeWriter objects
State Transition Diagram for MimeWriter

Figure 7   Expansion of 'Part Headers' state from Figure 6
State Transition Diagram Expansion for MimeWriter