home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / m / message_ob < prev    next >
Text File  |  1996-11-14  |  4KB  |  84 lines

  1. <TITLE>Message Objects -- Python library reference</TITLE>
  2. Prev: <A HREF="../r/rfc822" TYPE="Prev">rfc822</A>  
  3. Up: <A HREF="../r/rfc822" TYPE="Up">rfc822</A>  
  4. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  5. <H2>10.11.1. Message Objects</H2>
  6. A <CODE>Message</CODE> instance has the following methods:
  7. <P>
  8. <DL><DT><B>rewindbody</B> () -- function of module rfc822<DD>
  9. Seek to the start of the message body.  This only works if the file
  10. object is seekable.
  11. </DL>
  12. <DL><DT><B>getallmatchingheaders</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
  13. Return a list of lines consisting of all headers matching
  14. <VAR>name</VAR>, if any.  Each physical line, whether it is a continuation
  15. line or not, is a separate list item.  Return the empty list if no
  16. header matches <VAR>name</VAR>.
  17. </DL>
  18. <DL><DT><B>getfirstmatchingheader</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
  19. Return a list of lines comprising the first header matching
  20. <VAR>name</VAR>, and its continuation line(s), if any.  Return <CODE>None</CODE>
  21. if there is no header matching <VAR>name</VAR>.
  22. </DL>
  23. <DL><DT><B>getrawheader</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
  24. Return a single string consisting of the text after the colon in the
  25. first header matching <VAR>name</VAR>.  This includes leading whitespace,
  26. the trailing linefeed, and internal linefeeds and whitespace if there
  27. any continuation line(s) were present.  Return <CODE>None</CODE> if there is
  28. no header matching <VAR>name</VAR>.
  29. </DL>
  30. <DL><DT><B>getheader</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
  31. Like <CODE>getrawheader(<VAR>name</VAR>)</CODE>, but strip leading and trailing
  32. whitespace (but not internal whitespace).
  33. </DL>
  34. <DL><DT><B>getaddr</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
  35. Return a pair (full name, email address) parsed from the string
  36. returned by <CODE>getheader(<VAR>name</VAR>)</CODE>.  If no header matching
  37. <VAR>name</VAR> exists, return <CODE>None, None</CODE>; otherwise both the full
  38. name and the address are (possibly empty )strings.
  39. <P>
  40. Example: If <CODE>m</CODE>'s first <CODE>From</CODE> header contains the string*
  41. <CODE>'jack@cwi.nl (Jack Jansen)'</CODE>, then
  42. <CODE>m.getaddr('From')</CODE> will yield the pair
  43. <CODE>('Jack Jansen', 'jack@cwi.nl')</CODE>.
  44. If the header contained
  45. <CODE>'Jack Jansen <jack@cwi.nl>'</CODE> instead, it would yield the
  46. exact same result.
  47. </DL>
  48. <DL><DT><B>getaddrlist</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
  49. This is similar to <CODE>getaddr(<VAR>list</VAR>)</CODE>, but parses a header
  50. containing a list of email addresses (e.g. a <CODE>To</CODE> header) and
  51. returns a list of (full name, email address) pairs (even if there was
  52. only one address in the header).  If there is no header matching
  53. <VAR>name</VAR>, return an empty list.
  54. <P>
  55. XXX The current version of this function is not really correct.  It
  56. yields bogus results if a full name contains a comma.
  57. </DL>
  58. <DL><DT><B>getdate</B> (<VAR>name</VAR>) -- function of module rfc822<DD>
  59. Retrieve a header using <CODE>getheader</CODE> and parse it into a 9-tuple
  60. compatible with <CODE>time.mktime()</CODE>.  If there is no header matching
  61. <VAR>name</VAR>, or it is unparsable, return <CODE>None</CODE>.
  62. <P>
  63. Date parsing appears to be a black art, and not all mailers adhere to
  64. the standard.  While it has been tested and found correct on a large
  65. collection of email from many sources, it is still possible that this
  66. function may occasionally yield an incorrect result.
  67. </DL>
  68. <CODE>Message</CODE> instances also support a read-only mapping interface.
  69. In particular: <CODE>m[name]</CODE> is the same as <CODE>m.getheader(name)</CODE>;
  70. and <CODE>len(m)</CODE>, <CODE>m.has_key(name)</CODE>, <CODE>m.keys()</CODE>,
  71. <CODE>m.values()</CODE> and <CODE>m.items()</CODE> act as expected (and
  72. consistently).
  73. <P>
  74. Finally, <CODE>Message</CODE> instances have two public instance variables:
  75. <P>
  76. <DL><DT><B>headers</B> -- data of module rfc822<DD>
  77. A list containing the entire set of header lines, in the order in
  78. which they were read.  Each line contains a trailing newline.  The
  79. blank line terminating the headers is not contained in the list.
  80. </DL>
  81. <DL><DT><B>fp</B> -- data of module rfc822<DD>
  82. The file object passed at instantiation time.
  83. </DL>
  84.