| Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 1 | \declaremodule{standard}{email.Encoders} | 
|  | 2 | \modulesynopsis{Encoders for email message payloads.} | 
| Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 3 |  | 
|  | 4 | When creating \class{Message} objects from scratch, you often need to | 
|  | 5 | encode the payloads for transport through compliant mail servers. | 
| Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame^] | 6 | This is especially true for \mimetype{image/*} and \mimetype{text/*} | 
|  | 7 | type messages containing binary data. | 
| Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 8 |  | 
|  | 9 | The \module{email} package provides some convenient encodings in its | 
|  | 10 | \module{Encoders} module.  These encoders are actually used by the | 
|  | 11 | \class{MIMEImage} and \class{MIMEText} class constructors to provide default | 
|  | 12 | encodings.  All encoder functions take exactly one argument, the | 
|  | 13 | message object to encode.  They usually extract the payload, encode | 
|  | 14 | it, and reset the payload to this newly encoded value.  They should also | 
| Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame^] | 15 | set the \mailheader{Content-Transfer-Encoding} header as appropriate. | 
| Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 16 |  | 
|  | 17 | Here are the encoding functions provided: | 
|  | 18 |  | 
|  | 19 | \begin{funcdesc}{encode_quopri}{msg} | 
|  | 20 | Encodes the payload into \emph{Quoted-Printable} form and sets the | 
|  | 21 | \code{Content-Transfer-Encoding:} header to | 
|  | 22 | \code{quoted-printable}\footnote{Note that encoding with | 
|  | 23 | \method{encode_quopri()} also encodes all tabs and space characters in | 
|  | 24 | the data.}. | 
|  | 25 | This is a good encoding to use when most of your payload is normal | 
|  | 26 | printable data, but contains a few unprintable characters. | 
|  | 27 | \end{funcdesc} | 
|  | 28 |  | 
|  | 29 | \begin{funcdesc}{encode_base64}{msg} | 
|  | 30 | Encodes the payload into \emph{Base64} form and sets the | 
| Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame^] | 31 | \mailheader{Content-Transfer-Encoding} header to | 
| Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 32 | \code{base64}.  This is a good encoding to use when most of your payload | 
|  | 33 | is unprintable data since it is a more compact form than | 
|  | 34 | Quoted-Printable.  The drawback of Base64 encoding is that it | 
|  | 35 | renders the text non-human readable. | 
|  | 36 | \end{funcdesc} | 
|  | 37 |  | 
|  | 38 | \begin{funcdesc}{encode_7or8bit}{msg} | 
|  | 39 | This doesn't actually modify the message's payload, but it does set | 
| Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame^] | 40 | the \mailheader{Content-Transfer-Encoding} header to either \code{7bit} or | 
| Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 41 | \code{8bit} as appropriate, based on the payload data. | 
|  | 42 | \end{funcdesc} | 
|  | 43 |  | 
|  | 44 | \begin{funcdesc}{encode_noop}{msg} | 
|  | 45 | This does nothing; it doesn't even set the | 
| Barry Warsaw | c5f8fe3 | 2001-09-26 22:21:52 +0000 | [diff] [blame^] | 46 | \mailheader{Content-Transfer-Encoding} header. | 
| Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame] | 47 | \end{funcdesc} |