Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 1 | % Copyright (C) 2001,2002 Python Software Foundation |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 2 | % Author: barry@zope.com (Barry Warsaw) |
| 3 | |
Fred Drake | a6a885b | 2001-09-26 16:52:18 +0000 | [diff] [blame] | 4 | \section{\module{email} --- |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 5 | An email and MIME handling package} |
| 6 | |
| 7 | \declaremodule{standard}{email} |
| 8 | \modulesynopsis{Package supporting the parsing, manipulating, and |
| 9 | generating email messages, including MIME documents.} |
| 10 | \moduleauthor{Barry A. Warsaw}{barry@zope.com} |
Fred Drake | 90e6878 | 2001-09-27 20:09:39 +0000 | [diff] [blame] | 11 | \sectionauthor{Barry A. Warsaw}{barry@zope.com} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 12 | |
| 13 | \versionadded{2.2} |
| 14 | |
| 15 | The \module{email} package is a library for managing email messages, |
| 16 | including MIME and other \rfc{2822}-based message documents. It |
| 17 | subsumes most of the functionality in several older standard modules |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 18 | such as \refmodule{rfc822}, \refmodule{mimetools}, |
| 19 | \refmodule{multifile}, and other non-standard packages such as |
Barry Warsaw | 5e17d20 | 2001-11-16 22:16:04 +0000 | [diff] [blame] | 20 | \module{mimecntl}. It is specifically \emph{not} designed to do any |
| 21 | sending of email messages to SMTP (\rfc{2821}) servers; that is the |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 22 | function of the \refmodule{smtplib} module. The \module{email} |
| 23 | package attempts to be as RFC-compliant as possible, supporting in |
| 24 | addition to \rfc{2822}, such MIME-related RFCs as |
| 25 | \rfc{2045}-\rfc{2047}, and \rfc{2231}. |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 26 | |
| 27 | The primary distinguishing feature of the \module{email} package is |
| 28 | that it splits the parsing and generating of email messages from the |
| 29 | internal \emph{object model} representation of email. Applications |
| 30 | using the \module{email} package deal primarily with objects; you can |
| 31 | add sub-objects to messages, remove sub-objects from messages, |
| 32 | completely re-arrange the contents, etc. There is a separate parser |
| 33 | and a separate generator which handles the transformation from flat |
Andrew M. Kuchling | 43dc1fc | 2001-11-05 01:55:03 +0000 | [diff] [blame] | 34 | text to the object model, and then back to flat text again. There |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 35 | are also handy subclasses for some common MIME object types, and a few |
| 36 | miscellaneous utilities that help with such common tasks as extracting |
| 37 | and parsing message field values, creating RFC-compliant dates, etc. |
| 38 | |
| 39 | The following sections describe the functionality of the |
| 40 | \module{email} package. The ordering follows a progression that |
| 41 | should be common in applications: an email message is read as flat |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 42 | text from a file or other source, the text is parsed to produce the |
| 43 | object structure of the email message, this structure is manipulated, |
| 44 | and finally rendered back into flat text. |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 45 | |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 46 | It is perfectly feasible to create the object structure out of whole |
| 47 | cloth --- i.e. completely from scratch. From there, a similar |
| 48 | progression can be taken as above. |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 49 | |
| 50 | Also included are detailed specifications of all the classes and |
| 51 | modules that the \module{email} package provides, the exception |
| 52 | classes you might encounter while using the \module{email} package, |
| 53 | some auxiliary utilities, and a few examples. For users of the older |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 54 | \module{mimelib} package, or previous versions of the \module{email} |
| 55 | package, a section on differences and porting is provided. |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 56 | |
Barry Warsaw | 5e17d20 | 2001-11-16 22:16:04 +0000 | [diff] [blame] | 57 | \begin{seealso} |
| 58 | \seemodule{smtplib}{SMTP protocol client} |
| 59 | \end{seealso} |
| 60 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 61 | \subsection{Representing an email message} |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 62 | \input{emailmessage} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 63 | |
| 64 | \subsection{Parsing email messages} |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 65 | \input{emailparser} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 66 | |
| 67 | \subsection{Generating MIME documents} |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 68 | \input{emailgenerator} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 69 | |
| 70 | \subsection{Creating email and MIME objects from scratch} |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 71 | \input{emailmimebase} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 72 | |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 73 | \subsection{Internationalized headers} |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 74 | \input{emailheaders} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 75 | |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 76 | \subsection{Representing character sets} |
| 77 | \input{emailcharsets} |
| 78 | |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 79 | \subsection{Encoders} |
| 80 | \input{emailencoders} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 81 | |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 82 | \subsection{Exception classes} |
| 83 | \input{emailexc} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 84 | |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 85 | \subsection{Miscellaneous utilities} |
| 86 | \input{emailutil} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 87 | |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 88 | \subsection{Iterators} |
| 89 | \input{emailiter} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 90 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 91 | \subsection{Differences from \module{email} v1 (up to Python 2.2.1)} |
| 92 | |
| 93 | Version 1 of the \module{email} package was bundled with Python |
| 94 | releases up to Python 2.2.1. Version 2 was developed for the Python |
| 95 | 2.3 release, and backported to Python 2.2.2. It was also available as |
| 96 | a separate distutils based package. \module{email} version 2 is |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 97 | almost entirely backward compatible with version 1, with the |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 98 | following differences: |
| 99 | |
| 100 | \begin{itemize} |
| 101 | \item The \module{email.Header} and \module{email.Charset} modules |
| 102 | have been added. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 103 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 104 | \item The pickle format for \class{Message} instances has changed. |
| 105 | Since this was never (and still isn't) formally defined, this |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 106 | isn't considered a backward incompatibility. However if your |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 107 | application pickles and unpickles \class{Message} instances, be |
| 108 | aware that in \module{email} version 2, \class{Message} |
| 109 | instances now have private variables \var{_charset} and |
| 110 | \var{_default_type}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 111 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 112 | \item Several methods in the \class{Message} class have been |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 113 | deprecated, or their signatures changed. Also, many new methods |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 114 | have been added. See the documentation for the \class{Message} |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 115 | class for details. The changes should be completely backward |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 116 | compatible. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 117 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 118 | \item The object structure has changed in the face of |
| 119 | \mimetype{message/rfc822} content types. In \module{email} |
| 120 | version 1, such a type would be represented by a scalar payload, |
| 121 | i.e. the container message's \method{is_multipart()} returned |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 122 | false, \method{get_payload()} was not a list object, but a single |
| 123 | \class{Message} instance. |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 124 | |
| 125 | This structure was inconsistent with the rest of the package, so |
| 126 | the object representation for \mimetype{message/rfc822} content |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 127 | types was changed. In \module{email} version 2, the container |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 128 | \emph{does} return \code{True} from \method{is_multipart()}, and |
| 129 | \method{get_payload()} returns a list containing a single |
| 130 | \class{Message} item. |
| 131 | |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 132 | Note that this is one place that backward compatibility could |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 133 | not be completely maintained. However, if you're already |
| 134 | testing the return type of \method{get_payload()}, you should be |
| 135 | fine. You just need to make sure your code doesn't do a |
| 136 | \method{set_payload()} with a \class{Message} instance on a |
| 137 | container with a content type of \mimetype{message/rfc822}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 138 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 139 | \item The \class{Parser} constructor's \var{strict} argument was |
| 140 | added, and its \method{parse()} and \method{parsestr()} methods |
| 141 | grew a \var{headersonly} argument. The \var{strict} flag was |
| 142 | also added to functions \function{email.message_from_file()} |
| 143 | and \function{email.message_from_string()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 144 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 145 | \item \method{Generator.__call__()} is deprecated; use |
| 146 | \method{Generator.flatten()} instead. The \class{Generator} |
| 147 | class has also grown the \method{clone()} method. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 148 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 149 | \item The \class{DecodedGenerator} class in the |
| 150 | \module{email.Generator} module was added. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 151 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 152 | \item The intermediate base classes \class{MIMENonMultipart} and |
| 153 | \class{MIMEMultipart} have been added, and interposed in the |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 154 | class hierarchy for most of the other MIME-related derived |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 155 | classes. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 156 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 157 | \item The \var{_encoder} argument to the \class{MIMEText} constructor |
| 158 | has been deprecated. Encoding now happens implicitly based |
| 159 | on the \var{_charset} argument. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 160 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 161 | \item The following functions in the \module{email.Utils} module have |
| 162 | been deprecated: \function{dump_address_pairs()}, |
| 163 | \function{decode()}, and \function{encode()}. The following |
| 164 | functions have been added to the module: |
| 165 | \function{make_msgid()}, \function{decode_rfc2231()}, |
| 166 | \function{encode_rfc2231()}, and \function{decode_params()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 167 | |
Barry Warsaw | 5b9da89 | 2002-10-01 01:05:52 +0000 | [diff] [blame] | 168 | \item The non-public function \function{email.Iterators._structure()} |
| 169 | was added. |
| 170 | \end{itemize} |
| 171 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 172 | \subsection{Differences from \module{mimelib}} |
| 173 | |
| 174 | The \module{email} package was originally prototyped as a separate |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 175 | library called |
| 176 | \ulink{\module{mimelib}}{http://mimelib.sf.net/}. |
| 177 | Changes have been made so that |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 178 | method names are more consistent, and some methods or modules have |
| 179 | either been added or removed. The semantics of some of the methods |
| 180 | have also changed. For the most part, any functionality available in |
Fred Drake | 90e6878 | 2001-09-27 20:09:39 +0000 | [diff] [blame] | 181 | \module{mimelib} is still available in the \refmodule{email} package, |
Barry Warsaw | 5db478f | 2002-10-01 04:33:16 +0000 | [diff] [blame] | 182 | albeit often in a different way. Backward compatibility between |
| 183 | the \module{mimelib} package and the \module{email} package was not a |
| 184 | priority. |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 185 | |
| 186 | Here is a brief description of the differences between the |
Fred Drake | 90e6878 | 2001-09-27 20:09:39 +0000 | [diff] [blame] | 187 | \module{mimelib} and the \refmodule{email} packages, along with hints on |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 188 | how to port your applications. |
| 189 | |
| 190 | Of course, the most visible difference between the two packages is |
Fred Drake | 90e6878 | 2001-09-27 20:09:39 +0000 | [diff] [blame] | 191 | that the package name has been changed to \refmodule{email}. In |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 192 | addition, the top-level package has the following differences: |
| 193 | |
| 194 | \begin{itemize} |
| 195 | \item \function{messageFromString()} has been renamed to |
| 196 | \function{message_from_string()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 197 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 198 | \item \function{messageFromFile()} has been renamed to |
| 199 | \function{message_from_file()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 200 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 201 | \end{itemize} |
| 202 | |
| 203 | The \class{Message} class has the following differences: |
| 204 | |
| 205 | \begin{itemize} |
| 206 | \item The method \method{asString()} was renamed to \method{as_string()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 207 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 208 | \item The method \method{ismultipart()} was renamed to |
| 209 | \method{is_multipart()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 210 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 211 | \item The \method{get_payload()} method has grown a \var{decode} |
| 212 | optional argument. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 213 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 214 | \item The method \method{getall()} was renamed to \method{get_all()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 215 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 216 | \item The method \method{addheader()} was renamed to \method{add_header()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 217 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 218 | \item The method \method{gettype()} was renamed to \method{get_type()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 219 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 220 | \item The method\method{getmaintype()} was renamed to |
| 221 | \method{get_main_type()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 222 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 223 | \item The method \method{getsubtype()} was renamed to |
| 224 | \method{get_subtype()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 225 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 226 | \item The method \method{getparams()} was renamed to |
| 227 | \method{get_params()}. |
| 228 | Also, whereas \method{getparams()} returned a list of strings, |
| 229 | \method{get_params()} returns a list of 2-tuples, effectively |
Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame] | 230 | the key/value pairs of the parameters, split on the \character{=} |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 231 | sign. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 232 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 233 | \item The method \method{getparam()} was renamed to \method{get_param()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 234 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 235 | \item The method \method{getcharsets()} was renamed to |
| 236 | \method{get_charsets()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 237 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 238 | \item The method \method{getfilename()} was renamed to |
| 239 | \method{get_filename()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 240 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 241 | \item The method \method{getboundary()} was renamed to |
| 242 | \method{get_boundary()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 243 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 244 | \item The method \method{setboundary()} was renamed to |
| 245 | \method{set_boundary()}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 246 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 247 | \item The method \method{getdecodedpayload()} was removed. To get |
| 248 | similar functionality, pass the value 1 to the \var{decode} flag |
| 249 | of the {get_payload()} method. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 250 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 251 | \item The method \method{getpayloadastext()} was removed. Similar |
| 252 | functionality |
| 253 | is supported by the \class{DecodedGenerator} class in the |
| 254 | \refmodule{email.Generator} module. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 255 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 256 | \item The method \method{getbodyastext()} was removed. You can get |
| 257 | similar functionality by creating an iterator with |
| 258 | \function{typed_subpart_iterator()} in the |
| 259 | \refmodule{email.Iterators} module. |
| 260 | \end{itemize} |
| 261 | |
| 262 | The \class{Parser} class has no differences in its public interface. |
| 263 | It does have some additional smarts to recognize |
Fred Drake | a6a885b | 2001-09-26 16:52:18 +0000 | [diff] [blame] | 264 | \mimetype{message/delivery-status} type messages, which it represents as |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 265 | a \class{Message} instance containing separate \class{Message} |
| 266 | subparts for each header block in the delivery status |
| 267 | notification\footnote{Delivery Status Notifications (DSN) are defined |
Fred Drake | 90e6878 | 2001-09-27 20:09:39 +0000 | [diff] [blame] | 268 | in \rfc{1894}.}. |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 269 | |
| 270 | The \class{Generator} class has no differences in its public |
| 271 | interface. There is a new class in the \refmodule{email.Generator} |
| 272 | module though, called \class{DecodedGenerator} which provides most of |
| 273 | the functionality previously available in the |
| 274 | \method{Message.getpayloadastext()} method. |
| 275 | |
| 276 | The following modules and classes have been changed: |
| 277 | |
| 278 | \begin{itemize} |
| 279 | \item The \class{MIMEBase} class constructor arguments \var{_major} |
| 280 | and \var{_minor} have changed to \var{_maintype} and |
| 281 | \var{_subtype} respectively. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 282 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 283 | \item The \code{Image} class/module has been renamed to |
| 284 | \code{MIMEImage}. The \var{_minor} argument has been renamed to |
| 285 | \var{_subtype}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 286 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 287 | \item The \code{Text} class/module has been renamed to |
| 288 | \code{MIMEText}. The \var{_minor} argument has been renamed to |
| 289 | \var{_subtype}. |
Barry Warsaw | dd868d3 | 2002-10-01 15:29:09 +0000 | [diff] [blame^] | 290 | |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 291 | \item The \code{MessageRFC822} class/module has been renamed to |
| 292 | \code{MIMEMessage}. Note that an earlier version of |
| 293 | \module{mimelib} called this class/module \code{RFC822}, but |
| 294 | that clashed with the Python standard library module |
| 295 | \refmodule{rfc822} on some case-insensitive file systems. |
| 296 | |
| 297 | Also, the \class{MIMEMessage} class now represents any kind of |
Fred Drake | a6a885b | 2001-09-26 16:52:18 +0000 | [diff] [blame] | 298 | MIME message with main type \mimetype{message}. It takes an |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 299 | optional argument \var{_subtype} which is used to set the MIME |
Fred Drake | a6a885b | 2001-09-26 16:52:18 +0000 | [diff] [blame] | 300 | subtype. \var{_subtype} defaults to \mimetype{rfc822}. |
Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 301 | \end{itemize} |
| 302 | |
| 303 | \module{mimelib} provided some utility functions in its |
| 304 | \module{address} and \module{date} modules. All of these functions |
| 305 | have been moved to the \refmodule{email.Utils} module. |
| 306 | |
| 307 | The \code{MsgReader} class/module has been removed. Its functionality |
| 308 | is most closely supported in the \function{body_line_iterator()} |
| 309 | function in the \refmodule{email.Iterators} module. |
| 310 | |
| 311 | \subsection{Examples} |
| 312 | |
Barry Warsaw | 2bb077f | 2001-11-05 17:50:53 +0000 | [diff] [blame] | 313 | Here are a few examples of how to use the \module{email} package to |
| 314 | read, write, and send simple email messages, as well as more complex |
| 315 | MIME messages. |
| 316 | |
| 317 | First, let's see how to create and send a simple text message: |
| 318 | |
Fred Drake | fcc31b4 | 2002-10-01 14:17:10 +0000 | [diff] [blame] | 319 | \verbatiminput{email-simple.py} |
Barry Warsaw | 2bb077f | 2001-11-05 17:50:53 +0000 | [diff] [blame] | 320 | |
| 321 | Here's an example of how to send a MIME message containing a bunch of |
Barry Warsaw | ea66abc | 2002-10-01 04:48:06 +0000 | [diff] [blame] | 322 | family pictures that may be residing in a directory: |
Barry Warsaw | 2bb077f | 2001-11-05 17:50:53 +0000 | [diff] [blame] | 323 | |
Fred Drake | fcc31b4 | 2002-10-01 14:17:10 +0000 | [diff] [blame] | 324 | \verbatiminput{email-mime.py} |
Barry Warsaw | 2bb077f | 2001-11-05 17:50:53 +0000 | [diff] [blame] | 325 | |
| 326 | Here's an example\footnote{Thanks to Matthew Dixon Cowles for the |
| 327 | original inspiration and examples.} of how to send the entire contents |
| 328 | of a directory as an email message: |
| 329 | |
Fred Drake | fcc31b4 | 2002-10-01 14:17:10 +0000 | [diff] [blame] | 330 | \verbatiminput{email-dir.py} |
Barry Warsaw | 2bb077f | 2001-11-05 17:50:53 +0000 | [diff] [blame] | 331 | |
| 332 | And finally, here's an example of how to unpack a MIME message like |
| 333 | the one above, into a directory of files: |
| 334 | |
Fred Drake | fcc31b4 | 2002-10-01 14:17:10 +0000 | [diff] [blame] | 335 | \verbatiminput{email-unpack.py} |