This module defines a class, Message, which represents an ``email message'' as defined by the Internet standard RFC 2822.7.6 Such messages consist of a collection of message headers, and a message body. This module also defines a helper class AddressList for parsing RFC 2822 addresses. Please refer to the RFC for information on the specific syntax of RFC 2822 messages.
The mailbox module provides classes to read mailboxes produced by various end-user mail programs.
This class can work with any input object that supports a readline() method. If the input object has seek and tell capability, the rewindbody() method will work; also, illegal lines will be pushed back onto the input stream. If the input object lacks seek but has an unread() method that can push back a line of input, Message will use that to push back illegal lines. Thus this class can be used to parse messages coming from a buffered stream.
The optional seekable argument is provided as a workaround for certain stdio libraries in which tell() discards buffered data before discovering that the lseek() system call doesn't work. For maximum portability, you should set the seekable argument to zero to prevent that initial tell() when passing in an unseekable object such as a file object created from a socket object.
Input lines as read from the file may either be terminated by CR-LF or by a single linefeed; a terminating CR-LF is replaced by a single linefeed before the line is stored.
All header matching is done independent of upper or lower case;
m['FROM'] all yield the same result.
Noneyields an empty list.)
(None, None)is returned.
(realname, email_address)and returns the string value suitable for a To: or Cc: header. If the first element of pair is false, then the second element is returned unmodified.
'Mon, 20 Nov 1995 19:12:08 -0500'. If it succeeds in parsing the date, parsedate() returns a 9-tuple that can be passed directly to time.mktime(); otherwise
Nonewill be returned. Note that fields 6, 7, and 8 of the result tuple are not usable.
Noneor a 10-tuple; the first 9 elements make up a tuple that can be passed directly to time.mktime(), and the tenth is the offset of the date's timezone from UTC (which is the official term for Greenwich Mean Time). (Note that the sign of the timezone offset is the opposite of the sign of the
time.timezonevariable for the same timezone; the latter variable follows the POSIX standard while this module follows RFC 2822.) If the input string has no timezone, the last element of the tuple returned is
None. Note that fields 6, 7, and 8 of the result tuple are not usable.
None, assume local time. Minor deficiency: this first interprets the first 8 elements as a local time and then compensates for the timezone difference; this may yield a slight error around daylight savings time switch dates. Not enough to worry about for common use.