ó
‰wÛjc           @   sâ  d  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 d d g Z	 e j
 d Z d Z d	 d d
 „  ƒ  YZ e ƒ  a d Z d Z d Z d d „ Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d  d „  ƒ  YZ d „  Z e d k rÞe ƒ  Z e j Z d e k rÁe j d ƒ Z  e! e e   e" ƒ  e# ƒ  d g ƒ Z$ e e  d Z n d d l% Z$ e& e$ e ƒ Z' e' e j( e j) f e j* e j+ f ƒ Z, e j- r¹y d d l. Z. Wn+ e/ k
 rIe j0 d IJe j1 d ƒ n Xe. j2 d ƒ d Z3 y e j- e3 ƒ Wq¹e4 k
 rµZ5 e5 j e j6 k r˜‚  n  e j0 d IJe j1 d ƒ q¹Xn  y e j7 ƒ  WqÞe8 k
 rÚqÞXn  d S(!   sc  An RFC 2821 smtp proxy.

Usage: %(program)s [options] [localhost:localport [remotehost:remoteport]]

Options:

    --nosetuid
    -n
        This program generally tries to setuid `nobody', unless this flag is
        set.  The setuid call will fail if this program is not run as root (in
        which case, use this flag).

    --version
    -V
        Print the version number and exit.

    --class classname
    -c classname
        Use `classname' as the concrete SMTP proxy class.  Uses `PureProxy' by
        default.

    --debug
    -d
        Turn on debugging prints.

    --help
    -h
        Print this message and exit.

Version: %(__version__)s

If localhost is not given then `localhost' is used, and if localport is not
given then 8025 is used.  If remotehost is not given then `localhost' is used,
and if remoteport is not given, then 25 is used.
iÿÿÿÿNt
   SMTPServert   DebuggingServert	   PureProxyt   MailmanProxyi    s   Python SMTP proxy version 0.2t   Devnullc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   d  S(   N(    (   t   selft   msg(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt   writeX   t    c         C   s   d  S(   N(    (   R   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt   flushY   R   (   t   __name__t
   __module__R   R	   (    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR   W   s   	s   
R   s   , c         C   s;   t  j t t ƒ  IJ| r* t  j | IJn  t  j |  ƒ d  S(   N(   t   syst   stderrt   __doc__t   globalst   exit(   t   codeR   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt   usageb   s    t   SMTPChannelc           B   s€   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   i    i   c         C   s
  t  j j |  | ƒ | |  _ | |  _ | |  _ g  |  _ |  j |  _ d |  _	 d  |  _ g  |  _ d |  _ t j ƒ  |  _ y | j ƒ  |  _ Wn: t j k
 rÅ } |  j ƒ  | d t j k rÁ ‚  n  d  SXt d It |  j ƒ IJ|  j d |  j t f ƒ |  j d ƒ d  S(   Ni    R   s   Peer:s	   220 %s %ss   
(   t   asynchatt
   async_chatt   __init__t   _SMTPChannel__servert   _SMTPChannel__connt   _SMTPChannel__addrt   _SMTPChannel__linet   COMMANDt   _SMTPChannel__statet   _SMTPChannel__greetingt   Nonet   _SMTPChannel__mailfromt   _SMTPChannel__rcpttost   _SMTPChannel__datat   sockett   getfqdnt   _SMTPChannel__fqdnt   getpeernamet   _SMTPChannel__peert   errort   closet   errnot   ENOTCONNt   DEBUGSTREAMt   reprt   pusht   __version__t   set_terminator(   R   t   servert   connt   addrt   err(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR   m   s*    								
c         C   s   t  j j |  | d ƒ d  S(   Ns   
(   R   R   R-   (   R   R   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR-   ‡   s    c         C   s   |  j  j | ƒ d  S(   N(   R   t   append(   R   t   data(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt   collect_incoming_data‹   s    c   	      C   sø  t  j |  j ƒ } t d It | ƒ IJg  |  _ |  j |  j k ró | sZ |  j d ƒ d  Sd  } | j	 d ƒ } | d k  r� | j
 ƒ  } d  } n$ | |  j
 ƒ  } | | d j ƒ  } t |  d | d  ƒ } | så |  j d | ƒ d  S| | ƒ d  S|  j |  j k r|  j d ƒ d  Sg  } xN | j d	 ƒ D]= } | r\| d d
 k r\| j | d ƒ q,| j | ƒ q,Wt j | ƒ |  _ |  j j |  j |  j |  j |  j ƒ } g  |  _ d  |  _ |  j |  _ |  j d	 ƒ | sç|  j d ƒ n |  j | ƒ d  S(   Ns   Data:s   500 Error: bad syntaxt    i    i   t   smtp_s'   502 Error: command "%s" not implementeds   451 Internal confusions   
t   .s   250 Ok(   t   EMPTYSTRINGt   joinR   R+   R,   R   R   R-   R   t   findt   uppert   stript   getattrt   DATAt   splitR4   t   NEWLINER!   R   t   process_messageR&   R   R    R/   (	   R   t   linet   methodt   it   commandt   argR5   t   textt   status(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt   found_terminator�   sP    		
		c         C   sQ   | s |  j  d ƒ d  S|  j r0 |  j  d ƒ n | |  _ |  j  d |  j ƒ d  S(   Ns   501 Syntax: HELO hostnames   503 Duplicate HELO/EHLOs   250 %s(   R-   R   R$   (   R   RH   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   smtp_HELOÀ   s    		c         C   s'   | r |  j  d ƒ n |  j  d ƒ d  S(   Ns   501 Syntax: NOOPs   250 Ok(   R-   (   R   RH   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   smtp_NOOPÊ   s    c         C   s   |  j  d ƒ |  j ƒ  d  S(   Ns   221 Bye(   R-   t   close_when_done(   R   RH   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   smtp_QUITÐ   s    c         C   s„   d  } t | ƒ } | |  j ƒ  | k r€ | | j ƒ  } | sA q€ | d d k r€ | d d k r€ | d k r€ | d d !} q€ n  | S(   Ni    t   <iÿÿÿÿt   >s   <>i   (   R   t   lenR=   R>   (   R   t   keywordRH   t   addresst   keylen(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   __getaddrÖ   s    ,c         C   sŒ   t  d I| IJ| r( |  j d | ƒ n d  } | sE |  j d ƒ d  S|  j r_ |  j d ƒ d  S| |  _ t  d I|  j IJ|  j d ƒ d  S(   Ns	   ===> MAILs   FROM:s   501 Syntax: MAIL FROM:<address>s   503 Error: nested MAIL commands   sender:s   250 Ok(   R+   t   _SMTPChannel__getaddrR   R-   R   (   R   RH   RT   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   smtp_MAILã   s    		c         C   s“   t  d I| IJ|  j s* |  j d ƒ d  S| rB |  j d | ƒ n d  } | s_ |  j d ƒ d  S|  j j | ƒ t  d I|  j IJ|  j d ƒ d  S(   Ns	   ===> RCPTs   503 Error: need MAIL commands   TO:s   501 Syntax: RCPT TO: <address>s   recips:s   250 Ok(   R+   R   R-   RW   R   R    R4   (   R   RH   RT   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   smtp_RCPTð   s    	c         C   sO   | r |  j  d ƒ d  Sd  |  _ g  |  _ d |  _ |  j |  _ |  j  d ƒ d  S(   Ns   501 Syntax: RSETR   s   250 Ok(   R-   R   R   R    R!   R   R   (   R   RH   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   smtp_RSETý   s    			c         C   s[   |  j  s |  j d ƒ d  S| r1 |  j d ƒ d  S|  j |  _ |  j d ƒ |  j d ƒ d  S(   Ns   503 Error: need RCPT commands   501 Syntax: DATAs   
.
s#   354 End data with <CR><LF>.<CR><LF>(   R    R-   R@   R   R/   (   R   RH   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   smtp_DATA  s    	(   R
   R   R   R@   R   R-   R6   RK   RL   RM   RO   RW   RX   RY   RZ   R[   (    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR   i   s   				1	
						c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   sª   | |  _  | |  _ t j j |  ƒ y> |  j t j t j ƒ |  j	 ƒ  |  j
 | ƒ |  j d ƒ Wn |  j ƒ  ‚  n0 Xt d |  j j t j t j ƒ  ƒ | | f IJd  S(   Ni   s0   %s started at %s
	Local addr: %s
	Remote addr:%s(   t
   _localaddrt   _remoteaddrt   asyncoret
   dispatcherR   t   create_socketR"   t   AF_INETt   SOCK_STREAMt   set_reuse_addrt   bindt   listenR(   R+   t	   __class__R
   t   timet   ctime(   R   t	   localaddrt
   remoteaddr(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR     s    		

c         C   sQ   |  j  ƒ  } | d  k	 rM | \ } } t d t | ƒ IJt |  | | ƒ } n  d  S(   Ns   Incoming connection from %s(   t   acceptR   R+   R,   R   (   R   t   pairR1   R2   t   channel(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt   handle_accept)  s
    c         C   s
   t  ‚ d S(   sI  Override this abstract method to handle messages from the client.

        peer is a tuple containing (ipaddr, port) of the client that made the
        socket connection to our smtp port.

        mailfrom is the raw address the client claims the message is coming
        from.

        rcpttos is a list of raw addresses the client wishes to deliver the
        message to.

        data is a string containing the entire full text of the message,
        headers (if supplied) and all.  It has been `de-transparencied'
        according to RFC 821, Section 4.5.2.  In other words, a line
        containing a `.' followed by other text has had the leading dot
        removed.

        This function should return None, for a normal `250 Ok' response;
        otherwise it returns the desired response string in RFC 821 format.

        N(   t   NotImplementedError(   R   t   peert   mailfromt   rcpttosR5   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyRC   1  s    (   R
   R   R   Rn   RC   (    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR      s   		c           B   s   e  Z d  „  Z RS(   c         C   s\   d } | j  d ƒ } d GHx6 | D]. } | rJ | rJ d G| d GHd } n  | GHq! Wd GHd  S(   Ni   s   
s%   ---------- MESSAGE FOLLOWS ----------s   X-Peer:i    s%   ------------ END MESSAGE ------------(   RA   (   R   Rp   Rq   Rr   R5   t	   inheaderst   linesRD   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyRC   L  s    		(   R
   R   RC   (    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR   J  s   c           B   s   e  Z d  „  Z d „  Z RS(   c   	      C   sŠ   | j  d ƒ } d } x" | D] } | s, Pn  | d 7} q W| j | d | d ƒ t j | ƒ } |  j | | | ƒ } t d I| IJd  S(   Ns   
i    i   s
   X-Peer: %ss   we got some refusals:(   RA   t   insertRB   R;   t   _deliverR+   (	   R   Rp   Rq   Rr   R5   Rt   RF   RD   t   refused(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyRC   Z  s    c         C   s  d d  l  } i  } yU | j ƒ  } | j |  j d |  j d ƒ z | j | | | ƒ } Wd  | j ƒ  XWnŸ | j k
 r’ } t d IJ| j } nw t	 j
 | j f k
 r} t d I| j IJt | d d ƒ } t | d d ƒ }	 x" | D] }
 | |	 f | |
 <që Wn X| S(	   Niÿÿÿÿi    i   s   got SMTPRecipientsRefusedt   gott	   smtp_codet
   smtp_errort   ignore(   t   smtplibt   SMTPt   connectR]   t   sendmailt   quitt   SMTPRecipientsRefusedR+   t
   recipientsR"   R'   t   SMTPExceptionRf   R?   (   R   Rq   Rr   R5   R|   Rw   t   st   et   errcodet   errmsgt   r(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyRv   h  s$    
(   R
   R   RC   Rv   (    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR   Y  s   	c           B   s   e  Z d  „  Z RS(   c         C   s  d d l  m } d d l m } d d l m } d d l m } g  }	 xµ | D]­ }
 |
 j ƒ  j d ƒ d } | j d ƒ } t | ƒ d	 k r“ qM n  | d } t | ƒ d	 k r¼ | d
 } n d } | j	 | ƒ sM | d! k rä qM n  |	 j
 |
 | | f ƒ qM Wx$ |	 D] \ }
 } } | j |
 ƒ qWt d Id j | ƒ IJ| rl|  j | | | ƒ } t d I| IJn  i  } | | ƒ } | j | ƒ } | j d ƒ s©| | d <n  | j d ƒ sÔt j t j ƒ  ƒ | d <n  x+|	 D]#\ }
 } } t d I|
 IJ| j | ƒ } | s1| j | d d ƒ} | | | <n  | d k rS| j | d d
 ƒqÛ| d k ru| j | d d
 ƒqÛ| d k r—| j | d d
 ƒqÛ| d k r¹| j | d d
 ƒqÛ| d" k rÛ| d k rÞd | d <n
 d  | d <| j | d d
 ƒqÛqÛWd  S(#   Niÿÿÿÿ(   t   StringIO(   t   Utils(   t   Message(   t   MailListt   @i    t   -i   i   R   t   admint   ownert   requestR;   t   leaves   forwarding recips:R7   s   we got refusals:t   fromt   Fromt   datet   Dates   sending message tot   lockt   tolistt   toadmint   toownert	   torequestt	   subscribet   Subjectt   unsubscribe(   R   R�   R�   R‘   R;   R’   (   R;   R’   (   t	   cStringIOR‰   t   MailmanRŠ   R‹   RŒ   t   lowerRA   RR   t   list_existsR4   t   removeR+   R;   Rv   t	   getheaderRg   Rh   t   gett   Enqueue(   R   Rp   Rq   Rr   R5   R‰   RŠ   R‹   RŒ   t	   listnamest   rcptt   localt   partst   listnameRG   Rw   t   mlistsR„   R   t   mlist(    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyRC   ‚  sd    
	
(   R
   R   RC   (    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR   �  s   t   Optionsc           B   s   e  Z d  Z d Z RS(   i   R   (   R
   R   t   setuidt	   classname(    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyR®   Ï  s   c    	      C   sŠ  y5 t  j  t j d d d d d d d g ƒ \ }  } Wn# t  j k
 rZ } t d | ƒ n Xt ƒ  } xž |  D]– \ } } | d k r� t d
 ƒ qk | d k r¹ t j t IJt j d
 ƒ qk | d k rÑ d
 | _	 qk | d  k ré | | _
 qk | d! k rk t j a qk qk Wt | ƒ d k  r&d } d } nh t | ƒ d k  rK| d
 } d } nC t | ƒ d k  rt| d
 } | d } n t d d t j | ƒ ƒ | j d ƒ } | d
 k  r½t d d | ƒ n  | |  | _ y t | | d ƒ | _ Wn" t k
 r	t d d | ƒ n X| j d ƒ } | d
 k  r9t d d | ƒ n  | |  | _ y t | | d ƒ | _ Wn" t k
 r…t d d | ƒ n X| S("   Ni   s   nVhc:ds   class=t   nosetuidt   versiont   helpt   debugs   -hs   --helpi    s   -Vs	   --versions   -ns
   --nosetuids   -cs   --classs   -ds   --debugs   localhost:8025s   localhost:25i   i   s   Invalid arguments: %st   :s   Bad local spec: %ss   Bad local port: %ss   Bad remote spec: %ss   Bad remote port: %s(   s   -hs   --help(   s   -Vs	   --version(   s   -ns
   --nosetuid(   s   -cs   --class(   s   -ds   --debug(   t   getoptR   t   argvR'   R   R®   R   R.   R   R¯   R°   R+   RR   t
   COMMASPACER;   R<   t	   localhostt   intt	   localportt
   ValueErrort
   remotehostt
   remoteport(	   t   optst   argsR…   t   optionst   optRH   t	   localspect
   remotespecRF   (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt	   parseargsÔ  s\    "		
	
t   __main__R9   i   s7   Cannot import module "pwd"; try running with -n option.t   nobodyi   s3   Cannot setuid "nobody"; try running with -n option.(    (    (9   R   R   t   osR)   R¶   Rg   R"   R^   R   t   __all__R·   t   programR.   R   R+   RB   R:   R¸   R   R   R   R_   R    R   R   R   R®   RÅ   R
   RÁ   R°   t   rfindt   lastdott
   __import__R   t   localst   modRÆ   R?   t   class_R¹   R»   R½   R¾   t   proxyR¯   t   pwdt   ImportErrorR   R   t   getpwnamRÇ   t   OSErrorR…   t   EPERMt   loopt   KeyboardInterrupt(    (    (    s{   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/smtpd.pyt   <module>$   sn   $	«6(N	8		"	 