Previous section
To contents
Next section
14.11 MIME
RFC1521, the
Multipurpose Internet Mail Extensions memo, defines a
structure which is the base for all messages read and written by modern mail
and news programs. It is also partly the base for the HTTP protocol.
Just like RFC822,
MIME declares that a message should consist of two entities,
the headers and the body. In addition, the following properties are given
to these two entities:
- Headers
-
- Body
-
The MIME module can extract and analyze these two entities from a stream
of bytes. It can also recreate such a stream from these entities.
To encapsulate the headers and body entities, the class MIME.Message is
used. An object of this class holds all the headers as a mapping from
string to string, and it is possible to obtain the body data in either
raw or encoded form as a string. Common attributes such as message type and
text char set are also extracted into separate variables for easy access.
The Message class does not make any interpretation of the body data, unless
the content type is multipart. A multipart message contains several
individual messages separated by boundary strings. The create
method of the Message class will divide a multipart body on these boundaries,
and then create individual Message objects for each part. These objects
will be collected in the array body_parts within the original
Message object. If any of the new Message objects have a body of type
multipart, the process is of course repeated recursively. The following
figure illustrates a multipart message containing three parts, one of
which contains plain text, one containing a graphical image, and the third
containing raw uninterpreted data:
Previous section
To contents
Next section