mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00

svn+ssh://pythondev@svn.python.org/python/trunk ........ r68133 | antoine.pitrou | 2009-01-01 16:38:03 +0100 (Thu, 01 Jan 2009) | 1 line fill in actual issue number in tests ........ r68134 | hirokazu.yamamoto | 2009-01-01 16:45:39 +0100 (Thu, 01 Jan 2009) | 2 lines Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `str' filename on Windows. ........ r68141 | benjamin.peterson | 2009-01-01 17:43:12 +0100 (Thu, 01 Jan 2009) | 1 line fix highlighting ........ r68142 | benjamin.peterson | 2009-01-01 18:29:49 +0100 (Thu, 01 Jan 2009) | 2 lines welcome to 2009, Python! ........ r68145 | amaury.forgeotdarc | 2009-01-02 01:03:54 +0100 (Fri, 02 Jan 2009) | 5 lines #4801 _collections module fails to build on cygwin. _PyObject_GC_TRACK is the macro version of PyObject_GC_Track, and according to documentation it should not be used for extension modules. ........ r68146 | ronald.oussoren | 2009-01-02 11:44:46 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue4472: "configure --enable-shared doesn't work on OSX" ........ r68148 | ronald.oussoren | 2009-01-02 11:48:31 +0100 (Fri, 02 Jan 2009) | 2 lines Forgot to add a NEWS item in my previous checkin ........ r68149 | ronald.oussoren | 2009-01-02 11:50:48 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue4780 ........ r68159 | ronald.oussoren | 2009-01-02 15:48:17 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue 1627952 ........ r68160 | ronald.oussoren | 2009-01-02 15:52:09 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue r1737832 ........ r68161 | ronald.oussoren | 2009-01-02 16:00:05 +0100 (Fri, 02 Jan 2009) | 3 lines Fix for issue 1149804 ........ r68162 | ronald.oussoren | 2009-01-02 16:06:00 +0100 (Fri, 02 Jan 2009) | 3 lines Fix for issue 4472 is incompatible with Cygwin, this patch should fix that. ........ r68166 | benjamin.peterson | 2009-01-02 19:26:23 +0100 (Fri, 02 Jan 2009) | 1 line document PyMemberDef ........ r68171 | georg.brandl | 2009-01-02 21:25:14 +0100 (Fri, 02 Jan 2009) | 3 lines #4811: fix markup glitches (mostly remains of the conversion), found by Gabriel Genellina. ........ r68172 | martin.v.loewis | 2009-01-02 21:32:55 +0100 (Fri, 02 Jan 2009) | 2 lines Issue #4075: Use OutputDebugStringW in Py_FatalError. ........ r68173 | martin.v.loewis | 2009-01-02 21:40:14 +0100 (Fri, 02 Jan 2009) | 2 lines Issue #4051: Prevent conflict of UNICODE macros in cPickle. ........ r68174 | benjamin.peterson | 2009-01-02 21:47:27 +0100 (Fri, 02 Jan 2009) | 1 line fix compilation on non-Windows platforms ........ r68179 | raymond.hettinger | 2009-01-02 22:26:45 +0100 (Fri, 02 Jan 2009) | 1 line Issue #4615. Document how to use itertools for de-duping. ........ r68195 | georg.brandl | 2009-01-03 14:45:15 +0100 (Sat, 03 Jan 2009) | 2 lines Remove useless string literal. ........ r68196 | georg.brandl | 2009-01-03 15:29:53 +0100 (Sat, 03 Jan 2009) | 2 lines Fix indentation. ........ r68210 | georg.brandl | 2009-01-03 20:10:12 +0100 (Sat, 03 Jan 2009) | 2 lines Set eol-style correctly for mp_distributing.py. ........ r68214 | georg.brandl | 2009-01-03 20:44:48 +0100 (Sat, 03 Jan 2009) | 2 lines Make indentation consistent. ........ r68215 | georg.brandl | 2009-01-03 21:15:14 +0100 (Sat, 03 Jan 2009) | 2 lines Fix role name. ........ r68217 | georg.brandl | 2009-01-03 21:30:15 +0100 (Sat, 03 Jan 2009) | 2 lines Add rstlint, a little tool to find subtle markup problems and inconsistencies in the Doc sources. ........ r68218 | georg.brandl | 2009-01-03 21:38:59 +0100 (Sat, 03 Jan 2009) | 2 lines Recognize usage of the default role. ........ r68219 | georg.brandl | 2009-01-03 21:47:01 +0100 (Sat, 03 Jan 2009) | 2 lines Fix uses of the default role. ........ r68220 | georg.brandl | 2009-01-03 21:55:06 +0100 (Sat, 03 Jan 2009) | 2 lines Remove trailing whitespace. ........ r68221 | georg.brandl | 2009-01-03 22:04:55 +0100 (Sat, 03 Jan 2009) | 2 lines Remove tabs from the documentation. ........ r68222 | georg.brandl | 2009-01-03 22:11:58 +0100 (Sat, 03 Jan 2009) | 2 lines Disable the line length checker by default. ........
190 lines
8.4 KiB
ReStructuredText
190 lines
8.4 KiB
ReStructuredText
:mod:`email`: Creating email and MIME objects from scratch
|
|
----------------------------------------------------------
|
|
|
|
.. module:: email.mime
|
|
:synopsis: Build MIME messages.
|
|
|
|
|
|
Ordinarily, you get a message object structure by passing a file or some text to
|
|
a parser, which parses the text and returns the root message object. However
|
|
you can also build a complete message structure from scratch, or even individual
|
|
:class:`Message` objects by hand. In fact, you can also take an existing
|
|
structure and add new :class:`Message` objects, move them around, etc. This
|
|
makes a very convenient interface for slicing-and-dicing MIME messages.
|
|
|
|
You can create a new object structure by creating :class:`Message` instances,
|
|
adding attachments and all the appropriate headers manually. For MIME messages
|
|
though, the :mod:`email` package provides some convenient subclasses to make
|
|
things easier.
|
|
|
|
Here are the classes:
|
|
|
|
.. currentmodule:: email.mime.base
|
|
|
|
.. class:: MIMEBase(_maintype, _subtype, **_params)
|
|
|
|
Module: :mod:`email.mime.base`
|
|
|
|
This is the base class for all the MIME-specific subclasses of :class:`Message`.
|
|
Ordinarily you won't create instances specifically of :class:`MIMEBase`,
|
|
although you could. :class:`MIMEBase` is provided primarily as a convenient
|
|
base class for more specific MIME-aware subclasses.
|
|
|
|
*_maintype* is the :mailheader:`Content-Type` major type (e.g. :mimetype:`text`
|
|
or :mimetype:`image`), and *_subtype* is the :mailheader:`Content-Type` minor
|
|
type (e.g. :mimetype:`plain` or :mimetype:`gif`). *_params* is a parameter
|
|
key/value dictionary and is passed directly to :meth:`Message.add_header`.
|
|
|
|
The :class:`MIMEBase` class always adds a :mailheader:`Content-Type` header
|
|
(based on *_maintype*, *_subtype*, and *_params*), and a
|
|
:mailheader:`MIME-Version` header (always set to ``1.0``).
|
|
|
|
|
|
.. currentmodule:: email.mime.nonmultipart
|
|
|
|
.. class:: MIMENonMultipart()
|
|
|
|
Module: :mod:`email.mime.nonmultipart`
|
|
|
|
A subclass of :class:`MIMEBase`, this is an intermediate base class for MIME
|
|
messages that are not :mimetype:`multipart`. The primary purpose of this class
|
|
is to prevent the use of the :meth:`attach` method, which only makes sense for
|
|
:mimetype:`multipart` messages. If :meth:`attach` is called, a
|
|
:exc:`MultipartConversionError` exception is raised.
|
|
|
|
.. versionadded:: 2.2.2
|
|
|
|
|
|
.. currentmodule:: email.mime.multipart
|
|
|
|
.. class:: MIMEMultipart([_subtype[, boundary[, _subparts[, _params]]]])
|
|
|
|
Module: :mod:`email.mime.multipart`
|
|
|
|
A subclass of :class:`MIMEBase`, this is an intermediate base class for MIME
|
|
messages that are :mimetype:`multipart`. Optional *_subtype* defaults to
|
|
:mimetype:`mixed`, but can be used to specify the subtype of the message. A
|
|
:mailheader:`Content-Type` header of :mimetype:`multipart/_subtype` will be
|
|
added to the message object. A :mailheader:`MIME-Version` header will also be
|
|
added.
|
|
|
|
Optional *boundary* is the multipart boundary string. When ``None`` (the
|
|
default), the boundary is calculated when needed.
|
|
|
|
*_subparts* is a sequence of initial subparts for the payload. It must be
|
|
possible to convert this sequence to a list. You can always attach new subparts
|
|
to the message by using the :meth:`Message.attach` method.
|
|
|
|
Additional parameters for the :mailheader:`Content-Type` header are taken from
|
|
the keyword arguments, or passed into the *_params* argument, which is a keyword
|
|
dictionary.
|
|
|
|
.. versionadded:: 2.2.2
|
|
|
|
|
|
.. currentmodule:: email.mime.application
|
|
|
|
.. class:: MIMEApplication(_data[, _subtype[, _encoder[, **_params]]])
|
|
|
|
Module: :mod:`email.mime.application`
|
|
|
|
A subclass of :class:`MIMENonMultipart`, the :class:`MIMEApplication` class is
|
|
used to represent MIME message objects of major type :mimetype:`application`.
|
|
*_data* is a string containing the raw byte data. Optional *_subtype* specifies
|
|
the MIME subtype and defaults to :mimetype:`octet-stream`.
|
|
|
|
Optional *_encoder* is a callable (i.e. function) which will perform the actual
|
|
encoding of the data for transport. This callable takes one argument, which is
|
|
the :class:`MIMEApplication` instance. It should use :meth:`get_payload` and
|
|
:meth:`set_payload` to change the payload to encoded form. It should also add
|
|
any :mailheader:`Content-Transfer-Encoding` or other headers to the message
|
|
object as necessary. The default encoding is base64. See the
|
|
:mod:`email.encoders` module for a list of the built-in encoders.
|
|
|
|
*_params* are passed straight through to the base class constructor.
|
|
|
|
.. versionadded:: 2.5
|
|
|
|
|
|
.. currentmodule:: email.mime.audio
|
|
|
|
.. class:: MIMEAudio(_audiodata[, _subtype[, _encoder[, **_params]]])
|
|
|
|
Module: :mod:`email.mime.audio`
|
|
|
|
A subclass of :class:`MIMENonMultipart`, the :class:`MIMEAudio` class is used to
|
|
create MIME message objects of major type :mimetype:`audio`. *_audiodata* is a
|
|
string containing the raw audio data. If this data can be decoded by the
|
|
standard Python module :mod:`sndhdr`, then the subtype will be automatically
|
|
included in the :mailheader:`Content-Type` header. Otherwise you can explicitly
|
|
specify the audio subtype via the *_subtype* parameter. If the minor type could
|
|
not be guessed and *_subtype* was not given, then :exc:`TypeError` is raised.
|
|
|
|
Optional *_encoder* is a callable (i.e. function) which will perform the actual
|
|
encoding of the audio data for transport. This callable takes one argument,
|
|
which is the :class:`MIMEAudio` instance. It should use :meth:`get_payload` and
|
|
:meth:`set_payload` to change the payload to encoded form. It should also add
|
|
any :mailheader:`Content-Transfer-Encoding` or other headers to the message
|
|
object as necessary. The default encoding is base64. See the
|
|
:mod:`email.encoders` module for a list of the built-in encoders.
|
|
|
|
*_params* are passed straight through to the base class constructor.
|
|
|
|
|
|
.. currentmodule:: email.mime.image
|
|
|
|
.. class:: MIMEImage(_imagedata[, _subtype[, _encoder[, **_params]]])
|
|
|
|
Module: :mod:`email.mime.image`
|
|
|
|
A subclass of :class:`MIMENonMultipart`, the :class:`MIMEImage` class is used to
|
|
create MIME message objects of major type :mimetype:`image`. *_imagedata* is a
|
|
string containing the raw image data. If this data can be decoded by the
|
|
standard Python module :mod:`imghdr`, then the subtype will be automatically
|
|
included in the :mailheader:`Content-Type` header. Otherwise you can explicitly
|
|
specify the image subtype via the *_subtype* parameter. If the minor type could
|
|
not be guessed and *_subtype* was not given, then :exc:`TypeError` is raised.
|
|
|
|
Optional *_encoder* is a callable (i.e. function) which will perform the actual
|
|
encoding of the image data for transport. This callable takes one argument,
|
|
which is the :class:`MIMEImage` instance. It should use :meth:`get_payload` and
|
|
:meth:`set_payload` to change the payload to encoded form. It should also add
|
|
any :mailheader:`Content-Transfer-Encoding` or other headers to the message
|
|
object as necessary. The default encoding is base64. See the
|
|
:mod:`email.encoders` module for a list of the built-in encoders.
|
|
|
|
*_params* are passed straight through to the :class:`MIMEBase` constructor.
|
|
|
|
|
|
.. currentmodule:: email.mime.message
|
|
|
|
.. class:: MIMEMessage(_msg[, _subtype])
|
|
|
|
Module: :mod:`email.mime.message`
|
|
|
|
A subclass of :class:`MIMENonMultipart`, the :class:`MIMEMessage` class is used
|
|
to create MIME objects of main type :mimetype:`message`. *_msg* is used as the
|
|
payload, and must be an instance of class :class:`Message` (or a subclass
|
|
thereof), otherwise a :exc:`TypeError` is raised.
|
|
|
|
Optional *_subtype* sets the subtype of the message; it defaults to
|
|
:mimetype:`rfc822`.
|
|
|
|
|
|
.. currentmodule:: email.mime.text
|
|
|
|
.. class:: MIMEText(_text[, _subtype[, _charset]])
|
|
|
|
Module: :mod:`email.mime.text`
|
|
|
|
A subclass of :class:`MIMENonMultipart`, the :class:`MIMEText` class is used to
|
|
create MIME objects of major type :mimetype:`text`. *_text* is the string for
|
|
the payload. *_subtype* is the minor type and defaults to :mimetype:`plain`.
|
|
*_charset* is the character set of the text and is passed as a parameter to the
|
|
:class:`MIMENonMultipart` constructor; it defaults to ``us-ascii``. No guessing
|
|
or encoding is performed on the text data.
|
|
|
|
.. versionchanged:: 2.4
|
|
The previously deprecated *_encoding* argument has been removed. Encoding
|
|
happens implicitly based on the *_charset* argument.
|
|
|