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