
    h                        % S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	  SSK
JrJrJrJrJr  SSKJrJr  SSKJr  S	rS
r " S S5      rS rS rS rS rS r " S S\R:                  \R<                  5      r/ r \\!   \"S'   g)z
A POP3 client protocol implementation.

Don't use this module directly.  Use twisted.mail.pop3 instead.

@author: Jp Calderone
    N)md5)List)defererror
interfaces) InsecureAuthenticationDisallowedLineTooLongServerErrorResponseTLSErrorTLSNotSupportedError)basicpolicies)logs   +OKs   -ERRc                   $    \ rS rSrSrS rS rSrg)_ListSetter!   a  
A utility class to construct a list from a multi-line response accounting
for deleted messages.

POP3 responses sometimes occur in the form of a list of lines containing
two pieces of data, a message index and a value of some sort.  When a
message is deleted, it is omitted from these responses.  The L{setitem}
method of this class is meant to be called with these two values.  In the
cases where indices are skipped, it takes care of padding out the missing
values with L{None}.

@ivar L: See L{__init__}
c                     Xl         g)zm
@type L: L{list} of L{object}
@param L: The list being constructed.  An empty list should be
    passed in.
NL)selfr   s     _/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/mail/_pop3client.py__init___ListSetter.__init__0   s	         c                     Uu  p#U[        U R                  5      -
  S-   nUS:  a  U R                  R                  S/U-  5        X0R                  U'   g)a  
Add the value at the specified position, padding out missing entries.

@type itemAndValue: C{tuple}
@param itemAndValue: A tuple of (item, value).  The I{item} is the 0-based
index in the list at which the value should be placed.  The value is
is an L{object} to put in the list.
   r   N)lenr   extend)r   itemAndValueitemvaluediffs        r   setitem_ListSetter.setitem8   sJ     %c$&&k!A%!8FFMM4&4-(tr   r   N)__name__
__module____qualname____firstlineno____doc__r   r#   __static_attributes__ r   r   r   r   !   s    r   r   c                 V    U R                  SS5      u  p[        U5      [        U5      4$ )a  
Parse the response to a STAT command.

@type line: L{bytes}
@param line: The response from the server to a STAT command minus the
    status indicator.

@rtype: 2-L{tuple} of (0) L{int}, (1) L{int}
@return: The number of messages in the mailbox and the size of the mailbox.
Nr   splitint)linenumMsgs	totalSizes      r   
_statXformr3   H   s*     D!,Gw<Y''r   c                 \    U R                  SS5      u  p[        U5      S-
  [        U5      4$ )aj  
Parse a line of the response to a LIST command.

The line from the LIST response consists of a 1-based message number
followed by a size.

@type line: L{bytes}
@param line: A non-initial line from the multi-line response to a LIST
    command.

@rtype: 2-L{tuple} of (0) L{int}, (1) L{int}
@return: The 0-based index of the message and the size of the message.
Nr   r-   )r0   indexsizes      r   
_listXformr7   W   s-     **T1%KEu:>3t9$$r   c                 J    U R                  SS5      u  p[        U5      S-
  U4$ )a  
Parse a line of the response to a UIDL command.

The line from the UIDL response consists of a 1-based message number
followed by a unique id.

@type line: L{bytes}
@param line: A non-initial line from the multi-line response to a UIDL
    command.

@rtype: 2-L{tuple} of (0) L{int}, (1) L{bytes}
@return: The 0-based index of the message and the unique identifier
    for the message.
Nr   r-   )r0   r5   uids      r   	_uidXformr:   i   s)     D!$JEu:>3r   c                 V    U R                  SS5      n[        U5      S:X  a  US   S4$ U$ )z
Parse the first line of a multi-line server response.

@type line: L{bytes}
@param line: The first line of a multi-line server response.

@rtype: 2-tuple of (0) L{bytes}, (1) L{bytes}
@return: The status indicator and the rest of the server response.
    r   r   r   r.   r   )r0   partss     r   _codeStatusSplitr?   |   s2     JJtQE
5zQQx}Lr   c                 <    U R                  S5      (       a  U SS $ U $ )a  
Remove a byte-stuffed termination character at the beginning of a line if
present.

When the termination character (C{'.'}) appears at the beginning of a line,
the server byte-stuffs it by adding another termination character to
avoid confusion with the terminating sequence (C{'.\r\n'}).

@type line: L{bytes}
@param line: A received line.

@rtype: L{bytes}
@return: The line without the byte-stuffed termination character at the
    beginning if it was present. Otherwise, the line unchanged.
s   ..r   N)
startswith)r0   s    r   _dotUnquoterrB      s#      uABxKr   c                   X   \ rS rSrSrSrSrSrSrSr	\
R                  " S5      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 rS rS rS 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*S! r+S" r,S# r-S$ r.S/S% jr/S& r0S' r1S0S( jr2S) r3S.S* jr4S.S+ jr5S, r6S-r7g)1
POP3Client   a2  
A POP3 client protocol.

Instances of this class provide a convenient, efficient API for
retrieving and deleting messages from a POP3 server.

This API provides a pipelining interface but POP3 pipelining
on the network is not yet supported.

@type startedTLS: L{bool}
@ivar startedTLS: An indication of whether TLS has been negotiated
    successfully.

@type allowInsecureLogin: L{bool}
@ivar allowInsecureLogin: An indication of whether plaintext login should
    be allowed when the server offers no authentication challenge and the
    transport does not offer any protection via encryption.

@type serverChallenge: L{bytes} or L{None}
@ivar serverChallenge: The challenge received in the server greeting.

@type timeout: L{int}
@ivar timeout: The number of seconds to wait on a response from the server
    before timing out a connection.  If the number is <= 0, no timeout
    checking will be performed.

@type _capCache: L{None} or L{dict} mapping L{bytes}
    to L{list} of L{bytes} and/or L{bytes} to L{None}
@ivar _capCache: The cached server capabilities.  Capabilities are not
    allowed to change during the session (except when TLS is negotiated),
    so the first response to a capabilities command can be used for
    later lookups.

@type _challengeMagicRe: L{Pattern <re.Pattern.search>}
@ivar _challengeMagicRe: A regular expression which matches the
    challenge in the server greeting.

@type _blockedQueue: L{None} or L{list} of 3-L{tuple}
    of (0) L{Deferred <defer.Deferred>}, (1) callable which results
    in a L{Deferred <defer.Deferred>}, (2) L{tuple}
@ivar _blockedQueue: A list of blocked commands.  While a command is
    awaiting a response from the server, other commands are blocked.  When
    no command is outstanding, C{_blockedQueue} is set to L{None}.
    Otherwise, it contains a list of information about blocked commands.
    Each list entry provides the following information about a blocked
    command: the deferred that should be called when the response to the
    command is received, the function that sends the command, and the
    arguments to the function.

@type _waiting: L{Deferred <defer.Deferred>} or
    L{None}
@ivar _waiting: A deferred which fires when the response to the
    outstanding command is received from the server.

@type _timedOut: L{bool}
@ivar _timedOut: An indication of whether the connection was dropped
    because of a timeout.

@type _greetingError: L{bytes} or L{None}
@ivar _greetingError: The server greeting minus the status indicator, when
    the connection was dropped because of an error in the server greeting.
    Otherwise, L{None}.

@type state: L{bytes}
@ivar state: The state which indicates what type of response is expected
    from the server.  Valid states are: 'WELCOME', 'WAITING', 'SHORT',
    'LONG_INITIAL', 'LONG'.

@type _xform: L{None} or callable that takes L{bytes}
    and returns L{object}
@ivar _xform: The transform function which is used to convert each
    line of a multi-line response into usable values for use by the
    consumer function.  If L{None}, each line of the multi-line response
    is sent directly to the consumer function.

@type _consumer: callable that takes L{object}
@ivar _consumer: The consumer function which is used to store the
    values derived by the transform function from each line of a
    multi-line response into a list.
Fr   Ns	   (<[^>]+>)c                     U R                   b4  [        R                  " 5       nU R                   R                  X1U45        U$ / U l         g)a~  
Block a command, if necessary.

If commands are being blocked, append information about the function
which sends the command to a list and return a deferred that will be
chained with the return value of the function when it eventually runs.
Otherwise, set up for subsequent commands to be blocked and return
L{None}.

@type f: callable
@param f: A function which sends a command.

@type a: L{tuple}
@param a: Arguments to the function.

@rtype: L{None} or L{Deferred <defer.Deferred>}
@return: L{None} if the command can run immediately.  Otherwise,
    a deferred that will eventually trigger with the return value of
    the function.
N)_blockedQueuer   Deferredappend)r   fads       r   _blockedPOP3Client._blocked   sD    * ) A%%qQi0Hr   c                     U R                   / :X  a  SU l         gU R                   bY  U R                   nSU l         UR                  S5      u  p#nU" U6 nUR                  U5        U R                   R                  U5        gg)z
Send the next blocked command.

If there are no more commands in the blocked queue, set up for the next
command to be sent immediately.
Nr   )rG   popchainDeferredr   )r   rG   rL   rJ   rK   d2s         r   _unblockPOP3Client._unblock  s     #!%D+ ..M!%D#''*GA!ABQ
 %%m4 ,r   c                     U R                  U R                  X5      nUb  U$ U(       a  U R                  US-   U-   5        OU R                  U5        SU l        [        R
                  " 5       U l        U R                  $ )a  
Send a POP3 command to which a short response is expected.

Block all further commands from being sent until the response is
received.  Transition the state to SHORT.

@type cmd: L{bytes}
@param cmd: A POP3 command.

@type args: L{bytes}
@param args: The command arguments.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the entire response is received.
    On an OK response, it returns the response from the server minus
    the status indicator.  On an ERR response, it issues a server
    error response failure with the response from the server minus the
    status indicator.
r<   SHORT)rM   	sendShortsendLinestater   rH   _waiting)r   cmdargsrL   s       r   rW   POP3Client.sendShort1  se    * MM$..#4=HMM#*t+,MM#
(}}r   c                    U R                  U R                  XX45      nUb  U$ U(       a  U R                  US-   U-   5        OU R                  U5        SU l        X@l        X0l        [        R                  " 5       U l        U R                  $ )a  
Send a POP3 command to which a multi-line response is expected.

Block all further commands from being sent until the entire response is
received.  Transition the state to LONG_INITIAL.

@type cmd: L{bytes}
@param cmd: A POP3 command.

@type args: L{bytes}
@param args: The command arguments.

@type consumer: callable that takes L{object}
@param consumer: A consumer function which should be used to put
    the values derived by a transform function from each line of the
    multi-line response into a list.

@type xform: L{None} or callable that takes
    L{bytes} and returns L{object}
@param xform: A transform function which should be used to transform
    each line of the multi-line response into usable values for use by
    a consumer function.  If L{None}, each line of the multi-line
    response should be sent directly to the consumer function.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    callable that takes L{object} and fails with L{ServerErrorResponse}
@return: A deferred which fires when the entire response is received.
    On an OK response, it returns the consumer function.  On an ERR
    response, it issues a server error response failure with the
    response from the server minus the status indicator and the
    consumer function.
r<   LONG_INITIAL)	rM   sendLongrX   rY   _xform	_consumerr   rH   rZ   )r   r[   r\   consumerxformrL   s         r   r`   POP3Client.sendLongR  sr    B MM$--HD=HMM#*t+,MM##
!(}}r   c                 v    U R                   S:  a  U R                  U R                   5        SU l        / U l        g)zu
Wait for a greeting from the server after the connection has been made.

Start the connection in the WELCOME state.
r   WELCOMEN)timeout
setTimeoutrY   rG   r   s    r   connectionMadePOP3Client.connectionMade  s/     <<!OODLL)
r   c                 F    SU l         U R                  R                  5         g)z?
Drop the connection when the server does not respond in time.
TN)	_timedOut	transportloseConnectionrj   s    r   timeoutConnectionPOP3Client.timeoutConnection  s     %%'r   c           
         U R                   S:  a  U R                  S5        U R                  (       a  [        R                  " 5       nO&U R
                  (       a  [        U R
                  5      n/ nU R                  b"  UR                  U R                  5        SU l        U R                  b9  UR                  U R                   VVVs/ s H  u  p4oSPM	     snnn5        SU l	        U H  nUR                  U5        M     gs  snnnf )a  
Clean up when the connection has been lost.

When the loss of connection was initiated by the client due to a
timeout, the L{_timedOut} flag will be set.  When it was initiated by
the client due to an error in the server greeting, L{_greetingError}
will be set to the server response minus the status indicator.

@type reason: L{Failure <twisted.python.failure.Failure>}
@param reason: The reason the connection was terminated.
r   N)rh   ri   rn   r   TimeoutError_greetingErrorr
   rZ   rI   rG   r   errback)r   reasonrL   deferredrJ   rK   ws          r   connectionLostPOP3Client.connectionLost  s     <<!OOD!>>'')F  ()<)<=F==$HHT]]# DM)HHt7I7IJ7I#3Hh7IJK!%DAIIf  Ks   Dc                     U R                   S:  a  U R                  5         U R                  nSU l        [        U SU-   5      " U5      =(       d    UnU R                  c  X l        gg)z
Pass a received line to a state machine function and
transition to the next state.

@type line: L{bytes}
@param line: A received line.
r   Nstate_)rh   resetTimeoutrY   getattr)r   r0   rY   s      r   lineReceivedPOP3Client.lineReceived  s[     <<!


h./5>::J r   c                     U R                   b,  U R                   Sso l         UR                  [        5       5        U R                  R	                  5         g)z
Drop the connection when a server response exceeds the maximum line
length (L{LineOnlyReceiver.MAX_LENGTH}).

@type buffer: L{bytes}
@param buffer: A received line which exceeds the maximum line length.
N)rZ   rv   r	   ro   rp   )r   bufferwaitings      r   lineLengthExceededPOP3Client.lineLengthExceeded  s<     ==$%)]]D"G]OOKM*%%'r   c                    [        U5      u  p#U[        :w  a!  X0l        U R                  R	                  5         OEU R
                  R                  U5      nUb  UR                  S5      U l        U R                  U5        U R                  5         g)a`  
Handle server responses for the WELCOME state in which the server
greeting is expected.

WELCOME is the first state.  The server should send one line of text
with a greeting and possibly an APOP challenge.  Transition the state
to WAITING.

@type line: L{bytes}
@param line: A line received from the server.

@rtype: L{bytes}
@return: The next state.
r   WAITING)r?   OKru   ro   rp   _challengeMagicResearchgroupserverChallengeserverGreetingrS   )r   r0   codestatusms        r   state_WELCOMEPOP3Client.state_WELCOME  sr     (-2:"(NN))+&&--f5A}'(wwqz$'r   c                 H    [         R                  " S[        U5      -   5        g)z
Log an error for server responses received in the WAITING state during
which the server is not expected to send anything.

@type line: L{bytes}
@param line: A line received from the server.
zIllegal line from server: N)r   msgrepr)r   r0   s     r   state_WAITINGPOP3Client.state_WAITING  s     	,tDz9:r   c                     U R                   Sso l         U R                  5         [        U5      u  p4U[        :X  a  UR	                  U5        gUR                  [        U5      5        g)aa  
Handle server responses for the SHORT state in which the server is
expected to send a single line response.

Parse the response and fire the deferred which is waiting on receipt of
a complete response.  Transition the state back to WAITING.

@type line: L{bytes}
@param line: A line received from the server.

@rtype: L{bytes}
@return: The next state.
Nr   )rZ   rS   r?   r   callbackrv   r
   )r   r0   rx   r   r   s        r   state_SHORTPOP3Client.state_SHORT  s\     #'---'-2:f%  089r   c                     [        U5      u  p#U[        :X  a  gU R                  nU R                  nS=U l        =U l        U l        U R                  5         UR                  [        X45      5        g)a}  
Handle server responses for the LONG_INITIAL state in which the server
is expected to send the first line of a multi-line response.

Parse the response.  On an OK response, transition the state to
LONG.  On an ERR response, cleanup and transition the state to
WAITING.

@type line: L{bytes}
@param line: A line received from the server.

@rtype: L{bytes}
@return: The next state.
LONGNr   )r?   r   rb   rZ   ra   rS   rv   r
   )r   r0   r   r   rc   rx   s         r   state_LONG_INITIALPOP3Client.state_LONG_INITIAL  sa     (-2:>>==7;;;,V>?r   c                 ,   US:X  aO  U R                   nU R                  nS=U l         =U l        U l        U R                  5         UR	                  U5        gU R                  b!  U R                  U R                  U5      5        gU R                  U5        g)a  
Handle server responses for the LONG state in which the server is
expected to send a non-initial line of a multi-line response.

On receipt of the last line of the response, clean up, fire the
deferred which is waiting on receipt of a complete response, and
transition the state to WAITING. Otherwise, pass the line to the
transform function, if provided, and then the consumer function.

@type line: L{bytes}
@param line: A line received from the server.

@rtype: L{bytes}
@return: The next state.
   .Nr   r   )rb   rZ   ra   rS   r   )r   r0   rc   rx   s       r   
state_LONGPOP3Client.state_LONG+  s    " 4<~~H}}H;??DN?T]T[MMOh'{{&t{{401  t$r   c                     g)z
Handle the server greeting.

@type greeting: L{bytes}
@param greeting: The server greeting minus the status indicator.
    For servers implementing APOP authentication, this will contain a
    challenge string.
Nr+   )r   greetings     r   r   POP3Client.serverGreetingK  s    r   c                 N   [         R                  " U R                  S5      nUc  [        R                  " [        S5      5      $ Uc  U R                  5       nUc  [        R                  " [        S5      5      $ U R                  5       nUR                  U R                  X5        U$ )aT  
Switch to encrypted communication using TLS.

The first step of switching to encrypted communication is obtaining
the server's capabilities.  When that is complete, the L{_startTLS}
callback function continues the switching process.

@type contextFactory: L{None} or
    L{ClientContextFactory <twisted.internet.ssl.ClientContextFactory>}
@param contextFactory: The context factory with which to negotiate TLS.
    If not provided, try to create a new one.

@rtype: L{Deferred <defer.Deferred>} which successfully results in
    L{dict} mapping L{bytes} to L{list} of L{bytes} and/or L{bytes} to
    L{None} or fails with L{TLSError}
@return: A deferred which fires when the transport has been
    secured according to the given context factory with the server
    capabilities, or which fails with a TLS error if the transport
    cannot be secured.
Nz@POP3Client transport does not implement interfaces.ITLSTransportz@POP3Client requires a TLS context to initiate the STLS handshake)
r   ITLSTransportro   r   failr   _getContextFactorycapabilitiesaddCallback	_startTLS)r   contextFactorytlsrL   s       r   startTLSPOP3Client.startTLSV  s    * &&t~~t<;::/  !!446N!::2  	dnnn:r   c                   ^  T R                   (       a   S5       eSU;  a  [        R                  " [        S5      5      $ T R	                  SS5      nUR                  T R                  X#5        UR                  U 4S j5        U$ )a  
Continue the process of switching to encrypted communication.

This callback function runs after the server capabilities are received.

The next step is sending the server an STLS command to request a
switch to encrypted communication.  When an OK response is received,
the L{_startedTLS} callback function completes the switch to encrypted
communication. Then, the new server capabilities are requested.

@type caps: L{dict} mapping L{bytes} to L{list} of L{bytes} and/or
    L{bytes} to L{None}
@param caps: The server capabilities.

@type contextFactory: L{ClientContextFactory
    <twisted.internet.ssl.ClientContextFactory>}
@param contextFactory: A context factory with which to negotiate TLS.

@type tls: L{ITLSTransport <interfaces.ITLSTransport>}
@param tls: A TCP transport that supports switching to TLS midstream.

@rtype: L{Deferred <defer.Deferred>} which successfully triggers with
    L{dict} mapping L{bytes} to L{list} of L{bytes} and/or L{bytes} to
    L{None} or fails with L{TLSNotSupportedError}
@return: A deferred which successfully fires when the response from
    the server to the request to start TLS has been received and the
    new server capabilities have been received or fails when the server
    does not support TLS.
z5Client and Server are currently communicating via TLS   STLSz:Server does not support secure communication via TLS / SSLNc                 $   > TR                  5       $ N)r   )_r   s    r   <lambda>&POP3Client._startTLS.<locals>.<lambda>  s     1 1 3r   )
startedTLSr   r   r   rW   r   _startedTLS)r   capsr   r   rL   s   `    r   r   POP3Client._startTLS  s|    > 	CB	C $::$S  NN7D)	d&&<	34r   c                 d    X0l         U R                   R                  U5        SU l        SU l        U$ )a  
Complete the process of switching to encrypted communication.

This callback function runs after the response to the STLS command has
been received.

The final steps are discarding the cached capabilities and initiating
TLS negotiation on the transport.

@type result: L{dict} mapping L{bytes} to L{list} of L{bytes} and/or
    L{bytes} to L{None}
@param result: The server capabilities.

@type context: L{ClientContextFactory
    <twisted.internet.ssl.ClientContextFactory>}
@param context: A context factory with which to negotiate TLS.

@type tls: L{ITLSTransport <interfaces.ITLSTransport>}
@param tls: A TCP transport that supports switching to TLS midstream.

@rtype: L{dict} mapping L{bytes} to L{list} of L{bytes} and/or L{bytes}
    to L{None}
@return: The server capabilities.
NT)ro   r   	_capCacher   )r   resultcontextr   s       r   r   POP3Client._startedTLS  s.    2 (r   c                      SSK Jn  UR                  5       nUR                  R                  Ul        U$ ! [         a     gf = f)z
Get a context factory with which to negotiate TLS.

@rtype: L{None} or
    L{ClientContextFactory <twisted.internet.ssl.ClientContextFactory>}
@return: A context factory or L{None} if TLS is not supported on the
    client.
r   )sslN)twisted.internetr   ClientContextFactorySSLTLSv1_2_METHODmethodImportError)r   r   r   s      r   r   POP3Client._getContextFactory  sD    	, ..0G WW33GNN  		s   5 
AAc                 ^    U R                  5       nUR                  U R                  X5        U$ )ao  
Log in to the server.

If APOP is available it will be used.  Otherwise, if TLS is
available, an encrypted session will be started and plaintext
login will proceed.  Otherwise, if L{allowInsecureLogin} is set,
insecure plaintext login will proceed.  Otherwise,
L{InsecureAuthenticationDisallowed} will be raised.

The first step of logging into the server is obtaining the server's
capabilities.  When that is complete, the L{_login} callback function
continues the login process.

@type username: L{bytes}
@param username: The username with which to log in.

@type password: L{bytes}
@param password: The password with which to log in.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes}
@return: A deferred which fires when the login process is complete.
    On a successful login, it returns the server's response minus the
    status indicator.
)r   r   _login)r   usernamepasswordrL   s       r   loginPOP3Client.login  s)    4 	dkk86r   c                 B   U R                   b  U R                  X#U R                   5      $ SU;   n[        R                  " U R                  S5      SLn[        R
                  " U R                  S5      SL nU R                  (       dC  U(       a<  U(       a5  U(       a.  U R                  5       nUR                  U R                  X#5        U$ U R                  (       d  U(       a  U R                  (       a  U R                  X#5      $ [        R                  " [        5       5      $ )a  
Continue the process of logging in to the server.

This callback function runs after the server capabilities are received.

If the server provided a challenge in the greeting, proceed with an
APOP login.  Otherwise, if the server and the transport support
encrypted communication, try to switch to TLS and then complete
the login process with the L{_loginTLS} callback function.  Otherwise,
if insecure authentication is allowed, do a plaintext login.
Otherwise, fail with an L{InsecureAuthenticationDisallowed} error.

@type caps: L{dict} mapping L{bytes} to L{list} of L{bytes} and/or
    L{bytes} to L{None}
@param caps: The server capabilities.

@type username: L{bytes}
@param username: The username with which to log in.

@type password: L{bytes}
@param password: The password with which to log in.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes}
@return: A deferred which fires when the login process is complete.
    On a successful login, it returns the server's response minus the
    status indicator.
Nr   )r   _apopr   r   ro   ISSLTransportr   r   r   	_loginTLSallowInsecureLogin
_plaintextr   r   r   )r   r   r   r   tryTLStlsableTransportnontlsTransportrL   s           r   r   POP3Client._login   s    : +::h$2F2FGGD &33DNNDIQUU %224>>4HDP6.>?AMM$..(=H__Ot7N7N??866::>@AAr   c                 $    U R                  X#5      $ )a  
Do a plaintext login over an encrypted transport.

This callback function runs after the transport switches to encrypted
communication.

@type res: L{dict} mapping L{bytes} to L{list} of L{bytes} and/or
    L{bytes} to L{None}
@param res: The server capabilities.

@type username: L{bytes}
@param username: The username with which to log in.

@type password: L{bytes}
@param password: The password with which to log in.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server accepts the username
    and password or fails when the server rejects either.  On a
    successful login, it returns the server's response minus the
    status indicator.
)r   )r   resr   r   s       r   r   POP3Client._loginTLS5  s    0 x22r   c                 P   ^ ^ T R                  U5      R                  UU 4S j5      $ )a
  
Perform a plaintext login.

@type username: L{bytes}
@param username: The username with which to log in.

@type password: L{bytes}
@param password: The password with which to log in.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server accepts the username
    and password or fails when the server rejects either.  On a
    successful login, it returns the server's response minus the
    status indicator.
c                 &   > TR                  T5      $ r   )r   )rr   r   s    r   r   'POP3Client._plaintext.<locals>.<lambda>`  s    x9Pr   )userr   )r   r   r   s   ` `r   r   POP3Client._plaintextO  s     " yy"../PQQr   c                 x    [        X2-   5      R                  5       R                  S5      nU R                  X5      $ )a  
Perform an APOP login.

@type username: L{bytes}
@param username: The username with which to log in.

@type password: L{bytes}
@param password: The password with which to log in.

@type challenge: L{bytes}
@param challenge: A challenge string.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On a successful login, it returns the server response minus
    the status indicator.
ascii)r   	hexdigestencodeapop)r   r   r   	challengedigests        r   r   POP3Client._apopb  s4    & Y)*446==gFyy**r   c                 2    U R                  SUS-   U-   5      $ )a  
Send an APOP command to perform authenticated login.

This should be used in special circumstances only, when it is
known that the server supports APOP authentication, and APOP
authentication is absolutely required.  For the common case,
use L{login} instead.

@type username: L{bytes}
@param username: The username with which to log in.

@type digest: L{bytes}
@param digest: The challenge response to authenticate with.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the server
    response minus the status indicator.  On an ERR response, the
    deferred fails with a server error response failure.
s   APOPr<   rW   )r   r   r   s      r   r   POP3Client.apopx  s    , ~~gx$'?@@r   c                 &    U R                  SU5      $ )aK  
Send a USER command to perform the first half of plaintext login.

Unless this is absolutely required, use the L{login} method instead.

@type username: L{bytes}
@param username: The username with which to log in.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the server
    response minus the status indicator.  On an ERR response, the
    deferred fails with a server error response failure.
s   USERr   )r   r   s     r   r   POP3Client.user        ~~gx00r   c                 &    U R                  SU5      $ )a\  
Send a PASS command to perform the second half of plaintext login.

Unless this is absolutely required, use the L{login} method instead.

@type password: L{bytes}
@param password: The plaintext password with which to authenticate.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the server
    response minus the status indicator.  On an ERR response, the
    deferred fails with a server error response failure.
s   PASSr   )r   r   s     r   r   POP3Client.password  r   r   c                 4    U R                  SSUS-   4-  5      $ )a  
Send a DELE command to delete a message from the server.

@type index: L{int}
@param index: The 0-based index of the message to delete.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the server
    response minus the status indicator.  On an ERR response, the
    deferred fails with a server error response failure.
s   DELE   %dr   r   )r   r5   s     r   deletePOP3Client.delete  s      ~~gu	|';<<r   c                    ^ Uc<  / m[        T5      R                  nU R                  XX45      R                  U4S j5      $ U R                  XX45      $ )a   
Send a command to which a long response is expected and process the
multi-line response into a list accounting for deleted messages.

@type cmd: L{bytes}
@param cmd: A POP3 command to which a long response is expected.

@type args: L{bytes}
@param args: The command arguments.

@type consumer: L{None} or callable that takes
    L{object}
@param consumer: L{None} or a function that consumes the output from
    the transform function.

@type xform: L{None}, callable that takes
    L{bytes} and returns 2-L{tuple} of (0) L{int}, (1) L{object},
    or callable that takes L{bytes} and returns L{object}
@param xform: A function that parses a line from a multi-line response
    and transforms the values into usable form for input to the
    consumer function.  If no consumer function is specified, the
    output must be a message index and corresponding value.  If no
    transform function is specified, the line is used as is.

@rtype: L{Deferred <defer.Deferred>} which fires with L{list} of
    L{object} or callable that takes L{list} of L{object}
@return: A deferred which fires when the entire response has been
    received.  When a consumer is not provided, the return value is a
    list of the value for each message or L{None} for deleted messages.
    Otherwise, it returns the consumer itself.
c                    > T$ r   r+   r   r   s    r   r   .POP3Client._consumeOrSetItem.<locals>.<lambda>      STr   )r   r#   r`   r   r   r[   r\   rc   rd   r   s        @r   _consumeOrSetItemPOP3Client._consumeOrSetItem  sM    @ A"1~--H==H<HHUU}}S88r   c                    ^ Uc3  / mTR                   nU R                  XX45      R                  U4S j5      $ U R                  XX45      $ )a2  
Send a command to which a long response is expected and process the
multi-line response into a list.

@type cmd: L{bytes}
@param cmd: A POP3 command which expects a long response.

@type args: L{bytes}
@param args: The command arguments.

@type consumer: L{None} or callable that takes
    L{object}
@param consumer: L{None} or a function that consumes the output from the
    transform function.

@type xform: L{None} or callable that takes
    L{bytes} and returns L{object}
@param xform: A function that transforms a line from a multi-line
    response into usable form for input to the consumer function.  If
    no transform function is specified, the line is used as is.

@rtype: L{Deferred <defer.Deferred>} which fires with L{list} of
    2-L{tuple} of (0) L{int}, (1) L{object} or callable that
    takes 2-L{tuple} of (0) L{int}, (1) L{object}
@return: A deferred which fires when the entire response has been
    received.  When a consumer is not provided, the return value is a
    list of the transformed lines.  Otherwise, it returns the consumer
    itself.
c                    > T$ r   r+   r   s    r   r   -POP3Client._consumeOrAppend.<locals>.<lambda>  r   r   )rI   r`   r   r   s        @r   _consumeOrAppendPOP3Client._consumeOrAppend  sF    < AxxH==H<HHUU}}S88r   c                    ^ ^ U(       a-  T R                   b   [        R                  " T R                   5      $ 0 mU4S jnS nUU 4S jnT R                  SSUS5      nUR	                  U5      R                  U5        U$ )a  
Send a CAPA command to retrieve the capabilities supported by
the server.

Not all servers support this command.  If the server does not
support this, it is treated as though it returned a successful
response listing no capabilities.  At some future time, this may be
changed to instead seek out information about a server's
capabilities in some other fashion (only if it proves useful to do
so, and only if there are servers still in use which do not support
CAPA but which do support POP3 extensions that are useful).

@type useCache: L{bool}
@param useCache: A flag that determines whether previously retrieved
    results should be used if available.

@rtype: L{Deferred <defer.Deferred>} which successfully results in
    L{dict} mapping L{bytes} to L{list} of L{bytes} and/or L{bytes} to
    L{None}
@return: A deferred which fires with a mapping of capability name to
parameters.  For example::

    C: CAPA
    S: +OK Capability list follows
    S: TOP
    S: USER
    S: SASL CRAM-MD5 KERBEROS_V4
    S: RESP-CODES
    S: LOGIN-DELAY 900
    S: PIPELINING
    S: EXPIRE 60
    S: UIDL
    S: IMPLEMENTATION Shlemazle-Plotz-v302
    S: .

will be lead to a result of::

    | {'TOP': None,
    |  'USER': None,
    |  'SASL': ['CRAM-MD5', 'KERBEROS_V4'],
    |  'RESP-CODES': None,
    |  'LOGIN-DELAY': ['900'],
    |  'PIPELINING': None,
    |  'EXPIRE': ['60'],
    |  'UIDL': None,
    |  'IMPLEMENTATION': ['Shlemazle-Plotz-v302']}
Nc                    > U R                  5       n[        U5      S:X  a	  S TUS   '   g [        U5      S:  a  USS  TUS   '   g g )Nr   r   r=   )r0   tmpcaches     r   consume(POP3Client.capabilities.<locals>.consumeC  sI    **,C3x1} $c!fSA #ABc!f r   c                 .    U R                  [        5        g r   )trapr
   )errs    r   capaNotSupported1POP3Client.capabilities.<locals>.capaNotSupportedJ  s    HH()r   c                    > TTl         T$ r   )r   )r   r	  r   s    r   gotCapabilities0POP3Client.capabilities.<locals>.gotCapabilitiesN  s    "DNLr   s   CAPA)r   r   succeedr  
addErrbackr   )r   useCacher
  r  r  rL   r	  s   `     @r   r   POP3Client.capabilities  sn    ` 2==00	(		 !!'4$?	%&22?Cr   c                 &    U R                  SS5      $ )a  
Send a NOOP command asking the server to do nothing but respond.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the server
    response minus the status indicator.  On an ERR response, the
    deferred fails with a server error response failure.
s   NOOPNr   rj   s    r   noopPOP3Client.noopV       ~~gt,,r   c                 &    U R                  SS5      $ )a  
Send a RSET command to unmark any messages that have been flagged
for deletion on the server.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the server
    response minus the status indicator.  On an ERR response, the
    deferred fails with a server error response failure.
s   RSETNr   rj   s    r   resetPOP3Client.resetc  s     ~~gt,,r   c                     SUS-   4-  nUc  U R                  SXB[        5      $ U R                  SSXC4-  U[        5      $ )aM  
Send a RETR or TOP command to retrieve all or part of a message from
the server.

@type index: L{int}
@param index: A 0-based message index.

@type consumer: L{None} or callable that takes
    L{bytes}
@param consumer: A function which consumes each transformed line from a
    multi-line response as it is received.

@type lines: L{None} or L{int}
@param lines: If specified, the number of lines of the message to be
    retrieved.  Otherwise, the entire message is retrieved.

@rtype: L{Deferred <defer.Deferred>} which fires with L{list} of
    L{bytes}, or callable that takes 2-L{tuple} of (0) L{int},
    (1) L{object}
@return: A deferred which fires when the entire response has been
    received.  When a consumer is not provided, the return value is a
    list of the transformed lines.  Otherwise, it returns the consumer
    itself.
r   r   s   RETRs   TOPs   %b %d)r  rB   )r   r5   rc   linesidxs        r   retrievePOP3Client.retrieveq  sQ    2 uqyl"=((#NN$$H|+X|
 	
r   c                 L    U R                  SS5      R                  [        5      $ )a  
Send a STAT command to get information about the size of the mailbox.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    a 2-tuple of (0) L{int}, (1) L{int} or fails with
    L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the number of
    messages in the mailbox and the size of the mailbox in octets.
    On an ERR response, the deferred fails with a server error
    response failure.
s   STATN)rW   r   r3   rj   s    r   statPOP3Client.stat  s      ~~gt,88DDr   c                 2    U R                  SSU[        5      $ )ar  
Send a LIST command to retrieve the sizes of all messages on the
server.

@type consumer: L{None} or callable that takes
    2-L{tuple} of (0) L{int}, (1) L{int}
@param consumer: A function which consumes the 0-based message index
    and message size derived from the server response.

@rtype: L{Deferred <defer.Deferred>} which fires L{list} of L{int} or
    callable that takes 2-L{tuple} of (0) L{int}, (1) L{int}
@return: A deferred which fires when the entire response has been
    received.  When a consumer is not provided, the return value is a
    list of message sizes.  Otherwise, it returns the consumer itself.
s   LISTN)r   r7   r   rc   s     r   listSizePOP3Client.listSize  s      %%gtXzJJr   c                 2    U R                  SSU[        5      $ )ax  
Send a UIDL command to retrieve the UIDs of all messages on the server.

@type consumer: L{None} or callable that takes
    2-L{tuple} of (0) L{int}, (1) L{bytes}
@param consumer: A function which consumes the 0-based message index
    and UID derived from the server response.

@rtype: L{Deferred <defer.Deferred>} which fires with L{list} of
    L{object} or callable that takes 2-L{tuple} of (0) L{int},
    (1) L{bytes}
@return: A deferred which fires when the entire response has been
    received.  When a consumer is not provided, the return value is a
    list of message sizes.  Otherwise, it returns the consumer itself.
s   UIDLN)r   r:   r(  s     r   listUIDPOP3Client.listUID  s      %%gtXyIIr   c                 &    U R                  SS5      $ )a  
Send a QUIT command to disconnect from the server.

@rtype: L{Deferred <defer.Deferred>} which successfully fires with
    L{bytes} or fails with L{ServerErrorResponse}
@return: A deferred which fires when the server response is received.
    On an OK response, the deferred succeeds with the server
    response minus the status indicator.  On an ERR response, the
    deferred fails with a server error response failure.
s   QUITNr   rj   s    r   quitPOP3Client.quit  r  r   )rG   r   rb   ru   rn   rZ   ra   r   r   rY   ro   r   )T)NN)8r%   r&   r'   r(   r)   r   r   rh   r   r   recompiler   rG   rZ   rn   ru   rM   rS   rW   r`   rk   rq   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r"  r%  r)  r,  r/  r*   r+   r   r   rD   rD      s   Ob JGOI

<0MHIN85,B-`
 (<"(<;.2@+Z,\>$<3Bj34R&+,A01$1$= $9L"9HFP--
BEK$J$-r   rD   __all__)#r)   r1  hashlibr   typingr   r   r   r   r   twisted.mail._exceptr   r	   r
   r   r   twisted.protocolsr   r   twisted.pythonr   r   ERRr   r3   r7   r:   r?   rB   LineOnlyReceiverTimeoutMixinrD   r3  str__annotations__r+   r   r   <module>r>     s    
   5 5  . $ $N(%$& *o-'')>)> o-d! c r   