-í
ë¶<c      s†   d  Z  d k l Z d k Z d k Z d k Z d k l Z d k l	 Z	 d k
 Z
 d k Z d Z e i d ƒ Z d f  d „  ƒ  YZ d S(	   s9   Basic message object for the email package object model.
(   s
   generatorsN(   s   StringIO(   s   ListTypes   ; s   \s*;\s*s   Messagec     sa  t  Z d  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 e	 Z
 e d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z e d „ Z d „  Z e d „ Z e d „ Z e d „ Z d „  Z e d d „ Z e d d „ Z e d „ Z  e d „ Z! d  „  Z" d! „  Z# e d" „ Z$ RS(#   sn  Basic message object for use inside the object tree.

    A message object is defined as something that has a bunch of RFC 2822
    headers and a payload.  If the body of the message is a multipart, then
    the payload is a list of Messages, otherwise it is a string.

    These objects implement part of the `mapping' interface, which assumes
    there is exactly one occurrance of the header per message.  Some headers
    do in fact appear multiple times (e.g. Received:) and for those headers,
    you must use the explicit API to set or get all the headers.  Not all of
    the mapping methods are implemented.

    c   s/   g  |  _ t |  _ t |  _ t |  _ |  _ d  S(   N(   s   selfs   _headerss   Nones	   _unixfroms   _payloads   preambles   epilogue(   s   self(    (    s#   /usr/lib/python2.2/email/Message.pys   __init__& s    			c   s   |  i d d ƒ Sd S(   sw   Return the entire formatted message as a string.
        This includes the headers, body, and `unixfrom' line.
        s   unixfromi   N(   s   selfs	   as_string(   s   self(    (    s#   /usr/lib/python2.2/email/Message.pys   __str__- s     i    c   s@   d k  l  } t ƒ  } | | ƒ } | |  d | ƒ| i ƒ  Sd S(   s–   Return the entire formatted message as a string.
        Optional `unixfrom' when true, means include the Unix From_ envelope
        header.
        (   s	   Generators   unixfromN(   s	   Generators   StringIOs   fps   gs   selfs   unixfroms   getvalue(   s   selfs   unixfroms   fps	   Generators   g(    (    s#   /usr/lib/python2.2/email/Message.pys	   as_string3 s     	c   s&   t  |  i ƒ t j o d Sn d Sd S(   s6   Return true if the message consists of multiple parts.i   i    N(   s   types   selfs   _payloads   ListType(   s   self(    (    s#   /usr/lib/python2.2/email/Message.pys   is_multipart> s     c   s   | |  _ d  S(   N(   s   unixfroms   selfs	   _unixfrom(   s   selfs   unixfrom(    (    s#   /usr/lib/python2.2/email/Message.pys   set_unixfromG s    c   s   |  i Sd  S(   N(   s   selfs	   _unixfrom(   s   self(    (    s#   /usr/lib/python2.2/email/Message.pys   get_unixfromJ s    c   s‰   |  i t j o | |  _ ni t |  i ƒ t j o |  i i | ƒ n? |  i ƒ  t d f j o t i	 d ƒ ‚ n |  i | g |  _ d S(   s°   Add the given payload to the current payload.

        If the current payload is empty, then the current payload will be made
        a scalar, set to the given value.
        s	   multiparts9   Message main Content-Type: must be "multipart" or missingN(
   s   selfs   _payloads   Nones   payloads   types   ListTypes   appends   get_main_types   Errorss   MultipartConversionError(   s   selfs   payload(    (    s#   /usr/lib/python2.2/email/Message.pys   add_payloadP s     c   sÌ   | t j o |  i } n1 t |  i ƒ t j	 o t | ‚ n |  i | } | os |  i	 ƒ  o t Sn |  i
 d d ƒ } | i ƒ  d j o t i | ƒ Sn% | i ƒ  d j o t i | ƒ Sn n | Sd S(   sh  Return the current payload exactly as is.

        Optional i returns that index into the payload.

        Optional decode is a flag indicating whether the payload should be
        decoded or not, according to the Content-Transfer-Encoding: header.
        When true and the message is not a multipart, the payload will be
        decoded if this header's value is `quoted-printable' or `base64'.  If
        some other encoding is used, or the header is missing, the payload is
        returned as-is (undecoded).  If the message is a multipart and the
        decode flag is true, then None is returned.
        s   content-transfer-encodings    s   quoted-printables   base64N(   s   is   Nones   selfs   _payloads   payloads   types   ListTypes	   TypeErrors   decodes   is_multiparts   gets   ctes   lowers   Utilss   _qdecodes   _bdecode(   s   selfs   is   decodes   ctes   payload(    (    s#   /usr/lib/python2.2/email/Message.pys   get_payloadc s     c   s   | |  _ d S(   s#   Set the payload to the given value.N(   s   payloads   selfs   _payload(   s   selfs   payload(    (    s#   /usr/lib/python2.2/email/Message.pys   set_payloadƒ s     c   s   t  |  i ƒ Sd S(   s9   Return the total number of headers, including duplicates.N(   s   lens   selfs   _headers(   s   self(    (    s#   /usr/lib/python2.2/email/Message.pys   __len__Š s     c   s   |  i | ƒ Sd S(   s,  Get a header value.

        Return None if the header is missing instead of raising an exception.

        Note that if the header appeared multiple times, exactly which
        occurrance gets returned is undefined.  Use getall() to get all
        the values matching a header field name.
        N(   s   selfs   gets   name(   s   selfs   name(    (    s#   /usr/lib/python2.2/email/Message.pys   __getitem__Ž s     c   s   |  i i | | f ƒ d S(   s¸   Set the value of a header.

        Note: this does not overwrite an existing header with the same field
        name.  Use __delitem__() first to delete any existing headers.
        N(   s   selfs   _headerss   appends   names   val(   s   selfs   names   val(    (    s#   /usr/lib/python2.2/email/Message.pys   __setitem__™ s     c   sc   | i ƒ  } g  } xA |  i D]6 \ } } | i ƒ  | j o | i | | f ƒ n q W| |  _ d S(   sw   Delete all occurrences of a header, if present.

        Does not raise an exception if the header is missing.
        N(   s   names   lowers
   newheaderss   selfs   _headerss   ks   vs   append(   s   selfs   names   ks
   newheaderss   v(    (    s#   /usr/lib/python2.2/email/Message.pys   __delitem__¡ s     
 c   sD   | i ƒ  g  i } |  i D] \ } } | | i ƒ  ƒ q ~ j Sd  S(   N(   s   keys   lowers   appends   _[1]s   selfs   _headerss   ks   v(   s   selfs   keys   _[1]s   ks   v(    (    s#   /usr/lib/python2.2/email/Message.pys   __contains__­ s     c   s    g  } |  i | | ƒ | j	 Sd S(   s/   Return true if the message contains the header.N(   s   missings   selfs   gets   name(   s   selfs   names   missing(    (    s#   /usr/lib/python2.2/email/Message.pys   has_key° s     c   s2   g  i  } |  i D] \ } } | | ƒ q ~ Sd S(   s	  Return a list of all the message's header field names.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.
        N(   s   appends   _[1]s   selfs   _headerss   ks   v(   s   selfs   _[1]s   ks   v(    (    s#   /usr/lib/python2.2/email/Message.pys   keysµ s      c   s2   g  i  } |  i D] \ } } | | ƒ q ~ Sd S(   s  Return a list of all the message's header values.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.
        N(   s   appends   _[1]s   selfs   _headerss   ks   v(   s   selfs   _[1]s   ks   v(    (    s#   /usr/lib/python2.2/email/Message.pys   values¾ s      c   s   |  i Sd S(   s  Get all the message's header fields and values.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.
        N(   s   selfs   _headers(   s   self(    (    s#   /usr/lib/python2.2/email/Message.pys   itemsÇ s     c   sI   | i ƒ  } x2 |  i D]' \ } } | i ƒ  | j o | Sn q W| Sd S(   s~   Get a header value.

        Like __getitem__() but return failobj instead of None when the field
        is missing.
        N(   s   names   lowers   selfs   _headerss   ks   vs   failobj(   s   selfs   names   failobjs   ks   v(    (    s#   /usr/lib/python2.2/email/Message.pys   getÐ s     
 c   sh   g  } | i ƒ  } x; |  i D]0 \ } } | i ƒ  | j o | i | ƒ n q W| o | Sn | Sd S(   sQ  Return a list of all the values for the named field.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.

        If no such fields exist, failobj is returned (defaults to None).
        N(	   s   valuess   names   lowers   selfs   _headerss   ks   vs   appends   failobj(   s   selfs   names   failobjs   valuess   vs   k(    (    s#   /usr/lib/python2.2/email/Message.pys   get_allà s     
 c   s´   g  } xg | i ƒ  D]Y \ } } | t j o | i | i d d ƒ ƒ n$ | i d | i d d ƒ | f ƒ q W| t j	 o | i	 d | ƒ n |  i i | t i | ƒ f ƒ d S(   s´  Extended header setting.

        name is the header field to add.  keyword arguments can be used to set
        additional parameters for the header field, with underscores converted
        to dashes.  Normally the parameter will be added as key="value" unless
        value is None, in which case only the key will be added.

        Example:

        msg.add_header('content-disposition', 'attachment', filename='bud.gif')

        s   _s   -s   %s="%s"i    N(   s   partss   _paramss   itemss   ks   vs   Nones   appends   replaces   _values   inserts   selfs   _headerss   _names	   SEMISPACEs   join(   s   selfs   _names   _values   _paramss   partss   vs   k(    (    s#   /usr/lib/python2.2/email/Message.pys
   add_headerò s      'c   sH   g  } |  i d | ƒ } | | j o | Sn t i | ƒ d i ƒ  Sd S(   s  Returns the message's content type.

        The returned string is coerced to lowercase and returned as a single
        string of the form `maintype/subtype'.  If there was no Content-Type:
        header in the message, failobj is returned (defaults to None).
        s   content-typei    N(   s   missings   selfs   gets   values   failobjs   paramres   splits   lower(   s   selfs   failobjs   values   missing(    (    s#   /usr/lib/python2.2/email/Message.pys   get_type	s     c   si   g  } |  i | ƒ } | | j o | Sn | i d ƒ } t | ƒ d j o | i d ƒ d Sn | Sd S(   s2   Return the message's main content type if present.s   /i    N(   s   missings   selfs   get_types   ctypes   failobjs   splits   partss   len(   s   selfs   failobjs   partss   ctypes   missing(    (    s#   /usr/lib/python2.2/email/Message.pys   get_main_types     c   si   g  } |  i | ƒ } | | j o | Sn | i d ƒ } t | ƒ d j o | i d ƒ d Sn | Sd S(   s0   Return the message's content subtype if present.s   /i   N(   s   missings   selfs   get_types   ctypes   failobjs   splits   partss   len(   s   selfs   failobjs   partss   ctypes   missing(    (    s#   /usr/lib/python2.2/email/Message.pys   get_subtype!s     c 	  s¦   g  } |  i | | ƒ } | | j o | Sn g  } xh t i | ƒ D]W } y | i d d ƒ \ } } Wn t j
 o | } d } n X| i | | f ƒ qC W| Sd  S(   Ns   =i   s    (   s   missings   selfs   gets   headers   values   failobjs   paramss   paramres   splits   ps   names   vals
   ValueErrors   append(	   s   selfs   failobjs   headers   names   vals   missings   ps   values   params(    (    s#   /usr/lib/python2.2/email/Message.pys   _get_params_preserve,s     s   content-typec   sk   g  } |  i | | ƒ } | | j o | Sn g  i } | D]% \ } } | | t
 i | ƒ f ƒ q; ~ Sd S(   s,  Return the message's Content-Type: parameters, as a list.

        The elements of the returned list are 2-tuples of key/value pairs, as
        split on the `=' sign.  The left hand side of the `=' is the key,
        while the right hand side is the value.  If there is no `=' sign in
        the parameter the value is the empty string.  The value is always
        unquoted.

        Optional failobj is the object to return if there is no Content-Type:
        header.  Optional header is the header to search instead of
        Content-Type:
        N(   s   missings   selfs   _get_params_preserves   headers   paramss   failobjs   appends   _[1]s   ks   vs   Utilss   unquote(   s   selfs   failobjs   headers   _[1]s   missings   paramss   vs   k(    (    s#   /usr/lib/python2.2/email/Message.pys
   get_params>s      c   sn   |  i | ƒ o | Sn xJ |  i | | ƒ D]6 \ } } | i ƒ  | i ƒ  j o t	 i
 | ƒ Sn q, W| Sd S(   sW  Return the parameter value if found in the Content-Type: header.

        Optional failobj is the object to return if there is no Content-Type:
        header.  Optional header is the header to search instead of
        Content-Type:

        Parameter keys are always compared case insensitively.  Values are
        always unquoted.
        N(   s   selfs   has_keys   headers   failobjs   _get_params_preserves   ks   vs   lowers   params   Utilss   unquote(   s   selfs   params   failobjs   headers   vs   k(    (    s#   /usr/lib/python2.2/email/Message.pys	   get_paramQs    	  c   sG   g  } |  i d | d ƒ } | | j o | Sn t i | i ƒ  ƒ Sd S(   sÀ   Return the filename associated with the payload if present.

        The filename is extracted from the Content-Disposition: header's
        `filename' parameter, and it is unquoted.
        s   filenames   content-dispositionN(   s   missings   selfs	   get_params   filenames   failobjs   Utilss   unquotes   strip(   s   selfs   failobjs   filenames   missing(    (    s#   /usr/lib/python2.2/email/Message.pys   get_filenamebs     c   sD   g  } |  i d | ƒ } | | j o | Sn t i | i ƒ  ƒ Sd S(   s¹   Return the boundary associated with the payload if present.

        The boundary is extracted from the Content-Type: header's `boundary'
        parameter, and it is unquoted.
        s   boundaryN(   s   missings   selfs	   get_params   boundarys   failobjs   Utilss   unquotes   strip(   s   selfs   failobjs   boundarys   missing(    (    s#   /usr/lib/python2.2/email/Message.pys   get_boundaryns     c   s‡  g  } |  i | d ƒ } | | j o t i d ‚ n g  } d } x[ | D]S \ } } | i
 ƒ  d j o! | i d d | f ƒ d } n | i | | f ƒ qH W| o | i d d | f ƒ n g  }	 x¯ |  i D]¤ \ } }
 | i
 ƒ  d j or g  } xI | D]A \ } }
 |
 d j o | i | ƒ n | i d | |
 f ƒ qþ W|	 i | t i | ƒ f ƒ n |	 i | |
 f ƒ qÒ W|	 |  _ d	 S(
   s¿  Set the boundary parameter in Content-Type: to 'boundary'.

        This is subtly different than deleting the Content-Type: header and
        adding a new one with a new boundary parameter via add_header().  The
        main difference is that using the set_boundary() method preserves the
        order of the Content-Type: header in the original message.

        HeaderParseError is raised if the message has no Content-Type: header.
        s   content-types   No Content-Type: header foundi    s   boundarys   "%s"i   s    s   %s=%sN(   s   missings   selfs   _get_params_preserves   paramss   Errorss   HeaderParseErrors	   newparamss   foundps   pks   pvs   lowers   appends   boundarys
   newheaderss   _headerss   hs   vs   partss   ks	   SEMISPACEs   join(   s   selfs   boundarys   foundps   pvs	   newparamss   missings   hs   partss   paramss
   newheaderss   vs   pks   k(    (    s#   /usr/lib/python2.2/email/Message.pys   set_boundaryzs8    	  

   c   #sK   |  V|  i ƒ  o6 x/ |  i ƒ  D]! } x | i ƒ  D]
 } | Vq1 Wq Wn d S(   s•   Walk over the message tree, yielding each subpart.

        The walk is performed in depth-first order.  This method is a
        generator.
        N(   s   selfs   is_multiparts   get_payloads   subparts   walks
   subsubpart(   s   selfs
   subsubparts   subpart(    (    s#   /usr/lib/python2.2/email/Message.pys   walk§s       c   s;   g  i  } |  i ƒ  D] } | | i d | ƒ ƒ q ~ Sd S(   s×  Return a list containing the charset(s) used in this message.

        The returned list of items describes the Content-Type: headers'
        charset parameter for this message and all the subparts in its
        payload.

        Each item will either be a string (the value of the charset parameter
        in the Content-Type: header of that part) or the value of the
        'failobj' parameter (defaults to None), if the part does not have a
        main MIME type of "text", or the charset is not defined.

        The list will contain one string for each part of the message, plus
        one for the container message (i.e. self), so that a non-multipart
        message will still return a list of length 1.
        s   charsetN(   s   appends   _[1]s   selfs   walks   parts	   get_params   failobj(   s   selfs   failobjs   _[1]s   part(    (    s#   /usr/lib/python2.2/email/Message.pys   get_charsets³s      (%   s   __name__s
   __module__s   __doc__s   __init__s   __str__s	   as_strings   is_multiparts   set_unixfroms   get_unixfroms   add_payloads   attachs   Nones   get_payloads   set_payloads   __len__s   __getitem__s   __setitem__s   __delitem__s   __contains__s   has_keys   keyss   valuess   itemss   gets   get_alls
   add_headers   get_types   get_main_types   get_subtypes   _get_params_preserves
   get_paramss	   get_params   get_filenames   get_boundarys   set_boundarys   walks   get_charsets(    (    (    s#   /usr/lib/python2.2/email/Message.pys   Message sD    							 																-	(   s   __doc__s
   __future__s
   generatorss   res   base64s   quopris	   cStringIOs   StringIOs   typess   ListTypes   Errorss   Utilss	   SEMISPACEs   compiles   paramres   Message(   s   Errorss   StringIOs   Utilss   base64s   res
   generatorss   ListTypes	   SEMISPACEs   Messages   paramres   quopri(    (    s#   /usr/lib/python2.2/email/Message.pys   ? s   					