ó
7ü½cc           @   sx  d  Z  d d l 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 d d l m Z d d l	 m Z d Z e j e
 j d ƒ ƒ d  Z d „  Z e a i t d ƒ e j 6t d ƒ e j 6t d ƒ e j 6t d ƒ e j 6Z e j a d d d „  ƒ  YZ d d d „  ƒ  YZ  d S(   s   Handle delivery bounces.iÿÿÿÿN(   t
   StringType(   t   MIMEText(   t   MIMEMessage(   t   mm_cfg(   t   Utils(   t   Message(   t   MemberAdaptor(   t   Pending(   t   MMUnknownListError(   t   syslog(   t   i18nt    i   i   c         C   s   |  S(   N(    (   t   s(    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyt   D_+   R   s   due to excessive bouncess   by yourselfs   by the list administrators   for unknown reasonst   _BounceInfoc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s)   | |  _  d  |  _ |  j | | | ƒ d  S(   N(   t   membert   Nonet   cookiet   reset(   t   selfR   t   scoret   datet   noticesleft(    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyt   __init__9   s    		c         C   s(   | |  _  | |  _ | |  _ t |  _ d  S(   N(   R   R   R   t   ZEROHOUR_PLUSONEDAYt
   lastnotice(   R   R   R   R   (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyR   >   s    			c         C   s   d |  j  S(   Nsí   <bounce info for member %(member)s
        current score: %(score)s
        last bounce date: %(date)s
        email notices left: %(noticesleft)s
        last notice date: %(lastnotice)s
        confirmation cookie: %(cookie)s
        >(   t   __dict__(   R   (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyt   __repr__D   s    	(   t   __name__t
   __module__R   R   R   (    (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyR   8   s   		t   Bouncerc           B   sM   e  Z d  „  Z d d e d „ Z d „  Z d d „ Z d „  Z d d „ Z	 RS(   c         C   s‚   t  j |  _ t  j |  _ t  j |  _ t  j |  _ t  j	 |  _
 t  j |  _ t  j |  _ t  j |  _ t  j |  _ i  |  _ i  |  _ d  S(   N(   R   t   DEFAULT_BOUNCE_PROCESSINGt   bounce_processingt   DEFAULT_BOUNCE_SCORE_THRESHOLDt   bounce_score_thresholdt   DEFAULT_BOUNCE_INFO_STALE_AFTERt   bounce_info_stale_aftert(   DEFAULT_BOUNCE_YOU_ARE_DISABLED_WARNINGSt    bounce_you_are_disabled_warningst1   DEFAULT_BOUNCE_YOU_ARE_DISABLED_WARNINGS_INTERVALt)   bounce_you_are_disabled_warnings_intervalt.   DEFAULT_BOUNCE_UNRECOGNIZED_GOES_TO_LIST_OWNERt&   bounce_unrecognized_goes_to_list_ownert/   DEFAULT_BOUNCE_NOTIFY_OWNER_ON_BOUNCE_INCREMENTt'   bounce_notify_owner_on_bounce_incrementt&   DEFAULT_BOUNCE_NOTIFY_OWNER_ON_DISABLEt   bounce_notify_owner_on_disablet&   DEFAULT_BOUNCE_NOTIFY_OWNER_ON_REMOVALt   bounce_notify_owner_on_removalt   bounce_infot   delivery_status(   R   (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyt   InitVarsR   s    	g      ð?c         C   s  |  j  | ƒ s$|  j s | r# d  Sd d l m } xê |  j D]ß } | j d ƒ \ } }	 | j ƒ  } | |  j ƒ  k rŒ t d d | ƒ q= n  zm d  }
 y | | ƒ }
 Wn* t	 k
 rÑ t d d |  j
 | ƒ w= n X|
 j | | | | d t ƒ|
 j ƒ  Wd  |
 r|
 j ƒ  r|
 j ƒ  n  Xq= Wd  S|  j | ƒ } t } | d  k rXt j ƒ  d  } n  t | t ƒ s¡t | | | |  j ƒ } t d	 d
 |  j ƒ  | | j ƒ n|  j | ƒ t j k rÖt d	 d |  j ƒ  | ƒ d  S| j | k rt } t d	 d |  j ƒ  | t j d | d ƒ ƒ n t j | ƒ } t j | j ƒ } | |  j | k  r€| j  | | |  j ƒ t d	 d |  j ƒ  | ƒ n7 | j | 7_ | | _ t d	 d |  j ƒ  | | j ƒ | j |  j! k r9t" j# r#t d	 d |  j ƒ  | | j |  j! ƒ |  j$ | | ƒ | j  d | j | j% ƒ qg|  j& | | | ƒ n. |  j' rg| rg|  j( | | d t) d ƒ ƒn  |  j  | ƒ r‰|  j* | | ƒ n  d  S(   Niÿÿÿÿ(   t   MailListt   @t   errors(   Bouncer: %s: Include list self references)   Bouncer: %s: Include list "%s" not found.t   siblingi   t   bounces   %s: %s bounce score: %ss   %s: %s residual bounce receiveds*   %s: %s already scored a bounce for date %ss   %d-%b-%Yi    i   s'   %s: %s has stale bounce info, resettings   %s: %s current bounce score: %ss-   sending %s list probe to: %s (score %s >= %s)t   dids   bounce score incremented(   i    i    i    i    i   i    (+   t   isMembert   regular_include_listst   Mailman.MailListR4   t   splitt   lowert   internal_nameR	   R   R   t	   real_namet   registerBouncet   Truet   Savet   Lockedt   Unlockt   getBounceInfot   timet	   localtimet
   isinstanceR   R&   R   t   getDeliveryStatusR   t   ENABLEDR   t   Falset   strftimeR   t   midnightR$   R   R"   R   t   VERP_PROBESt	   sendProbeR   t   disableBouncingMemberR,   t   _Bouncer__sendAdminBounceNoticet   _t   setBounceInfo(   R   R   t   msgt   weightt   dayR7   R4   t   listaddrt   listnamet   hostnamet   siblistt   infot   first_todayt   nowt
   lastbounce(    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyRA   m   sŒ    						
c         C   sÁ   |  j  t j |  j ƒ  | ƒ } | | _ |  j | | ƒ t j r\ t d d |  j ƒ  | ƒ n% t d d |  j ƒ  | | j	 |  j
 ƒ |  j | t j ƒ |  j | ƒ |  j r½ |  j | | ƒ n  d  S(   NR8   s-   %s: %s disabling due to probe bounce receiveds-   %s: %s disabling due to bounce score %s >= %s(   t   pend_newR   t	   RE_ENABLER?   R   RT   R   RO   R	   R   R"   t   setDeliveryStatusR   t   BYBOUNCEt   sendNextNotificationR.   RR   (   R   R   R\   RU   R   (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyRQ   Ð   s    					c         C   s$  | d  k r t d ƒ } n  t j |  j ƒ } t j d i |  j d 6| d 6d d 6| d 6d d 6d d	 6| d
 6d |  ƒ} t d ƒ } t j |  j	 ƒ  | | d |  j
 ƒ} | j d ƒ | j t | d t j |  j
 ƒ ƒƒ t | t ƒ r | j t | ƒ ƒ n | j t | ƒ ƒ | j |  ƒ d  S(   Nt   disableds
   bounce.txtRY   t   addrR   t   negativeR9   t   butt   reenablet	   owneraddrt   mlists   Bounce action notificationt   langs   multipart/mixedt   _charset(   R   RS   R   t   get_site_emailt	   host_namet   maketextR@   R   t   UserNotificationt   GetOwnerEmailt   preferred_languaget   set_typet   attachR   t
   GetCharSetRI   R    R   t   send(   R   R   RU   R9   t	   siteownert   textt   subjectt   umsg(    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyt   __sendAdminBounceNoticeå   s0    
		c         C   sº  |  j  | ƒ } | d  k r d  S|  j | ƒ } | j d k r t a |  j | t d ƒ d |  j d d ƒt j a |  j	 | j
 ƒ | t j k r¬ t d d |  j ƒ  | ƒ n  t d d	 |  j ƒ  | i d
 t j 6d t j 6d t j 6d t j 6j | d ƒ ƒ d  Sd |  j d d d ƒ| j
 f } |  j | d d ƒ} |  j ƒ  } |  j | ƒ } t j | ƒ } | d  k r|t d ƒ } n t | ƒ } | t j k r×t j d t j t j | j ƒ ƒ ƒ }	 t d ƒ }
 | |
 7} n  t j d i |  j d 6| j d 6| d 6| d 6|  j  | ƒ d 6|  j! ƒ  d 6| d 6d | d |  ƒ} t" j# | | d | d | ƒ} | d  =d! | j
 | d" <| j$ |  d# t% ƒ| j d 8_ t j ƒ  d$  | _& |  j' | | ƒ d  S(%   Ni    s   disabled addresst   admin_notift   useracki   R8   s'   %s: %s deleted after exhausting noticest	   subscribes%   %s: %s auto-unsubscribed [reason: %s]Rc   t   BYUSERt   BYADMINt   UNKNOWNs   invalid values   %s/%st   confirmt   absolutes   for unknown reasonss   %d-%b-%Ys5    The last bounce received from you was dated %(date)ss   disabled.txtRY   R   t
   confirmurlt
   optionsurlt   passwordRj   t   reasonRl   Rk   Ry   Rz   s   confirm t   Subjectt   noprecedencei   ((   RF   R   RJ   R   R   RS   t   ApprovedDeleteMemberR0   R
   t   pend_confirmR   R   Rc   R	   R?   R€   R   R‚   t   gett   GetScriptURLt   GetOptionsURLt   GetRequestEmailt   getMemberLanguaget   REASONSRG   RM   RH   R   RN   R   Rp   R@   t   getMemberPasswordRr   R   Rq   Rw   RB   R   RT   (   R   R   R\   Rˆ   R…   R†   t   reqaddrRl   t	   txtreasonR   t   extraRy   RU   (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyRd     sl    				

	

c   	      C   sõ   | j  ƒ  } | j d t d ƒ ƒ } t j | t j |  j ƒ ƒ } | d  k r] t d ƒ } n t | j ƒ  ƒ } t	 j
 | j  ƒ  |  j ƒ  | d |  j ƒ} | j d ƒ t | d t j |  j ƒ ƒ} | j | ƒ | j t | ƒ ƒ | j |  ƒ d  S(   NRz   s   (no subject)s!   [No bounce details are available]Rl   s   multipart/mixedRm   (   t
   get_senderR   RS   R   t   onelineRv   Rs   R   t   noticeR   Rq   Rr   Rt   R   Ru   R   Rw   (	   R   RU   t   msgdatat   et   senderRz   R™   t   bmsgt   txt(    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyt   BounceMessageK  s"    			N(
   R   R   R3   R   RL   RA   RQ   RR   Rd   RŸ   (    (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyR   Q   s   	c	"	D(    (    (!   t   __doc__t   sysRG   t   typesR    t   email.MIMETextR   t   email.MIMEMessageR   t   MailmanR   R   R   R   R   t   Mailman.ErrorsR   t   Mailman.Logging.SyslogR	   R
   t   EMPTYSTRINGRH   t   daysR   R   RS   Rc   R€   R   R‚   R’   R   R   (    (    (    s.   /export/web/mailman/mailman/Mailman/Bouncer.pyt   <module>   s0   		