ó
Nü½cc           @   sz   d  Z  d d l Z d d l m Z d „  Z e j d e j ƒ Z e j d e j ƒ Z e j d ƒ Z	 d „  Z
 d	 „  Z d S(
   sT  Parse bounce messages generated by Postfix.

This also matches something called `Keftamail' which looks just like Postfix
bounces with the word Postfix scratched out and the word `Keftamail' written
in in crayon.

It also matches something claiming to be `The BNS Postfix program', and
`SMTP_Gateway'.  Everybody's gotta be different, huh?
iÿÿÿÿN(   t   StringIOc         C   sD   |  j  ƒ  r3 x1 |  j ƒ  D] } t | | ƒ q Wn | j |  ƒ d  S(   N(   t   is_multipartt   get_payloadt   flattent   append(   t   msgt   leavest   part(    (    s7   /export/web/mailman/mailman/Mailman/Bouncers/Postfix.pyR       s    s5   [ \t]*the\s*(bns)?\s*(postfix|keftamail|smtp_gateway)s   failure reason:$s   <(?P<addr>[^>]*)>:c         C   sÁ   g  } t  |  j ƒ  ƒ } d } xœ | j ƒ  } | s7 Pn  | j ƒ  } | d k rv t j | ƒ sm t j | ƒ rv d } q! | d k r! | r! t j | ƒ } | r¹ | j	 | j
 d ƒ ƒ q¹ q! q! W| S(   Ni    i   t   addr(   R    R   t   readlinet   rstript   pcret   matcht   rcret   acret   searchR   t   group(   R   t   addrst   bodyt   statet   linet   mo(    (    s7   /export/web/mailman/mailman/Mailman/Bouncers/Postfix.pyt   findaddr0   s    *	 c         C   sx   |  j  ƒ  d k r d  Sg  } t |  | ƒ xH | D]@ } | j  ƒ  d k r0 | j d d ƒ j ƒ  d k r0 t | ƒ Sq0 Wd  S(   Ns   multipart/mixeds   multipart/reports
   text/plains   content-descriptiont    t   notification(   s   multipart/mixeds   multipart/report(   t   get_content_typet   NoneR   t   gett   lowerR   (   R   R   t   subpart(    (    s7   /export/web/mailman/mailman/Mailman/Bouncers/Postfix.pyt   processI   s    (   t   __doc__t   ret	   cStringIOR    R   t   compilet
   IGNORECASER   R   R   R   R   (    (    (    s7   /export/web/mailman/mailman/Mailman/Bouncers/Postfix.pyt   <module>   s   			