email.generator.Generator.flatten()

flatten(msg, unixfrom=False, linesep=None)

Print the textual representation of the message object structure rooted at msg to the output file specified when the Generator instance was created. Subparts are visited depth-first and the resulting text will be properly MIME encoded.

Optional unixfrom is a flag that forces the printing of the envelope header delimiter before the first RFC 2822 header of the root message object. If the root object has no envelope header, a standard one is crafted. By default, this is set to False to inhibit the printing of the envelope delimiter.

Note that for subparts, no envelope header is ever printed.

Optional linesep specifies the line separator character used to terminate lines in the output. If specified it overrides the value specified by the msg‘s or Generator‘s policy.

Because strings cannot represent non-ASCII bytes, if the policy that applies when flatten is run has cte_type set to 8bit, Generator will operate as if it were set to 7bit. This means that messages parsed with a Bytes parser that have a Content-Transfer-Encoding of 8bit will be converted to a use a 7bit Content-Transfer-Encoding. Non-ASCII bytes in the headers will be RFC 2047 encoded with a charset of unknown-8bit.

Changed in version 3.2: Added support for re-encoding 8bit message bodies, and the linesep argument.

doc_python
2016-10-07 17:32:25
Comments
Leave a Comment

Please login to continue.