HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/twisted/mail/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/twisted/mail/__pycache__/pop3.cpython-312.pyc
�

Ϫ�fk����dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZmZddlmZdd	lmZmZmZdd
lmZmZddlmZmZddlmZe	ej@jB�Gd
�d��Z"Gd�d�Z#Gd�d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+e	ejX�Gd�dejZej\��Z/e	e�Gd�d��Z0e1d�\Z2Z3Z4Z5iZ6e2e6e2<e2e6e3<e5e6e4<e2e6e5<Gd�d ejZ�Z7dd!lm8Z8m9Z9m:Z:m;Z;m<Z<dd"l=m7Z>gd#�Z?y)$zQ
Post-office Protocol version 3.

@author: Glyph Lefkowitz
@author: Jp Calderone
�N)�md5)�Optional)�implementer)�cred)�defer�
interfaces�task)�smtp)�POP3ClientError�	POP3Error�_POP3MessageDeleted)�IMailboxPOP3�IServerFactoryPOP3)�basic�policies)�logc��eZdZdZd�Zd�Zy)�APOPCredentialsz�
    Credentials for use in APOP authentication.

    @ivar magic: See L{__init__}
    @ivar username: See L{__init__}
    @ivar digest: See L{__init__}
    c�.�||_||_||_y)a�
        @type magic: L{bytes}
        @param magic: The challenge string used to encrypt the password.

        @type username: L{bytes}
        @param username: The username associated with these credentials.

        @type digest: L{bytes}
        @param digest: An encrypted version of the user's password.  Should be
            generated as an MD5 hash of the challenge string concatenated with
            the plaintext password.
        N)�magic�username�digest)�selfrrrs    �3/usr/lib/python3/dist-packages/twisted/mail/pop3.py�__init__zAPOPCredentials.__init__-s����
� ��
����c�p�|j|z}t|�j�}||jk(S)a4
        Validate a plaintext password against the credentials.

        @type password: L{bytes}
        @param password: A plaintext password.

        @rtype: L{bool}
        @return: C{True} if the credentials represented by this object match
        the given password, C{False} if they do not.
        )rr�	hexdigestr)r�password�seed�myDigests    r�
checkPasswordzAPOPCredentials.checkPassword>s3���z�z�H�$���t�9�&�&�(���4�;�;�&�&rN)�__name__�
__module__�__qualname__�__doc__rr"�rrrr#s����"
'rrc��eZdZdZd�Zd�Zy)�_HeadersPlusNLinesa�
    A utility class to retrieve the header and some lines of the body of a mail
    message.

    @ivar _file: See L{__init__}
    @ivar _extraLines: See L{__init__}

    @type linecount: L{int}
    @ivar linecount: The number of full lines of the message body scanned.

    @type headers: L{bool}
    @ivar headers: An indication of which part of the message is being scanned.
        C{True} for the header and C{False} for the body.

    @type done: L{bool}
    @ivar done: A flag indicating when the desired part of the message has been
        scanned.

    @type buf: L{bytes}
    @ivar buf: The portion of the message body that has been scanned, up to
        C{n} lines.
    c�X�||_||_d|_d|_d|_d|_y)z�
        @type file: file-like object
        @param file: A file containing a mail message.

        @type extraLines: L{int}
        @param extraLines: The number of lines of the message body to retrieve.
        r�rN)�_file�_extraLines�	linecount�headers�done�buf)r�file�
extraLiness   rrz_HeadersPlusNLines.__init__fs/����
�%�����������	���rc��|jry|jj|�}|s|S|jrN|j	d�d}}|dk(r|j	d�d}}|dk7r ||z
}|d|}||d}d|_d	|_nd}|j
d	kDru|j|zjd
�}|d|_|ddD]C}|j
|jkDrd|_cS|d
zz
}|xj
dz
c_�ES|S)a
        Scan bytes from the file.

        @type bytes: L{int}
        @param bytes: The number of bytes to read from the file.

        @rtype: L{bytes}
        @return: Each portion of the header as it is scanned.  Then, full lines
            of the message body as they are scanned.  When more than one line
            of the header and/or body has been scanned, the result is the
            concatenation of the lines.  When the scan results in no full
            lines, the empty string is returned.
        rs

����s

�Nr+r�
)	r0r,�readr/�findr.r1�splitr-)r�bytes�data�df�sz�val�dsplit�lns        rr9z_HeadersPlusNLines.readus���9�9���z�z���u�%����K��<�<��Y�Y�{�+�Q��B��R�x����7�+�Q�B���R�x��b����3�B�i���B�C�y��!"��� ����C��>�>�A���h�h��o�,�,�U�3�F��b�z�D�H��S�b�k�
$���>�>�D�$4�$4�4� !�D�I��J��r�E�z�!�����!�#��
$��J��KrN)r#r$r%r&rr9r'rrr)r)Ns���.
�*rr)c�,�eZdZdZdZdd�Zd�Zd�ZeZy)�_IteratorBuffera�
    An iterator which buffers the elements of a container and periodically
    passes them as input to a writer.

    @ivar write: See L{__init__}.
    @ivar memoryBufferSize: See L{__init__}.

    @type bufSize: L{int}
    @ivar bufSize: The number of bytes currently in the buffer.

    @type lines: L{list} of L{bytes}
    @ivar lines: The buffer, which is a list of strings.

    @type iterator: iterator which yields L{bytes}
    @ivar iterator: An iterator over a container of strings.
    rNc�V�g|_||_t|�|_|�d}||_y)a�
        @type write: callable that takes L{list} of L{bytes}
        @param write: A writer which is a callable that takes a list of
            strings.

        @type iterable: iterable which yields L{bytes}
        @param iterable: An iterable container of strings.

        @type memoryBufferSize: L{int} or L{None}
        @param memoryBufferSize: The number of bytes to buffer before flushing
            the buffer to the writer.
        Ni)�lines�write�iter�iterator�memoryBufferSize)rrG�iterablerJs    rrz_IteratorBuffer.__init__�s1����
���
��X���
��#�$�� 0��rc��|S)z�
        Return an iterator.

        @rtype: iterator which yields L{bytes}
        @return: An iterator over strings.
        r'�rs r�__iter__z_IteratorBuffer.__iter__�s	���rc��	t|j�}|�}|jj|�|xjt|�z
c_|j|jkDr*|j|j�g|_d|_yyy#t$r/|jr|j|j�|`|`|`�wxYw)a\
        Get the next string from the container, buffer it, and possibly send
        the buffer to the writer.

        The contents of the buffer are written when it is full or when no
        further values are available from the container.

        @raise StopIteration: When no further values are available from the
        container.
        Nr)	�nextrIrF�append�bufSize�lenrJrG�
StopIteration)r�vs  r�__next__z_IteratorBuffer.__next__�s���	%��T�]�]�#�A��}��
�
�!�!�!�$�����A��&���<�<�$�"7�"7�7��J�J�t�z�z�*�!#�D�J�#$�D�L�8����	��z�z��
�
�4�:�:�&��
�t�z�4�:��	�s�B�8C�N)	r#r$r%r&rRrrNrVrPr'rrrDrD�s$���"�G�1�(�%�8�DrrDc�d�t|jj|�}|j|�S)a}
    Direct the output of an iterator to the transport of a protocol and arrange
    for iteration to take place.

    @type proto: L{POP3}
    @param proto: A POP3 server protocol.

    @type gen: iterator which yields L{bytes}
    @param gen: An iterator over strings.

    @rtype: L{Deferred <defer.Deferred>}
    @return: A deferred which fires when the iterator finishes.
    )rD�	transport�
writeSequence�schedule)�proto�gen�colls   r�iterateLineGeneratorr_�s)���5�?�?�8�8�#�>�D��>�>�$��rc�f�t|t�st|�jd�}d|zdzS)z�
    Format an object as a positive response.

    @type response: stringifyable L{object}
    @param response: An object with a string representation.

    @rtype: L{bytes}
    @return: A positive POP3 response string.
    �utf-8s+OK �
)�
isinstancer<�str�encode)�responses r�successResponsergs2���h��&��x�=�'�'��0���X���'�'rc#�bK�d}d}|D]}|dz
}||z
}d���td||fz���y�w)a�
    Format a list of message sizes into a STAT response.

    This generator function is intended to be used with
    L{Cooperator <twisted.internet.task.Cooperator>}.

    @type msgs: L{list} of L{int}
    @param msgs: A list of message sizes.

    @rtype: L{None} or L{bytes}
    @return: Yields none until a result is available, then a string that is
        suitable for use in a STAT response. The string consists of the number
        of messages and the total size of the messages in octets.
    rr+N�%d %d�rg)�msgs�ir<�sizes    r�formatStatResponsernsN����	
�A�
�E����	�Q���
��
���
���(�a��Z�/�
0�0�s�-/c#�:K�d}|D]}|dz
}d||fz���y�w)a_
    Format a list of message sizes for use in a LIST response.

    @type msgs: L{list} of L{int}
    @param msgs: A list of message sizes.

    @rtype: L{bytes}
    @return: Yields a series of strings that are suitable for use as scan
        listings in a LIST response. Each string consists of a message number
        and its size in octets.
    rr+s%d %d
Nr')rkrlrms   r�formatListLinesrp+s4����	
�A��'��	�Q����a��Y�&�&�'�s�c#�rK�tdt|�fz���t|�Ed{���d��y7�	�w)ai
    Format a list of message sizes into a complete LIST response.

    This generator function is intended to be used with
    L{Cooperator <twisted.internet.task.Cooperator>}.

    @type msgs: L{list} of L{int}
    @param msgs: A list of message sizes.

    @rtype: L{bytes}
    @return: Yields a series of strings which make up a complete LIST response.
    s%dN�.
)rgrSrp)rks r�formatListResponsers=s6�����%�3�t�9�,�.�
/�/��t�$�$�$�
�N�%�s�)7�5�
7c#�K�t|�D]F\}}|��	||�}t|t�st|�j	d�}d|dz|fz���Hy�w)ar
    Format a list of message sizes for use in a UIDL response.

    @param msgs: See L{formatUIDListResponse}
    @param getUidl: See L{formatUIDListResponse}

    @rtype: L{bytes}
    @return: Yields a series of strings that are suitable for use as unique-id
        listings in a UIDL response. Each string consists of a message number
        and its unique id.
    Nras%d %b
r+)�	enumeratercr<rdre)rk�getUidlrl�m�uids     r�formatUIDListLinesryOs\�����$��.���1��=��!�*�C��c�5�)��#�h�o�o�g�.���!�a�%���-�-�.�s�A�AAc#�ZK�td���t||�Ed{���d��y7�	�w)a.
    Format a list of message sizes into a complete UIDL response.

    This generator function is intended to be used with
    L{Cooperator <twisted.internet.task.Cooperator>}.

    @type msgs: L{list} of L{int}
    @param msgs: A list of message sizes.

    @type getUidl: one-argument callable returning bytes
    @param getUidl: A callable which takes a message index number and returns
        the UID of the corresponding message in the mailbox.

    @rtype: L{bytes}
    @return: Yields a series of strings which make up a complete UIDL response.
    �Nrr)rgry)rkrvs  r�formatUIDListResponser|cs-����"�"�
��!�$��0�0�0�
�N�1�s�+�)�
+c�j�eZdZUdZdZeeed<dZdZ	gd�Z
dZdZdZ
dZdZdZeej&�ZdZd�Zd	�Zd
�Zd/d�Zd0d�Zd
�Zd�Zd�Zd�Zd�Zd�Z d1d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d1d�Z,d1d�Z-d �Z.d!�Z/d"�Z0d#�Z1d$�Z2d%�Z3d&�Z4d'�Z5d(�Z6d)�Z7d*�Z8d+�Z9d,�Z:d-�Z;d.�Z<y)2�POP3a�
    A POP3 server protocol.

    @type portal: L{Portal}
    @ivar portal: A portal for authentication.

    @type factory: L{IServerFactory} provider
    @ivar factory: A server factory which provides an interface for querying
        capabilities of the server.

    @type timeOut: L{int}
    @ivar timeOut: The number of seconds to wait for a command from the client
        before disconnecting.

    @type schedule: callable that takes interator and returns
        L{Deferred <defer.Deferred>}
    @ivar schedule: A callable that arranges for an iterator to be
        cooperatively iterated over along with all other iterators which have
        been passed to it such that runtime is divided between all of them.  It
        returns a deferred which fires when the iterator finishes.

    @type magic: L{bytes} or L{None}
    @ivar magic: An APOP challenge.  If not set, an APOP challenge string
        will be generated when a connection is made.

    @type _userIs: L{bytes} or L{None}
    @ivar _userIs: The username sent with the USER command.

    @type _onLogout: no-argument callable or L{None}
    @ivar _onLogout: The function to be executed when the connection is
        lost.

    @type mbox: L{IMailbox} provider
    @ivar mbox: The mailbox for the authenticated user.

    @type state: L{bytes}
    @ivar state: The state which indicates what type of messages are expected
        from the client.  Valid states are 'COMMAND' and 'AUTH'

    @type blocked: L{None} or L{list} of 2-L{tuple} of
        (E{1}) L{bytes} (E{2}) L{tuple} of L{bytes}
    @ivar blocked: A list of blocked commands.  While a response to a command
        is being generated by the server, other commands are blocked.  When
        no command is outstanding, C{blocked} is set to none.  Otherwise, it
        contains a list of information about blocked commands.  Each list
        entry consists of the command and the arguments to the command.

    @type _highest: L{int}
    @ivar _highest: The 1-based index of the highest message retrieved.

    @type _auth: L{IUsernameHashedPassword
        <cred.credentials.IUsernameHashedPassword>} provider
    @ivar _auth: Authorization credentials.
    Nr)sCAPA�USER�PASS�APOPsAUTHsRPOP�QUITi,�COMMANDrc�T�|j�|j�|_|j|j�|j|j�t|jdd�r:tjdt|jj��z�yy)zS
        Send a greeting to the client after the connection has been made.
        N�noisyTzNew connection from )r�
generateMagicrg�
setTimeout�timeOut�getattr�factoryr�msgrdrY�getPeerrMs r�connectionMadezPOP3.connectionMade�sy���:�:���+�+�-�D�J����T�Z�Z�(�������%��4�<�<��$�/��G�G�*�S����1G�1G�1I�-J�J�K�0rc�l�|j�|j�d|_|jd�y)z�
        Clean up when the connection has been lost.

        @type reason: L{Failure}
        @param reason: The reason the connection was terminated.
        N)�	_onLogoutr�)r�reasons  r�connectionLostzPOP3.connectionLost�s+���>�>�%��N�N��!�D�N�����rc�*�tj�S)z}
        Generate an APOP challenge.

        @rtype: L{bytes}
        @return: An RFC 822 message id format string.
        )r
�	messageidrMs rr�zPOP3.generateMagic�s���~�~��rc�L�|jjt|��y)z�
        Send a response indicating success.

        @type message: stringifyable L{object}
        @param message: An object whose string representation should be
            included in the response.
        N)rYrGrg�r�messages  rrgzPOP3.successResponse�s��	
�����_�W�5�6rc��t|t�st|�jd�}|j	d|z�y)z�
        Send a response indicating failure.

        @type message: stringifyable L{object}
        @param message: An object whose string representation should be
            included in the response.
        ras-ERR N)rcr<rdre�sendLiner�s  r�failResponsezPOP3.failResponse�s3���'�5�)��'�l�)�)�'�2�G��
�
�h��(�)rc�b�|j�t|d|jz�|�y)z�
        Pass a received line to a state machine function.

        @type line: L{bytes}
        @param line: A received line.
        �state_N)�resetTimeoutr��state�r�lines  r�lineReceivedzPOP3.lineReceiveds*��	
����,���h����+�,�T�2rc��|j}d|_|rB|j�6|jd�\}}|j|g|���|r
|j��6|j�|jj|�yy)z�
        Process as many blocked commands as possible.

        If there are no more blocked commands, set up for the next command to
        be sent immediately.

        @type _: L{object}
        @param _: Ignored.
        Nr)�blocked�pop�processCommand�extend)r�_�commands�cmd�argss     r�_unblockz
POP3._unblocksw���<�<������4�<�<�/� ���Q��I�C���D����+�d�+��4�<�<�/��<�<�#��L�L����)�$rc
�r�	|j|jd��S#tttt
f$r}}t
j�|jdjd|jjjd�dj|j�g��Yd}~yd}~wwxYw)z�
        Handle received lines for the COMMAND state in which commands from the
        client are expected.

        @type line: L{bytes}
        @param line: A received command.
        � s: sbad protocol or serverrarN)r�r;�
ValueError�AttributeErrorr�	TypeErrorr�errr��join�	__class__r#rer�)rr��es   r�
state_COMMANDzPOP3.state_COMMANDs���	�&�4�&�&��
�
�4�(8�9�9���N�I�y�A�
	��G�G�I�����
�
�1����,�,�3�3�G�<�������(���
�
��
	�s� �B6�A3B1�1B6c�2�|j�|jj||f�y|j�}||jv}|js|std|z��t
|d|jd�zd�}|r||�Std|z��)aq
        Dispatch a command from the client for handling.

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

        @type args: L{tuple} of L{bytes}
        @param args: Arguments to the command.

        @raise POP3Error: When the command is invalid or the command requires
            prior authentication which hasn't been performed.
        Ns!not authenticated yet: cannot do �do_rasUnknown protocol command: )r�rQ�upper�	AUTH_CMDS�mboxrr��decode)r�commandr��authCmd�fs     rr�zPOP3.processCommand4s����<�<�#��L�L����$��0���-�-�/���T�^�^�+���y�y���@�7�J�K�K��D�%�'�.�.��"9�9�4�@����d�8�O��5��?�@�@rc���gd�}tj|j��r	|jj�}|r*t	|t
�st
|�jd�}|jd|z�	|jj�}|r*t	|t
�st
|�jd�}|�d}|jj�r@|jr/t
|jj �jd�}n|dz}|jd|z�	|jj#�}|r*t	|t
�st
|�jd�}|jj%�r@|jr/t
|jj&�jd�}n|dz}|jd|z�	|jj(}|jdd	j+|j-��z�|S|S#t$rY���t$rtj�Y���wxYw#t$rY��<t$rtj�Y��[wxYw#t$rY��t$rtj�Y��wxYw#t.$rY|St$rtj�Y|SwxYw)
z�
        Return a list of server capabilities suitable for use in a CAPA
        response.

        @rtype: L{list} of L{bytes}
        @return: A list of server capabilities.
        )sTOPr�UIDLsPIPELINEsCELERITYsAUSPEXsPOTENCErasIMPLEMENTATION sNEVERs USERsEXPIRE sLOGIN-DELAY sSASL r�)�IServerFactory�
providedByr��cap_IMPLEMENTATIONrcr<rdrerQ�NotImplementedError�
BaseExceptionrr��
cap_EXPIRE�perUserExpirationr��messageExpiration�cap_LOGIN_DELAY�perUserLoginDelay�
loginDelay�challengersr��keysr�)r�baseCapsrUs   r�listCapabilitieszPOP3.listCapabilitiesNs_��
���$�$�T�\�\�2�	
8��L�L�3�3�5���Z��5�1��A��
�
�g�.�A���� 2�Q� 6�7�
0��L�L�+�+�-���Z��5�1��A��
�
�g�.�A��9� �A��<�<�1�1�3��y�y���	�	� ;� ;�<�C�C�G�L����L�����
�Q��/�
5��L�L�0�0�2���Z��5�1��A��
�
�g�.�A��<�<�1�1�3��y�y���	�	� 4� 4�5�<�<�W�E����L������!� 3�4�
@��L�L�,�,������4�9�9�Q�V�V�X�+>� >�?���x���c'�
�� �
����	�
��'�
�� �
����	�
�� '�
�� �
����	�
��"�
��
��	!�
����	���	
�sb�AH:�AI)�:AJ�/K�:	I&�I&�%I&�)	J�5J�J�	K�#K�K�	K1�K1�0K1c��|jd�|j�D]}|j|��|jd�y)zW
        Handle a CAPA command.

        Respond with the server capabilities.
        sI can do the following:�.N)rgr�r�)r�caps  r�do_CAPAzPOP3.do_CAPA�sC��	
���7�8��(�(�*�	�C��M�M�#��	��
�
�d�rc�~�t|jdd�s|jd�y|�]|jd�|jjD]!}|j|j
���#|jd�y|jjj|j�j
��}|jr|s|jd�y|�|_
|jj�}|jdtj|�z�d|_y)	a�
        Handle an AUTH command.

        If the AUTH extension is not supported, send an error response.  If an
        authentication mechanism was not specified in the command, send a list
        of all supported authentication methods.  Otherwise, send an
        authentication challenge to the client and transition to the
        AUTH state.

        @type args: L{bytes} or L{None}
        @param args: The name of an authentication mechanism.
        r�NsAUTH extension unsupportedz!Supported authentication methods:r�sUnsupported SASL selecteds+ �AUTH)r�r�r�rgr�r�r��get�strip�portal�_auth�getChallenge�base64�	b64encoder�)rr��a�auth�chals     r�do_AUTHzPOP3.do_AUTH�s����t�|�|�]�D�9����;�<���<�� � �!D�E��\�\�-�-�
)���
�
�a�g�g�i�(�
)��M�M�$����|�|�'�'�+�+�D�J�J�L�,>�,>�,@�A���{�{�$����:�;���V��
��z�z�&�&�(���
�
�e�f�.�.�t�4�4�5���
rc�B�d|_	tj|�jdd�}t	|�dk7r|jd�y|d|j_|d|j_|jj|jdt�}|j|j|d�|j|j�|j|j �y#t"j$$r|jd�YywxYw)a�
        Handle received lines for the AUTH state in which an authentication
        challenge response from the client is expected.

        Transition back to the COMMAND state.  Check the credentials and
        complete the authorization process with the L{_cbMailbox}
        callback function on success or the L{_ebMailbox} and L{_ebUnexpected}
        errback functions on failure.

        @type line: L{bytes}
        @param line: The challenge response.
        r�Nr+r7sInvalid AUTH responsersInvalid BASE64 encoding)r�r��	b64decoder;rSr�r�rrfr��login�IMailbox�addCallback�
_cbMailbox�
addErrback�
_ebMailbox�
_ebUnexpected�binascii�Error)rr��parts�ds    r�
state_AUTHzPOP3.state_AUTH�s�����
�
	-��$�$�T�*�0�0��q�9�E��5�z�Q���!�!�":�;��"'��(�D�J�J��"'��(�D�J�J�����!�!�$�*�*�d�H�=�A�
�M�M�$�/�/�5��8�4�
�L�L����)�
�L�L��+�+�,���~�~�	:����8�9�	:�s�%C7�7$D�Dc���tj|j||�}|j|j|j
|f��j
|j�y)a�
        Handle an APOP command.

        Perform APOP authentication and complete the authorization process with
        the L{_cbMailbox} callback function on success or the L{_ebMailbox}
        and L{_ebUnexpected} errback functions on failure.

        @type user: L{bytes}
        @param user: A username.

        @type digest: L{bytes}
        @param digest: An MD5 digest string.
        ��callbackArgsN)r�
maybeDeferred�authenticateUserAPOP�addCallbacksr�r�r�r�)r�userrr�s    r�do_APOPzPOP3.do_APOP�sP��
���� 9� 9�4��H��	����O�O�T�_�_�D�7�	�	
�
�*�T�'�'�
(rc��|\}}}|tur'|jd�tjd�y||_||_|j
d�t|jdd�rtjd|z�yy)a�
        Complete successful authentication.

        Save the mailbox and logout function for the authenticated user and
        send a successful response to the client.

        @type result: C{tuple}
        @param result: The first item of the tuple is a
            C{zope.interface.Interface} which is the interface
            supported by the avatar.  The second item of the tuple is a
            L{IMailbox} provider which is the mailbox for the
            authenticated user.  The third item of the tuple is a no-argument
            callable which is a function to be invoked when the session is
            terminated.

        @type user: L{bytes}
        @param user: The user being authenticated.
        �Authentication failedz9_cbMailbox() called with an interface other than IMailboxNzAuthentication succeededr�TsAuthenticated login for )
r�r�rr�r�r�rgr�r�r�)r�resultr��	interface�avatar�logouts      rr�zPOP3._cbMailbox�s{��&'-�#��F�F��H�$����6�7��G�G�O�P����	�������7�8��4�<�<��$�/��G�G�/�$�6�7�0rc��|jtjjtjj�}t|tjj�r|j
dt|�z�n5t|tjj�r|j
d�t|jdd�r:tjdt|jj��z�yy)a
        Handle an expected authentication failure.

        Send an appropriate error response for a L{LoginDenied} or
        L{LoginFailed} authentication failure.

        @type failure: L{Failure}
        @param failure: The authentication error.
        zAccess denied: r�r�TzDenied login attempt from N)�trapr�error�LoginDenied�LoginFailed�
issubclassr�rdr�r�rr�rYr��r�failures  rr�zPOP3._ebMailboxs����,�,�t�z�z�5�5�t�z�z�7M�7M�N���g�t�z�z�5�5�6����/�#�g�,�>�?�
�����!7�!7�
8����6�7��4�<�<��$�/��G�G�0�3�t�~�~�7M�7M�7O�3P�P�Q�0rc�r�|jd|j�z�tj|�y)z�
        Handle an unexpected authentication failure.

        Send an error response for an unexpected authentication failure.

        @type failure: L{Failure}
        @param failure: The authentication error.
        zServer error: N)r��getErrorMessagerr�rs  rr�zPOP3._ebUnexpected)s-��	
���*�W�-D�-D�-F�F�G�����rc�4�||_|jd�y)z�
        Handle a USER command.

        Save the username and send a successful response prompting the client
        for the password.

        @type user: L{bytes}
        @param user: A username.
        sUSER accepted, send PASSN)�_userIsrg�rr�s  r�do_USERzPOP3.do_USER5s��������8�9rc�V�|j�|jd�y|j}d|_dj|f|z�}tj|j
||�}|j
|j|j|f��j|j�y)a2
        Handle a PASS command.

        If a USER command was previously received, authenticate the user and
        complete the authorization process with the L{_cbMailbox} callback
        function on success or the L{_ebMailbox} and L{_ebUnexpected} errback
        functions on failure.  If a USER command was not previously received,
        send an error response.

        @type password: L{bytes}
        @param password: A password.

        @type words: L{tuple} of L{bytes}
        @param words: Other parts of the password split by spaces.
        NsUSER required before PASSr�r�)rr�r�rr��authenticateUserPASSr�r�r�r�r�)rr�wordsr�r�s     r�do_PASSzPOP3.do_PASSBs��� �<�<�����:�;���|�|������9�9�h�[�5�0�1������ 9� 9�4��J��	����O�O�T�_�_�D�7�	�	
�
�*�T�'�'�
(rc�����j��jd�g�_|j�j�|j��fd��|S)a�
        Stop timeouts and block further command processing while a long
        operation completes.

        @type d: L{Deferred <defer.Deferred>}
        @param d: A deferred which triggers at the completion of a long
            operation.

        @rtype: L{Deferred <defer.Deferred>}
        @return: A deferred which triggers after command processing resumes and
            timeouts restart after the completion of a long operation.
        Nc�&���j��SrW)r�)�ignrr�s ��r�<lambda>z%POP3._longOperation.<locals>.<lambda>ns���$�/�/�'�":�r)r�r�r�r�r�)rr�r�s` @r�_longOperationzPOP3._longOperation]sC����,�,����������	�
�
�d�m�m�$�	�
�
�:�;��rc�`�|jt|jj|��S)aG
        Direct the output of an iterator to the transport and arrange for
        iteration to take place.

        @type gen: iterable which yields L{bytes}
        @param gen: An iterator over strings.

        @rtype: L{Deferred <defer.Deferred>}
        @return: A deferred which fires when the iterator finishes.
        )r[rDrYrZ)rr]s  r�
_coiteratezPOP3._coiterateqs$���}�}�_�T�^�^�-I�-I�3�O�P�Prc���tj�jj�}�fd�}�fd�}�j	|j||��S)z�
        Handle a STAT command.

        @rtype: L{Deferred <defer.Deferred>}
        @return: A deferred which triggers after the response to the STAT
            command has been issued.
        c�8���jt|��SrW)rrn�rkrs �r�
cbMessagesz POP3.do_STAT.<locals>.cbMessages�s����?�?�#5�d�#;�<�<rc����j|j��tjd�tj|�y)NzUnexpected do_STAT failure:�r�rrr�r��r�rs �r�
ebMessagesz POP3.do_STAT.<locals>.ebMessages�s2������c�1�1�3�4��G�G�1�2��G�G�C�Lr)rr�r��listMessagesrr�)rr�rrs`   r�do_STATzPOP3.do_STAT~sG���
����	�	� 6� 6�7��	=�	�
�"�"�1�>�>�*�j�#I�J�Jrc�<�����Ttj�jj�}�fd�}�fd�}�j	|j||��S	t
����dkr
t��	tj�jj�dz
�}��fd�}��fd�}|j||��j	|�S#t$rAt�t�st��jd���jd�z�YywxYw)	a
        Handle a LIST command.

        @type i: L{bytes} or L{None}
        @param i: A 1-based message index.

        @rtype: L{Deferred <defer.Deferred>}
        @return: A deferred which triggers after the response to the LIST
            command has been issued.
        Nc�8���jt|��SrW)rrsrs �rrz POP3.do_LIST.<locals>.cbMessages�s������'9�$�'?�@�@rc����j|j��tjd�tj|�y)N�Unexpected do_LIST failure:rrs �rrz POP3.do_LIST.<locals>.ebMessages��2����!�!�#�"5�"5�"7�8����5�6�����rr+c�2���jd�|fz�y)Nrirj)r�rlrs ��r�	cbMessagezPOP3.do_LIST.<locals>.cbMessage�s����(�(��Q��H�)<�=rc���|jtt�}|�e|turtjdt
��}|r*t
|t�st|�jd�}�jd|z�y�j|j��tjd�tj|�y)N�}twisted.mail.pop3.IMailbox.listMessages may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.ra�Invalid message-number: r")�checkr��
IndexError�warnings�warn�PendingDeprecationWarningrcr<rdrer�rrr�r�)r��errcls�
invalidNumrlrs   ��r�	ebMessagezPOP3.do_LIST.<locals>.ebMessage�s���� �Y�Y�z�:�>�F��)�!�Z�/�%�M�M�!M�!:�	�&'�
�%�j��U�.K�),�Z��)?�)?��)H�J��)�)�*E�
�*R�S��)�)�#�*=�*=�*?�@���� =�>�����rrar()
rr�r�rrr��intr�rcr<rdrer�)rrlr�rrr%r0s``     r�do_LISTzPOP3.do_LIST�s���
�9��#�#�D�I�I�$:�$:�;�A�
A�
�
�&�&�q�~�~�j�*�'M�N�N�%
.���F���q�5�$�,�&���'�'��	�	�(>�(>��A��F��>�%�,���y�)�4��*�*�1�-�-��C�
C�!�!�U�+��A��
�
�g�.�A��!�!�"=��"A�B�
C�s�C�AD�Dc���|�Ttj�jj�}�fd�}�fd�}�j	|j||��S	t
|�}|dkr
t��		�jj|dz
�}t|t�st|�jd�}�j|�y#t$r.tj dt"��j%d�Yyt$r�j%d�YywxYw#t$r�j%d�YywxYw)a
        Handle a UIDL command.

        @type i: L{bytes} or L{None}
        @param i: A 1-based message index.

        @rtype: L{Deferred <defer.Deferred>}
        @return: A deferred which triggers after the response to the UIDL
            command has been issued.
        Nc�b���jt|�jj��SrW)rr|r�rvrs �rrz POP3.do_UIDL.<locals>.cbMessages�s(������)�$��	�	�0A�0A�B��rc����j|j��tjd�tj|�y)NzUnexpected do_UIDL failure:rrs �rrz POP3.do_UIDL.<locals>.ebMessages�r#rr+razxtwisted.mail.pop3.IMailbox.getUidl may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.�Bad message number argument)rr�r�rrr�r1r�rvrcr<rdrergr*r+r,r-r�)rrlr�rrr�s`     r�do_UIDLzPOP3.do_UIDL�s*���
�9��#�#�D�I�I�$:�$:�;�A�
�

�
�&�&�q�~�~�j�*�'M�N�N�
.���F���q�5�$�,�&��
.��)�)�+�+�A��E�2�C�&�c�5�1�!�#�h�o�o�g�6���(�(��-��"�E��M�M�4�2�	��%�%�&C�D�!�E��%�%�&C�D�E���
A��!�!�"?�@�
A�s*�D$�5C�4D!�D!� D!�$E�Ec�`���	t|�dz
��dkr
t��	tj
�jj��}��fd�}�fd�}|j|�|j|�|S#t$r)�jd�tjd�cYSwxYw)a�
        Retrieve the size and contents of a message.

        @type i: L{bytes}
        @param i: A 1-based message index.

        @rtype: L{Deferred <defer.Deferred>} which successfully fires with
            2-L{tuple} of (E{1}) L{int}, (E{2}) file-like object
        @return: A deferred which successfully fires with the size of the
            message and a file containing the contents of the message.
        r+rr6Nc������stjt��Stj�jj
��}|j
�fd��|S)Nc����|fSrWr')�fObjrms �rrz=POP3._getMessageFile.<locals>.cbMessageSize.<locals>.<lambda>s���4��,�r)r�failr
r�r��
getMessager�)rm�fileDeferredr�rs` ��r�
cbMessageSizez+POP3._getMessageFile.<locals>.cbMessageSizesJ�����z�z�"5�"7�8�8� �.�.�t�y�y�/C�/C�S�I�L��$�$�%>�?��rc�P��|jttt�}|tur�j	d�y|ttfvr4|turtjdt��j	d�ytjd�tj|�y)Nzmessage deletedr'r6z#Unexpected _getMessageFile failure:)r)r
r�r*r�r+r,r-rr�r�)r�r.rs  �r�ebMessageSomethingz0POP3._getMessageFile.<locals>.ebMessageSomething!s�����Y�Y�2�J�
�K�F��,�,��!�!�"3�4���J�
�3�3��Z�'��M�M�4�2�	��!�!�"?�@�����=�>������r)
r1r�r�r�succeedr�r�rr�r�)rrl�sizeDeferredr?rAr�s`    @r�_getMessageFilezPOP3._getMessageFiles����	'��a�&�1�*�C��Q�w� �l�"���*�*�4�9�9�+A�+A�3�G��	 �	�&	� � ��/���� 2�3����E�	'����;�<��=�=��&�&�	'�s�A;�;/B-�,B-c�|������j��}����fd�}�j|j|��S)a�
        Send the contents of a message.

        @type i: L{bytes}
        @param i: A 1-based message index.

        @type fpWrapper: callable that takes a file-like object and returns
            a file-like object
        @param fpWrapper:

        @type successResponse: callable that takes L{int} and returns
            L{bytes}
        @param successResponse:

        @rtype: L{Deferred}
        @return: A deferred which triggers after the message has been sent.
        c�l��|�yt�	jt����	_|\}}�|�}�	j�
|��t	j
�}|j
|�	j�	j�}�	fd�}�	fd�}|j|�|j|�|S)Nc�<��|dk7rd}nd}�j|�y)Nr8�
.r��r�)�lastsentr�rs  �r�cbFileTransferzGPOP3._sendMessageContent.<locals>.cbMessageFile.<locals>.cbFileTransferYs!����u�$�#�D��D��
�
�d�#rc����jj�tjd�tj|�y)Nz(Unexpected error in _sendMessageContent:)rY�loseConnectionrr�r�rs �r�ebFileTransferzGPOP3._sendMessageContent.<locals>.cbMessageFile.<locals>.ebFileTransfer`s+������-�-�/����B�C�����r)�max�_highestr1rgr�
FileSender�beginFileTransferrY�transformChunkr�r�)�info�resp�fp�sr�rKrN�	fpWrapperrlrrgs       ����r�
cbMessageFilez/POP3._sendMessageContent.<locals>.cbMessageFileLs�����|����
�
�s�1�v�6�D�M��H�D�"��2��B�� � ���!6�7�� � �"�A��#�#�B�����8K�8K�L�A�
$�
�

�M�M�.�)�
�L�L��(��Hr)rDrr�)rrlrXrgr�rYs````  r�_sendMessageContentzPOP3._sendMessageContent8s6���$
� � ��#��	�:�"�"�1�=�=��#?�@�@rc���	t����dkrt�	|j|�fd�d��S#t$r|jd�YywxYw)a[
        Handle a TOP command.

        @type i: L{bytes}
        @param i: A 1-based message index.

        @type size: L{bytes}
        @param size: The number of lines of the message to retrieve.

        @rtype: L{Deferred}
        @return: A deferred which triggers after the response to the TOP
            command has been issued.
        rc���t|��SrW)r))rVrms �rrzPOP3.do_TOP.<locals>.<lambda>�s���-�b�$�7�rc��y)NzTop of message followsr'�rms rrzPOP3.do_TOP.<locals>.<lambda>�s�rzBad line count argumentN)r1r�rZr�)rrlrms  `r�do_TOPzPOP3.do_TOPksa���	��t�9�D��a�x� � ��
�+�+��7�5��
���	9����7�8�	9�s�1�A�
Ac�,�|j|d�d��S)z�
        Handle a RETR command.

        @type i: L{bytes}
        @param i: A 1-based message index.

        @rtype: L{Deferred}
        @return: A deferred which triggers after the response to the RETR
            command has been issued.
        c��|SrWr')rVs rrzPOP3.do_RETR.<locals>.<lambda>�s��b�rc��d|fzS)Nz%dr'r^s rrzPOP3.do_RETR.<locals>.<lambda>�s��t�t�g�~�r)rZ�rrls  r�do_RETRzPOP3.do_RETR�s���'�'��=�:U�V�Vrc�F�|jdd�jdd�S)a�
        Transform a chunk of a message to POP3 message format.

        Make sure each line ends with C{'\r\n'} and byte-stuff the
        termination character (C{'.'}) by adding an extra one when one appears
        at the beginning of a line.

        @type chunk: L{bytes}
        @param chunk: A string to transform.

        @rtype: L{bytes}
        @return: The transformed string.
        r8rbrHs
..)�replace)r�chunks  rrSzPOP3.transformChunk�s"���}�}�U�G�,�4�4�X�y�I�Irc�:�|dk7rd}nd}|j|�y)z�
        Send the termination sequence.

        @type lastsent: L{bytes}
        @param lastsent: The last character of the file.
        r8rHr�NrI)rrJr�s   r�finishedFileTransferzPOP3.finishedFileTransfer�s"���u���D��D��
�
�d�rc�v�t|�dz
}|jj|�|j�y)z�
        Handle a DELE command.

        Mark a message for deletion and issue a successful response.

        @type i: L{int}
        @param i: A 1-based message index.
        r+N)r1r��
deleteMessagergrcs  r�do_DELEzPOP3.do_DELE�s/��
��F�Q�J���	�	����"����rc�$�|j�y)z]
        Handle a NOOP command.

        Do nothing but issue a successful response.
        NrjrMs r�do_NOOPzPOP3.do_NOOP�s��	
���rc���	|jj�d|_|j�y#t$r'tj�|j�YywxYw)zj
        Handle a RSET command.

        Unmark any messages that have been flagged for deletion.
        rN)r��undeleteMessagesrPrgr�rr�r�rMs r�do_RSETzPOP3.do_RSET�sR��	#��I�I�&�&�(�
�D�M�� � �"���	 ��G�G�I�����	 �s�4�-A$�#A$c�:�|j|j�y)zr
        Handle a LAST command.

        Respond with the 1-based index of the highest retrieved message.
        N)rgrPrMs r�do_LASTzPOP3.do_LAST�s��	
���T�]�]�+rc�&�|jd�y)z�
        Handle an RPOP command.

        RPOP is not supported.  Send an error response.

        @type user: L{bytes}
        @param user: A username.

        zpermission denied, suckerN)r�rs  r�do_RPOPzPOP3.do_RPOP�s��	
���5�6rc��|jr|jj�|j�|jj	�y)z�
        Handle a QUIT command.

        Remove any messages marked for deletion, issue a successful response,
        and drop the connection.
        N)r��syncrgrYrMrMs r�do_QUITzPOP3.do_QUIT�s5���9�9��I�I�N�N���������%�%�'rc���|j�6|jjt|j||�dt�St
jj��)ax
        Perform APOP authentication.

        @type user: L{bytes}
        @param user: The name of the user attempting to log in.

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

        @rtype: L{Deferred <defer.Deferred>} which successfully results in
            3-L{tuple} of (E{1}) L{IMailbox <pop3.IMailbox>}, (E{2})
            L{IMailbox <pop3.IMailbox>} provider, (E{3}) no-argument callable
        @return: A deferred which fires when authentication is complete.  If
            successful, it returns an L{IMailbox <pop3.IMailbox>} interface, a
            mailbox, and a function to be invoked with the session is
            terminated.  If authentication fails, the deferred fails with an
            L{UnathorizedLogin <cred.error.UnauthorizedLogin>} error.

        @raise cred.error.UnauthorizedLogin: When authentication fails.
        N)r�r�rrr�rr��UnauthorizedLogin�rr�rs   rr�zPOP3.authenticateUserAPOP�sN��*�;�;�"��;�;�$�$���
�
�D�&�9�4���
��j�j�*�*�,�,rc���|j�?|jjtjj	||�dt
�Stjj��)a�
        Perform authentication for a username/password login.

        @type user: L{bytes}
        @param user: The name of the user attempting to log in.

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

        @rtype: L{Deferred <defer.Deferred>} which successfully results in
            3-L{tuple} of (E{1}) L{IMailbox <pop3.IMailbox>}, (E{2}) L{IMailbox
            <pop3.IMailbox>} provider, (E{3}) no-argument callable
        @return: A deferred which fires when authentication is complete.  If
            successful, it returns a L{pop3.IMailbox} interface, a mailbox,
            and a function to be invoked with the session is terminated.
            If authentication fails, the deferred fails with an
            L{UnathorizedLogin <cred.error.UnauthorizedLogin>} error.

        @raise cred.error.UnauthorizedLogin: When authentication fails.
        N)r�r�r�credentials�UsernamePasswordr�r�rz)rr�rs   rrzPOP3.authenticateUserPASSsT��*�;�;�"��;�;�$�$�� � �1�1�$��A�4���
��j�j�*�*�,�,rc��t��rW)r�rMs r�
stopProducingzPOP3.stopProducing*s��!�#�#r�r{)rrW)=r#r$r%r&rrr<�__annotations__rr�r�r�r�r�r�r�r��staticmethodr	�	coiterater[rPr�r�r�rgr�r�r�r�r�r�r�r�r�r�r�r�r�r	r
rrrr2r7rDrZr_rdrSrirlrnrqrsrurxr�rr�r'rrr~r~ys2��5�n"�E�8�E�?�!��G��I�O�I�
�F��G��D��G��E��G��D�N�N�+�H��H�	L�
� �7�
*�3�*�$�,A�4J�X	�!�F-�:)�&8�>R�$
�:�)�6�(Q�K�(=.�~1.�f2�h1A�f�6W�J� ���
#�,�
7�
(�-�6-�6$rr~c�6�eZdZdZd	d�Zd�Zd�Zd�Zd�Zd�Z	y)
�Mailboxz%
    A base class for mailboxes.
    Nc��gS)a�
        Retrieve the size of a message, or, if none is specified, the size of
        each message in the mailbox.

        @type i: L{int} or L{None}
        @param i: The 0-based index of the message.

        @rtype: L{int}, sequence of L{int}, or L{Deferred <defer.Deferred>}
        @return: The number of octets in the specified message, or, if an
            index is not specified, a sequence of the number of octets for
            all messages in the mailbox or a deferred which fires with
            one of those. Any value which corresponds to a deleted message
            is set to 0.

        @raise ValueError or IndexError: When the index does not correspond to
            a message in the mailbox.  The use of ValueError is preferred.
        r'rcs  rrzMailbox.listMessages5s	��$�	rc��t�)a
        Retrieve a file containing the contents of a message.

        @type i: L{int}
        @param i: The 0-based index of a message.

        @rtype: file-like object
        @return: A file containing the message.

        @raise ValueError or IndexError: When the index does not correspond to
            a message in the mailbox.  The use of ValueError is preferred.
        �r�rcs  rr=zMailbox.getMessageIs
���rc��t�)a�
        Get a unique identifier for a message.

        @type i: L{int}
        @param i: The 0-based index of a message.

        @rtype: L{bytes}
        @return: A string of printable characters uniquely identifying the
            message for all time.

        @raise ValueError or IndexError: When the index does not correspond to
            a message in the mailbox.  The use of ValueError is preferred.
        r�rcs  rrvzMailbox.getUidlX�
���rc��t�)a�
        Mark a message for deletion.

        This must not change the number of messages in this mailbox.  Further
        requests for the size of the deleted message should return 0.  Further
        requests for the message itself may raise an exception.

        @type i: L{int}
        @param i: The 0-based index of a message.

        @raise ValueError or IndexError: When the index does not correspond to
            a message in the mailbox.  The use of ValueError is preferred.
        r�rcs  rrkzMailbox.deleteMessagehr�rc��y)z�
        Undelete all messages marked for deletion.

        Any message which can be undeleted should be returned to its original
        position in the message sequence and retain its original UID.
        Nr'rMs rrpzMailbox.undeleteMessagesxs��	
rc��y)zJ
        Discard the contents of any message marked for deletion.
        Nr'rMs rrwzMailbox.sync�s��	
rrW)
r#r$r%r&rr=rvrkrprwr'rrr�r�/s%����(
�� � 
�
rr�r5c��eZdZdZeZdZddlZejd�Z	d�Z
dd�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zdd�Zdd�Zd�Zd�ZeZd�Zy)�
POP3Clienta|
    A POP3 client protocol.

    @type mode: L{int}
    @ivar mode: The type of response expected from the server.  Choices include
    none (0), a one line response (1), the first line of a multi-line
    response (2), and subsequent lines of a multi-line response (3).

    @type command: L{bytes}
    @ivar command: The command most recently sent to the server.

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

    @type welcomeCode: L{bytes}
    @ivar welcomeCode: The APOP challenge passed in the server greeting.
    sWELCOMErNs<(.*)>c�>�ddl}|jdtd��y)z,
        Issue deprecation warning.
        rNzdtwisted.mail.pop3.POP3Client is deprecated, please use twisted.mail.pop3.AdvancedPOP3Client instead.�)�
stacklevel)r+r,�DeprecationWarning)rr+s  rrzPOP3Client.__init__�s"��	���
�
�
�
��	
rc���|�Bt|t�st|�jd�}|j	|dz|z�n|j	|�||_t|_y)z�
        Send a POP3 command to which a short response is expected.

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

        @type params: stringifyable L{object} or L{None}
        @param params: Command arguments.
        Nrar�)rcr<rdrer�r��SHORT�mode�rr��paramss   r�	sendShortzPOP3Client.sendShort�sW�����f�e�,��V��+�+�G�4���M�M�'�D�.�6�1�2��M�M�'�"������	rc���|rBt|t�st|�jd�}|j	|dz|z�n|j	|�||_t|_y)z�
        Send a POP3 command to which a long response is expected.

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

        @type params: stringifyable L{object}
        @param params: Command arguments.
        rar�N)rcr<rdrer�r��
FIRST_LONGr�r�s   r�sendLongzPOP3Client.sendLong�sT����f�e�,��V��+�+�G�4���M�M�'�D�.�6�1�2��M�M�'�"������	rc�,�|dddk(rt|_yy)z�
        Handle responses from the server for which no other handler exists.

        @type line: L{bytes}
        @param line: A received line.
        N���s-ERR)�NONEr�r�s  r�handle_defaultzPOP3Client.handle_default�s�����9����D�I� rc���|jdd�\}}|dk7r|jj�y|jj	|�}|r|jd�|_yy)z�
        Handle a server response which is expected to be a server greeting.

        @type line: L{bytes}
        @param line: A received line.
        r�r+s+OKN)r;rYrM�	welcomeRe�match�group�welcomeCode)rr��coder=rws     r�handle_WELCOMEzPOP3Client.handle_WELCOME�s[���Z�Z��a�(�
��d��6�>��N�N�)�)�+����$�$�T�*�A��#$�7�7�1�:�� �rc��	t|d|jd�z|�}|�||�yy#t$rtj�YywxYw)a�
        Dispatch a response from the server for handling.

        Command X is dispatched to handle_X() if it exists.  If not, it is
        dispatched to the default handler.

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

        @type default: callable that takes L{bytes} or
            L{None}
        @param default: The default handler.

        @type args: L{tuple} or L{None}
        @param args: Arguments to the handler function.
        �handle_raN)r�r�r�rr�)rr��defaultr��methods     r�	_dispatchzPOP3Client._dispatch�sM��"	��T�9�w�~�~�g�/F�#F��P�F��!���
�"���	��G�G�I�	�s�&*�A
�	A
c���|jtk(s|jtk(r@t|j|_|j	|j
|j|�y|jtk(rk|dk(r8t|j|_|j	|j
dzd�y|dddk(r|dd}|j	|j
dzd|�yy)a�
        Dispatch a received line for processing.

        The choice of function to handle the received line is based on the
        type of response expected to the command sent to the server and how
        much of that response has been received.

        An expected one line response to command X is handled by handle_X().
        The first line of a multi-line response to command X is also handled by
        handle_X().  Subsequent lines of the multi-line response are handled by
        handle_X_continue() except for the last line which is handled by
        handle_X_end().

        @type line: L{bytes}
        @param line: A received line.
        r�s_endNr+s	_continue)r�r�r��NEXTr�r�r��LONGr�s  rr�zPOP3Client.lineReceiveds���"�9�9������j�!8��T�Y�Y��D�I��N�N�4�<�<��)<�)<�d�C�
�Y�Y�$�
��t�|� ����O��	����t�|�|�g�5�t�<���B�Q�x�4���A�B�x���N�N�4�<�<�,�6��d�C�rc�~�t||z�j�jd�}|j||�y)a@
        Perform an authenticated login.

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

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

        @type magic: L{bytes}
        @param magic: The challenge provided by the server.
        �asciiN)rrre�apop)rr�rrrs     r�apopAuthenticatezPOP3Client.apopAuthenticate-s5���U�X�%�&�0�0�2�9�9�'�B���	�	�$��rc�J�|jddj||f��y)a
        Send an APOP command to perform authenticated login.

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

        @type digest: L{bytes}
        @param digest: The challenge response with which to authenticate.
        r�r�N)r�r�r{s   rr�zPOP3Client.apop=s��	
�
�
�g�t�y�y�$���8�9rc�(�|jd|�y)z�
        Send a RETR command to retrieve a message from the server.

        @type i: L{int} or L{bytes}
        @param i: A 0-based message index.
        sRETRN�r�rcs  r�retrzPOP3Client.retrIs��	
�
�
�g�q�!rc�(�|jd|�y)z�
        Send a DELE command to delete a message from the server.

        @type i: L{int} or L{bytes}
        @param i: A 0-based message index.
        sDELEN�r�rcs  r�delezPOP3Client.deleRs��	
���w��"rc�(�|jd|�y)a
        Send a LIST command to retrieve the size of a message or, if no message
        is specified, the sizes of all messages.

        @type i: L{int} or L{bytes}
        @param i: A 0-based message index or the empty string to specify all
            messages.
        sLISTNr�rcs  r�listzPOP3Client.list[���	
�
�
�g�q�!rc�(�|jd|�y)a,
        Send a UIDL command to retrieve the unique identifier of a message or,
        if no message is specified, the unique identifiers of all messages.

        @type i: L{int} or L{bytes}
        @param i: A 0-based message index or the empty string to specify all
            messages.
        r�Nr�rcs  r�uidlzPOP3Client.uidlfr�rc�(�|jd|�y)z�
        Send a USER command to perform the first half of a plaintext login.

        @type name: L{bytes}
        @param name: The username with which to log in.
        rNr�)r�names  rr�zPOP3Client.userqs��	
���w��%rc�(�|jd|�y)z�
        Perform the second half of a plaintext login.

        @type password: L{bytes}
        @param password: The plaintext password with which to authenticate.
        r�Nr�)rrs  rrzPOP3Client.passwordzs��	
���w��)rc�&�|jd�y)zD
        Send a QUIT command to disconnect from the server.
        r�Nr�rMs r�quitzPOP3Client.quit�s��	
���w�rrWr�)r#r$r%r&r�r�r��re�compiler�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�pass_r�r'rrr�r��s|���&�D��G�
��
�
�9�%�I�
��&�&�
.��0D�: � 
:�"�#�	"�	"�&�*�
�E� rr�)� InsecureAuthenticationDisallowed�LineTooLong�ServerErrorResponse�TLSError�TLSNotSupportedError)r�)r�r�rrr�r�r�r�r�r~r��AdvancedPOP3Clientrr�)@r&r�r�r+�hashlibr�typingr�zope.interfacer�twistedr�twisted.internetrrr	�twisted.mailr
�twisted.mail._exceptrrr
�twisted.mail.interfacesrr�rr��twisted.protocolsrr�twisted.pythonrr}�IUsernameHashedPasswordrr)rDr_rgrnrprsryr|�	IProducer�LineOnlyReceiver�TimeoutMixinr~r��ranger�r�r�r�r�r�r�r�r�r�r��twisted.mail._pop3clientr��__all__r'rr�<module>r�si��������&��4�4��P�P��.��
�T�
�
�
5�
5�6�''�''�7�''�TQ�Q�hM�M�` �$(�1�0'�$�$.�(�,
�Z�
!�
!�"�r$�5�!�!�8�#8�#8�r$�#�r$�j
�X��U
�U
��U
�p!&�a����e�Z��	��
��T�
���U����Z��
��T�
�x ��'�'�x �v��F��r