Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/mail/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/twisted/mail/__pycache__/pop3.cpython-310.pyc
o

�bg��@s�dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZmZddlmZdd	lmZmZmZdd
lmZmZddlmZmZddlmZe	ej j!�Gd
d�d��Z"Gdd�d�Z#Gdd�d�Z$dd�Z%dd�Z&dd�Z'dd�Z(dd�Z)dd�Z*dd �Z+e	ej,�Gd!d"�d"ej-ej.��Z/e	e�Gd#d$�d$��Z0e1d%�\Z2Z3Z4Z5iZ6e2e6e2<e2e6e3<e5e6e4<e2e6e5<Gd&d'�d'ej-�Z7dd(lm8Z8m9Z9m:Z:m;Z;m<Z<dd)l=m7Z>gd*�Z?dS)+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@� eZdZdZdd�Zdd�ZdS)�APOPCredentialsz�
    Credentials for use in APOP authentication.

    @ivar magic: See L{__init__}
    @ivar username: See L{__init__}
    @ivar digest: See L{__init__}
    cCs||_||_||_dS)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)�selfrrr�r�3/usr/lib/python3/dist-packages/twisted/mail/pop3.py�__init__-s

zAPOPCredentials.__init__cCs |j|}t|���}||jkS)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�myDigestrrr�
checkPassword>s

zAPOPCredentials.checkPasswordN)�__name__�
__module__�__qualname__�__doc__rrrrrrr#src@r)�_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.
    cCs(||_||_d|_d|_d|_d|_dS)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��N)�_file�_extraLines�	linecount�headers�done�buf)r�file�
extraLinesrrrrfs
z_HeadersPlusNLines.__init__cCs�|jrdS|j�|�}|s|S|jrA|�d�d}}|dkr&|�d�d}}|dkr@||7}|d|�}||d�}d|_d	|_nd}|jd	krz|j|�d
�}|d|_|dd�D]}|j|jkrjd|_|S||d
7}|jd7_q[|S|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.
        r&s

����s

�Nr%r�
)	r+r'�readr*�findr)r,�splitr()r�bytes�data�df�sz�val�dsplit�lnrrrr3us8�

z_HeadersPlusNLines.readN)r r!r"r#rr3rrrrr$Nsr$c@s2eZdZdZdZd
dd�Zdd�Zdd	�ZeZdS)�_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.
    rNcCs,g|_||_t|�|_|durd}||_dS)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)rr?�iterablerBrrrr�s


z_IteratorBuffer.__init__cC�|S)z�
        Return an iterator.

        @rtype: iterator which yields L{bytes}
        @return: An iterator over strings.
        r�rrrr�__iter__��z_IteratorBuffer.__iter__cCs�zt|j�}Wnty|jr|�|j�|`|`|`�w|durF|j�|�|jt|�7_|j|jkrH|�|j�g|_d|_dSdSdS)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)	�nextrA�
StopIterationr>r?�append�bufSize�lenrB)r�vrrr�__next__�s"�
�z_IteratorBuffer.__next__�N)	r r!r"r#rKrrFrNrHrrrrr=�s
	r=cCst|jj|�}|�|�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.
    )r=�	transport�
writeSequence�schedule)�proto�gen�collrrr�iterateLineGenerator�s
rVcCs$t|t�st|��d�}d|dS)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 �
)�
isinstancer6�str�encode)�responserrr�successResponses

r]ccs@�d}d}|D]
}|d7}||7}dVqtd||f�VdS)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�r])�msgs�ir6�sizerrr�formatStatResponses�rcccs*�d}|D]
}|d7}d||fVqdS)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)r`rarbrrr�formatListLines+s��rdccs.�tdt|�f�Vt|�EdHdVdS)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�.
)r]rLrd�r`rrr�formatListResponse=s�

rgccsR�t|�D]!\}}|dur&||�}t|t�st|��d�}d|d|fVqdS)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.
    NrWs%d %b
r%)�	enumeraterYr6rZr[)r`�getUidlra�m�uidrrr�formatUIDListLinesOs�
��rlccs&�td�Vt||�EdHdVdS)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.
    �Nre)r]rl)r`rirrr�formatUIDListResponsecs�

rnc@s�eZdZUdZdZeeed<dZdZ	gd�Z
dZdZdZ
dZdZdZeej�ZdZdd	�Zd
d�Zdd
�ZdXdd�ZdYdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z dZd d!�Z!d"d#�Z"d$d%�Z#d&d'�Z$d(d)�Z%d*d+�Z&d,d-�Z'd.d/�Z(d0d1�Z)d2d3�Z*d4d5�Z+dZd6d7�Z,dZd8d9�Z-d:d;�Z.d<d=�Z/d>d?�Z0d@dA�Z1dBdC�Z2dDdE�Z3dFdG�Z4dHdI�Z5dJdK�Z6dLdM�Z7dNdO�Z8dPdQ�Z9dRdS�Z:dTdU�Z;dVdW�Z<dS)[�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,�COMMANDrcCsZ|jdur
|��|_|�|j�|�|j�t|jdd�r+t�dt	|j
����dSdS)zS
        Send a greeting to the client after the connection has been made.
        N�noisyTzNew connection from )r�
generateMagicr]�
setTimeout�timeOut�getattr�factoryr�msgrZrP�getPeerrErrr�connectionMade�s

�zPOP3.connectionMadecCs&|jdur|��d|_|�d�dS)z�
        Clean up when the connection has been lost.

        @type reason: L{Failure}
        @param reason: The reason the connection was terminated.
        N)�	_onLogoutrw)r�reasonrrr�connectionLost�s
zPOP3.connectionLostcCst��S)z}
        Generate an APOP challenge.

        @rtype: L{bytes}
        @return: An RFC 822 message id format string.
        )r	�	messageidrErrrrv�szPOP3.generateMagicrmcCs|j�t|��dS)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)rPr?r]�r�messagerrrr]�szPOP3.successResponser&cCs*t|t�st|��d�}|�d|�dS)z�
        Send a response indicating failure.

        @type message: stringifyable L{object}
        @param message: An object whose string representation should be
            included in the response.
        rWs-ERR N)rYr6rZr[�sendLiner�rrr�failResponse�s
zPOP3.failResponsecCs |��t|d|j�|�dS)z�
        Pass a received line to a state machine function.

        @type line: L{bytes}
        @param line: A received line.
        �state_N)�resetTimeoutry�state�r�linerrr�lineReceivedszPOP3.lineReceivedcCsf|j}d|_|r$|jdur$|�d�\}}|j|g|�R�|r$|jdus
|jdur1|j�|�dSdS)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�argsrrr�_unblocks
�
�z
POP3._unblockcCsrz	|j|�d��WSttttfy8}zt��|�d�	d|j
j�d�d�	|j
�g��WYd}~dSd}~ww)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 serverrWr&N)r�r5�
ValueError�AttributeErrorr�	TypeErrorr�errr��join�	__class__r r[r�)rr��errr�
state_COMMANDs
�����zPOP3.state_COMMANDcGst|jdur|j�||f�dS|��}||jv}|js#|s#td|��t|d|�d�d�}|r4||�Std|��)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_rWsUnknown protocol command: )r�rJ�upper�	AUTH_CMDS�mboxrry�decode)r�commandr��authCmd�frrrr�4s



zPOP3.processCommandcCs�gd�}t�|j�r�z|j��}|rt|t�st|��d�}Wnty(Ynt	y4t
��Ynw|�d|�z|j�
�}|rPt|t�sPt|��d�}WntyZYn0t	yft
��Yn$w|durmd}|j��r�|jrt|jj��d�}n|d}|�d|�z|j��}|r�t|t�s�t|��d�}Wnty�Yn*t	y�t
��Ynw|j��r�|jr�t|jj��d�}n|d}|�d|�z|jj}Wnty�Y|St	y�t
��Y|Sw|�d	d
�|����|S)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.
        )sTOPrp�UIDLsPIPELINEsCELERITYsAUSPEXsPOTENCErWsIMPLEMENTATION NsNEVERs USERsEXPIRE sLOGIN-DELAY sSASL r�)�IServerFactory�
providedByrz�cap_IMPLEMENTATIONrYr6rZr[�NotImplementedError�
BaseExceptionrr�rJ�
cap_EXPIRE�perUserExpirationr��messageExpiration�cap_LOGIN_DELAY�perUserLoginDelay�
loginDelay�challengersr�r��keys)r�baseCapsrMrrr�listCapabilitiesNsp

��
��

��
�
�zPOP3.listCapabilitiescCs0|�d�|��D]}|�|�q	|�d�dS)zW
        Handle a CAPA command.

        Respond with the server capabilities.
        sI can do the following:�.N)r]r�r�)r�caprrr�do_CAPA�s
zPOP3.do_CAPAcCs�t|jdd�s|�d�dS|dur,|�d�|jjD]	}|�|���q|�d�dS|jj�|�����}|j	r<|sC|�d�dS|�|_
|j
��}|�dt�
|��d|_dS)	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)ryrzr�r]r�r�r��get�strip�portal�_auth�getChallenge�base64�	b64encoder�)rr��a�auth�chalrrr�do_AUTH�s"






zPOP3.do_AUTHcCs�d|_zt�|��dd�}Wntjy|�d�YdSwt|�dkr,|�d�dS|d|j_	|d|j_
|j�|jdt
�}|�|j|d�|�|j�|�|j�dS)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.
        rtNr%sInvalid BASE64 encodingr1sInvalid AUTH responser)r�r��	b64decoder5�binascii�Errorr�rLr�rr\r��login�IMailbox�addCallback�
_cbMailbox�
addErrback�
_ebMailbox�
_ebUnexpected)rr��parts�drrr�
state_AUTH�s
�
zPOP3.state_AUTHcCs2t�|j||�}|j|j|j|fd��|j�dS)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�rrr�do_APOP�s
�zPOP3.do_APOPcCsd|\}}}|tur|�d�t�d�dS||_||_|�d�t|jdd�r0t�	d|�dSdS)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 succeededruTsAuthenticated login for )
r�r�rr�r�r~r]ryrzr{)r�resultr��	interface�avatar�logoutrrrr��s



�zPOP3._cbMailboxcCs||�tjjtjj�}t|tjj�r|�dt|��nt|tjj�r'|�d�t|j	dd�r<t
�dt|j�
���dSdS)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�ruTzDenied login attempt from N)�trapr�error�LoginDenied�LoginFailed�
issubclassr�rZryrzrr{rPr|�r�failurerrrr�s

�zPOP3._ebMailboxcCs |�d|���t�|�dS)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�r�rrrr�)s	zPOP3._ebUnexpectedcCs||_|�d�dS)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)�_userIsr]�rr�rrr�do_USER5s
zPOP3.do_USERcGsf|jdur|�d�dS|j}d|_d�|f|�}t�|j||�}|j|j|j|fd��	|j
�dS)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�)r�r�r�rr��authenticateUserPASSr�r�r�r�r�)rr�wordsr�r�rrr�do_PASSBs

�zPOP3.do_PASScs:�j���d�g�_|��j�|���fdd��|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.
        Ncs
����SrO)rw)�ign�rrxrr�<lambda>n�
z%POP3._longOperation.<locals>.<lambda>)rxrwr�r�r�)rr�rr�r�_longOperation]s
zPOP3._longOperationcCs|�t|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.
        )rRr=rPrQ)rrTrrr�
_coiterateqszPOP3._coiteratecs8t��jj�}�fdd�}�fdd�}��|�||��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���t|��SrO)r�rcrfrErr�
cbMessages��z POP3.do_STAT.<locals>.cbMessagesc�&��|���t�d�t�|�dS)NzUnexpected do_STAT failure:�r�r�rr{r��r�rErr�
ebMessages��
z POP3.do_STAT.<locals>.ebMessages)rr�r��listMessagesr�r�)rr�r�r�rrEr�do_STAT~szPOP3.do_STATcs��dur t��jj�}�fdd�}�fdd�}��|�||��Sz
t����dkr,t��WntyJt�t	�s@t
���d����d��YdSwt��jj�d�}��fd	d
�}��fdd�}|�||���|�S)
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.
        Ncr�rO)r�rgrfrErrr��r�z POP3.do_LIST.<locals>.cbMessagescr�)N�Unexpected do_LIST failure:r�r�rErrr��r�z POP3.do_LIST.<locals>.ebMessagesr%rW�Invalid message-number: cs��d�|f�dS)Nr^r_)r{�rarrr�	cbMessage�szPOP3.do_LIST.<locals>.cbMessagecs�|�tt�}|dur-|turt�dt��}|r$t|t�s$t|��	d�}��
d|�dS��
|���t�
d�t�|�dS)N�}twisted.mail.pop3.IMailbox.listMessages may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.rWr�r�)�checkr��
IndexError�warnings�warn�PendingDeprecationWarningrYr6rZr[r�r�rr{r�)r��errcls�
invalidNumr�rr�	ebMessage�s�
zPOP3.do_LIST.<locals>.ebMessage)
rr�r�r�r�r��intr�rYr6rZr[r�)rrar�r�r�r�rrr�r�do_LIST�s(�
�
zPOP3.do_LISTcs�|dur t��jj�}�fdd�}�fdd�}��|�||��Sz
t|�}|dkr,t��Wnty<��d�YdSwz
�j�	|d�}Wn#t
y\t�dt
���d�YdStyj��d�YdSwt|t�swt|��d	�}��|�dS)
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.
        Ncs��t|�jj��SrO)r�rnr�rirfrErrr��s�z POP3.do_UIDL.<locals>.cbMessagescr�)NzUnexpected do_UIDL failure:r�r�rErrr��r�z POP3.do_UIDL.<locals>.ebMessagesr%�Bad message number argumentzxtwisted.mail.pop3.IMailbox.getUidl may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.rW)rr�r�r�r�r�r	r�r�rirrrrrYr6rZr[r])rrar�r�r�r{rrEr�do_UIDL�s6����
zPOP3.do_UIDLcs�zt|�d��dkrt��Wnty"��d�t�d�YSwt��jj��}��fdd�}�fdd�}|�|�|�	|�|S)	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%rrNcs6�st�t��St��jj��}|��fdd��|S)Ncs�|fSrOr)�fObj�rbrrr�sz=POP3._getMessageFile.<locals>.cbMessageSize.<locals>.<lambda>)r�failrr�r��
getMessager�)rb�fileDeferred�r{rrr�
cbMessageSizes
z+POP3._getMessageFile.<locals>.cbMessageSizecsj|�ttt�}|tur��d�dS|ttfvr)|tur"t�dt���d�dSt�	d�t�
|�dS)Nzmessage deletedrrz#Unexpected _getMessageFile failure:)rrr�rr�rrrrr{r�)r�rrErr�ebMessageSomething!s
��

�
z0POP3._getMessageFile.<locals>.ebMessageSomething)
r	r�r�r�succeedr�r�r�r�r�)rra�sizeDeferredrrrrr�_getMessageFiles�
�

zPOP3._getMessageFilecs,����}����fdd�}��|�|��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.
        cs�|durdSt�jt����_|\}}�|�}���|��t��}|�|�j�j�}�fdd�}�fdd�}|�	|�|�
|�|S)Ncs |dkrd}nd}��|�dS)Nr2�
.r��r�)�lastsentr�rErr�cbFileTransferYszGPOP3._sendMessageContent.<locals>.cbMessageFile.<locals>.cbFileTransfercs"�j��t�d�t�|�dS)Nz(Unexpected error in _sendMessageContent:)rP�loseConnectionrr{r�r�rErr�ebFileTransfer`s

zGPOP3._sendMessageContent.<locals>.cbMessageFile.<locals>.ebFileTransfer)�max�_highestr	r]r�
FileSender�beginFileTransferrP�transformChunkr�r�)�info�resp�fp�sr�rr��	fpWrapperrarr]rr�
cbMessageFileLs

z/POP3._sendMessageContent.<locals>.cbMessageFile)rr�r�)rrar(r]r�r)rr'r�_sendMessageContent8s
zPOP3._sendMessageContentcsRzt����dkrt�Wnty|�d�YdSw|�|�fdd�dd��S)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.
        rzBad line count argumentcs
t|��SrO)r$�r%rrrr��r�zPOP3.do_TOP.<locals>.<lambda>cS�dS)NzTop of message followsrrrrrr���N)r	r�r�r*)rrarbrrr�do_TOPks��
�zPOP3.do_TOPcCs|�|dd�dd��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.
        cSrDrOrr+rrrr��r-zPOP3.do_RETR.<locals>.<lambda>cSs
d|fS)Nz%drrrrrr��r�)r*�rrarrr�do_RETR�szPOP3.do_RETRcCs|�dd��dd�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.
        r2rXrs
..)�replace)r�chunkrrrr"�szPOP3.transformChunkcCs |dkrd}nd}|�|�dS)z�
        Send the termination sequence.

        @type lastsent: L{bytes}
        @param lastsent: The last character of the file.
        r2rr�Nr)rrr�rrr�finishedFileTransfer�szPOP3.finishedFileTransfercCs$t|�d}|j�|�|��dS)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)r	r��
deleteMessager]r/rrr�do_DELE�s	zPOP3.do_DELEcCs|��dS)z]
        Handle a NOOP command.

        Do nothing but issue a successful response.
        Nr_rErrr�do_NOOP�szPOP3.do_NOOPcCsFz|j��Wntyt��|��YdSwd|_|��dS)zj
        Handle a RSET command.

        Unmark any messages that have been flagged for deletion.
        rN)r��undeleteMessagesr�rr�r�rr]rErrr�do_RSET�s�zPOP3.do_RSETcCs|�|j�dS)zr
        Handle a LAST command.

        Respond with the 1-based index of the highest retrieved message.
        N)r]rrErrr�do_LAST�szPOP3.do_LASTcC�|�d�dS)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�r�rrr�do_RPOP�s
zPOP3.do_RPOPcCs&|jr|j��|��|j��dS)z�
        Handle a QUIT command.

        Remove any messages marked for deletion, issue a successful response,
        and drop the connection.
        N)r��syncr]rPrrErrr�do_QUIT�s
zPOP3.do_QUITcCs.|jdur|j�t|j||�dt�Stj���)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�rrrrr���

�
zPOP3.authenticateUserAPOPcCs.|jdur|j�tj�||�dt�Stj���)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�r>)rr�rrrrr�r@zPOP3.authenticateUserPASScCst��rO)r�rErrr�
stopProducing*szPOP3.stopProducing�rm)r&rO)=r r!r"r#rrr6�__annotations__r�r~r�r�rzr�rxr�r��staticmethodr�	coiteraterRrr}r�rvr]r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
rrr*r.r0r"r3r5r6r8r9r;r=r�r�rCrrrrroysj
7

	


L
#


?343


roc@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�Mailboxz%
    A base class for mailboxes.
    NcCsgS)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.
        rr/rrrr�5szMailbox.listMessagescC�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�r/rrrrIs
zMailbox.getMessagecCrI)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.
        rJr/rrrriX�zMailbox.getUidlcCrI)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.
        rJr/rrrr4hrKzMailbox.deleteMessagecCr,)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.
        NrrErrrr7xrGzMailbox.undeleteMessagescCr,)zJ
        Discard the contents of any message marked for deletion.
        NrrErrrr<�szMailbox.syncrO)
r r!r"r#r�rrir4r7r<rrrrrH/s
	rHr/c@s�eZdZdZeZdZddlZe�d�Z	dd�Z
d'dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd(dd�Zd(dd �Zd!d"�Zd#d$�ZeZd%d&�ZdS))�
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<(.*)>cCsddl}|jdtdd�dS)z,
        Issue deprecation warning.
        rNzdtwisted.mail.pop3.POP3Client is deprecated, please use twisted.mail.pop3.AdvancedPOP3Client instead.�)�
stacklevel)rr�DeprecationWarning)rrrrrr�s
�zPOP3Client.__init__cCsN|durt|t�st|��d�}|�|d|�n|�|�||_t|_dS)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.
        NrWr�)rYr6rZr[r�r��SHORT�mode�rr��paramsrrr�	sendShort�s



zPOP3Client.sendShortcCsJ|rt|t�st|��d�}|�|d|�n|�|�||_t|_dS)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.
        rWr�N)rYr6rZr[r�r��
FIRST_LONGrQrRrrr�sendLong�s



zPOP3Client.sendLongcCs|dd�dkr
t|_dSdS)z�
        Handle responses from the server for which no other handler exists.

        @type line: L{bytes}
        @param line: A received line.
        N���s-ERR)�NONErQr�rrr�handle_default�s
�zPOP3Client.handle_defaultcCsJ|�dd�\}}|dkr|j��dS|j�|�}|r#|�d�|_dSdS)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)r5rPr�	welcomeRe�match�group�welcomeCode)rr��coder7rjrrr�handle_WELCOME�s�zPOP3Client.handle_WELCOMEcGsPzt|d|�d�|�}|dur||�WdSWdSty't��YdSw)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_rWN)ryr�r�rr�)rr��defaultr��methodrrr�	_dispatch�s��zPOP3Client._dispatchcCs�|jtks
|jtkrt|j|_|�|j|j|�dS|jtkrO|dkr5t|j|_|�|jdd�dS|dd�dkrC|dd�}|�|jdd|�dSdS)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)rQrPrU�NEXTrcr�rY�LONGr�rrrr�s
�zPOP3Client.lineReceivedcCs&t||����d�}|�||�dS)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)rrr[�apop)rr�rrrrrr�apopAuthenticate-s
zPOP3Client.apopAuthenticatecCs|�dd�||f��dS)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.
        rrr�N)rVr�r?rrrrg=s
zPOP3Client.apopcC�|�d|�dS)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�rVr/rrr�retrI�zPOP3Client.retrcCri)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�rTr/rrr�deleRrlzPOP3Client.delermcCri)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.
        sLISTNrjr/rrr�list[�	zPOP3Client.listcCri)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�Nrjr/rrr�uidlfrpzPOP3Client.uidlcCri)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.
        rpNrm)r�namerrrr�qrlzPOP3Client.usercCri)z�
        Perform the second half of a plaintext login.

        @type password: L{bytes}
        @param password: The plaintext password with which to authenticate.
        rqNrm)rrrrrrzrlzPOP3Client.passwordcCr:)zD
        Send a QUIT command to disconnect from the server.
        rsNrmrErrr�quit�szPOP3Client.quitrOrD)r r!r"r#rPrQr��re�compilerZrrTrVrYr_rcr�rhrgrkrnrorqr�r�pass_rsrrrrrL�s.


	
	
		rL)� InsecureAuthenticationDisallowed�LineTooLong�ServerErrorResponse�TLSError�TLSNotSupportedError)rL)r�r�rr
rwryrxrzr{rorL�AdvancedPOP3ClientrrH)@r#r�r�r�hashlibr�typingr�zope.interfacer�twistedr�twisted.internetrrr�twisted.mailr	�twisted.mail._exceptr
rr�twisted.mail.interfacesr
r�rr��twisted.protocolsrr�twisted.pythonrrA�IUsernamePasswordrr$r=rVr]rcrdrgrlrn�	IProducer�LineOnlyReceiver�TimeoutMixinrorH�rangerXrPrUrerdrLrwrxryrzr{�twisted.mail._pop3clientr|�__all__rrrr�<module>s^
*TP<X|

Spamworldpro Mini