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