
    h                        S SK r S SKJr  S SKJr  S SKJr  SrSrSr	Sq
SqS	qS	qS	qS	qS	qS	qS	qS	qS	q S
r/ SQrSrSrSrSrSrSrSrSrSrSr Sr!Sr"Sr# " S S\RH                  5      r%Sr&S r'S r(S r)\*S:X  a  \)" 5         gg)     N)reactor)Factory)basictesttwistediL  TFs(   +OK POP3 localhost v2003.83 server ready)s   TOPs   LOGIN-DELAY 180   USERs
   SASL LOGIN   STLS   UIDLs   -ERR Unknown requests   +OK Command Completeds   -ERR LOGIN faileds   +OK Mailbox open, 0 messagess*   -ERR server side error start TLS handshakes   +OK quit completeds'   -ERR Unknown AUHORIZATION state commands   +OK 0 0s    +OK Unique-ID listing follows
.s#   +OK Mailbox scan listing follows
.s   +OK Capability list follows:c                   T    \ rS rSrSS jrS rS rS rS rS r	S	 r
S
 rS rS rSrg)POP3TestServer5   Nc                 :    SU l         S U l        S U l        Xl        g )NF)loggedIncapstmpUserctx)selfcontextFactorys     g/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/mail/test/pop3testserver.py__init__POP3TestServer.__init__6   s    	!    c                 .    U R                  [        5        g N)sendLineSTATr   reqs     r   sendSTATRespPOP3TestServer.sendSTATResp<       dr   c                 .    U R                  [        5        g r   )r   UIDLr   s     r   sendUIDLRespPOP3TestServer.sendUIDLResp?   r!   r   c                 .    U R                  [        5        g r   )r   LISTr   s     r   sendLISTRespPOP3TestServer.sendLISTRespB   r!   r   c                    U R                   c  [        /U l         [        (       a  U R                   R                  [        5        [
        (       a  U R                   R                  [        5        [         H  nU R                   R                  U5        M      SR                  U R                   5      nUS-  nU R                  U5        g )Ns   
s   
.)
r   	CAP_STARTUIDL_SUPPORTappendCAPABILITIES_UIDLSSL_SUPPORTCAPABILITIES_SSLCAPABILITIESjoinr   )r   capresps      r   sendCapabilitiesPOP3TestServer.sendCapabilitiesE   s    99"DI<II./;II-.CIIS!  ||DII&dr   c                     [         (       a  U R                  5         g [        (       a"  [        R                  " SU R
                  5        g U R                  5         g )N   )DENY_CONNECTION
disconnectSLOW_GREETINGr   	callLatersendGreetingr   s    r   connectionMadePOP3TestServer.connectionMadeV   s=    ?OO=b$"3"34 r   c                 .    U R                  [        5        g r   )r   CONNECTION_MADEr>   s    r   r=   POP3TestServer.sendGreetinga   s    o&r   c                   ^ UR                  5       mU4S jn[        (       a  g[        (       a  U R                  5         gU" S5      (       a2  [        (       a  U R                  [        5        gU R                  5         gU" S5      (       a  [        (       a  U R                  5         gU" S5      (       aU  [        (       a  U R                  [        5        gSn UR                  S5      S   U l        [        nU R                  U5        gU" S5      (       as  Sn UR                  S5      S   nU R                  b  Uc  [        nO3U R                  [         :X  a  U["        :X  a  [$        nS	U l        O[        n U R                  U5        gU" S
5      (       a-  SU l        U R                  [(        5        U R                  5         g[*        (       a  U R                  [        5        gU R&                  (       d  U R                  [,        5        gU" S5      (       a  U R                  [        5        gU" S5      (       a"  [.        (       a  gU R                  [0        5        gU" S5      (       a"  [.        (       a  gU R                  [2        5        gU" S5      (       aC  [.        (       a  g[4        (       d  U R                  [        5        gU R                  [6        5        gg! [         a
    [        n GNf = f! [         a
    [        n GNf = f)zError Conditionsc                 ,   > TR                  U 5      S:g  $ )N)find)sulines    r   <lambda>-POP3TestServer.lineReceived.<locals>.<lambda>h   s    A",r   Ns   CAPAr	   r       s   PASSTs   QUITFs   NOOPs   STATs   LISTr
   )upperTIMEOUT_RESPONSEDROP_CONNECTIONr:   INVALID_CAPABILITY_RESPONSEr   INVALID_RESPONSEr5   r/   startTLSINVALID_LOGIN_RESPONSEsplitr   VALID_RESPONSEBaseExceptionAUTH_DECLINEDUSERPASSAUTH_ACCEPTEDr   LOGOUT_COMPLETEINVALID_SERVER_RESPONSENOT_LOGGED_INTIMEOUT_DEFERREDr   r'   r,   r#   )r   linerG   r4   pwdrI   s        @r   lineReceivedPOP3TestServer.lineReceivedd   s(    

,?OO']]**./%%'']]{{MMO']]%%./D%#zz#q1% MM$']]D%jjoa(<<'3;(D\\T)cTk(D$(DM(D MM$']]!DMMM/*OO$$MM*+MM-(']]MM.)']]MM$']]MM$']]!\./MM$ ] ! %$%" ! %$%s0   K *K5 +K5 1K5 K21K25L	L	c                     [         (       aD  U R                  b7  U R                  S5        U R                  R	                  U R                  5        g U R                  S5        g )Ns   +OK Begin TLS negotiation nows   -ERR TLS not available)r/   r   r   	transportrS   r>   s    r   rS   POP3TestServer.startTLS   s@    ;488/MM:;NN##DHH-MM34r   c                 8    U R                   R                  5         g r   )re   loseConnectionr>   s    r   r:   POP3TestServer.disconnect   s    %%'r   )r   r   r   r   r   )__name__
__module____qualname____firstlineno__r   r   r$   r(   r5   r?   r=   rb   rS   r:   __static_attributes__ r   r   r   r   5   s6    ""	 'U n5(r   r   a  popServer.py [arg] (default is Standard POP Server with no messages)
no_ssl  - Start with no SSL support
no_uidl - Start with no UIDL support
bad_resp - Send a non-RFC compliant response to the Client
bad_cap_resp - send a non-RFC compliant response when the Client sends a 'CAPABILITY' request
bad_login_resp - send a non-RFC compliant response when the Client sends a 'LOGIN' request
deny - Deny the connection
drop - Drop the connection after sending the greeting
bad_tls - Send a bad response to a STARTTLS
timeout - Do not return a response to a Client request
to_deferred - Do not return a response on a 'Select' request. This
              will test Deferred callback handling
slow - Wait 20 seconds after the connection is made to return a Server Greeting
c                      [        SU -  5        g )NzServer Starting in %s mode)print)msgs    r   printMessagers      s    	
&
,-r   c                    U R                  5       S:X  a  Sq[        S5        g U R                  5       S:X  a  Sq[        S5        g U R                  5       S:X  a  Sq[        S5        g U R                  5       S	:X  a  Sq[        S
5        g U R                  5       S:X  a  Sq[        S
5        g U R                  5       S:X  a  Sq[        S5        g U R                  5       S:X  a  Sq[        S5        g U R                  5       S:X  a  Sq	[        S5        g U R                  5       S:X  a  Sq
[        S5        g U R                  5       S:X  a  Sq[        S5        g U R                  5       S:X  a  Sq[        S5        g U R                  5       S:X  a%  [        [        5        [        R                   " 5         g [        [        5        [        R                   " 5         g )Nno_sslFzNON-SSLno_uidlzNON-UIDLbad_respTzInvalid Server Responsebad_cap_respzInvalid Capability Responsebad_login_respdenyzDeny ConnectiondropzDrop Connectionbad_tlszBad TLS ResponsetimeoutzTimeout Responseto_deferredzTimeout Deferred ResponseslowzSlow Greetingz--help)lowerr/   rs   r,   r]   rQ   rT   r9   rP   BAD_TLS_RESPONSErO   r_   r;   rq   usagesysexit)args    r   
processArgr      sj   
yy{hY			!Z 	
	""&./		&&*#23	(	(!%23		&'		&'			!'(			!'(		%01		_%		 e
 	e
r   c                  .   [        [        R                  5      S:  a  [        S5        O'[        R                  SS  n U  H  n[	        U5        M     [        5       n[        Ul        [        R                  " [        U5        [        R                  " 5         g )N   zPOP3 with no messagesrM   )lenr   argvrs   r   r   r   protocolr   	listenTCPPORTrun)argsr   fs      r   mainr     sd    
388}q,-xx|CsO  		AAJdAKKMr   __main__)+r   twisted.internetr   twisted.internet.protocolr   twisted.protocolsr   rY   rZ   r   r/   r,   r]   rQ   rT   r9   rP   r   rO   r_   r;   rB   r1   r0   r.   rR   rV   rX   r[   	TLS_ERRORr\   r^   r   r#   r'   r+   LineReceiverr   r   rs   r   r   rj   ro   r   r   <module>r      s     $ - # #      =C   + )$/9	':,/+	N(U'' N(b	 .>B zF r   