12.3.3 Generating MIME documents

The mimelib.Generator class (hereafter referred to as Generator) is used to render a message object model into its flat text representation, including MIME encoding any sub-messages, generating the correct RFC 822 headers, etc.

The constructor for the Generator class takes a file-like object called outfp for an argument. outfp must support the write() method and be usable as the output file in a Python 2.0 extended print statement.

The other public Generator methods are:

write (msg[, unixfrom])
Print the textual representation of the message object model rooted at msg to the output file specified when the Generator instance was created. Sub-objects are visited correctly and the resulting text will be properly MIME encoded.

Optional unixfrom is a flag that forces the printing of the ``Unix-From'' (a.k.a. envelope header or From_ header) delimiter before the first header of the root message object. If the root object has no ``Unix-From'' header, a standard one is crafted. Set this to 0 to inhibit the printing of the ``Unix-From'' delimiter (the default value of this flag is 1).

Note that for sub-objects, no ``Unix-From'' header is ever printed.

See About this document... for information on suggesting changes.