Package email :: Module utils
[hide private]
[frames] | no frames]

Module utils

Miscellaneous utilities.

Functions [hide private]
 
_identity(s)
 
_bdecode(s)
 
fix_eols(s)
Replace all line-ending characters with .
 
formataddr(pair)
The inverse of parseaddr(), this takes a 2-tuple of the form (realname, email_address) and returns the string value suitable for an RFC 2822 From, To or Cc header.
 
getaddresses(fieldvalues)
Return a list of (REALNAME, EMAIL) for each fieldvalue.
 
formatdate(timeval=None, localtime=False, usegmt=False)
Returns a date string as specified by RFC 2822, e.g.:
 
make_msgid(idstring=None)
Returns a string suitable for RFC 2822 compliant Message-ID, e.g:
 
parsedate(data)
 
parsedate_tz(data)
 
parseaddr(addr)
 
unquote(str)
Remove quotes from a string.
 
decode_rfc2231(s)
Decode string according to RFC 2231
 
encode_rfc2231(s, charset=None, language=None)
Encode string according to RFC 2231.
 
decode_params(params)
Decode parameters list according to RFC 2231.
 
collapse_rfc2231_value(value, errors='replace', fallback_charset='us-ascii')
Variables [hide private]
  COMMASPACE = ', '
  EMPTYSTRING = ''
  UEMPTYSTRING = u''
  CRLF = '\r\n'
  TICK = '\''
  specialsre = re.compile(r'[\]\[\\\(\)<>@,:;"\.]')
  escapesre = re.compile(r'[\]\[\\\(\)"]')
  ecre = re.compile(r'(?ix)=\?(?P<charset>[^\?]*?)\?(?P<encoding...
  rfc2231_continuation = re.compile(r'^(?P<name>\w+)\*((?P<num>[...

Imports: os, re, time, base64, random, socket, urllib, warnings, StringIO, quote, _AddressList, mktime_tz, _parsedate, _parsedate_tz, _qdecode, _bencode, _qencode


Function Details [hide private]

formataddr(pair)

 

The inverse of parseaddr(), this takes a 2-tuple of the form (realname, email_address) and returns the string value suitable for an RFC 2822 From, To or Cc header.

If the first element of pair is false, then the second element is returned unmodified.

formatdate(timeval=None, localtime=False, usegmt=False)

 

Returns a date string as specified by RFC 2822, e.g.:

Fri, 09 Nov 2001 01:08:47 -0000

Optional timeval if given is a floating point time value as accepted by gmtime() and localtime(), otherwise the current time is used.

Optional localtime is a flag that when True, interprets timeval, and returns a date relative to the local timezone instead of UTC, properly taking daylight savings time into account.

Optional argument usegmt means that the timezone is written out as an ascii string, not numeric one (so "GMT" instead of "+0000"). This is needed for HTTP, and is only used when localtime==False.

make_msgid(idstring=None)

 

Returns a string suitable for RFC 2822 compliant Message-ID, e.g:

<20020201195627.33539.96671@nightshade.la.mastaler.com>

Optional idstring if given is a string used to strengthen the uniqueness of the message id.

encode_rfc2231(s, charset=None, language=None)

 

Encode string according to RFC 2231.

If neither charset nor language is given, then s is returned as-is. If charset is given but not language, the string is encoded using the empty string for language.

decode_params(params)

 

Decode parameters list according to RFC 2231.

params is a sequence of 2-tuples containing (param name, string value).


Variables Details [hide private]

ecre

Value:
re.compile(r'(?ix)=\?(?P<charset>[^\?]*?)\?(?P<encoding>[qb])\?(?P<ato\
m>.*?)\?=')

rfc2231_continuation

Value:
re.compile(r'^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$')