ó
<ü½cc        y   @   s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l 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 m Z y d d l m Z Wn' e k
 r%d Z e e j ƒ  Z n Xd 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" d d l$ Z$ e$ j% Z& e$ j' Z( Wn; e k
 rÕd d l% Z% d d l) Z) e% j* Z& e) j* Z( n Xy e+ e, f Wn e- k
 rd Z+ d Z, n Xy& d d l. Z/ d d l0 m1 Z1 e+ Z2 Wn e k
 rCe, Z2 n Xy d d l3 Z3 e+ Z4 Wn e k
 rse, Z4 n Xd Z5 d Z6 d Z7 d Z8 d Z9 e e d Z: e j; d e j< ƒ Z= e j; d e j< ƒ Z> d „  Z? d „  Z@ d e+ d „ ZA d „  ZB d „  ZC d „  ZD e j; d  ƒ ZE e j; d! e j< ƒ ZF d" „  ZG e j; d# ƒ ZH d$ d% „ ZI d& „  ZJ d e, d' „ ZL d( „  ZM e, d) „ ZN dü ZO dý ZP g  ZQ xA eO D]9 ZR x0 eP D]( ZS eQ jT eS eR ƒ eQ jT eR eS ƒ q¡Wq”W[S [R d@ „  ZU dA „  ZV e jW dB „ ZX dC „  ZY e+ dD „ ZZ e+ dE „ Z[ e+ dF „ Z\ e j; dG e j< ƒ Z] e, dH „ Z^ dI „  Z_ e, dJ „ Z` dK „  Za dL eb f dM „  ƒ  YZc d e, d d dN „ Zd d e, d d dO „ Ze i dþ dP 6dÿ dQ 6d dR 6ddS 6ddT 6ddV 6ddW 6ddY 6ddZ 6dd[ 6dd\ 6Zf d] „  Zg d e+ d^ „ Zh d e, d_ „ Zi d` „  Zj da „  Zk db „  Zl dc „  Zm dd „  Zn d d de „ Zo d ap df „  Zq d dg „ Zr dh „  Zs di „  Zt dj „  Zu dk „  Zv d dl „ Zw d dm „ Zx dn „  Zy do „  Zz dp „  Z{ dq dr ds dt du dv dw dx dy dz d{ d| d} d~ d d€ d� d‚ dƒ d„ d… d† d‡ dˆ d‰ dŠ d‹ dŒ d� dŽ d� d� d‘ d’ d“ d” d• d– d— d˜ d™ dš d› dœ d� dž dŸ d  d¡ d¢ d£ d¤ d¥ d¦ d§ d¨ d© dª d« d¬ d­ d® d¯ d° d± d² d³ d´ dµ d¶ d· d¸ d¹ dº d» d¼ d½ d¾ d¿ dÀ dÁ dÂ dÃ dÄ dÅ dÆ dÇ dÈ dÉ dÊ dË dÌ dÍ dÎ dÏ dÐ dÑ dÒ dÓ dÔ dÕ dÖ d× dØ dÙ dÚ dÛ dÜ dÝ dÞ dß dà dá dâ dã dä då dæ dç dè dé gy Z| e j; dê j} e| ƒ e j< ƒ Z~ e j; dë ƒ Z e j; dì e j< ƒ Z€ dí „  Z� dî „  Z‚ i  aƒ dï „  Z„ dð „  Z… dñ „  Z† dò „  Z‡ e, dó „ Zˆ i  Z‰ d aŠ dô „  Z‹ dõ „  ZŒ dö „  Z� d÷ „  ZŽ dø „  Z� dù „  Z� dú „  Z‘ dû „  Z’ d S(	  sø   Miscellaneous essential routines.

This includes actual message transmission routines, address checking and
message and address munging, a handy-dandy routine to map a function on all
the mailing lists, and whatever else doesn't belong elsewhere.

iÿÿÿÿ(   t   nested_scopesN(   t   HeaderParseError(   t   UnicodeType(   t
   whitespacet   digits(   t   ascii_letterst   abcdefghijklmnopqrstuvwxyz(   t   mm_cfg(   t   Errors(   t   Site(   t   SafeDict(   t   syslogi   i    (   t   DNSExceptiont    u    s   s   
t   .t   _s   %\(([_a-z]\w*?)\)s?s%   (\${2})|\$([_a-z]\w*)|\${([_a-z]\w*)}c         C   sÁ   t  t j t j d |  ƒ ƒ d k rn t j j d t j j d t j j d d ƒ ƒ ƒ } t d d |  | ƒ t	 St
 j |  ƒ } x= d D]5 } t j j | d | ƒ } t j j | ƒ r„ t Sq„ Wt	 S(   s'   Return true iff list `listname' exists.R   i    t   HTTP_FORWARDED_FORt   HTTP_X_FORWARDED_FORt   REMOTE_ADDRs   unidentified origint   mischiefs(   Hostile listname: listname=%s: remote=%ss   .pcks	   .pck.lasts   .dbs   .db.lastt   config(   s   .pcks	   .pck.lasts   .dbs   .db.last(   t   lent   ret   subR   t   ACCEPTABLE_LISTNAME_CHARACTERSt   ost   environt   getR   t   FalseR	   t   get_listpatht   patht   joint   existst   True(   t   listnamet   remotet   basepatht   extt   dbfile(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   list_existsg   s    
$c           C   s
   t  j ƒ  S(   s8   Return the names of all lists in default list directory.(   R	   t   get_listnames(    (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt
   list_names�   s    iF   c         C   sz  d } t  j d |  ƒ } xW| D]O} g  } t } x“ | j t ƒ D]‚ } | s` | j | ƒ qA n  | r | d t k r t }	 n t }	 | r° |	 r° | d j ƒ  d | | d <n | j | ƒ |	 } qA Wxš| D]’}  x|  rUt |  ƒ | k rþ |  } d }  nJ| }
 x* |
 d k r0|  |
 t k r0|
 d 8}
 qW|
 } x* | d k rc|  | t k rc| d 8} q:W| d k rï| } x0 | t |  ƒ k  r¨|  | t k r¨| d 7} qyW| }
 x0 |
 t |  ƒ k  rá|  |
 t k rá|
 d 7}
 q²W|
 d 8}
 n  |  | d  d } |
 d 7}
 x0 |
 t |  ƒ k  r=|  |
 t k r=|
 d 7}
 qW|  |
 }  | | 7} q× W| d 7} qÎ W| d 7} q W| d  S(	   sÒ  Wrap and fill the text to the specified column.

    Wrapping is always in effect, although if it is not possible to wrap a
    line (because some word is longer than `column' characters) the line is
    broken at the next available whitespace boundary.  Paragraphs are also
    always filled, unless honor_leading_ws is true and the line begins with
    whitespace.  This is the algorithm that the Python FAQ wizard uses, and
    seems like a good compromise.

    R   s   

i    iÿÿÿÿt    i   s   
iþÿÿÿ(	   R   t   splitR   t   NLt   appendR   R!   t   rstripR   (   t   textt   columnt   honor_leading_wst   wrappedt   parast   parat   linest   fillprevt   linet   fillthist   bolt   eol(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   wrap‰   sX    	
		%%
%
c         C   s"   d } d } | j  |  j | ƒ ƒ S(   Ns   
 .
s   
.
(   R   R+   (   R/   t   JOINERt   SEP(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   QuotePeriodsÔ   s    c         C   sn   d  } d  } |  j ƒ  }  |  j d ƒ } | d k  r= |  d  f S|  |  } |  | d } | j d ƒ } | | f S(   Nt   @i   R   (   t   Nonet   lowert   findR+   (   t   emailt   usert   domaint   at_signt   rest(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt
   ParseEmailÛ   s    

c         C   s=   |  j  d ƒ } | d k r |  S|  |  d |  | d j ƒ  S(   s3   returns the address with the domain part lowercasedR?   iÿÿÿÿi   (   RB   RA   (   t   addrt   atind(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   LCDomainè   s    s"   [][()<>|:;^,\\"\000-\037\177-\377]s	   [-a-z0-9]c         C   s8  t  |  t ƒ s t  |  t ƒ rF t |  ƒ d k r9 d }  qF |  d }  n  |  sb |  j d ƒ d k rn t j ‚ n  t j |  ƒ rŒ t j	 |  ‚ n  t
 |  ƒ \ } } | s³ t j |  ‚ n  t | ƒ d k  rÔ t j |  ‚ n  x] | D]U } t | ƒ d k s!| d d k s!t t j d | ƒ ƒ d k rÛ t j	 |  ‚ qÛ qÛ Wd S(   s0   Verify that an email address isn't grossly evil.i    R   iÿÿÿÿR*   i   t   -N(   t
   isinstancet   listt   tupleR   t   countR   t   MMBadEmailErrort	   _badcharst   searcht   MMHostileAddressRH   t   _valid_domainR   (   t   sRD   t   domain_partst   p(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   ValidateEmail÷   s     	@s   [^\x21-\x7e]t	   PATH_INFOc         C   sZ  t  j j |  ƒ } | rVt  j j d t  j j d t  j j d d ƒ ƒ ƒ } t j | ƒ r† t j | ƒ d } t d d t ƒ  | ƒ n  g  | j d ƒ D] } | r– | ^ q– } t j	 d k rÉ t j	 } n= t
 ƒ  } | r t g  | D] } t | ƒ ^ qâ ƒ } n d	 } | rRt | d ƒ | k rRt d
 d | d | ƒ | d |  d | d <n  | Sd  S(   NR   R   R   s   unidentified origini    t   errors;   Warning: Possible malformed path attack domain=%s remote=%st   /i   R   s(   Hostile listname: listname=%s: remote=%ss   ...(   R   R   R   t   CRNLpatRS   R+   R   t
   get_domainR   t   MAX_LISTNAME_LENGTHR)   t   maxR   R@   (   t   envarR   R#   RX   t   piecest   longestt	   lst_namest   x(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   GetPathPieces  s2    
(	(c           C   s   t  j j d ƒ S(   Nt   REQUEST_METHOD(   R   R   R   (    (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   GetRequestMethod:  s    c         C   s&  | d k r< t j t ƒ  } | d d k r< | d } q< n  t j j d ƒ } | d k r… t j j d d ƒ t j j d d ƒ } n  t j | ƒ d } | r| j | ƒ r| t	 | ƒ } | j
 d ƒ } | d	 k rñ | j d d	 | ƒ } n | j d ƒ } d
 | |  } n
 | |  } | t j S(   s£   target - scriptname only, nothing extra
    web_page_url - the list's configvar of the same name
    absolute - a flag which if set, generates an absolute url
    iÿÿÿÿR\   t   REQUEST_URIt   SCRIPT_NAMER   RZ   i   t   ?i    s   ../N(   R@   R   t   DEFAULT_URL_PATTERNR^   R   R   R   t   urlparset
   startswithR   RB   RP   t   CGIEXT(   t   targett   web_page_urlt   absolutet   fullpatht   baseurlt   iRP   R   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt	   ScriptURL?  s$    
c         C   s�   |  j  ƒ  }  t |  ƒ \ } } |  g } | r} | d } xC t | ƒ d k ry | j d | t j | ƒ f ƒ | d } q: Wn  | S(   s  returns a sorted list of addresses that could possibly match
    a given name.

    For Example, given scott@pobox.com, return ['scott@pobox.com'],
    given scott@blackbox.pobox.com return ['scott@blackbox.pobox.com',
                                           'scott@pobox.com']i   i   s   %s@%s(   RA   RH   R   R-   t   DOTR   (   t   nameRD   RE   t   res(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   GetPossibleMatchingAddrs\  s    	
 c         C   sO   i  } | r0 x< |  D] } t  | | j ƒ  <q Wn x |  D] } t  | | <q7 W| S(   s<   Return a dict keyed by the entries in the list passed to it.(   R!   RA   (   t   Lt   foldcaset   dRu   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt	   List2Dictp  s    t   at   eRu   t   ot   ut   bt   cR}   t   ft   gt   ht   kt   mt   nRX   t   rRV   t   tt   vt   wRe   t   zc         C   sJ   g  } x0 t  | ƒ d |  k  r8 | j t j t ƒ ƒ q	 Wt j | ƒ |   S(   Ni   (   R   R-   t   randomt   choicet
   _syllablest   EMPTYSTRINGR   (   t   lengtht   syls(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   UserFriendly_MakeRandomPasswordˆ  s    c         C   sG  d } g  } d  } zxÞ | |  k  rõ y t j |  | ƒ } Wn— t t f k
 rÔ | d  k r» y t j d t j ƒ } Wq» t k
 r· } | j t j	 k r  ‚  n  t
 d d ƒ t |  ƒ SXn  t j | |  | ƒ } n X| j | ƒ | t | ƒ 7} q Wt j t j | ƒ ƒ } | j d d ƒ |   SWd  | d  k	 rBt j | ƒ n  Xd  S(   Ni    s   /dev/urandomR[   s+   urandom not available, passwords not secures   
R   (   R@   R   t   urandomt   AttributeErrort   NotImplementedErrort   opent   O_RDONLYt   OSErrort   errnot   ENOENTR   R–   t   readR-   R   t   base64t   encodestringR“   R   t   replacet   close(   R”   t	   bytesreadt   bytest   fdt   newbytesR€   RV   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   Secure_MakeRandomPassword�  s0    c         C   s   t  j r t |  ƒ St |  ƒ S(   N(   R   t   USER_FRIENDLY_PASSWORDSR–   R¨   (   R”   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   MakeRandomPassword°  s    	
c          C   sR   t  t j ƒ  d ƒ }  t  t j ƒ  d ƒ } d „  } d t t | |  | f ƒ ƒ S(   Ni4   c         S   sV   d |  k o d k  n r) |  d 7}  n  d |  k o@ d k  n rR |  d 7}  n  |  S(   Ni    i   iA   i4   iG   (    (   R„   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   mkletter¹  s
    s   %c%c(   t   intR�   RO   t   map(   t   chr1t   chr2R«   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   GetRandomSeed¶  s    	c         C   sy   | r t  j } n	 t  j } t j d ƒ } z: t | d ƒ } | j t |  ƒ j ƒ  d ƒ | j	 ƒ  Wd  t j | ƒ Xd  S(   Ni   RŽ   s   
(
   R   t   SITE_PW_FILEt   LISTCREATOR_PW_FILER   t   umaskRš   t   writet   sha_newt	   hexdigestR£   (   t   pwt	   siteadmint   filenamet   omaskt   fp(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   set_global_passwordÄ  s    	c         C   sx   |  r t  j } n	 t  j } y* t | ƒ } | j ƒ  d  } | j ƒ  Wn, t k
 rs } | j t j k ro ‚  n  d  SX| S(   Niÿÿÿÿ(
   R   R±   R²   Rš   RŸ   R£   t   IOErrorR�   Rž   R@   (   R¸   R¹   R»   t	   challengeR€   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   get_global_passwordÓ  s    	 c         C   s2   t  | ƒ } | d  k r d  S| t |  ƒ j ƒ  k S(   N(   R¿   R@   Rµ   R¶   (   t   responseR¸   R¾   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   check_global_passwordã  s    s   &amp;((?:#[0-9]+|[a-z]+);)c         C   sÍ   t  |  t ƒ s t  |  t ƒ rF t |  ƒ d k r9 d }  qF |  d }  n  t j r‘ t  |  t ƒ r‘ x- t j D] } |  j | t j | ƒ }  qh Wq‘ n  | rª t	 j
 |  d t ƒSt j d t	 j
 |  d t ƒƒ Sd  S(   Ni    R   iÿÿÿÿt   quotes   &\1(   RM   RN   RO   R   R   t   BROKEN_BROWSER_WORKAROUNDt   strt   BROKEN_BROWSER_REPLACEMENTSR¢   t   cgit   escapeR!   t   _ampreR   (   RV   t   doubleescapeRˆ   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   websafeì  s    		#c         C   sa   |  j  d d ƒ } t | ƒ d k rW y | d t | d ƒ f SWqW t k
 rS qW Xn  |  d f S(   Nt   :i   i   i    iw   (   R+   R   R¬   t
   ValueError(   RV   t   parts(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt	   nntpsplit  s    c         C   s*   | r |  j  d d ƒ S|  j  d d ƒ Sd S(   s¢   Make email address unrecognizable to web spiders, but invertable.

    When for_text option is set (not default), make a sentence fragment
    instead of a token.R?   s    at s   --at--N(   R¢   (   RI   t   for_text(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   ObscureEmail  s    c         C   s   |  j  d d ƒ S(   s!   Invert ObscureEmail() conversion.s   --at--R?   (   R¢   (   RI   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   UnobscureEmail  s    t	   OuterExitc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyRÒ   "  s   c         C   sÁ  g  } | d  k	 r" | j | ƒ n  | d  k	 rA | j | j ƒ n  | j t j ƒ g  } | d  k	 r› | j | j ƒ  ƒ | j t j j t j	 | j
 ƒ ƒ n  | j t j j t j	 d ƒ ƒ | j t j	 ƒ d  } yˆ x� | D]y } xp | D]h } t j j | | |  ƒ }	 y t |	 ƒ } t ‚ Wqç t k
 rN}
 |
 j t j k rE‚  n  d  } qç Xqç WqÚ WWn t k
 rkn X| d  k réy+ t j j t j	 d |  ƒ }	 t |	 ƒ } Wqét k
 rå}
 |
 j t j k rÍ‚  n  t t j d |  ƒ ‚ qéXn  | j ƒ  } | j ƒ  | } | d  k	 r¡y^ t | ƒ } y | j | ƒ } Wn8 t k
 rmt | t | ƒ d ƒ } | j | ƒ } n XWq¡t t f k
 r�}
 t d d |	 |
 ƒ q¡Xn  | r±| |	 f St | ƒ |	 f S(   Nt   sitet   ens   No template file foundR¢   R[   s   broken template: %s
%s(   R@   R-   t   preferred_languageR   t   DEFAULT_SERVER_LANGUAGERs   R   R   R   t   TEMPLATE_DIRt	   host_nameRš   RÒ   R½   R�   Rž   RŸ   R£   R
   t   interpolatet   UnicodeErrort   unicodet
   GetCharSett	   TypeErrorRÌ   R   R;   (   t   templatefilet   dictt   rawt   langt   mlistt	   languagest
   searchdirsR»   t   dirR¹   R€   t   templateR/   t   sdictt	   utemplate(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   findtext%  sf    4%
  

c         C   s   t  |  | | | | ƒ d S(   Ni    (   Rë   (   Rà   Rá   Râ   Rã   Rä   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   maketext”  s    t   confirmt   helpt   infot   listst   optionsi   t   passwordt   removei   t   sett	   subscribet   unsubscribet   whoc         C   s¥  d } g  } xc t  j j |  ƒ D]O } | d k r5 Pn  | j ƒ  rN | d 7} n  | t j k ra t S| j | ƒ q Wt j	 | ƒ } t
 j | j ƒ  j ƒ  ƒ r  t S| d  } t |  j d d ƒ ƒ } | j | ƒ xÏ | D]Ç } | j ƒ  sî qÖ n  g  | j ƒ  D] } | j ƒ  ^ qû } t
 j | d d ƒ \ }	 }
 |	 d  k rM|
 d  k rMqÖ n  |	 t | d ƒ k on|
 k n rÖ | d d k r™| d d k r™qÖ n  t SqÖ Wt S(   Ni    s   -- i   i   t   subjectR   Rô   i   t   ont   off(   NN(   Rù   Rú   (   RC   t	   Iteratorst   body_line_iteratort   stripR   t   DEFAULT_MAIL_COMMANDS_MAX_LINESR   R-   R,   R   t	   ADMINDATAt   has_keyRA   R!   RÄ   R   R+   R@   R   (   t   msgt   linecntR5   R7   t   bodytextt	   bodylinesRø   t   wordt   wordst   minargst   maxargs(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   is_administrivia«  s8    
%& c         C   s{   |  } t  j j d ƒ r( t  j d } n? t  j j d ƒ rg t  j j d ƒ rg t  j d t  j d } n  | rw t | ƒ S| S(   s  Return the full virtual path this CGI script was invoked with.

    Newer web servers seems to supply this info in the REQUEST_URI
    environment variable -- which isn't part of the CGI/1.1 spec.
    Thus, if REQUEST_URI isn't available, we concatenate SCRIPT_NAME
    and PATH_INFO, both of which are part of CGI/1.1.

    Optional argument `fallback' (default `None') is returned if both of
    the above methods fail.

    The url will be cgi escaped to prevent cross-site scripting attacks,
    unless `escape' is set to 0.
    Ri   Rj   RZ   (   R   R   R   RÊ   (   t   fallbackRÇ   t   url(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   GetRequestURIÒ  s    $
c         C   s±   xª |  r¬ | r | ƒ  n  y t  j d t  j ƒ \ } } Wn6 t k
 rp } | j t j k rb ‚  n  |  j ƒ  Pn X| d k rŸ y |  | =WqŸ t k
 r› qŸ Xn  | r Pq q Wd  S(   Niÿÿÿÿi    (   R   t   waitpidt   WNOHANGRœ   R�   t   ECHILDt   cleart   KeyError(   t   kidst   funct   oncet   pidt   statusR€   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   reapì  s"    	

c         C   s   t  j |  d S(   Ni    (   R   t   LC_DESCRIPTIONS(   Rã   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   GetLanguageDescr  s    c         C   s   t  j |  d S(   Ni   (   R   R  (   Rã   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyRÞ     s    c         C   s   t  j |  d S(   Ni   (   R   R  (   Rã   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   GetDirection	  s    c         C   s   t  j j |  ƒ S(   N(   R   R  R   (   Rã   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt
   IsLanguage  s    c          C   s¹   t  j j d t  j j d ƒ ƒ }  t  j j d ƒ } | rd |  j d | ƒ rd |  t | ƒ d  }  n  t j rƒ |  rƒ t |  j ƒ  ƒ St j	 r¢ t
 j
 t j	 ƒ d p¨ t j } | j ƒ  Sd  S(   Nt	   HTTP_HOSTt   SERVER_NAMEt   SERVER_PORTRË   i   (   R   R   R   t   endswithR   R   t   VIRTUAL_HOST_OVERVIEWRÊ   RA   t   DEFAULT_URLRm   t   DEFAULT_URL_HOST(   t   hostt   portt   hostname(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyR^     s    !		c         C   s[   |  d  k r* t j j t ƒ  t ƒ  ƒ }  n  | d  k rG d t j |  f Sd t j | |  f S(   Ns   %s@%ss   %s-%s@%s(   R@   R   t   VIRTUAL_HOSTSR   R^   t   MAILMAN_SITE_LIST(   R%  t   extra(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   get_site_email"  s
    c         C   s<   d t  t j ƒ  t j ƒ  |  j ƒ  |  j f } t  d 7a  | S(   Ns   <mailman.%d.%d.%d.%s@%s>i   (   t   _serialt   timeR   t   getpidt   internal_nameRÚ   (   Rä   t   msgid(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   unique_message_id3  s
    
c         C   s4   |  d  k r t j ƒ  d  }  n  t j |  d d ƒ S(   Ni   i    i   iÿÿÿÿ(   i    (   i    i    i    i    i    (   iÿÿÿÿ(   R@   R+  t	   localtimet   mktime(   t   date(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   midnight>  s    c         C   s®   |  j  d d ƒ j  d d ƒ }  t j |  ƒ } xq t d t | ƒ d ƒ D]W } | | d r‹ | | d d t k r‹ d | | d	 | | <qF d | | | | <qF Wt j | ƒ S(
   s$   Convert from %-strings to $-strings.t   $s   $$s   %%t   %i   i   i    s   ${t   }(   R¢   t   creR+   t   rangeR   t
   IDENTCHARSR“   R   (   RV   RÍ   Ru   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt	   to_dollarM  s    &c         C   sÖ   |  j  d d ƒ j  d d ƒ }  t j |  ƒ } x� t d t | ƒ d ƒ D]v } | | d
 k	 ri d | | <qF | | d d
 k	 rž d | | d d | | d <qF d | | d	 d | | d	 <qF Wt j t d
 | ƒ ƒ S(   s$   Convert from $-strings to %-strings.R5  s   %%s   $$R4  i   i   s   %(s   )si   N(	   R¢   t   dreR+   R8  R   R@   R“   R   t   filter(   RV   RÍ   Ru   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt
   to_percentY  s    !"c         C   s_   i  } xR t  d g  t j |  ƒ D]! \ } } } | p= | p= d ^ q ƒ D] } t | | <qG W| S(   s?   Return the set (dictionary) of identifiers found in a $-string.N(   R<  R@   R;  t   findallR!   (   RV   R}   R   Rƒ   R„   Rx   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   dollar_identifiersg  s    Gc         C   s.   i  } x! t  j |  ƒ D] } t | | <q W| S(   s?   Return the set (dictionary) of identifiers found in a %-string.(   R7  R>  R!   (   RV   R}   Rx   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   percent_identifierso  s    c            sD  g  ‰ t  j d |  ƒ } ‡ f d †  } ‡  f d †  } xø t r0ˆ j | | j d ƒ ƒ ƒ | se Pn  | j d ƒ } | j d ƒ rÍ y | t | d ƒ ƒ Wq-t k
 rÉ ˆ j | d | d ƒ ƒ q-Xq9 t j	 j
 | d	 ƒ } | j d ƒ r| j d ƒ r| t | d d
 !ƒ ƒ q9 ˆ j | | ƒ ƒ q9 Wt j ˆ ƒ } | S(   Ns   &(?P<ref>[^;]+);c            s   ˆ  j  t |  ƒ ƒ d  S(   N(   R-   t   unichr(   Ru   (   t   newparts(    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   appchr}  s    c            sY   t  |  t ƒ r |  Sˆ  d  k r( d } n! t ˆ  ƒ } | d k rI d } n  t |  | d ƒ S(   Ns
   iso-8859-1s   us-asciiR¢   (   RM   RÝ   R@   RÞ   (   RV   t   charset(   Rã   (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt	   tounicode€  s    		i    t   #i   t   &t   ;Rk   iÿÿÿÿ(   R   R+   R!   R-   t   popRn   R¬   RÌ   t   htmlentitydefst
   entitydefsR   R  R“   R   (   RV   Rã   RÍ   RC  RE  t   refR„   t   newstr(    (   Rã   RB  s,   /export/web/mailman/mailman/Mailman/Utils.pyt   canonstrz  s(    	"c         C   sˆ   |  d  k r d }  n  | d  k r* d } n t | ƒ } y3 t |  t ƒ rU |  j | ƒ St |  | ƒ } |  SWn t k
 rƒ t |  ƒ SXd  S(   Nu    s   us-ascii(   R@   RÞ   RM   R   t   encodeRÝ   RÜ   t   uquote(   RV   Rã   RD  R‚   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt
   uncanonstr©  s    		c         C   sc   g  } xG |  D]? } t  | ƒ } | d k r? | j d | ƒ q | j | ƒ q Wt t j | ƒ ƒ S(   Ni   s   &#%3d;(   t   ordR-   RÄ   R“   R   (   RV   R   R„   R�   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyRP  ¾  s    c         C   s‡   yS t  j j t  j j |  ƒ ƒ } | j ƒ  } t j | j ƒ  ƒ } | j | d ƒ SWn- t	 t
 t t f k
 r‚ t j |  j ƒ  ƒ SXd  S(   NR¢   (   RC   t   Headert   make_headert   decode_headert   __unicode__t   UEMPTYSTRINGR   t
   splitlinesRO  t   LookupErrorRÜ   RÌ   R   R“   (   RV   t   csetR‡   t   ustrR7   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   onelineÊ  s    c         C   sô  t  |  t ƒ s |  Sd } d } t } t } t } x¼| t |  ƒ k  rï|  | } | r› | t k ro | d 7} n# | t k rˆ | d 7} n
 | | 7} t } nG| r¹ | t k rât } qân)| d k rÕ | rÕ t } n| d k r| rt } | | 7} t } ná | d k r&| r&t } | | 7} n¼ t j d | ƒ r€| râ| t k rW| d 7} q}| t k rp| d 7} q}| | 7} qânb | d	 k r¦| r¦| | 7} t } n< | t k r¿| d 7} n# | t k rØ| d 7} n
 | | 7} | d
 7} q4 W| S(   NR   i    s   \ns   \rRF  t   [t   ]s   \ss   \i   (	   RM   RÄ   R   R   R,   t   CRR!   R   RS   (   t   patternt
   newpatternRu   t   inclasst	   skiptoeolt   copynextR„   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   strip_verbose_patternÖ  sZ    

		
	
	
s   <i?frames2   <link(?! rel="SHORTCUT ICON" href="<mm-favicon>">)s   <metas   <objects   <scripts
   @keyframess   \bj(?:ava)?script\bs   \bvbs(?:cript)?\bs   \bdomactivate\bs   \bdomattrmodified\bs   \bdomcharacterdatamodified\bs   \bdomfocus(?:in|out)\bs   \bdommenuitem(?:in)?active\bs   \bdommousescroll\bs$   \bdomnodeinserted(?:intodocument)?\bs#   \bdomnoderemoved(?:fromdocument)?\bs   \bdomsubtreemodified\bs   \bfscommand\bs   \bonabort\bs   \bon(?:de)?activate\bs   \bon(?:after|before)print\bs   \bon(?:after|before)update\bs+   \b(?:on)?animation(?:end|iteration|start)\bs8   \bonbefore(?:(?:de)?activate|copy|cut|editfocus|paste)\bs   \bonbeforeunload\bs   \bonbegin\bs
   \bonblur\bs   \bonbounce\bs   \bonbroadcast\bs   \boncanplay(?:through)?\bs   \bon(?:cell)?change\bs   \boncheckboxstatechange\bs   \bon(?:dbl)?click\bs   \bonclose\bs   \boncommand(?:update)?\bs   \boncomposition(?:end|start)\bs   \boncontextmenu\bs   \boncontrolselect\bs
   \boncopy\bs	   \boncut\bs   \bondataavailable\bs!   \bondataset(?:changed|complete)\bs5   \bondrag(?:drop|end|enter|exit|gesture|leave|over)?\bs   \bondragstart\bs
   \bondrop\bs   \bondurationchange\bs   \bonemptied\bs   \bonend(?:ed)?\bs   \bonerror(?:update)?\bs   \bonfilterchange\bs   \bonfinish\bs   \bonfocus(?:in|out)?\bs   \bonhashchange\bs
   \bonhelp\bs   \boninput\bs   \bonkey(?:up|down|press)\bs   \bonlayoutcomplete\bs   \bon(?:un)?load\bs   \bonloaded(?:meta)?data\bs   \bonloadstart\bs   \bonlosecapture\bs   \bonmedia(?:complete|error)\bs   \bonmessage\bs6   \bonmouse(?:down|enter|leave|move|out|over|up|wheel)\bs   \bonmove(?:end|start)?\bs   \bon(?:off|on)line\bs
   \bonopen\bs   \bonoutofsync\bs   \bonoverflow(?:changed)?\bs   \bonpage(?:hide|show)\bs   \bonpaint\bs   \bonpaste\bs   \bonpause\bs   \bonplay(?:ing)?\bs   \bonpopstate\bs*   \bonpopup(?:hidden|hiding|showing|shown)\bs   \bonprogress\bs   \bonpropertychange\bs   \bonradiostatechange\bs   \bonratechange\bs   \bonreadystatechange\bs   \bonrepeat\bs   \bonreset\bs   \bonresize(?:end|start)?\bs   \bonresume\bs   \bonreverse\bs'   \bonrow(?:delete|enter|exit|inserted)\bs#   \bonrows(?:delete|enter|inserted)\bs   \bonscroll\bs   \bonsearch\bs   \bonseek(?:ed|ing)?\bs   \bonselect(?:start)?\bs   \bonselectionchange\bs
   \bonshow\bs   \bonstart\bs   \bonstalled\bs
   \bonstop\bs   \bonstorage\bs   \bonsubmit\bs   \bonsuspend\bs   \bonsync(?:from|to)preference\bs   \bonsyncrestored\bs
   \bontext\bs   \bontime(?:error|update)\bs   \bontoggle\bs$   \bontouch(?:cancel|end|move|start)\bs   \bontrackchange\bs   \b(?:on)?transitionend\bs   \bonunderflow\bs   \bonurlflip\bs   \bonvolumechange\bs   \bonwaiting\bs   \bonwheel\bs   \bseeksegmenttime\bs   \bsvgabort\bs   \bsvgerror\bs   \bsvgload\bs   \bsvgresize\bs   \bsvgscroll\bs   \bsvgunload\bs   \bsvgzoom\bt   |s   [ -	--Ÿ]s,   (&#[0-9]+;?)|(&#x[0-9a-f]+;?)|(%[0-9a-f]{2})c         C   s•   |  j  ƒ  j ƒ  j d ƒ } yG | j d ƒ s< | j d ƒ rR t | d d ƒ } n t | d ƒ } Wn t k
 rv d SX| d k  r� t | ƒ Sd Sd	 S(
   s=   Translate &#... and %xx encodings into the encoded character.s   &#;Re   R5  i   i   i
   R   i   N(   t   groupRA   Rý   Rn   R¬   RÌ   t   chr(   t   mot   matcht   val(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt
   _translatež  s    
c         C   s3   t  j t j d t j t |  ƒ ƒ ƒ r+ t St Sd S(   sW  Check HTML string for various tags, script language names and
    'onxxx' actions that can be used in XSS attacks.
    Currently, this a very simple minded test.  It just looks for
    patterns without analyzing context.  Thus, it potentially flags lots
    of benign stuff.
    Returns True if anything suspicious found, False otherwise.
    R   N(   t   _badhtmlRS   t   _filtercharsR   t   _encodedcharsRl  R!   R   (   t   html(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   suspiciousHTML®  s    	c         C   s:  t  r
 d S|  s d Sy t j |  ƒ } Wn* t j k
 rS } t d d |  | ƒ d SXxß | j ƒ  D]Ñ } | j ƒ  sa | j d ƒ sa | j d ƒ r˜ qa n  t j	 d d | j ƒ  ƒ } | s¿ qa n  | j
 ƒ  j d ƒ } | d	 j d
 ƒ r	t } | d	 d g | d } n t } | j ƒ  d j | ƒ } | t  | <qa Wd S(   s\   This loads and parses the data from the url argument into s_dict for
    use by get_org_dom.NR[   s#   Unable to retrieve data from %s: %sR*   s   //s    .*R   R   i    t   !i   (   t   s_dictt   urllib2t   urlopent   URLErrorR   t	   readlinesRý   Rn   R   R   RA   R+   R!   R   t   reverseR   (   R  R}   R€   R7   RÍ   t   excRˆ   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   get_suffixesÅ  s2    
+
c         C   s4   |  t  | d t |  ƒ ƒ  } | j ƒ  d j | ƒ S(   sJ   A helper to get a domain name consisting of the first l+1 labels
    in d.i   R   (   t   minR   Rx  R   (   R}   t   lt   dom(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   _get_domä  s    
c         C   s—  t  s t t j ƒ n  g  } |  j ƒ  j d ƒ } | j ƒ  xÅ t  j ƒ  D]· } | j d ƒ } t | ƒ t | ƒ k rH x‡ t	 t | ƒ d ƒ D]. } | | | | k rŒ | | d k rŒ PqŒ qŒ W| t | ƒ d | d k sì | d d k rÿ | j
 | ƒ qÿ qH qH W| st | d ƒ Sd } xk | D]c } t  | rSt | t | j d ƒ ƒ d ƒ St | j d ƒ ƒ | k r#t | j d ƒ ƒ } q#q#Wt | | ƒ S(   sq   Given a domain name, this returns the corresponding Organizational
    Domain which may be the same as the input.R   i   t   *iÿÿÿÿi    (   Rs  Rz  R   t$   DMARC_ORGANIZATIONAL_DOMAIN_DATA_URLRA   R+   Rx  t   keysR   R8  R-   R~  (   RE   t   hitsR}   Rˆ   t   ksRu   R|  (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   get_org_domë  s,    
$.
 c         C   sÇ   t  s t d d |  j ƒ t S| j ƒ  } | j d ƒ } | d k  rH t S| | d } t |  | d | ƒ } | d k r| | St | ƒ } | | k rÃ t |  | d | d t ƒ} | d k rÃ | Sn  t S(   NR[   s@   DNS lookup for dmarc_moderation_action for list %s not availableR?   i   s   _dmarc.t   continuet   org(	   t   dns_resolverR   t	   real_nameR   RA   t   rfindt   _DMARCProhibitedR„  R!   (   Rä   RC   RF   t   f_domRe   t   o_dom(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   IsDMARCProhibited  s&    
c      
   C   s  yO t  j j ƒ  } t t j ƒ | _ t t j ƒ | _ | j	 | t  j
 j ƒ } Wnz t  j j t  j j f k
 ru d St  j j k
 rŸ t d d | | ƒ t St k
 rË } t d d | | | j ƒ t SXi  } i  } t | d g ƒ }	 x¢ | j j D]” }
 |
 j j ƒ  j ƒ  } |
 j t  j
 j k rE|
 j d j j ƒ  | | <n  |
 j t  j
 j k r`qø n  | j | g  ƒ j d j |
 j d j  ƒ ƒ qø Wt! |	 ƒ } t | ƒ } x~ | r(| j" d ƒ } | | k r«| | | k râq«n  | j | | ƒ | j# | | ƒ |	 j# | | ƒ |	 j$ | ƒ q«q«Wt% |	 ƒ d k rNt d d	 | ƒ n  x¸|	 D]°} | | k rmqUn  t& d
 „  | | ƒ } t% | ƒ d k r™d St% | ƒ d k rÈt d d | t% | ƒ ƒ t' Sx:| D]2} t( j) d | t( j* ƒ } | r| r| j+ d ƒ j ƒ  } n9 t( j) d | t( j* ƒ } | rÏ| j+ d ƒ j ƒ  } n qÏ| d k ryt d d |  j, | | | | ƒ t S|  j- r±| d k r±t d d |  j, | | | | ƒ t S|  j. rÏ|  j- rÏ|  j/ d k rÏ| d k rÏt d d |  j, | | | | ƒ t SqÏWqUWt' S(   NR…  R[   s2   DNSException: No Nameservers available for %s (%s)s:   DNSException: Unable to query DMARC policy for %s (%s). %sR   i    R   i   sY   multiple DMARC entries in results for %s,
                   processing each to be strictc         S   s   |  j  d ƒ S(   Ns	   v=DMARC1;(   Rn   (   RŠ   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   <lambda>`  R   sf   RRset of TXT records for %s has %d v=DMARC1 entries;
                       ignoring them per RFC 7849s   \bsp=(\w*)\bs   \bp=(\w*)\bt   rejectt   vettes6   %s: DMARC lookup for %s (%s) found p=reject in %s = %st
   quarantines:   %s: DMARC lookup for %s (%s) found p=quarantine in %s = %si   t   nones4   %s: DMARC lookup for %s (%s) found p=none in %s = %s(   i   i   (0   t   dnst   resolvert   Resolvert   floatR   t   DMARC_RESOLVER_TIMEOUTt   timeoutt   DMARC_RESOLVER_LIFETIMEt   lifetimet   queryt	   rdatatypet   TXTt   NXDOMAINt   NoAnswert   NoNameserversR   R!   R   t   __doc__Rô   RÀ   t   answerRx   t   to_textRA   t   rdtypet   CNAMEt   itemsRp   t
   setdefaultR-   R   t   stringsRN   RI  t   addt   discardR   R<  R   R   RS   t
   IGNORECASERg  Rˆ  t"   dmarc_quarantine_moderation_actiont   dmarc_none_moderation_actiont   dmarc_moderation_action(   Rä   RC   t   dmarc_domainR†  R”  t   txt_recsR€   t   results_by_namet   cnamest
   want_namest   txt_recRx   t   expandst   seent   itemt   dmarcst   entryRi  t   policy(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyRŠ  #  s¦    
	
				c         C   sv  |  j  d k r t S| j ƒ  } t j ƒ  } t j | g  ƒ j | t |  j ƒ ƒ t	 t
 t | ƒ ƒ } | j ƒ  x0 | D]( } t | | | k  rx t | | =qx qx Wt d 7a t t j k rDd a x~ t j ƒ  D]m } t	 t
 t | ƒ ƒ } | j ƒ  x0 | D]( } t | | | k  rý t | | =qý qý Wt | sÐ t | =qÐ qÐ Wn  |  j | ƒ sWt St
 t j | g  ƒ ƒ |  j  k S(   s;  For lists that request it, we keep track of recent posts by address.
A message from an address to a list, if the list requests it, is remembered
for a specified time whether or not the address is a list member, and if the
address is a member and the member is over the threshold for the list, that
fact is returned.i    i   (   t   member_verbosity_thresholdR   RA   R+  t   recentMemberPostingsR§  R-   R–  t   member_verbosity_intervalR8  R   Rx  t   clean_countR   t   VERBOSE_CLEAN_LIMITR�  t   isMemberR   (   Rä   RC   t   nowRe   Ru   RI   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   IsVerboseMember’  s4    	



c         C   sê   | s
 g  Sy |  j  d d ƒ \ } } Wn t k
 r: g  SX| j ƒ  } t j d d | ƒ j ƒ  } | j d ƒ } g  } x$ | D] } | j | j d ƒ ƒ q~ WxE | D]= } | | k r¥ g  | D]  } | | k r¾ | d | ^ q¾ Sq¥ Wg  S(   sU  The arguments are an email address and a string representing a
    list of lists in a form like 'a,b,c;1,2' representing [['a', 'b',
    'c'],['1', '2']].  The inner lists are domains which are
    equivalent in some sense.  The return is an empty list or a list
    of email addresses equivalent to the first argument.
    For example, given

    email = 'user@me.com'
    domains_list = '''domain1, domain2; mac.com, me.com, icloud.com;
                   domaina, domainb
                   '''

    check_eq_domains(email, domains_list) will return
    ['user@mac.com', 'user@icloud.com']
    R?   i   s   \sR   RH  t   ,(   t   rsplitRÌ   RA   R   R   R+   R-   (   RC   t   domains_listt   localRE   t   domainsR}   Re   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   check_eq_domains¼  s     /c         C   s–   y} |  j  d ƒ d  d k r9 t t |  j  d ƒ d ƒ ƒ S|  j  d ƒ d  j ƒ  d k rx t t |  j  d ƒ d d ƒ ƒ Sd SWn t k
 r‘ d SXd  S(   Ni   RF  R‚   i   u   ï¿½(   Rg  RA  R¬   RA   RÌ   (   Ri  (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   _invert_xmlÞ  s     c         C   sW   t  |  t ƒ rO |  j | d ƒ } t j d t | ƒ } t j d t | ƒ } | S|  Sd S(   sk  This converts a string s, encoded in cset to a unicode with translation
    of XML character references and textual \uxxxx escapes.  It is more or less
    the inverse of unicode.decode(cset, errors='xmlcharrefreplace').  It is
    similar to canonstr above except for replacing invalid refs with the
    unicode replace character and recognizing \u escapes.
    R¢   u   &(#[0-9]+);u   (?i)\\(u[a-f0-9]{4})N(   RM   RÄ   t   decodeR   R   RÉ  (   RV   RZ  t   us(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   xml_to_unicodeí  s    c         C   sA  t  s
 t St r{ y. t |  d d d d ƒ} t j | ƒ j } Wn t k
 rR t SXd j d j	 | j
 d ƒ d  ƒ ƒ } nM |  j
 d ƒ } t | ƒ d k r  t Sd	 j | d
 | d | d | d ƒ } t j j ƒ  } y | j | t j j ƒ } Wn t k
 rt SX| st S| j j ƒ  } t j d | t j ƒ r=t St S(   Nt   encodings   us-asciit   errorsR¢   s   {0}.zen.spamhaus.orgR   iþÿÿÿi   s    {0}.{1}.{2}.{3}.zen.spamhaus.orgi   i   i   i    s   127\.0\.0\.[2-7]$(   R‡  R   t   have_ipaddressRÝ   t	   ipaddresst
   ip_addresst   reverse_pointerRÌ   t   formatR   R+   R   R“  R”  R•  R›  Rœ  t   AR   t   rrsetR£  R   RS   t	   MULTILINER!   (   t   ipt   uipt   ptrt   lookupRÍ   R”  t   ansR/   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt	   banned_ipü  s6    (c         C   sÆ   t  s
 t S|  j ƒ  }  t |  ƒ \ } } d | } t j j ƒ  } y | j | t j j	 ƒ } Wn t
 k
 rq t SX| s| t S| j j ƒ  } t j d | t j ƒ rÂ t j d | t j ƒ sÂ t Sn  t S(   Ns   %s.dbl.spamhaus.orgs   127\.0\.1\.\d{1,3}$s   127\.0\.1\.255$(   R‡  R   RA   RH   R“  R”  R•  R›  Rœ  RÔ  R   RÕ  R£  R   RS   RÖ  R!   (   RC   RD   RE   RÚ  R”  RÛ  R/   (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   banned_domain  s"    
c         C   sx   | | k r d } n  | | } t  j t | ƒ ƒ } | | d } |  j d d d ƒ} t | ƒ | | d t | ƒ f S(   sg   Returns a CAPTCHA question, the HTML for the answer box, and
    the data to be put into the CSRF tokenRÖ   i    t   captcha_answert   sizei   RL   (   R�   t	   randrangeR   t	   FormatBoxRÊ   RÄ   (   Rä   Rã   t   captchast   idxt   questiont   box_html(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   captcha_display1  s    	
c         C   s’   y% |  j  d ƒ \ } }  t |  ƒ }  Wn t k
 r9 t SX| | k rJ t S| | } |  t t | ƒ ƒ k rp t S| |  d d } t j | | ƒ S(   NRL   i   R4  (   R+   R¬   RÌ   R   R8  R   R   Rj  (   Rã  t   given_answerRâ  Rã   t   correct_answer_pattern(    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   captcha_verify>  s    
(   R   R€   Ru   R�   R‚   (   Rƒ   R„   R}   R…   R†   R‡   Rˆ   R‰   RŠ   RX   R‹   RV   RŒ   R�   RŽ   Re   R�   (   i   i   (   i    i    (   i    i    (   i    i    (   i    i    (   i   i   (   i    i    (   i   i   (   i    i   (   i    i   (   i    i   (“   R¡  t
   __future__R    R   t   sysR   RÆ   R+  R�   R    R�   Rt  Rm   RJ  t   email.HeaderRC   t   email.Iteratorst   email.ErrorsR   t   typesR   t   stringR   R   R   t   ImportErrort   _lowert   uppert   MailmanR   R   R	   t   Mailman.SafeDictR
   t   Mailman.Logging.SyslogR   t   hashlibt   md5t   md5_newt   sha1Rµ   t   shat   newR!   R   t	   NameErrort   dns.resolverR“  t   dns.exceptionR   R‡  RÐ  RÏ  R“   RW  R_  R,   Rw   R9  t   compileR«  R7  R;  R'   R)   R;   R>   RH   RK   RR   RU   RY   R]   Rf   Rh   R@   Rv   Rz   R~   t   _vowelst   _consonantsR’   R�   R„   R-   R–   R¨   t   MEMBER_PASSWORD_LENGTHRª   R°   R¼   R¿   RÁ   RÈ   RÊ   RÎ   RÐ   RÑ   t	   ExceptionRÒ   Rë   Rì   Rÿ   R	  R  R  R  RÞ   R  R  R^   R)  R*  R/  R3  R:  R=  R?  R@  RN  RQ  RP  R\  Re  t	   _badwordsR   Rm  Rn  Ro  Rl  Rq  Rs  Rz  R~  R„  R�  RŠ  R¼  R¾  RÂ  RÈ  RÉ  RÌ  RÜ  RÝ  Ræ  Ré  (    (    (    s,   /export/web/mailman/mailman/Mailman/Utils.pyt   <module>   s&  		




		K					"		 		!		
	o
	'										/			@							 	l	*	"					