ó
Fü½cc           @   sö   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d	 l m Z d d
 l m Z d d l m Z y e Wn! e k
 rÍ d d l m Z n Xd „  Z d „  Z d „  Z d „  Z d S(   sS  Calculate the regular (i.e. non-digest) recipients of the message.

This module calculates the non-digest recipients for the message based on the
list's membership and configuration options.  It places the list of recipients
on the `recips' attribute of the message.  This attribute is used by the
SendmailDeliver and BulkDeliver modules.
iÿÿÿÿN(   t   mm_cfg(   t   Utils(   t   Message(   t   Errors(   t   ENABLED(   t   MailList(   t   _(   t   syslog(   t   MMUnknownListError(   t   Setc         C   sÈ  | j  d ƒ r d  Sd } | j ƒ  } y" |  j | t j ƒ rF d } n  Wn t j k
 r] n Xg  } | j d | ƒ } | | k	 r |  j t j	 t j
 t j f | ƒ rÓ |  j |  j ƒ  |  j ƒ  ƒ } | | d <d  S|  j } t d ƒ }	 t j t j |	 ƒ ‚ n  g  |  j ƒ  D]* }
 |  j |
 ƒ t k r|  j |
 ƒ ^ q} | s}y | j |  j | ƒ ƒ Wq}t j t f k
 ryq}Xn  t |  | | | ƒ t |  | | | ƒ } t |  | | | ƒ } | | d <d  S(   Nt   recipsi   i    t   urgents   Your urgent message to the %(realname)s mailing list was not authorized for
delivery.  The original message as received by Mailman is attached.
(   t   has_keyt
   get_sendert   getMemberOptionR    t   DontReceiveOwnPostsR   t   NotAMemberErrort   gett   Authenticatet   AuthListPostert   AuthListModeratort   AuthListAdmint   getMemberCPAddressest   getRegularMemberKeyst   getDigestMemberKeyst	   real_nameR   t   RejectMessageR   t   wrapt   getDeliveryStatusR   t   getMemberCPAddresst   removet
   ValueErrort   do_topic_filterst
   do_excludet
   do_include(   t   mlistt   msgt   msgdatat   include_sendert   sendert   missingt   passwordR
   t   realnamet   textt   m(    (    s:   /export/web/mailman/mailman/Mailman/Handlers/CalcRecips.pyt   process-   sH    		
		*c   	      C   sò   |  j  s d  S| j d ƒ } g  } | r… x¥ | D]O } |  j | ƒ } | sP q/ n  x+ | D] } | | k rW PqW qW W| j | ƒ q/ WnK xH | D]@ } |  j | ƒ s§ qŒ n  |  j | t j ƒ sŒ | j | ƒ qŒ qŒ Wx | D] } | j | ƒ q× Wd  S(   Nt	   topichits(   t   topics_enabledR   t   getMemberTopicst   appendR   R    t   ReceiveNonmatchingTopicsR   (	   R#   R$   R%   R
   t   hitst	   zaprecipst   usert   utopicst   topic(    (    s:   /export/web/mailman/mailman/Mailman/Handlers/CalcRecips.pyR    k   s*    		c         C   s  |  j  s | St | ƒ } t j j | j d g  ƒ | j d g  ƒ ƒ } g  | D] \ } } | j ƒ  ^ qN } x¤|  j  D]™} | j ƒ  } | | k rš qv n  | j d ƒ \ } }	 | |  j ƒ  k r× t	 d d | ƒ qv n  y t
 | d t ƒ}
 Wn$ t k
 rt	 d d | ƒ qv n Xt j rC|
 j |	 k rCt	 d d | ƒ qv n  |  j rÂxs | j ƒ  D]_ } |
 j | ƒ rrPn  x0 t j | |
 j ƒ D] } |
 j | ƒ rˆPqˆqˆW|
 j | ƒ rYPqYqYWqv n  t g  |
 j ƒ  D]* } |
 j | ƒ t k rÒ|
 j | ƒ ^ qÒƒ } | | 8} qv Wt | ƒ S(	   Nt   tot   cct   @t   errors$   Exclude list %s is a self reference.t   locks   Exclude list %s not found.s*   Exclude list %s is not in the same domain.(   t   regular_exclude_listst   sett   emailR   t   getaddressest   get_allt   lowert   splitt   internal_nameR   R   t   FalseR   R    t   ALLOW_CROSS_DOMAIN_SIBLINGt	   host_namet   regular_exclude_ignoret   get_senderst   isMembert   check_eq_domainst   equivalent_domainsR   R   R   R   t   list(   R#   R$   R%   R
   t   destinationst   xt   yt   listnamet   listlhst   hostnamet   slistR'   R,   t   srecips(    (    s:   /export/web/mailman/mailman/Mailman/Handlers/CalcRecips.pyR!   ™   sR    	%	
		-c         C   sž  |  j  s | St | ƒ } t j j | j d g  ƒ | j d g  ƒ ƒ } g  | D] \ } } | j ƒ  ^ qN } x%|  j  D]} | j ƒ  } | | k rš qv n  | j d ƒ \ } }	 | |  j ƒ  k r× t	 d d | ƒ qv n  y t
 | d t ƒ}
 Wn$ t k
 rt	 d d | ƒ qv n Xt j rC|
 j |	 k rCt	 d d | ƒ qv n  t g  |
 j ƒ  D]* } |
 j | ƒ t k rS|
 j | ƒ ^ qSƒ } | | O} qv Wt | ƒ S(	   NR8   R9   R:   R;   s$   Include list %s is a self reference.R<   s   Include list %s not found.s*   Include list %s is not in the same domain.(   t   regular_include_listsR>   R?   R   R@   RA   RB   RC   RD   R   R   RE   R   R    RF   RG   R   R   R   R   RM   (   R#   R$   R%   R
   RN   RO   RP   RQ   RR   RS   RT   R,   RU   (    (    s:   /export/web/mailman/mailman/Mailman/Handlers/CalcRecips.pyR"   Ê   s<    	%	
	-(   t   __doc__t   email.UtilsR?   t   MailmanR    R   R   R   t   Mailman.MemberAdaptorR   t   Mailman.MailListR   t   Mailman.i18nR   t   Mailman.Logging.SyslogR   t   Mailman.ErrorsR   R>   t	   NameErrort   setsR	   R-   R    R!   R"   (    (    (    s:   /export/web/mailman/mailman/Mailman/Handlers/CalcRecips.pyt   <module>   s$   	>	.	1