blob: a9cc09f90b986f80f27f6c62616d7a7989c2d6d8 [file] [log] [blame]
Fred Drake28bc7111999-02-12 19:26:09 +00001\section{\module{MimeWriter} ---
2 Generic MIME file writer}
3
4\declaremodule{standard}{MimeWriter}
5
6\modulesynopsis{Generic MIME file writer.}
7\sectionauthor{Christopher G. Petrilli}{petrilli@amber.org}
8
Fred Drake46138762002-09-25 22:13:27 +00009\deprecated{2.3}{The \refmodule{email} package should be used in
10 preference to the \module{MimeWriter} module. This
11 module is present only to maintain backward
12 compatibility.}
13
Fred Drake28bc7111999-02-12 19:26:09 +000014This module defines the class \class{MimeWriter}. The
15\class{MimeWriter} class implements a basic formatter for creating
16MIME multi-part files. It doesn't seek around the output file nor
17does it use large amounts of buffer space. You must write the parts
18out in the order that they should occur in the final
19file. \class{MimeWriter} does buffer the headers you add, allowing you
20to rearrange their order.
21
22\begin{classdesc}{MimeWriter}{fp}
23Return a new instance of the \class{MimeWriter} class. The only
24argument passed, \var{fp}, is a file object to be used for
25writing. Note that a \class{StringIO} object could also be used.
26\end{classdesc}
27
28
29\subsection{MimeWriter Objects \label{MimeWriter-objects}}
30
31
32\class{MimeWriter} instances have the following methods:
33
34\begin{methoddesc}{addheader}{key, value\optional{, prefix}}
35Add a header line to the MIME message. The \var{key} is the name of
36the header, where the \var{value} obviously provides the value of the
37header. The optional argument \var{prefix} determines where the header
38is inserted; \samp{0} means append at the end, \samp{1} is insert at
39the start. The default is to append.
40\end{methoddesc}
41
42\begin{methoddesc}{flushheaders}{}
43Causes all headers accumulated so far to be written out (and
44forgotten). This is useful if you don't need a body part at all,
45e.g.\ for a subpart of type \mimetype{message/rfc822} that's (mis)used
46to store some header-like information.
47\end{methoddesc}
48
49\begin{methoddesc}{startbody}{ctype\optional{, plist\optional{, prefix}}}
50Returns a file-like object which can be used to write to the
51body of the message. The content-type is set to the provided
52\var{ctype}, and the optional parameter \var{plist} provides
53additional parameters for the content-type declaration. \var{prefix}
54functions as in \method{addheader()} except that the default is to
55insert at the start.
56\end{methoddesc}
57
58\begin{methoddesc}{startmultipartbody}{subtype\optional{,
59 boundary\optional{, plist\optional{, prefix}}}}
60Returns a file-like object which can be used to write to the
61body of the message. Additionally, this method initializes the
Fred Drake38e5d272000-04-03 20:13:55 +000062multi-part code, where \var{subtype} provides the multipart subtype,
Fred Drake28bc7111999-02-12 19:26:09 +000063\var{boundary} may provide a user-defined boundary specification, and
64\var{plist} provides optional parameters for the subtype.
65\var{prefix} functions as in \method{startbody()}. Subparts should be
66created using \method{nextpart()}.
67\end{methoddesc}
68
69\begin{methoddesc}{nextpart}{}
70Returns a new instance of \class{MimeWriter} which represents an
71individual part in a multipart message. This may be used to write the
72part as well as used for creating recursively complex multipart
73messages. The message must first be initialized with
74\method{startmultipartbody()} before using \method{nextpart()}.
75\end{methoddesc}
76
77\begin{methoddesc}{lastpart}{}
78This is used to designate the last part of a multipart message, and
79should \emph{always} be used when writing multipart messages.
80\end{methoddesc}