Ñò
?]Mc           @   sg  d  Z  d d k Z d d k l Z d d k Z d d k Z d d k Z d d k Z d d k l	 Z	 d d k
 l Z d d k l Z l Z d d k l Z d d k l Z d	 Z e i d
 e i ƒ Z e g  Z e i ƒ  i d ƒ D] Z e e e ƒ qà [ ƒ Z d e i i f d „  ƒ  YZ d e i i f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d S(   s¢   Standard Mailman message object.

This is a subclass of email.Message but provides a slightly extended interface
which is more convenient for use inside Mailman.
iÿÿÿÿN(   t   StringIO(   t   Charset(   t   Header(   t   ListTypet
   StringType(   t   mm_cfg(   t   Utilss   , s   ([\d.]+)t   .t	   Generatorc           B   s)   e  Z d  Z e d d d „ Z d „  Z RS(   s…   Generates output from a Message object tree, keeping signatures.

       Headers will by default _not_ be folded in attachments.
    iN   i    c         C   s/   t  i i i |  | d | d | ƒ| |  _ d  S(   Nt   mangle_from_t   maxheaderlen(   t   emailR   t   __init__t!   _Generator__children_maxheaderlen(   t   selft   outfpR	   R
   t   children_maxheaderlen(    (    s#   /usr/lib/mailman/Mailman/Message.pyR   3   s    c         C   s   |  i  | |  i |  i |  i ƒ S(   s7   Clone this generator with maxheaderlen set for children(   t	   __class__t   _mangle_from_R   (   R   t   fp(    (    s#   /usr/lib/mailman/Mailman/Message.pyt   clone9   s    (   t   __name__t
   __module__t   __doc__t   TrueR   R   (    (    (    s#   /usr/lib/mailman/Mailman/Message.pyR   .   s   t   Messagec           B   s\   e  Z d  „  Z d „  Z d „  Z d d d „ Z d d d „ Z d d „ Z e	 e
 d „ Z RS(	   c         C   s    t  |  _ t i i i |  ƒ d  S(   N(   t   VERSIONt   __version__R   R   R   (   R   (    (    s#   /usr/lib/mailman/Mailman/Message.pyR   A   s    	c         C   s
   |  i  ƒ  S(   N(   t   __str__(   R   (    (    s#   /usr/lib/mailman/Mailman/Message.pyt   __repr__G   s    c         C   sO  | |  _  | i d d ƒ } t | d <| t j o d  S| i d ƒ p d  |  _ n | i d ƒ p d |  _ n g  } d } x· |  i D]¬ \ } } t | t	 ƒ o} g  } d } xP | i
 D]E \ }	 }
 t |
 t ƒ o t |
 ƒ }
 d } n | i |	 |
 f ƒ q¹ W| o | | _
 d } q n | i | | f ƒ q‡ W| o | |  _ n d  S(   NR   i    t   _charsett   _default_types
   text/plaini   (   i    i    i    (   t   __dict__t   getR   t   has_keyt   NoneR   R   t   _headerst
   isinstanceR   t   _chunksR   R   t   append(   R   t   dt   versiont   headerst   hchangedt   kt   vt   chunkst   cchangedt   st   charset(    (    s#   /usr/lib/mailman/Mailman/Message.pyt   __setstate__J   s8    	

 
 
	i    c         C   s  t  i } | d j	 o
 | } n | o
 d } n d	 } x³ | D]~ } |  | } | p q> n t i | d ƒ } t i i | g ƒ } y | d \ } }	 Wn t j
 o
 q> n X|	 o Pq> q> W|  i ƒ  }
 |
 o |
 i	 ƒ  d }	 n d }	 | p |	 i
 ƒ  S|	 S(
   sÆ  Return the address considered to be the author of the email.

        This can return either the From: header, the Sender: header or the
        envelope header (a.k.a. the unixfrom header).  The first non-empty
        header value found is returned.  However the search order is
        determined by the following:

        - If mm_cfg.USE_ENVELOPE_SENDER is true, then the search order is
          Sender:, From:, unixfrom

        - Otherwise, the search order is From:, Sender:, unixfrom

        The optional argument use_envelope, if given overrides the
        mm_cfg.USE_ENVELOPE_SENDER setting.  It should be set to either 0 or 1
        (don't use None since that indicates no-override).

        unixfrom should never be empty.  The return address is always
        lowercased, unless preserve_case is true.

        This method differs from get_senders() in that it returns one and only
        one address, and uses a different search order.
        t   sendert   froms   us-asciii    i   t    N(   s   senderR4   (   R4   s   sender(   R   t   USE_ENVELOPE_SENDERR#   R   t   onelineR   t   getaddressest
   IndexErrort   get_unixfromt   splitt   lower(   R   t   use_envelopet   preserve_caset   senderfirstR*   t   ht   fieldvalt   addrst   realnamet   addresst   unixfrom(    (    s#   /usr/lib/mailman/Mailman/Message.pyt
   get_senders   s4    	

 
	c         C   sC  | d j o t i } n g  } xÉ | D]Á } | d j oN |  i ƒ  p d } y! | i d | i ƒ  d f ƒ Wqè t j
 o qè Xq' |  i | ƒ } | oJ g  } | D] } | t i	 | d ƒ q© ~ } | i
 t i i | ƒ ƒ q' q' Wg  }	 xJ | D]B }
 |
 d } | d j	 o | o | i ƒ  } n |	 i | ƒ qù W|	 S(   s  Return a list of addresses representing the author of the email.

        The list will contain the following addresses (in order)
        depending on availability:

        1. From:
        2. unixfrom
        3. Reply-To:
        4. Sender:

        The return addresses are always lower cased, unless `preserve_case' is
        true.  Optional `headers' gives an alternative search order, with None
        meaning, search the unixfrom header.  Items in `headers' are field
        names without the trailing colon.
        R5   i   s   us-asciiN(   R#   R   t   SENDER_HEADERSR:   R'   R;   R9   t   get_allR   R7   t   extendR   R8   R<   (   R   R>   R*   t   pairsR@   RA   t	   fieldvalst   _[1]t   fvt   authorst   pairRD   (    (    s#   /usr/lib/mailman/Mailman/Message.pyt   get_senders±   s0     !	&! 
c         C   sD   y  t  i i i |  | ƒ } | SWn t t t f j
 o | SXd S(   s   Some MUA have bugs in RFC2231 filename encoding and cause
        Mailman to stop delivery in Scrubber.py (called from ToDigest.py).
        N(   R   R   t   get_filenamet   UnicodeErrort   LookupErrort
   ValueError(   R   t   failobjt   filename(    (    s#   /usr/lib/mailman/Mailman/Message.pyRQ   Ý   s
    c         C   s8   t  ƒ  } t | d | ƒ} | i |  d | ƒ| i ƒ  S(   sò   Return entire formatted message as a string using
        Mailman.Message.Generator.

        Operates like email.Message.Message.as_string, only
	using Mailman's Message.Generator class. Only the top headers will
        get folded.
        R	   RE   (   R    R   t   flattent   getvalue(   R   RE   R	   R   t   g(    (    s#   /usr/lib/mailman/Mailman/Message.pyt	   as_stringè   s    	N(   R   R   R   R   R2   R#   RF   RP   RQ   t   FalseR   RZ   (    (    (    s#   /usr/lib/mailman/Mailman/Message.pyR   @   s   			)>,t   UserNotificationc           B   s2   e  Z d  Z d d d d „ Z d „  Z d „  Z RS(   s&   Class for internally crafted messages.c         C   sä   t  i |  ƒ d  } | d  j	 o t t i | ƒ ƒ } n | d  j	 o |  i | | ƒ n | d  j o
 d } n t | | d d d d ƒ|  d <| |  d <t | t	 ƒ o  t
 i | ƒ |  d <| |  _ n | |  d <| g |  _ d  S(   Ns   (no subject)t   header_namet   Subjectt   errorst   replacet   Fromt   To(   R   R   R#   R   R   t
   GetCharSett   set_payloadR   R%   R   t
   COMMASPACEt   joint   recips(   R   t   recipR3   t   subjectt   textt   langR1   (    (    s#   /usr/lib/mailman/Mailman/Message.pyR   ú   s     


c         K   s†   |  i  d ƒ p t i | ƒ |  d <n |  i  d ƒ p t i i d d ƒ |  d <n |  i  d ƒ p d |  d	 <n |  i | |  d
 S(   s|   Sends the message by enqueuing it to the `virgin' queue.

        This is used for all internally crafted messages.
        s
   message-ids
   Message-IDt   datet	   localtimei   t   Datet
   precedencet   bulkt
   PrecedenceN(   R"   R   t   unique_message_idR   t
   formatdatet   _enqueue(   R   t   mlistt   _kws(    (    s#   /usr/lib/mailman/Mailman/Message.pyt   send  s    c         K   sT   d d k  l } | t i ƒ } | i |  d | i ƒ  d |  i d d d d | d  S(   Niÿÿÿÿ(   t   get_switchboardt   listnameRg   t
   nodecoratei   t   reduced_list_headers(   t   Mailman.Queue.sbcacheRx   R   t   VIRGINQUEUE_DIRt   enqueuet   internal_nameRg   (   R   Ru   Rv   Rx   t   virginq(    (    s#   /usr/lib/mailman/Mailman/Message.pyRt   !  s    	N(   R   R   R   R#   R   Rw   Rt   (    (    (    s#   /usr/lib/mailman/Mailman/Message.pyR\   ÷   s   	t   OwnerNotificationc           B   s)   e  Z d  Z d d d d „ Z d „  Z RS(   sB   Like user notifications, but this message goes to the list owners.i   c         C   sƒ   | i  } | o | i | i ƒ n t i | i d ƒ } | i } t i |  | | | | | ƒ |  d =| i	 ƒ  |  d <| |  _
 d  S(   Nt   bouncest   toRb   (   t   ownerRI   t	   moderatorR   t   get_site_emailt	   host_namet   preferred_languageR\   R   t   GetOwnerEmailt   _sender(   R   Ru   Ri   Rj   t   tomoderatorsRg   R3   Rk   (    (    s#   /usr/lib/mailman/Mailman/Message.pyR   2  s    
	c         K   s]   d d k  l } | t i ƒ } | i |  d | i ƒ  d |  i d d d d d |  i | d  S(	   Niÿÿÿÿ(   Rx   Ry   Rg   Rz   i   R{   t	   envsender(   R|   Rx   R   R}   R~   R   Rg   RŠ   (   R   Ru   Rv   Rx   R€   (    (    s#   /usr/lib/mailman/Mailman/Message.pyRt   @  s    	N(   R   R   R   R#   R   Rt   (    (    (    s#   /usr/lib/mailman/Mailman/Message.pyR   /  s   (!   R   t   ret	   cStringIOR    R   t   email.Generatort   email.Messaget   email.Utilst   email.CharsetR   t   email.HeaderR   t   typesR   R   t   MailmanR   R   Re   t   matchR   t   mot   tupleRL   t   groupR;   R0   t   intR   R   R   R\   R   (    (    (    s#   /usr/lib/mailman/Mailman/Message.pyt   <module>   s$   <·8
