Ordinarily, you get a message object tree by passing some text to a Parser instance, which parses the text and returns the root of the represented object tree. Then you can manipulate that tree before transforming the object tree back into text with a Generator instance. However you can also build a complete object tree from scratch, or even individual Message object, by hand. In fact, you can also take an existing object tree and add new Message objects to the tree before generating the output text.
You can create a new message object tree by creating Message instances, adding payloads, and all the appropriate headers manually, but for MIME messages, mimelib provides some convenient classes to make things easier. Each of these classes should be imported from a module with the same name as the class, from within the mimelib package. E.g.:
import mimelib.Image.Image
or
from mimelib.Text import Text
_major is the Content-Type:
major type (e.g. ``text'' or
``image''), and _minor is the Content-Type:
minor type
(e.g. ``plain'' or ``gif''). _params is a parameter key/value
dictionary and is passed directly to Message.addheader().
The MIMEBase class always adds a Content-Type:
header
(based on _major, _minor, and _params), and a
MIME-Version:
header (always set to ``1.0'').
A subclass of MIMEBase, the Image class is used to
create MIME message objects of major type ``image''. _imagedata
is a string containing the raw image data. If this data can be
decoded by the standard Python module imghdr, then the
subtype will be automatically included in the Content-Type:
header. Otherwise you can explicitly specify the image subtype via
the _minor parameter. If the minor type could not be guessed
and _minor was not given, then ImageTypeError is
raised.
_encoding is a callable (i.e. function) which will perform the
actual encoding of the image data for transport. The callable takes
one argument, which is the Image object instance. It should
use get_payload() and set_payload() to change the
payload to encoded form. It should also add any
Content-Transfer-Encoding:
or other headers to the message
object as necessary. The default encoding is base64.
_params are passed straight through to the MIMEBase constructor.
See About this document... for information on suggesting changes.