| *outfp* for an argument. *outfp* must support the :meth:`write` method and be |
| usable as the output file in a Python extended print statement. |
| |
| Optional *mangle_from_* is a flag that, when ``True``, puts a ``>`` character in |
| front of any line in the body that starts exactly as ``From``, i.e. ``From`` |
| followed by a space at the beginning of the line. This is the only guaranteed |
| portable way to avoid having such lines be mistaken for a Unix mailbox format |
| envelope header separator (see `WHY THE CONTENT-LENGTH FORMAT IS BAD |
n | <http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html>`_ |
n | <http://www.jwz.org/doc/content-length.html>`_ for details). *mangle_from_* |
| for details). *mangle_from_* defaults to ``True``, but you might want to set |
| defaults to ``True``, but you might want to set this to ``False`` if you are not |
| this to ``False`` if you are not writing Unix mailbox format files. |
| writing Unix mailbox format files. |
| |
| Optional *maxheaderlen* specifies the longest length for a non-continued header. |
| When a header line is longer than *maxheaderlen* (in characters, with tabs |
| expanded to 8 spaces), the header will be split as defined in the |
| :mod:`email.header.Header` class. Set to zero to disable header wrapping. The |
| default is 78, as recommended (but not required) by :rfc:`2822`. |
| |
n | The other public :class:`Generator` methods are: |
n | The other public :class:`Generator` methods are: |
| |
| |
n | .. method:: Generator.flatten(msg[, unixfrom]) |
n | .. method:: flatten(msg[, unixfrom]) |
| |
n | Print the textual representation of the message object structure rooted at *msg* |
n | Print the textual representation of the message object structure rooted at |
| to the output file specified when the :class:`Generator` instance was created. |
| *msg* to the output file specified when the :class:`Generator` instance |
| Subparts are visited depth-first and the resulting text will be properly MIME |
| was created. Subparts are visited depth-first and the resulting text will |
| encoded. |
| be properly MIME encoded. |
| |
n | Optional *unixfrom* is a flag that forces the printing of the envelope header |
n | Optional *unixfrom* is a flag that forces the printing of the envelope |
| delimiter before the first :rfc:`2822` header of the root message object. If |
| header delimiter before the first :rfc:`2822` header of the root message |
| the root object has no envelope header, a standard one is crafted. By default, |
| object. If the root object has no envelope header, a standard one is |
| this is set to ``False`` to inhibit the printing of the envelope delimiter. |
| crafted. By default, this is set to ``False`` to inhibit the printing of |
| the envelope delimiter. |
| |
n | Note that for subparts, no envelope header is ever printed. |
n | Note that for subparts, no envelope header is ever printed. |
| |
n | .. versionadded:: 2.2.2 |
n | .. versionadded:: 2.2.2 |
| |
| |
n | .. method:: Generator.clone(fp) |
n | .. method:: clone(fp) |
| |
n | Return an independent clone of this :class:`Generator` instance with the exact |
n | Return an independent clone of this :class:`Generator` instance with the |
| same options. |
| exact same options. |
| |
n | .. versionadded:: 2.2.2 |
n | .. versionadded:: 2.2.2 |
| |
| |
n | .. method:: Generator.write(s) |
n | .. method:: write(s) |
| |
n | Write the string *s* to the underlying file object, i.e. *outfp* passed to |
n | Write the string *s* to the underlying file object, i.e. *outfp* passed to |
| :class:`Generator`'s constructor. This provides just enough file-like API for |
| :class:`Generator`'s constructor. This provides just enough file-like API |
| :class:`Generator` instances to be used in extended print statements. |
| for :class:`Generator` instances to be used in extended print statements. |
| |
| As a convenience, see the methods :meth:`Message.as_string` and |
| ``str(aMessage)``, a.k.a. :meth:`Message.__str__`, which simplify the generation |
| of a formatted string representation of a message object. For more detail, see |
| :mod:`email.message`. |
| |
| The :mod:`email.generator` module also provides a derived class, called |
| :class:`DecodedGenerator` which is like the :class:`Generator` base class, |
| message. If the subpart is of main type :mimetype:`text`, then it prints the |
| decoded payload of the subpart. Optional *_mangle_from_* and *maxheaderlen* are |
| as with the :class:`Generator` base class. |
| |
| If the subpart is not of main type :mimetype:`text`, optional *fmt* is a format |
| string that is used instead of the message payload. *fmt* is expanded with the |
| following keywords, ``%(keyword)s`` format: |
| |
n | * ``type`` -- Full MIME type of the non-\ :mimetype:`text` part |
n | * ``type`` -- Full MIME type of the non-\ :mimetype:`text` part |
| |
n | * ``maintype`` -- Main MIME type of the non-\ :mimetype:`text` part |
n | * ``maintype`` -- Main MIME type of the non-\ :mimetype:`text` part |
| |
n | * ``subtype`` -- Sub-MIME type of the non-\ :mimetype:`text` part |
n | * ``subtype`` -- Sub-MIME type of the non-\ :mimetype:`text` part |
| |
n | * ``filename`` -- Filename of the non-\ :mimetype:`text` part |
n | * ``filename`` -- Filename of the non-\ :mimetype:`text` part |
| |
n | * ``description`` -- Description associated with the non-\ :mimetype:`text` part |
n | * ``description`` -- Description associated with the non-\ :mimetype:`text` part |
| |
t | * ``encoding`` -- Content transfer encoding of the non-\ :mimetype:`text` part |
t | * ``encoding`` -- Content transfer encoding of the non-\ :mimetype:`text` part |
| |
| The default value for *fmt* is ``None``, meaning :: |
| |
| [Non-text (%(type)s) part of message omitted, filename %(filename)s] |
| |
| .. versionadded:: 2.2.2 |
| |
| .. versionchanged:: 2.5 |