Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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 | |
Fred Drake | 4613876 | 2002-09-25 22:13:27 +0000 | [diff] [blame] | 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 | |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 34 | \begin{methoddesc}[MimeWriter]{addheader}{key, value\optional{, prefix}} |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 42 | \begin{methoddesc}[MimeWriter]{flushheaders}{} |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 49 | \begin{methoddesc}[MimeWriter]{startbody}{ctype\optional{, plist\optional{, prefix}}} |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 58 | \begin{methoddesc}[MimeWriter]{startmultipartbody}{subtype\optional{, |
| 59 | boundary\optional{, plist\optional{, prefix}}}} |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 60 | Returns a file-like object which can be used to write to the |
| 61 | body of the message. Additionally, this method initializes the |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 62 | multi-part code, where \var{subtype} provides the multipart subtype, |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 69 | \begin{methoddesc}[MimeWriter]{nextpart}{} |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 77 | \begin{methoddesc}[MimeWriter]{lastpart}{} |
Fred Drake | 28bc711 | 1999-02-12 19:26:09 +0000 | [diff] [blame] | 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} |