blob: 8da385e0ce5a697cef8734c29c2620a66f3fb4c0 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`mimetools` --- Tools for parsing MIME messages
3====================================================
4
5.. module:: mimetools
6 :synopsis: Tools for parsing MIME-style message bodies.
Guido van Rossumda27fd22007-08-17 00:24:54 +00007 :deprecated:
Georg Brandl116aa622007-08-15 14:28:22 +00008
9
10.. deprecated:: 2.3
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.
13
14.. index:: module: rfc822
15
16This module defines a subclass of the :mod:`rfc822` module's :class:`Message`
17class and a number of utility functions that are useful for the manipulation for
18MIME multipart or encoded message.
19
20It defines the following items:
21
22
23.. class:: Message(fp[, seekable])
24
25 Return a new instance of the :class:`Message` class. This is a subclass of the
26 :class:`rfc822.Message` class, with some additional methods (see below). The
27 *seekable* argument has the same meaning as for :class:`rfc822.Message`.
28
29
30.. function:: choose_boundary()
31
32 Return a unique string that has a high likelihood of being usable as a part
33 boundary. The string has the form ``'hostipaddr.uid.pid.timestamp.random'``.
34
35
36.. function:: decode(input, output, encoding)
37
38 Read data encoded using the allowed MIME *encoding* from open file object
39 *input* and write the decoded data to open file object *output*. Valid values
40 for *encoding* include ``'base64'``, ``'quoted-printable'``, ``'uuencode'``,
41 ``'x-uuencode'``, ``'uue'``, ``'x-uue'``, ``'7bit'``, and ``'8bit'``. Decoding
42 messages encoded in ``'7bit'`` or ``'8bit'`` has no effect. The input is simply
43 copied to the output.
44
45
46.. function:: encode(input, output, encoding)
47
48 Read data from open file object *input* and write it encoded using the allowed
49 MIME *encoding* to open file object *output*. Valid values for *encoding* are
50 the same as for :meth:`decode`.
51
52
53.. function:: copyliteral(input, output)
54
55 Read lines from open file *input* until EOF and write them to open file
56 *output*.
57
58
59.. function:: copybinary(input, output)
60
61 Read blocks until EOF from open file *input* and write them to open file
62 *output*. The block size is currently fixed at 8192.
63
64
65.. seealso::
66
67 Module :mod:`email`
68 Comprehensive email handling package; supersedes the :mod:`mimetools` module.
69
70 Module :mod:`rfc822`
71 Provides the base class for :class:`mimetools.Message`.
72
73 Module :mod:`multifile`
74 Support for reading files which contain distinct parts, such as MIME data.
75
76 http://www.cs.uu.nl/wais/html/na-dir/mail/mime-faq/.html
77 The MIME Frequently Asked Questions document. For an overview of MIME, see the
78 answer to question 1.1 in Part 1 of this document.
79
80
81.. _mimetools-message-objects:
82
83Additional Methods of Message Objects
84-------------------------------------
85
86The :class:`Message` class defines the following methods in addition to the
87:class:`rfc822.Message` methods:
88
89
90.. method:: Message.getplist()
91
92 Return the parameter list of the :mailheader:`Content-Type` header. This is a
93 list of strings. For parameters of the form ``key=value``, *key* is converted
94 to lower case but *value* is not. For example, if the message contains the
95 header ``Content-type: text/html; spam=1; Spam=2; Spam`` then :meth:`getplist`
96 will return the Python list ``['spam=1', 'spam=2', 'Spam']``.
97
98
99.. method:: Message.getparam(name)
100
101 Return the *value* of the first parameter (as returned by :meth:`getplist`) of
102 the form ``name=value`` for the given *name*. If *value* is surrounded by
103 quotes of the form '``<``...\ ``>``' or '``"``...\ ``"``', these are removed.
104
105
106.. method:: Message.getencoding()
107
108 Return the encoding specified in the :mailheader:`Content-Transfer-Encoding`
109 message header. If no such header exists, return ``'7bit'``. The encoding is
110 converted to lower case.
111
112
113.. method:: Message.gettype()
114
115 Return the message type (of the form ``type/subtype``) as specified in the
116 :mailheader:`Content-Type` header. If no such header exists, return
117 ``'text/plain'``. The type is converted to lower case.
118
119
120.. method:: Message.getmaintype()
121
122 Return the main type as specified in the :mailheader:`Content-Type` header. If
123 no such header exists, return ``'text'``. The main type is converted to lower
124 case.
125
126
127.. method:: Message.getsubtype()
128
129 Return the subtype as specified in the :mailheader:`Content-Type` header. If no
130 such header exists, return ``'plain'``. The subtype is converted to lower case.
131