%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/mail/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/mail/__pycache__/_pop3client.cpython-312.pyc

�

Ϫ�f�����UdZddlZddlmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
mZmZddlmZmZddlmZd	Zd
ZGd�d�Zd
�Zd�Zd�Zd�Zd�ZGd�dej: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)�defer�error�
interfaces)� InsecureAuthenticationDisallowed�LineTooLong�ServerErrorResponse�TLSError�TLSNotSupportedError)�basic�policies)�logs+OKs-ERRc��eZdZdZd�Zd�Zy)�_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|j�z
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)�lenr�extend)r�itemAndValue�item�value�diffs     r�setitemz_ListSetter.setitem8sN��%�
��u��c�$�&�&�k�!�A�%���!�8��F�F�M�M�4�&�4�-�(�����t�rN)�__name__�
__module__�__qualname__�__doc__rr �rrrr!s����
rrc�X�|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.
    Nr��split�int)�line�numMsgs�	totalSizes   r�
_statXformr-Hs,�����D�!�,��G�Y��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*�index�sizes   r�
_listXformr1Ws/���*�*�T�1�%�K�E�4��u�:��>�3�t�9�$�$rc�L�|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�!�$�J�E�3��u�:��>�3��rc�T�|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.
    � rrr�r(r)r*�partss  r�_codeStatusSplitr9|s2��
�J�J�t�Q��E�
�5�z�Q���Q�x��}���Lrc�2�|jd�r|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 �� ���u���A�B�x���Krc�F�eZdZdZdZdZdZdZdZe	jd�ZdZdZ
dZdZd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd,d�Zd�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-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 <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.
    FrNs	(<[^>]+>)c��|j�4tj�}|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 <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�_blockedzPOP3Client._blocked�sF��*���)���� �A����%�%�q�!�Q�i�0��H����rc��|jgk(rd|_y|j�Z|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@rErCrD�d2s      r�_unblockzPOP3Client._unblocks�������#�!%�D��
�
�
�
+� �.�.�M�!%�D��#�'�'��*�G�A�q�!��A��B����Q��

���%�%�m�4�,rc���|j|j||�}|�|S|r|j|dz|z�n|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 <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.
        r6�SHORT)rF�	sendShort�sendLine�staterrA�_waiting)r�cmd�argsrEs    rrNzPOP3Client.sendShort1sg��*
�M�M�$�.�.�#�t�4���=��H���M�M�#��*�t�+�,��M�M�#����
����(��
��}�}�rc��|j|j||||�}|�|S|r|j|dz|z�n|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 <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.
        r6�LONG_INITIAL)	rF�sendLongrOrP�_xform�	_consumerrrArQ)rrRrS�consumer�xformrEs      rrVzPOP3Client.sendLongRsz��B
�M�M�$�-�-��d�H�e�D���=��H���M�M�#��*�t�+�,��M�M�#��#��
����!������(��
��}�}�rc�t�|jdkDr|j|j�d|_g|_y)z�
        Wait for a greeting from the server after the connection has been made.

        Start the connection in the WELCOME state.
        r�WELCOMEN)�timeout�
setTimeoutrPr@�rs r�connectionMadezPOP3Client.connectionMade�s/���<�<�!���O�O�D�L�L�)���
���rc�F�d|_|jj�y)zO
        Drop the connection when the server does not respond in time.
        TN)�	_timedOut�	transport�loseConnectionr_s r�timeoutConnectionzPOP3Client.timeoutConnection�s��������%�%�'rc
���|jdkDr|jd�|jrtj�}n!|j
rt
|j
�}g}|j�"|j|j�d|_|j�8|j|jD���cgc]\}}}|��
c}}}�d|_	|D]}|j|��ycc}}}w)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.
        rN)r]r^rbr�TimeoutError�_greetingErrorr
rQrBr@r�errback)r�reasonrE�deferredrCrD�ws       r�connectionLostzPOP3Client.connectionLost�s����<�<�!���O�O�D�!��>�>��'�'�)�F�
�
 �
 �(��)<�)<�=�F����=�=�$�
�H�H�T�]�]�#� �D�M����)�
�H�H�t�7I�7I�J�J�#3�H�a��h�J�K�!%�D���	�A�
�I�I�f��	��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.
        rN�state_)r]�resetTimeoutrP�getattr)rr*rPs   r�lineReceivedzPOP3Client.lineReceived�s_���<�<�!�������
�
����
�/���h��.�/��5�>����:�:���D�J�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)r�buffer�waitings   r�lineLengthExceededzPOP3Client.lineLengthExceeded�s>���=�=�$�%)�]�]�D�"�G�T�]��O�O�K�M�*����%�%�'rc��t|�\}}|tk7r"||_|jj	�nD|j
j
|�}|�|jd�|_|j|�|j�y)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)r9�OKrhrcrd�_challengeMagicRe�search�group�serverChallenge�serverGreetingrK)rr*�code�status�ms     r�
state_WELCOMEzPOP3Client.state_WELCOME�sv��(��-���f��2�:�"(�D���N�N�)�)�+��&�&�-�-�f�5�A��}�'(�w�w�q�z��$�����'��
�
��rc�F�tjdt|�z�y)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)r�msg�repr)rr*s  r�
state_WAITINGzPOP3Client.state_WAITING�s��	���,�t�D�z�9�:rc���|jdc}|_|j�t|�\}}|tk(r|j	|�y|jt
|��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)rQrKr9ry�callbackrir
)rr*rkrr�s     r�state_SHORTzPOP3Client.state_SHORT�s`��#'�-�-����$�-��
�
��'��-���f��2�:����f�%��
���0��8�9�rc���t|�\}}|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*rr�rYrks      r�state_LONG_INITIALzPOP3Client.state_LONG_INITIALse��(��-���f��2�:���>�>���=�=��7;�;���;������
�
�����,�V�X�>�?�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�;?�?�D�N�?�T�]�T�[��M�M�O����h�'���{�{�&����t�{�{�4�0�1�����t�$�rc��y)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%)r�greetings  rr~zPOP3Client.serverGreetingKs�rc�D�tj|jd�}|�tjtd��S|�|j
�}|�tjtd��S|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 <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�
ITLSTransportrcr�failr�_getContextFactory�capabilities�addCallback�	_startTLS)r�contextFactory�tlsrEs    r�startTLSzPOP3Client.startTLSVs���*�&�&�t�~�~�t�<���;��:�:��/���
��!�!�4�4�6�N��!��:�:��2���
�
�����	�
�
�d�n�n�n�c�:��rc����jrJd��d|vrtjtd��S�j	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
            <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�$���j�S�N)r�)�_rs �r�<lambda>z&POP3Client._startTLS.<locals>.<lambda>�s���� 1� 1� 3�r)�
startedTLSrr�rrNr��_startedTLS)r�capsr�r�rEs`    rr�zPOP3Client._startTLS�s~���>���	C�B�	C���$���:�:�$�S���
�
�N�N�7�D�)��	�
�
�d�&�&���<�	�
�
�3�4��rc�f�||_|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
            <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)rcr��	_capCacher�)r�result�contextr�s    rr�zPOP3Client._startedTLS�s0��2���������(��������
rc��	ddlm}|j�}|jj|_|S#t$rYywxYw)a
        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)rr�r�s   rr�zPOP3Client._getContextFactory�sD��	�,��.�.�0�G� �W�W�3�3�G�N��N���	��	�s�5�	A�Ac�`�|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 <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�passwordrEs    r�loginzPOP3Client.login�s+��4
�����	�
�
�d�k�k�8�X�6��rc��|j�|j|||j�Sd|v}tj|jd�du}tj
|jd�du}|js5|r3|r1|r/|j�}|j|j||�|S|js|r|jr|j||�Stjt��S)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}�_apoprr�rc�
ISSLTransportr�r�r��	_loginTLS�allowInsecureLogin�
_plaintextrr�r)rr�r�r��tryTLS�tlsableTransport�nontlsTransportrEs        rr�zPOP3Client._logins���:���+��:�:�h��$�2F�2F�G�G��D���&�3�3�D�N�N�D�I�QU�U��%�2�2�4�>�>�4�H�D�P�����6�.>�?��
�
��A�
�M�M�$�.�.�(�H�=��H�
�_�_�O�t�7N�7N��?�?�8�X�6�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 <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    rr�zPOP3Client._loginTLS5s��0���x��2�2rc�N����j|�j��fd��S)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 <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�&���j��Sr�)r�)�rr�rs ��rr�z'POP3Client._plaintext.<locals>.<lambda>`s������x�9P�r)�userr�)rr�r�s` `rr�zPOP3Client._plaintextOs ���"�y�y��"�.�.�/P�Q�Qrc�|�t||z�j�jd�}|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 <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)rr�r��	challenge�digests     rr�zPOP3Client._apopbs8��&�Y��)�*�4�4�6�=�=�g�F���y�y��6�*�*rc�2�|jd|dz|z�S)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.
        sAPOPr6�rN)rr�r�s   rr�zPOP3Client.apopxs��,�~�~�g�x�$���'?�@�@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 <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.
        sUSERr�)rr�s  rr�zPOP3Client.user���� �~�~�g�x�0�0rc�&�|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 <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.
        sPASSr�)rr�s  rr�zPOP3Client.password�r�rc�4�|jdd|dzfz�S)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 <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.
        sDELE�%drr�)rr/s  r�deletezPOP3Client.delete�s ���~�~�g�u���	�|�';�<�<rc���|�=g�t��j}|j||||�j�fd��S|j||||�S)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����Sr�r%�r�rs �rr�z.POP3Client._consumeOrSetItem.<locals>.<lambda>�����ST�r)rr rVr��rrRrSrYrZrs     @r�_consumeOrSetItemzPOP3Client._consumeOrSetItem�sU���@���A�"�1�~�-�-�H��=�=��d�H�e�<�H�H��U�U��}�}�S�$��%�8�8rc���|�4g��j}|j||||�j�fd��S|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 <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����Sr�r%r�s �rr�z-POP3Client._consumeOrAppend.<locals>.<lambda>r�r)rBrVr�r�s     @r�_consumeOrAppendzPOP3Client._consumeOrAppend�sN���<���A��x�x�H��=�=��d�H�e�<�H�H��U�U��}�}�S�$��%�8�8rc�����|r+�j�tj�j�Si��fd�}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 <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���|j�}t|�dk(r	d�|d<yt|�dkDr|dd�|d<yy)Nrrr7)r*�tmp�caches  �r�consumez(POP3Client.capabilities.<locals>.consumeCsI����*�*�,�C��3�x�1�}� $��c�!�f�
��S��A�� #�A�B���c�!�f�
�rc�.�|jt�yr�)�trapr
)�errs r�capaNotSupportedz1POP3Client.capabilities.<locals>.capaNotSupportedJs���H�H�(�)�rc�����_�Sr�)r�)r�r�rs ��r�gotCapabilitiesz0POP3Client.capabilities.<locals>.gotCapabilitiesNs���"�D�N��LrsCAPA)r�r�succeedr��
addErrbackr�)r�useCacher�r�r�rEr�s`     @rr�zPOP3Client.capabilitiessn���`����2��=�=����0�0���	(�	�	�
�!�!�'�4��$�?��	���%�&�2�2�?�C��rc�&�|jdd�S)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.
        sNOOPNr�r_s r�noopzPOP3Client.noopV����~�~�g�t�,�,rc�&�|jdd�S)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.
        sRSETNr�r_s r�resetzPOP3Client.resetcs���~�~�g�t�,�,rc��d|dzfz}|�|jd||t�S|jdd||fz|t�S)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 <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�rsRETRsTOPs%b %d)r�r<)rr/rY�lines�idxs     r�retrievezPOP3Client.retrieveqsU��2�u�q�y�l�"���=��(�(��#�x��N�N��$�$��H��U�|�+�X�|�
�	
rc�L�|jdd�jt�S)aJ
        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.
        sSTATN)rNr�r-r_s r�statzPOP3Client.stat�s ���~�~�g�t�,�8�8��D�Drc�2�|jdd|t�S)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 <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.
        sLISTN)r�r1�rrYs  r�listSizezPOP3Client.listSize�s�� �%�%�g�t�X�z�J�Jrc�2�|jdd|t�S)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 <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.
        sUIDLN)r�r4r�s  r�listUIDzPOP3Client.listUID�s�� �%�%�g�t�X�y�I�Irc�&�|jdd�S)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.
        sQUITNr�r_s r�quitzPOP3Client.quit�r�rr�)T)NN)6r!r"r#r$r�r�r]r}r��re�compilerzr@rQrbrhrFrKrNrVr`rermrrrvr�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%rrr>r>�s��O�b�J����G��O��I�"��
�
�<�0���M��H��I��N��85�,�B-�`
 �(��<�"(��<;��.�2�@�+�Z,�\�>�$�<3B�j3�4R�&+�,A�01�$1�$=� $9�L"9�HF�P-�-�
�B
E�K�$J�$-rr>�__all__)#r$r��hashlibr�typingrr�rrr�twisted.mail._exceptrr	r
rr�twisted.protocolsr
r�twisted.pythonrry�ERRrr-r1r4r9r<�LineOnlyReceiver�TimeoutMixinr>r��str�__annotations__r%rr�<module>r
s����
���5�5���.����
��$�$�N(�%�$�&
� �*o-��'�'��)>�)>�o-�d!���c��r

Zerion Mini Shell 1.0