ó
Pü½cc           @   s•  d  Z  d d l Z d d l 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 d l m Z d d l m Z d d l m Z d Z y e  e! f Wn e" k
 rId Z  d Z! n Xd d d „  ƒ  YZ# d e e# f d „  ƒ  YZ$ d „  Z% d „  Z& d „  Z' d S(   s   Bounce queue runner.iÿÿÿÿN(   t   MIMEText(   t   MIMEMessage(   t	   parseaddr(   t   mm_cfg(   t   Utils(   t   LockFile(   t   NotAMemberError(   t   UserNotification(   t   _BounceInfo(   t
   BouncerAPI(   t   Runner(   t   get_switchboard(   t   syslog(   t   _s   , i   i    t   BounceMixinc           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sQ   t  j j t j d t  j ƒ  ƒ |  _ d  |  _ d |  _	 t
 j
 ƒ  t j |  _ d  S(   Ns   bounce-events-%05d.pcki    (   t   ost   patht   joinR   t   DATA_DIRt   getpidt   _bounce_events_filet   Nonet   _bounce_events_fpt
   _bouncecntt   timet   REGISTER_BOUNCES_EVERYt   _nextaction(   t   self(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   __init__4   s
    !			c         C   sÊ   t  j ƒ  d  } |  j d  k r[ t j d ƒ } z t |  j d ƒ |  _ Wd  t j | ƒ Xn  x0 | D]( } t j	 | | | | f |  j d ƒ qb W|  j j
 ƒ  t j |  j j ƒ  ƒ |  j t | ƒ 7_ d  S(   Ni   i   s   a+bi   (   R   t	   localtimeR   R   R   t   umaskt   openR   t   cPicklet   dumpt   flusht   fsynct   filenoR   t   len(   R   t   listnamet   addrst   msgt   todayt   omaskt   addr(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   _queue_bounces[   s    c         C   sg  t  d d |  |  j ƒ i  } |  j j d ƒ x… t r³ y" t j |  j ƒ \ } } } } Wn4 t k
 r| } t  d d | ƒ n t k
 r Pn X| j	 | g  ƒ j
 | | | f ƒ q/ Wx} | j ƒ  D]o } |  j | ƒ } | j ƒ  zB x1 | | D]% \ } } } | j | | d | ƒqî W| j ƒ  Wd  | j ƒ  XqÁ W|  j j ƒ  d  |  _ t j |  j ƒ d |  _ d  S(   Nt   bounces   %s processing %s queued bouncesi    s   Error reading bounce events: %st   day(   R   R   R   t   seekt   TrueR    t   loadt
   ValueErrort   EOFErrort
   setdefaultt   appendt   keyst
   _open_listt   Lockt   registerBouncet   Savet   Unlockt   closeR   R   t   unlinkR   (   R   t   eventsR&   R+   R.   R(   t   et   mlist(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   _register_bouncesj   s0    		"&
	c         C   s    |  j  d k r |  j ƒ  n  d  S(   Ni    (   R   RA   (   R   (    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   _cleanup‰   s    c         C   sL   t  j  ƒ  } |  j | k s* |  j d k r. d  S| t j |  _ |  j ƒ  d  S(   Ni    (   R   R   R   R   R   RA   (   R   t   now(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   _doperiodic   s
    c         C   sÎ   | j  ƒ  } | s | j ƒ  n  z” | j | ƒ \ } } } yd | j | ƒ } | sw t | d t j ƒ  d  | j ƒ } n  | j | | | ƒ | s | j	 ƒ  n  Wn t
 k
 r± n XWd  | sÉ | j ƒ  n  Xd  S(   Ng        i   (   t   LockedR8   t   pend_confirmt   getBounceInfoR   R   R   t    bounce_you_are_disabled_warningst   disableBouncingMemberR:   R   R;   (   R   R@   t   tokent   lockedt   opR+   t   bmsgt   info(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   _probe_bounce•   s&    (   t   __name__t
   __module__R   R,   RA   RB   RD   RO   (    (    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyR   3   s   	'				t   BounceRunnerc           B   s;   e  Z e j Z d d  d „ Z d „  Z e j	 Z	 d „  Z
 RS(   i   c         C   s$   t  j |  | | ƒ t j |  ƒ d  S(   N(   R
   R   R   (   R   t   slicet	   numslices(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyR   ¸   s    c      	   C   sÎ  | j  ƒ  t t j ƒ } | j ƒ  j ƒ  t j j ƒ  k ro | j | | d | j d t	 j
 d d ƒ d d ƒd  S| j d ƒ t	 j
 | j d ƒ k rÔ | j | | d t	 j
 d d	 ƒ g d t	 j
 d d ƒ d d ƒd  S| j sá d  St | | ƒ } | rt j | | ƒ t j k rfd  SnN t | | ƒ } | rA|  j | | ƒ d  St j | | ƒ } | t j k rfd  St d  | ƒ } | s±t d
 d | j ƒ  | j d d ƒ ƒ t | | ƒ d  S|  j | j ƒ  | | ƒ d  S(   Nt   recipst	   envsendert   extrat   loopt
   nodecoratei   t   fromt   bouncest   ownerR-   s1   %s: bounce message w/no discernable addresses: %ss
   message-ids   n/a(   t   LoadR   R   t   OUTQUEUE_DIRt   internal_namet   lowert   MAILMAN_SITE_LISTt   enqueueR\   R   t   get_site_emailt   gett	   host_namet   bounce_processingt   verp_bounceR	   t   ScanMessagest   Stopt
   verp_probeRO   t   filterR   R   t   maybe_forwardR,   (   R   R@   R(   t   msgdatat   outqR'   RJ   (    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   _dispose¼   sL    
			c         C   s   t  j |  ƒ t j |  ƒ d  S(   N(   R   RB   R
   (   R   (    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyRB     s    N(   RP   RQ   R   t   BOUNCEQUEUE_DIRt   QDIRR   R   Ro   R   RD   RB   (    (    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyRR   µ   s
   		[	c   
      C   sþ   t  j |  j ƒ  ƒ \ } } g  } x' d D] } | j | j | g  ƒ ƒ q( Wx¬ | D]¤ } t | ƒ d } | st qR n  t j t j	 | ƒ } | s• qR n  y5 | | j
 d ƒ k r³ wR n  d | j
 d d	 ƒ }	 Wn% t k
 rñ t d
 d t j	 ƒ g  SX|	 g SWd  S(   Nt   tos   delivered-tos   envelope-tos   apparently-toi   R[   s   %s@%st   mailboxt   hostt   errors4   VERP_REGEXP doesn't yield the right match groups: %s(   Rr   s   delivered-tos   envelope-tos   apparently-to(   R   t
   ParseEmailt   GetBouncesEmailt   extendt   get_allR   t   ret   searchR   t   VERP_REGEXPt   groupt
   IndexErrorR   (
   R@   R(   t   bmailboxt   bdomaint   valst   headert   fieldRr   t   moR+   (    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyRg     s*    
c         C   s  t  j |  j ƒ  ƒ \ } } g  } x' d D] } | j | j | g  ƒ ƒ q( WxÅ | D]½ } t | ƒ d } | st qR n  t j t j	 | ƒ } | s• qR n  yS | | j
 d ƒ k r³ wR n  | j
 d ƒ }	 |  j |	 d t ƒ}
 |
 d  k	 rç |	 SWqR t k
 rt d	 d
 t j	 ƒ qR XqR Wd  S(   NRr   s   delivered-tos   envelope-tos   apparently-toi   R[   RJ   t   expungeRu   s:   VERP_PROBE_REGEXP doesn't yield the right match groups: %s(   Rr   s   delivered-tos   envelope-tos   apparently-to(   R   Rv   Rw   Rx   Ry   R   Rz   R{   R   t   VERP_PROBE_REGEXPR}   RF   t   FalseR   R~   R   (   R@   R(   R   R€   R   R‚   Rƒ   Rr   R„   RJ   t   data(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyRj   ?  s0    c         C   sž   |  j  ru |  j d d d ƒd } |  j | d t d ƒ d t d ƒ d	 d
 ƒt d d |  j ƒ  | j d d ƒ ƒ n% t d d |  j ƒ  | j d d ƒ ƒ d  S(   Nt   admint   absolutei   s   /bouncet   texts*  The attached message was received as a bounce, but either the bounce format
was not recognized, or no member addresses could be extracted from it.  This
mailing list has been configured to send all unrecognized bounce messages to
the list administrator(s).

For more information see:
%(adminurl)s

t   subjects   Uncaught bounce notificationt   tomoderatorsi    R-   s+   %s: forwarding unrecognized, message-id: %ss
   message-ids   n/as+   %s: discarding unrecognized, message-id: %s(   t&   bounce_unrecognized_goes_to_list_ownert   GetScriptURLt   ForwardMessageR   R   R_   Rd   (   R@   R(   t   adminurl(    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyRl   b  s    					(    ((   t   __doc__R   Rz   R   R    t   email.MIMETextR    t   email.MIMEMessageR   t   email.UtilsR   t   MailmanR   R   R   t   Mailman.ErrorsR   t   Mailman.MessageR   t   Mailman.BouncerR   t   Mailman.BouncersR	   t   Mailman.Queue.RunnerR
   t   Mailman.Queue.sbcacheR   t   Mailman.Logging.SyslogR   t   Mailman.i18nR   t
   COMMASPACER0   R‡   t	   NameErrorR   RR   Rg   Rj   Rl   (    (    (    s9   /export/web/mailman/mailman/Mailman/Queue/BounceRunner.pyt   <module>   s:   
‚j	 	#