There are several useful utilities provided in theemail.utilsmodule:
| str) |
| str) |
| address) |
('', '') is returned.| pair) |
(realname, email_address) and returns the string value suitablefor aTo: orCc: header. If the first element ofpair is false, then the second element is returned unmodified.| fieldvalues) |
parseaddr().fieldvalues is a sequence of header fieldvalues as might be returned byMessage.get_all(). Here's asimple example that gets all the recipients of a message:from email.utils import getaddressestos = msg.get_all('to', [])ccs = msg.get_all('cc', [])resent_tos = msg.get_all('resent-to', [])resent_ccs = msg.get_all('resent-cc', [])all_recipients = getaddresses(tos + ccs + resent_tos + resent_ccs)| date) |
"Mon, 20 Nov 1995 19:12:08 -0500". If it succeeds in parsingthe date,parsedate() returns a 9-tuple that can be passeddirectly totime.mktime(); otherwiseNone will bereturned. Note that fields 6, 7, and 8 of the result tuple are notusable.| date) |
None or a 10-tuple; the first 9 elements make up a tuplethat can be passed directly totime.mktime(), and the tenthis the offset of the date's timezone from UTC (which is the officialterm for Greenwich Mean Time)7.3. If the inputstring has no timezone, the last element of the tuple returned isNone. Note that fields 6, 7, and 8 of the result tuple are notusable.| tuple) |
None, assumelocal time. Minor deficiency:mktime_tz() interprets thefirst 8 elements oftuple as a local time and then compensatesfor the timezone difference. This may yield a slight error aroundchanges in daylight savings time, though not worth worrying about forcommon use.| [timeval[, localtime][, usegmt]]) |
Fri, 09 Nov 2001 01:08:47 -0000
Optionaltimeval if given is a floating point time value asaccepted bytime.gmtime() andtime.localtime(),otherwise the current time is used.
Optionallocaltime is a flag that whenTrue, interpretstimeval, and returns a date relative to the local timezoneinstead of UTC, properly taking daylight savings time into account.The default isFalse meaning UTC is used.
Optionalusegmt is a flag that whenTrue, outputs a date string with the timezone as an ascii stringGMT, ratherthan a numeric-0000. This is needed for some protocols (suchas HTTP). This only applies whenlocaltime isFalse.New in version 2.4.
| [idstring]) |
| s) |
| s[, charset[, language]]) |
| value[, errors[, fallback_charset]]) |
replace. Optionalfallback_charset specifies the character setto use if the one in theRFC 2231 header is not known by Python; it defaultstous-ascii.For convenience, if thevalue passed tocollapse_rfc2231_value() is not a tuple, it should be a string andit is returned unquoted.
| params) |
(content-type, string-value).Changed in version 2.4:Thedump_address_pair() function has been removed;useformataddr() instead.
Changed in version 2.4:Thedecode() function has been removed; use theHeader.decode_header() method instead.
Changed in version 2.4:Theencode() function has been removed; use theHeader.encode() method instead.
time.timezonevariable for the same timezone; the latter variable follows thePOSIX standard while this module followsRFC 2822.