Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-email.Errors.html" /> | |
13 | <link rel="prev" href="module-email.Charset.html" /> | |
14 | <link rel="parent" href="module-email.html" /> | |
15 | <link rel="next" href="module-email.Errors.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>12.2.7 Encoders</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="12.2.6 Representing character sets" | |
25 | href="module-email.Charset.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="12.2 email " | |
28 | href="module-email.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="12.2.8 Exception and Defect" | |
31 | href="module-email.Errors.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-email.Charset.html">12.2.6 Representing character sets</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-email.html">12.2 email </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-email.Errors.html">12.2.8 Exception and Defect</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION0014270000000000000000"> | |
56 | 12.2.7 Encoders</A> | |
57 | </H2> | |
58 | <A NAME="module-email.Encoders"></A> | |
59 | ||
60 | <P> | |
61 | When creating <tt class="class">Message</tt> objects from scratch, you often need to | |
62 | encode the payloads for transport through compliant mail servers. | |
63 | This is especially true for <span class="mimetype">image/*</span> and <span class="mimetype">text/*</span> | |
64 | type messages containing binary data. | |
65 | ||
66 | <P> | |
67 | The <tt class="module">email</tt> package provides some convenient encodings in its | |
68 | <tt class="module">Encoders</tt> module. These encoders are actually used by the | |
69 | <tt class="class">MIMEAudio</tt> and <tt class="class">MIMEImage</tt> class constructors to provide default | |
70 | encodings. All encoder functions take exactly one argument, the message | |
71 | object to encode. They usually extract the payload, encode it, and reset the | |
72 | payload to this newly encoded value. They should also set the | |
73 | <span class="mailheader">Content-Transfer-Encoding:</span> header as appropriate. | |
74 | ||
75 | <P> | |
76 | Here are the encoding functions provided: | |
77 | ||
78 | <P> | |
79 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
80 | <td><nobr><b><tt id='l2h-3931' xml:id='l2h-3931' class="function">encode_quopri</tt></b>(</nobr></td> | |
81 | <td><var>msg</var>)</td></tr></table></dt> | |
82 | <dd> | |
83 | Encodes the payload into quoted-printable form and sets the | |
84 | <span class="mailheader">Content-Transfer-Encoding:</span> header to | |
85 | <code>quoted-printable</code><A NAME="tex2html119" | |
86 | HREF="#foot58057"><SUP>12.2</SUP></A>. | |
87 | This is a good encoding to use when most of your payload is normal | |
88 | printable data, but contains a few unprintable characters. | |
89 | </dl> | |
90 | ||
91 | <P> | |
92 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
93 | <td><nobr><b><tt id='l2h-3932' xml:id='l2h-3932' class="function">encode_base64</tt></b>(</nobr></td> | |
94 | <td><var>msg</var>)</td></tr></table></dt> | |
95 | <dd> | |
96 | Encodes the payload into base64 form and sets the | |
97 | <span class="mailheader">Content-Transfer-Encoding:</span> header to | |
98 | <code>base64</code>. This is a good encoding to use when most of your payload | |
99 | is unprintable data since it is a more compact form than | |
100 | quoted-printable. The drawback of base64 encoding is that it | |
101 | renders the text non-human readable. | |
102 | </dl> | |
103 | ||
104 | <P> | |
105 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
106 | <td><nobr><b><tt id='l2h-3933' xml:id='l2h-3933' class="function">encode_7or8bit</tt></b>(</nobr></td> | |
107 | <td><var>msg</var>)</td></tr></table></dt> | |
108 | <dd> | |
109 | This doesn't actually modify the message's payload, but it does set | |
110 | the <span class="mailheader">Content-Transfer-Encoding:</span> header to either <code>7bit</code> or | |
111 | <code>8bit</code> as appropriate, based on the payload data. | |
112 | </dl> | |
113 | ||
114 | <P> | |
115 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
116 | <td><nobr><b><tt id='l2h-3934' xml:id='l2h-3934' class="function">encode_noop</tt></b>(</nobr></td> | |
117 | <td><var>msg</var>)</td></tr></table></dt> | |
118 | <dd> | |
119 | This does nothing; it doesn't even set the | |
120 | <span class="mailheader">Content-Transfer-Encoding:</span> header. | |
121 | </dl> | |
122 | ||
123 | <P> | |
124 | <BR><HR><H4>Footnotes</H4> | |
125 | <DL> | |
126 | <DT><A NAME="foot58057">...quoted-printable</A><A | |
127 | href="module-email.Encoders.html#tex2html119"><SUP>12.2</SUP></A></DT> | |
128 | <DD>Note that encoding with | |
129 | <tt class="method">encode_quopri()</tt> also encodes all tabs and space characters in | |
130 | the data. | |
131 | ||
132 | </DD> | |
133 | </DL> | |
134 | <DIV CLASS="navigation"> | |
135 | <div class='online-navigation'> | |
136 | <p></p><hr /> | |
137 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
138 | <tr> | |
139 | <td class='online-navigation'><a rel="prev" title="12.2.6 Representing character sets" | |
140 | href="module-email.Charset.html"><img src='../icons/previous.png' | |
141 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
142 | <td class='online-navigation'><a rel="parent" title="12.2 email " | |
143 | href="module-email.html"><img src='../icons/up.png' | |
144 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
145 | <td class='online-navigation'><a rel="next" title="12.2.8 Exception and Defect" | |
146 | href="module-email.Errors.html"><img src='../icons/next.png' | |
147 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
148 | <td align="center" width="100%">Python Library Reference</td> | |
149 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
150 | href="contents.html"><img src='../icons/contents.png' | |
151 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
152 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
153 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
154 | <td class='online-navigation'><a rel="index" title="Index" | |
155 | href="genindex.html"><img src='../icons/index.png' | |
156 | border='0' height='32' alt='Index' width='32' /></A></td> | |
157 | </tr></table> | |
158 | <div class='online-navigation'> | |
159 | <b class="navlabel">Previous:</b> | |
160 | <a class="sectref" rel="prev" href="module-email.Charset.html">12.2.6 Representing character sets</A> | |
161 | <b class="navlabel">Up:</b> | |
162 | <a class="sectref" rel="parent" href="module-email.html">12.2 email </A> | |
163 | <b class="navlabel">Next:</b> | |
164 | <a class="sectref" rel="next" href="module-email.Errors.html">12.2.8 Exception and Defect</A> | |
165 | </div> | |
166 | </div> | |
167 | <hr /> | |
168 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
169 | </DIV> | |
170 | <!--End of Navigation Panel--> | |
171 | <ADDRESS> | |
172 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
173 | </ADDRESS> | |
174 | </BODY> | |
175 | </HTML> |