ϪfUdZddlZddlmZddlmZddlmZmZm Z ddl m Z m Z m Z mZmZddlmZmZddlmZd Zd ZGd d Zd ZdZdZdZdZGddej:ej<ZgZ ee!e"d<y)z A POP3 client protocol implementation. Don't use this module directly. Use twisted.mail.pop3 instead. @author: Jp Calderone N)md5)List)defererror interfaces) InsecureAuthenticationDisallowed LineTooLongServerErrorResponseTLSErrorTLSNotSupportedError)basicpolicies)logs+OKs-ERRceZdZdZdZdZy) _ListSettera$ 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||_y)z @type L: L{list} of L{object} @param L: The list being constructed. An empty list should be passed in. N)L)selfrs :/usr/lib/python3/dist-packages/twisted/mail/_pop3client.py__init__z_ListSetter.__init__0s c|\}}|t|jz dz}|dkDr|jjdg|z||j|<y)aI 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. rN)lenrextend)r itemAndValueitemvaluediffs rsetitemz_ListSetter.setitem8sN% uc$&&k!A% !8 FFMM4&4- (t rN)__name__ __module__ __qualname____doc__rr rrrr!s  rrcX|jdd\}}t|t|fS)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. Nrsplitint)linenumMsgs totalSizes r _statXformr-Hs,D!,GY w<Y ''rc^|jdd\}}t|dz t|fS)a 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. Nrr')r*indexsizes r _listXformr1Ws/**T1%KE4 u:>3t9 $$rcL|jdd\}}t|dz |fS)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. Nrr')r*r/uids r _uidXformr4is+D!$JE3 u:>3 rcT|jdd}t|dk(r|ddfS|S)a 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.  rrrr(r)r*partss r_codeStatusSplitr9|s2 JJtQ E 5zQQx} Lrc2|jdr|ddS|S)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..rN) startswith)r*s r _dotUnquoterr<s  uABx KrcFeZdZdZdZdZdZdZdZe jdZ dZ dZ dZdZdZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZd,dZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)d Z*d!Z+d"Z,d#Z-d-d$Z.d%Z/d&Z0d.d'Z1d(Z2d,d)Z3d,d*Z4d+Z5y)/ POP3Clienta2 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 } @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 }, (1) callable which results in a L{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 } 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. FrNs (<[^>]+>)c|j4tj}|jj|||f|Sg|_y)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 } @return: L{None} if the command can run immediately. Otherwise, a deferred that will eventually trigger with the return value of the function. N) _blockedQueuerDeferredappend)rfads r_blockedzPOP3Client._blockedsF*    ) A    % %q!Qi 0Hrc|jgk(rd|_y|jZ|j}d|_|jd\}}}||}|j||jj|yy)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)r@pop chainDeferredr)rr@rErCrDd2s r_unblockzPOP3Client._unblocks    #!%D     + ..M!%D #''*GAq!AB   Q     % %m 4,rc|j|j||}||S|r|j|dz|zn|j|d|_t j |_|j S)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 } 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. r6SHORT)rF sendShortsendLinestaterrA_waiting)rcmdargsrEs rrNzPOP3Client.sendShort1sg* MM$..#t 4 =H  MM#*t+ , MM#  ( }}rc|j|j||||}||S|r|j|dz|zn|j|d|_||_||_t j|_|jS)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 } 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. r6 LONG_INITIAL) rFsendLongrOrP_xform _consumerrrArQ)rrRrSconsumerxformrEs rrVzPOP3Client.sendLongRszB MM$--dHe D =H  MM#*t+ , MM# #  !( }}rct|jdkDr|j|jd|_g|_y)z Wait for a greeting from the server after the connection has been made. Start the connection in the WELCOME state. rWELCOMEN)timeout setTimeoutrPr@rs rconnectionMadezPOP3Client.connectionMades/ <} @param reason: The reason the connection was terminated. rN) r]r^rbr TimeoutError_greetingErrorr rQrBr@rerrback)rreasonrEdeferredrCrDws rconnectionLostzPOP3Client.connectionLosts <>'')F  ()<)<=F  == $ HHT]] # DM    ) HHt7I7IJJ#3HahJ K!%D  A IIf  Ks: C0 c|jdkDr|j|j}d|_t|d|z|xs|}|j||_yy)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. rNstate_)r] resetTimeoutrPgetattr)rr*rPs r lineReceivedzPOP3Client.lineReceiveds_ < :: DJ rc|j-|jdc}|_|jt|jj y)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)rQrir rcrd)rbufferwaitings rlineLengthExceededzPOP3Client.lineLengthExceededs> == $%)]]D "GT] OOKM * %%'rct|\}}|tk7r"||_|jj nD|j j |}||jd|_|j||jy)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. rWAITING) r9OKrhrcrd_challengeMagicResearchgroupserverChallengeserverGreetingrK)rr*codestatusms r state_WELCOMEzPOP3Client.state_WELCOMEsv(- f 2:"(D  NN ) ) +&&--f5A}'(wwqz$    ' rcFtjdt|zy)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. zIllegal line from server: N)rmsgrepr)rr*s r state_WAITINGzPOP3Client.state_WAITINGs ,tDz9:rc|jdc}|_|jt|\}}|tk(r|j |y|j t |y)a 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. Nrx)rQrKr9rycallbackrir )rr*rkrrs r state_SHORTzPOP3Client.state_SHORTs`#'--$- '- f 2:   f %   08 9rct|\}}|tk(ry|j}|j}dx|_x|_|_|j |j t||y)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. LONGNrx)r9ryrXrQrWrKrir )rr*rrrYrks rstate_LONG_INITIALzPOP3Client.state_LONG_INITIALse(- f 2:>>==7;;; ,VX>?rc(|dk(rO|j}|j}dx|_x|_|_|j|j |y|j!|j|j|y|j|y)aL 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. .Nrxr)rXrQrWrKr)rr*rYrks r state_LONGzPOP3Client.state_LONG+s" 4<~~H}}H;? ?DN ?T]T[ MMO   h '{{&t{{401t$rcy)a 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%)rgreetings rr~zPOP3Client.serverGreetingKsrcDtj|jd}|tjt dS||j }|tjt dS|j}|j|j|||S)a 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 } @param contextFactory: The context factory with which to negotiate TLS. If not provided, try to create a new one. @rtype: L{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 ITLSTransportrcrfailr _getContextFactory capabilities addCallback _startTLS)rcontextFactorytlsrEs rstartTLSzPOP3Client.startTLSVs*&&t~~t< ;::/   !!446N  !::2      dnnnc:rcjrJdd|vrtjtdSj dd}|j j |||j fd|S)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 } @param contextFactory: A context factory with which to negotiate TLS. @type tls: L{ITLSTransport } @param tls: A TCP transport that supports switching to TLS midstream. @rtype: L{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 TLSSTLSz:Server does not support secure communication via TLS / SSLNc$jSN)r)_rs rz&POP3Client._startTLS..s 1 1 3r) startedTLSrrr rNr _startedTLS)rcapsrrrEs` rrzPOP3Client._startTLSs~> C B C  $ ::$S  NN7D ) d&&< 34rcf||_|jj|d|_d|_|S)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 } @param context: A context factory with which to negotiate TLS. @type tls: L{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)rcr _capCacher)rresultcontextrs rrzPOP3Client._startedTLSs02 ( rc ddlm}|j}|jj|_|S#t $rYywxYw)a Get a context factory with which to negotiate TLS. @rtype: L{None} or L{ClientContextFactory } @return: A context factory or L{None} if TLS is not supported on the client. r)sslN)twisted.internetrClientContextFactorySSLTLSv1_2_METHODmethod ImportError)rrrs rrzPOP3Client._getContextFactorysD  ,..0G WW33GNN   s5 AAc`|j}|j|j|||S)a 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 } 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. )rr_login)rusernamepasswordrEs rloginzPOP3Client.logins+4     dkk8X6rc|j|j|||jSd|v}tj|jddu}tj |jddu}|j s5|r3|r1|r/|j}|j|j|||S|j s|r |jr|j||StjtS)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 } 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}_apoprrrc ISSLTransportrrr _loginTLSallowInsecureLogin _plaintextrrr)rrrrtryTLStlsableTransportnontlsTransportrEs rrzPOP3Client._logins:    +::h$2F2FG GD&33DNNDIQUU%224>>4HDP6.>? A MM$..(H =H __Ot7N7N??8X6 6::>@A Arc&|j||S)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 } 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)rresrrs rrzPOP3Client._loginTLS5s0x22rcNj|jfdS)aj 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 } 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&jSr)r)rrrs rrz'POP3Client._plaintext..`sx9Pr)userr)rrrs` `rrzPOP3Client._plaintextOs "yy"../PQQrc|t||zjjd}|j||S)as 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 } 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 hexdigestencodeapop)rrr challengedigests rrzPOP3Client._apopbs8&Y)*446==gFyy6**rc2|jd|dz|zS)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 } 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. sAPOPr6rN)rrrs rrzPOP3Client.apopxs,~~gx$'?@@rc&|jd|S)a 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 } 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. sUSERr)rrs rrzPOP3Client.user ~~gx00rc&|jd|S)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 } 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. sPASSr)rrs rrzPOP3Client.passwordrrc4|jdd|dzfzS)aM 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 } 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. sDELE%drr)rr/s rdeletezPOP3Client.deletes ~~gu |';<} 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. cSrr%rrs rrz.POP3Client._consumeOrSetItem..STr)rr rVrrrRrSrYrZrs @r_consumeOrSetItemzPOP3Client._consumeOrSetItemsU@  A"1~--H==dHe<HHU U}}S$%88rc|4gj}|j||||jfdS|j||||S)a 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 } 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. cSrr%rs rrz-POP3Client._consumeOrAppend.. rr)rBrVrrs @r_consumeOrAppendzPOP3Client._consumeOrAppendsN<  AxxH==dHe<HHU U}}S$%88rc|r+jtjjSifd}d}fd}jdd|d}|j |j ||S)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 } 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|j}t|dk(r d|d<yt|dkDr |dd|d<yy)Nrrr7)r*tmpcaches rconsumez(POP3Client.capabilities..consumeCsI**,C3x1} $c!f SA #ABc!f rc.|jtyr)trapr )errs rcapaNotSupportedz1POP3Client.capabilities..capaNotSupportedJs HH( )rc_Sr)r)rrrs rgotCapabilitiesz0POP3Client.capabilities..gotCapabilitiesNs"DNLrsCAPA)rrsucceedr addErrbackr)ruseCacherrrrErs` @rrzPOP3Client.capabilitiessn` 2==0 0 (    ! !'4$ ? %&22?Crc&|jddS)a Send a NOOP command asking the server to do nothing but respond. @rtype: L{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. sNOOPNrr_s rnoopzPOP3Client.noopV~~gt,,rc&|jddS)a Send a RSET command to unmark any messages that have been flagged for deletion on the server. @rtype: L{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. sRSETNrr_s rresetzPOP3Client.resetcs~~gt,,rcd|dzfz}||jd||tS|jdd||fz|tS)a 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 } 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. rrsRETRsTOPs%b %d)rr<)rr/rYlinesidxs rretrievezPOP3Client.retrieveqsU2uqyl" =((#xN N$$ HU|+X|  rcL|jddjtS)aJ Send a STAT command to get information about the size of the mailbox. @rtype: L{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. sSTATN)rNrr-r_s rstatzPOP3Client.stats ~~gt,88DDrc2|jdd|tS)a 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 } 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. sLISTN)rr1rrYs rlistSizezPOP3Client.listSizes %%gtXzJJrc2|jdd|tS)a 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 } 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. sUIDLN)rr4rs rlistUIDzPOP3Client.listUIDs %%gtXyIIrc&|jddS)a Send a QUIT command to disconnect from the server. @rtype: L{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. sQUITNrr_s rquitzPOP3Client.quitrrr)T)NN)6r!r"r#r$rrr]r}rrecompilerzr@rQrbrhrFrKrNrVr`rermrrrvrrrrrr~rrrrrrrrrrrrrrrrrrrrrrrr%rrr>r>sObJGOI" <0MHIN85,B-`  (<" (<;.2@ +Z,\>$<3Bj34R&+,A01$1$= $9L"9HFP - - B EK$J$ -rr>__all__)#r$rhashlibrtypingrrrrrtwisted.mail._exceptrr r r r twisted.protocolsr rtwisted.pythonrryERRrr-r1r4r9r<LineOnlyReceiver TimeoutMixinr>rstr__annotations__r%rrr s  55.  $$N (%$&  *o-'')>)>o-d!cr