Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / module-rfc822.html
CommitLineData
86530b38
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-base64.html" />
13<link rel="prev" href="module-multifile.html" />
14<link rel="parent" href="netdata.html" />
15<link rel="next" href="message-objects.html" />
16<meta name='aesop' content='information' />
17<title>12.11 rfc822 -- Parse RFC 2822 mail headers</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.10.2 MultiFile Example"
25 href="multifile-example.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. Internet Data Handling"
28 href="netdata.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.11.1 Message Objects"
31 href="message-objects.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="multifile-example.html">12.10.2 MultiFile Example</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="netdata.html">12. Internet Data Handling</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="message-objects.html">12.11.1 Message Objects</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION00141100000000000000000">
5612.11 <tt class="module">rfc822</tt> --
57 Parse RFC 2822 mail headers</A>
58</H1>
59
60<P>
61<A NAME="module-rfc822"></A>
62
63<P>
64<div class="versionnote"><b>Deprecated since release 2.3.</b>
65The <tt class="module"><a href="module-email.html">email</a></tt> package should be used in
66 preference to the <tt class="module">rfc822</tt> module. This
67 module is present only to maintain backward
68 compatibility.</div><p></p>
69
70<P>
71This module defines a class, <tt class="class">Message</tt>, which represents an
72``email message'' as defined by the Internet standard
73<a class="rfc" id='rfcref-91168' xml:id='rfcref-91168'
74href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a>.<A NAME="tex2html141"
75 HREF="#foot60406"><SUP>12.6</SUP></A> Such messages
76consist of a collection of message headers, and a message body. This
77module also defines a helper class
78<tt class="class">AddressList</tt> for parsing <a class="rfc" id='rfcref-91170' xml:id='rfcref-91170'
79href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> addresses. Please refer to
80the RFC for information on the specific syntax of <a class="rfc" id='rfcref-91172' xml:id='rfcref-91172'
81href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> messages.
82
83<P>
84The <tt class="module"><a href="module-mailbox.html">mailbox</a></tt><a id='l2h-4083' xml:id='l2h-4083'></a> module provides classes
85to read mailboxes produced by various end-user mail programs.
86
87<P>
88<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
89 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-4074' xml:id='l2h-4074' class="class">Message</tt></b>(</nobr></td>
90 <td><var>file</var><big>[</big><var>, seekable</var><big>]</big><var></var>)</td></tr></table></dt>
91<dd>
92A <tt class="class">Message</tt> instance is instantiated with an input object as
93parameter. Message relies only on the input object having a
94<tt class="method">readline()</tt> method; in particular, ordinary file objects
95qualify. Instantiation reads headers from the input object up to a
96delimiter line (normally a blank line) and stores them in the
97instance. The message body, following the headers, is not consumed.
98
99<P>
100This class can work with any input object that supports a
101<tt class="method">readline()</tt> method. If the input object has seek and tell
102capability, the <tt class="method">rewindbody()</tt> method will work; also, illegal
103lines will be pushed back onto the input stream. If the input object
104lacks seek but has an <tt class="method">unread()</tt> method that can push back a
105line of input, <tt class="class">Message</tt> will use that to push back illegal
106lines. Thus this class can be used to parse messages coming from a
107buffered stream.
108
109<P>
110The optional <var>seekable</var> argument is provided as a workaround for
111certain stdio libraries in which <tt class="cfunction">tell()</tt> discards buffered
112data before discovering that the <tt class="cfunction">lseek()</tt> system call
113doesn't work. For maximum portability, you should set the seekable
114argument to zero to prevent that initial <tt class="method">tell()</tt> when passing
115in an unseekable object such as a file object created from a socket
116object.
117
118<P>
119Input lines as read from the file may either be terminated by CR-LF or
120by a single linefeed; a terminating CR-LF is replaced by a single
121linefeed before the line is stored.
122
123<P>
124All header matching is done independent of upper or lower case;
125e.g. <code><var>m</var>['From']</code>, <code><var>m</var>['from']</code> and
126<code><var>m</var>['FROM']</code> all yield the same result.
127</dl>
128
129<P>
130<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
131 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-4075' xml:id='l2h-4075' class="class">AddressList</tt></b>(</nobr></td>
132 <td><var>field</var>)</td></tr></table></dt>
133<dd>
134You may instantiate the <tt class="class">AddressList</tt> helper class using a single
135string parameter, a comma-separated list of <a class="rfc" id='rfcref-91175' xml:id='rfcref-91175'
136href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> addresses to be
137parsed. (The parameter <code>None</code> yields an empty list.)
138</dl>
139
140<P>
141<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
142 <td><nobr><b><tt id='l2h-4076' xml:id='l2h-4076' class="function">quote</tt></b>(</nobr></td>
143 <td><var>str</var>)</td></tr></table></dt>
144<dd>
145Return a new string with backslashes in <var>str</var> replaced by two
146backslashes and double quotes replaced by backslash-double quote.
147</dl>
148
149<P>
150<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
151 <td><nobr><b><tt id='l2h-4077' xml:id='l2h-4077' class="function">unquote</tt></b>(</nobr></td>
152 <td><var>str</var>)</td></tr></table></dt>
153<dd>
154Return a new string which is an <em>unquoted</em> version of <var>str</var>.
155If <var>str</var> ends and begins with double quotes, they are stripped
156off. Likewise if <var>str</var> ends and begins with angle brackets, they
157are stripped off.
158</dl>
159
160<P>
161<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
162 <td><nobr><b><tt id='l2h-4078' xml:id='l2h-4078' class="function">parseaddr</tt></b>(</nobr></td>
163 <td><var>address</var>)</td></tr></table></dt>
164<dd>
165Parse <var>address</var>, which should be the value of some
166address-containing field such as <span class="mailheader">To:</span> or <span class="mailheader">Cc:</span>,
167into its constituent ``realname'' and ``email address'' parts.
168Returns a tuple of that information, unless the parse fails, in which
169case a 2-tuple <code>(None, None)</code> is returned.
170</dl>
171
172<P>
173<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
174 <td><nobr><b><tt id='l2h-4079' xml:id='l2h-4079' class="function">dump_address_pair</tt></b>(</nobr></td>
175 <td><var>pair</var>)</td></tr></table></dt>
176<dd>
177The inverse of <tt class="method">parseaddr()</tt>, this takes a 2-tuple of the form
178<code>(<var>realname</var>, <var>email_address</var>)</code> and returns the string
179value suitable for a <span class="mailheader">To:</span> or <span class="mailheader">Cc:</span> header. If
180the first element of <var>pair</var> is false, then the second element is
181returned unmodified.
182</dl>
183
184<P>
185<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
186 <td><nobr><b><tt id='l2h-4080' xml:id='l2h-4080' class="function">parsedate</tt></b>(</nobr></td>
187 <td><var>date</var>)</td></tr></table></dt>
188<dd>
189Attempts to parse a date according to the rules in <a class="rfc" id='rfcref-91177' xml:id='rfcref-91177'
190href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a>.
191however, some mailers don't follow that format as specified, so
192<tt class="function">parsedate()</tt> tries to guess correctly in such cases.
193<var>date</var> is a string containing an <a class="rfc" id='rfcref-91179' xml:id='rfcref-91179'
194href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> date, such as
195<code>'Mon, 20 Nov 1995 19:12:08 -0500'</code>. If it succeeds in parsing
196the date, <tt class="function">parsedate()</tt> returns a 9-tuple that can be passed
197directly to <tt class="function">time.mktime()</tt>; otherwise <code>None</code> will be
198returned. Note that fields 6, 7, and 8 of the result tuple are not
199usable.
200</dl>
201
202<P>
203<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
204 <td><nobr><b><tt id='l2h-4081' xml:id='l2h-4081' class="function">parsedate_tz</tt></b>(</nobr></td>
205 <td><var>date</var>)</td></tr></table></dt>
206<dd>
207Performs the same function as <tt class="function">parsedate()</tt>, but returns
208either <code>None</code> or a 10-tuple; the first 9 elements make up a tuple
209that can be passed directly to <tt class="function">time.mktime()</tt>, and the tenth
210is the offset of the date's timezone from UTC (which is the official
211term for Greenwich Mean Time). (Note that the sign of the timezone
212offset is the opposite of the sign of the <code>time.timezone</code>
213variable for the same timezone; the latter variable follows the
214POSIX standard while this module follows <a class="rfc" id='rfcref-91181' xml:id='rfcref-91181'
215href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a>.) If the input
216string has no timezone, the last element of the tuple returned is
217<code>None</code>. Note that fields 6, 7, and 8 of the result tuple are not
218usable.
219</dl>
220
221<P>
222<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
223 <td><nobr><b><tt id='l2h-4082' xml:id='l2h-4082' class="function">mktime_tz</tt></b>(</nobr></td>
224 <td><var>tuple</var>)</td></tr></table></dt>
225<dd>
226Turn a 10-tuple as returned by <tt class="function">parsedate_tz()</tt> into a UTC
227timestamp. If the timezone item in the tuple is <code>None</code>, assume
228local time. Minor deficiency: this first interprets the first 8
229elements as a local time and then compensates for the timezone
230difference; this may yield a slight error around daylight savings time
231switch dates. Not enough to worry about for common use.
232</dl>
233
234<P>
235<div class="seealso">
236 <p class="heading">See Also:</p>
237
238 <dl compact="compact" class="seemodule">
239 <dt>Module <b><tt class="module"><a href="module-email.html">email</a></tt>:</b>
240 <dd>Comprehensive email handling package; supersedes
241 the <tt class="module">rfc822</tt> module.
242 </dl>
243 <dl compact="compact" class="seemodule">
244 <dt>Module <b><tt class="module"><a href="module-mailbox.html">mailbox</a></tt>:</b>
245 <dd>Classes to read various mailbox formats produced
246 by end-user mail programs.
247 </dl>
248 <dl compact="compact" class="seemodule">
249 <dt>Module <b><tt class="module"><a href="module-mimetools.html">mimetools</a></tt>:</b>
250 <dd>Subclass of <tt class="class">rfc822.Message</tt> that
251 handles MIME encoded messages.
252 </dl>
253</div>
254
255<P>
256<BR><HR><H4>Footnotes</H4>
257<DL>
258<DT><A NAME="foot60406">...2822.</A><A
259 href="module-rfc822.html#tex2html141"><SUP>12.6</SUP></A></DT>
260<DD>This module originally conformed to <a class="rfc" id='rfcref-91149' xml:id='rfcref-91149'
261href="http://www.faqs.org/rfcs/rfc822.html">RFC 822</a>,
262hence the name. Since then, <a class="rfc" id='rfcref-91151' xml:id='rfcref-91151'
263href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> has been released as an
264update to <a class="rfc" id='rfcref-91153' xml:id='rfcref-91153'
265href="http://www.faqs.org/rfcs/rfc822.html">RFC 822</a>. This module should be considered
266<a class="rfc" id='rfcref-91155' xml:id='rfcref-91155'
267href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a>-conformant, especially in cases where the
268syntax or semantics have changed since <a class="rfc" id='rfcref-91157' xml:id='rfcref-91157'
269href="http://www.faqs.org/rfcs/rfc822.html">RFC 822</a>.
270
271</DD>
272</DL>
273<p><br /></p><hr class='online-navigation' />
274<div class='online-navigation'>
275<!--Table of Child-Links-->
276<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
277
278<UL CLASS="ChildLinks">
279<LI><A href="message-objects.html">12.11.1 Message Objects</a>
280<LI><A href="addresslist-objects.html">12.11.2 AddressList Objects</a>
281</ul>
282<!--End of Table of Child-Links-->
283</div>
284
285<DIV CLASS="navigation">
286<div class='online-navigation'>
287<p></p><hr />
288<table align="center" width="100%" cellpadding="0" cellspacing="2">
289<tr>
290<td class='online-navigation'><a rel="prev" title="12.10.2 MultiFile Example"
291 href="multifile-example.html"><img src='../icons/previous.png'
292 border='0' height='32' alt='Previous Page' width='32' /></A></td>
293<td class='online-navigation'><a rel="parent" title="12. Internet Data Handling"
294 href="netdata.html"><img src='../icons/up.png'
295 border='0' height='32' alt='Up One Level' width='32' /></A></td>
296<td class='online-navigation'><a rel="next" title="12.11.1 Message Objects"
297 href="message-objects.html"><img src='../icons/next.png'
298 border='0' height='32' alt='Next Page' width='32' /></A></td>
299<td align="center" width="100%">Python Library Reference</td>
300<td class='online-navigation'><a rel="contents" title="Table of Contents"
301 href="contents.html"><img src='../icons/contents.png'
302 border='0' height='32' alt='Contents' width='32' /></A></td>
303<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
304 border='0' height='32' alt='Module Index' width='32' /></a></td>
305<td class='online-navigation'><a rel="index" title="Index"
306 href="genindex.html"><img src='../icons/index.png'
307 border='0' height='32' alt='Index' width='32' /></A></td>
308</tr></table>
309<div class='online-navigation'>
310<b class="navlabel">Previous:</b>
311<a class="sectref" rel="prev" href="multifile-example.html">12.10.2 MultiFile Example</A>
312<b class="navlabel">Up:</b>
313<a class="sectref" rel="parent" href="netdata.html">12. Internet Data Handling</A>
314<b class="navlabel">Next:</b>
315<a class="sectref" rel="next" href="message-objects.html">12.11.1 Message Objects</A>
316</div>
317</div>
318<hr />
319<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
320</DIV>
321<!--End of Navigation Panel-->
322<ADDRESS>
323See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
324</ADDRESS>
325</BODY>
326</HTML>