home *** CD-ROM | disk | FTP | other *** search
- <TITLE>Message Objects -- Python library reference</TITLE>
- Prev: <A HREF="../r/rfc822" TYPE="Prev">rfc822</A>
- Up: <A HREF="../r/rfc822" TYPE="Up">rfc822</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H2>10.11.1. Message Objects</H2>
- A <CODE>Message</CODE> instance has the following methods:
- <P>
- <DL><DT><B>rewindbody</B> () -- function of module rfc822<DD>
- Seek to the start of the message body. This only works if the file
- object is seekable.
- </DL>
- <DL><DT><B>getallmatchingheaders</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
- Return a list of lines consisting of all headers matching
- <VAR>name</VAR>, if any. Each physical line, whether it is a continuation
- line or not, is a separate list item. Return the empty list if no
- header matches <VAR>name</VAR>.
- </DL>
- <DL><DT><B>getfirstmatchingheader</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
- Return a list of lines comprising the first header matching
- <VAR>name</VAR>, and its continuation line(s), if any. Return <CODE>None</CODE>
- if there is no header matching <VAR>name</VAR>.
- </DL>
- <DL><DT><B>getrawheader</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
- Return a single string consisting of the text after the colon in the
- first header matching <VAR>name</VAR>. This includes leading whitespace,
- the trailing linefeed, and internal linefeeds and whitespace if there
- any continuation line(s) were present. Return <CODE>None</CODE> if there is
- no header matching <VAR>name</VAR>.
- </DL>
- <DL><DT><B>getheader</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
- Like <CODE>getrawheader(<VAR>name</VAR>)</CODE>, but strip leading and trailing
- whitespace (but not internal whitespace).
- </DL>
- <DL><DT><B>getaddr</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
- Return a pair (full name, email address) parsed from the string
- returned by <CODE>getheader(<VAR>name</VAR>)</CODE>. If no header matching
- <VAR>name</VAR> exists, return <CODE>None, None</CODE>; otherwise both the full
- name and the address are (possibly empty )strings.
- <P>
- Example: If <CODE>m</CODE>'s first <CODE>From</CODE> header contains the string*
- <CODE>'jack@cwi.nl (Jack Jansen)'</CODE>, then
- <CODE>m.getaddr('From')</CODE> will yield the pair
- <CODE>('Jack Jansen', 'jack@cwi.nl')</CODE>.
- If the header contained
- <CODE>'Jack Jansen <jack@cwi.nl>'</CODE> instead, it would yield the
- exact same result.
- </DL>
- <DL><DT><B>getaddrlist</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
- This is similar to <CODE>getaddr(<VAR>list</VAR>)</CODE>, but parses a header
- containing a list of email addresses (e.g. a <CODE>To</CODE> header) and
- returns a list of (full name, email address) pairs (even if there was
- only one address in the header). If there is no header matching
- <VAR>name</VAR>, return an empty list.
- <P>
- XXX The current version of this function is not really correct. It
- yields bogus results if a full name contains a comma.
- </DL>
- <DL><DT><B>getdate</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
- Retrieve a header using <CODE>getheader</CODE> and parse it into a 9-tuple
- compatible with <CODE>time.mktime()</CODE>. If there is no header matching
- <VAR>name</VAR>, or it is unparsable, return <CODE>None</CODE>.
- <P>
- Date parsing appears to be a black art, and not all mailers adhere to
- the standard. While it has been tested and found correct on a large
- collection of email from many sources, it is still possible that this
- function may occasionally yield an incorrect result.
- </DL>
- <CODE>Message</CODE> instances also support a read-only mapping interface.
- In particular: <CODE>m[name]</CODE> is the same as <CODE>m.getheader(name)</CODE>;
- and <CODE>len(m)</CODE>, <CODE>m.has_key(name)</CODE>, <CODE>m.keys()</CODE>,
- <CODE>m.values()</CODE> and <CODE>m.items()</CODE> act as expected (and
- consistently).
- <P>
- Finally, <CODE>Message</CODE> instances have two public instance variables:
- <P>
- <DL><DT><B>headers</B> -- data of module rfc822<DD>
- A list containing the entire set of header lines, in the order in
- which they were read. Each line contains a trailing newline. The
- blank line terminating the headers is not contained in the list.
- </DL>
- <DL><DT><B>fp</B> -- data of module rfc822<DD>
- The file object passed at instantiation time.
- </DL>
-