2 :mod:`mimetools` --- Tools for parsing MIME messages
3 ====================================================
6 :synopsis: Tools for parsing MIME-style message bodies.
11 The :mod:`email` package should be used in preference to the :mod:`mimetools`
12 module. This module is present only to maintain backward compatibility, and
13 it has been removed in 3.x.
15 .. index:: module: rfc822
17 This module defines a subclass of the :mod:`rfc822` module's :class:`Message`
18 class and a number of utility functions that are useful for the manipulation for
19 MIME multipart or encoded message.
21 It defines the following items:
24 .. class:: Message(fp[, seekable])
26 Return a new instance of the :class:`Message` class. This is a subclass of the
27 :class:`rfc822.Message` class, with some additional methods (see below). The
28 *seekable* argument has the same meaning as for :class:`rfc822.Message`.
31 .. function:: choose_boundary()
33 Return a unique string that has a high likelihood of being usable as a part
34 boundary. The string has the form ``'hostipaddr.uid.pid.timestamp.random'``.
37 .. function:: decode(input, output, encoding)
39 Read data encoded using the allowed MIME *encoding* from open file object
40 *input* and write the decoded data to open file object *output*. Valid values
41 for *encoding* include ``'base64'``, ``'quoted-printable'``, ``'uuencode'``,
42 ``'x-uuencode'``, ``'uue'``, ``'x-uue'``, ``'7bit'``, and ``'8bit'``. Decoding
43 messages encoded in ``'7bit'`` or ``'8bit'`` has no effect. The input is simply
47 .. function:: encode(input, output, encoding)
49 Read data from open file object *input* and write it encoded using the allowed
50 MIME *encoding* to open file object *output*. Valid values for *encoding* are
51 the same as for :meth:`decode`.
54 .. function:: copyliteral(input, output)
56 Read lines from open file *input* until EOF and write them to open file
60 .. function:: copybinary(input, output)
62 Read blocks until EOF from open file *input* and write them to open file
63 *output*. The block size is currently fixed at 8192.
69 Comprehensive email handling package; supersedes the :mod:`mimetools` module.
72 Provides the base class for :class:`mimetools.Message`.
74 Module :mod:`multifile`
75 Support for reading files which contain distinct parts, such as MIME data.
77 http://faqs.cs.uu.nl/na-dir/mail/mime-faq/.html
78 The MIME Frequently Asked Questions document. For an overview of MIME, see the
79 answer to question 1.1 in Part 1 of this document.
82 .. _mimetools-message-objects:
84 Additional Methods of Message Objects
85 -------------------------------------
87 The :class:`Message` class defines the following methods in addition to the
88 :class:`rfc822.Message` methods:
91 .. method:: Message.getplist()
93 Return the parameter list of the :mailheader:`Content-Type` header. This is a
94 list of strings. For parameters of the form ``key=value``, *key* is converted
95 to lower case but *value* is not. For example, if the message contains the
96 header ``Content-type: text/html; spam=1; Spam=2; Spam`` then :meth:`getplist`
97 will return the Python list ``['spam=1', 'spam=2', 'Spam']``.
100 .. method:: Message.getparam(name)
102 Return the *value* of the first parameter (as returned by :meth:`getplist`) of
103 the form ``name=value`` for the given *name*. If *value* is surrounded by
104 quotes of the form '``<``...\ ``>``' or '``"``...\ ``"``', these are removed.
107 .. method:: Message.getencoding()
109 Return the encoding specified in the :mailheader:`Content-Transfer-Encoding`
110 message header. If no such header exists, return ``'7bit'``. The encoding is
111 converted to lower case.
114 .. method:: Message.gettype()
116 Return the message type (of the form ``type/subtype``) as specified in the
117 :mailheader:`Content-Type` header. If no such header exists, return
118 ``'text/plain'``. The type is converted to lower case.
121 .. method:: Message.getmaintype()
123 Return the main type as specified in the :mailheader:`Content-Type` header. If
124 no such header exists, return ``'text'``. The main type is converted to lower
128 .. method:: Message.getsubtype()
130 Return the subtype as specified in the :mailheader:`Content-Type` header. If no
131 such header exists, return ``'plain'``. The subtype is converted to lower case.