2007-08-15 11:28:01 -03:00
|
|
|
:mod:`email`: Encoders
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
.. module:: email.encoders
|
|
|
|
:synopsis: Encoders for email message payloads.
|
|
|
|
|
|
|
|
|
Merged revisions 71540,71544,71546,71563,71572,71607,71653 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r71540 | georg.brandl | 2009-04-12 22:30:53 +0200 (So, 12 Apr 2009) | 1 line
#5719: add short usage example to optparse docstring.
........
r71544 | benjamin.peterson | 2009-04-13 01:19:56 +0200 (Mo, 13 Apr 2009) | 1 line
fix extra parenthesis #5774
........
r71546 | benjamin.peterson | 2009-04-13 01:44:15 +0200 (Mo, 13 Apr 2009) | 1 line
fix missing quote
........
r71563 | georg.brandl | 2009-04-13 14:36:18 +0200 (Mo, 13 Apr 2009) | 1 line
Simplify markup.
........
r71572 | georg.brandl | 2009-04-13 15:13:25 +0200 (Mo, 13 Apr 2009) | 1 line
#5745: more linking for identifiers in email docs.
........
r71607 | benjamin.peterson | 2009-04-14 23:23:09 +0200 (Di, 14 Apr 2009) | 1 line
tupel -> tuple
........
r71653 | raymond.hettinger | 2009-04-16 20:16:10 +0200 (Do, 16 Apr 2009) | 1 line
Clarify the behavior of any() and all() with an empty iterable.
........
2009-04-28 15:16:02 -03:00
|
|
|
When creating :class:`~email.message.Message` objects from scratch, you often
|
|
|
|
need to encode the payloads for transport through compliant mail servers. This
|
|
|
|
is especially true for :mimetype:`image/\*` and :mimetype:`text/\*` type messages
|
|
|
|
containing binary data.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
The :mod:`email` package provides some convenient encodings in its
|
|
|
|
:mod:`encoders` module. These encoders are actually used by the
|
Merged revisions 71540,71544,71546,71563,71572,71607,71653 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r71540 | georg.brandl | 2009-04-12 22:30:53 +0200 (So, 12 Apr 2009) | 1 line
#5719: add short usage example to optparse docstring.
........
r71544 | benjamin.peterson | 2009-04-13 01:19:56 +0200 (Mo, 13 Apr 2009) | 1 line
fix extra parenthesis #5774
........
r71546 | benjamin.peterson | 2009-04-13 01:44:15 +0200 (Mo, 13 Apr 2009) | 1 line
fix missing quote
........
r71563 | georg.brandl | 2009-04-13 14:36:18 +0200 (Mo, 13 Apr 2009) | 1 line
Simplify markup.
........
r71572 | georg.brandl | 2009-04-13 15:13:25 +0200 (Mo, 13 Apr 2009) | 1 line
#5745: more linking for identifiers in email docs.
........
r71607 | benjamin.peterson | 2009-04-14 23:23:09 +0200 (Di, 14 Apr 2009) | 1 line
tupel -> tuple
........
r71653 | raymond.hettinger | 2009-04-16 20:16:10 +0200 (Do, 16 Apr 2009) | 1 line
Clarify the behavior of any() and all() with an empty iterable.
........
2009-04-28 15:16:02 -03:00
|
|
|
:class:`~email.mime.audio.MIMEAudio` and :class:`~email.mime.image.MIMEImage`
|
|
|
|
class constructors to provide default encodings. All encoder functions take
|
|
|
|
exactly one argument, the message object to encode. They usually extract the
|
|
|
|
payload, encode it, and reset the payload to this newly encoded value. They
|
|
|
|
should also set the :mailheader:`Content-Transfer-Encoding` header as appropriate.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
Here are the encoding functions provided:
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: encode_quopri(msg)
|
|
|
|
|
|
|
|
Encodes the payload into quoted-printable form and sets the
|
|
|
|
:mailheader:`Content-Transfer-Encoding` header to ``quoted-printable`` [#]_.
|
|
|
|
This is a good encoding to use when most of your payload is normal printable
|
|
|
|
data, but contains a few unprintable characters.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: encode_base64(msg)
|
|
|
|
|
|
|
|
Encodes the payload into base64 form and sets the
|
|
|
|
:mailheader:`Content-Transfer-Encoding` header to ``base64``. This is a good
|
|
|
|
encoding to use when most of your payload is unprintable data since it is a more
|
|
|
|
compact form than quoted-printable. The drawback of base64 encoding is that it
|
|
|
|
renders the text non-human readable.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: encode_7or8bit(msg)
|
|
|
|
|
|
|
|
This doesn't actually modify the message's payload, but it does set the
|
|
|
|
:mailheader:`Content-Transfer-Encoding` header to either ``7bit`` or ``8bit`` as
|
|
|
|
appropriate, based on the payload data.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: encode_noop(msg)
|
|
|
|
|
|
|
|
This does nothing; it doesn't even set the
|
|
|
|
:mailheader:`Content-Transfer-Encoding` header.
|
|
|
|
|
|
|
|
.. rubric:: Footnotes
|
|
|
|
|
|
|
|
.. [#] Note that encoding with :meth:`encode_quopri` also encodes all tabs and space
|
|
|
|
characters in the data.
|
|
|
|
|