%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__/protocols.cpython-312.pyc

�

Ϫ�f&0��j�dZddlmZddlmZddlmZmZddlm	Z	ddl
mZmZddl
mZmZmZddlmZeej&�Gd	�d
��ZGd�de�ZGd
�de�ZGd�dej.�ZGd�de�ZGd�dej2�ZGd�dej6�Zy)z
Mail protocol support.
�)�implementer)�longversion)�CramMD5Credentials�UsernamePassword)�UnauthorizedLogin)�defer�protocol)�pop3�relay�smtp)�logc�T�eZdZUdZdZdZeed<ejfd�Z
d�Zd�Zd�Z
y)	�DomainDeliveryBaseaN
    A base class for message delivery using the domains of a mail service.

    @ivar service: See L{__init__}
    @ivar user: See L{__init__}
    @ivar host: See L{__init__}

    @type protocolName: L{bytes}
    @ivar protocolName: The protocol being used to deliver the mail.
        Sub-classes should set this appropriately.
    Nsnot-implemented-protocol�protocolNamec�.�||_||_||_y)z�
        @type service: L{MailService}
        @param service: A mail service.

        @type user: L{bytes} or L{None}
        @param user: The authenticated SMTP user.

        @type host: L{bytes}
        @param host: The hostname.
        N)�service�user�host)�selfrrrs    �8/usr/lib/python3/dist-packages/twisted/mail/protocols.py�__init__zDomainDeliveryBase.__init__%s�������	���	�c��dx}}|jrd|jjd�z}|drd|dz}d|dzdz|dzd	z|z|z}d
|jzdz|jzdzt	jd
�zdz}ddjt
t|��zdztj�z}d|zdz|zdz|zS)a�
        Generate a received header string for a message.

        @type helo: 2-L{tuple} of (L{bytes}, L{bytes})
        @param helo: The client's identity as sent in the HELO command and its
            IP address.

        @type origin: L{Address}
        @param origin: The origination address of the message.

        @type recipients: L{list} of L{User}
        @param recipients: The destination addresses for the message.

        @rtype: L{bytes}
        @return: A received header string.
        rs auth=�xtextrs helo=sfrom s ([��]sby s with s (�ascii�)sfor <� s> s
Received: s
	)
r�encoderrr�join�map�bytesr�
rfc822date)	r�helo�origin�
recipients�authStr�heloStr�fromUser�by�forUsers	         r�receivedHeaderz!DomainDeliveryBase.receivedHeader4s��" ���'��9�9��$�)�)�"2�"2�7�";�;�G���7��$�q�'�)�G��d�1�g�%��.��a��8�4�?�'�I�G�S����i�i�
��
����
 ��	
�
� � ��)�
*��

�	�
�t�y�y��U�J�!7�8�8�5�@�4�?�?�CT�T�	��x�'�'�1�B�6��@�7�J�Jrc��|jrs|jjr]|jjj	|j
jd�}|�Ntj|jd�}n-|jj|j
j}tj|j|�S)a9
        Validate the address for which a message is destined.

        @type user: L{User}
        @param user: The destination address.

        @rtype: L{Deferred <defer.Deferred>} which successfully fires with
            no-argument callable which returns L{IMessage <smtp.IMessage>}
            provider.
        @return: A deferred which successfully fires with a no-argument
            callable which returns a message receiver for the destination.

        @raise SMTPBadRcpt: When messages cannot be accepted for the
            destination address.
        NT)rr�queue�domains�get�dest�domainr�DomainQueuerr�
maybeDeferred�exists)rr�ds   r�
validateTozDomainDeliveryBase.validateToYs���"�9�9����+�+����$�$�(�(����)9�)9�4�@�A��y��&�&�t�|�|�T�:�����$�$�T�Y�Y�%5�%5�6�A��"�"�1�8�8�T�2�2rc��|stj|dd��|jdk7r&|jdk(rtj|dd��|S)a�
        Validate the address from which a message originates.

        @type helo: 2-L{tuple} of (L{bytes}, L{bytes})
        @param helo: The client's identity as sent in the HELO command and its
            IP address.

        @type origin: L{Address}
        @param origin: The origination address of the message.

        @rtype: L{Address}
        @return: The origination address.

        @raise SMTPBadSender: When messages cannot be accepted from the
            origination address.
        i�zWho are you?  Say HELO first.ri�z#Sender address must contain domain.)r�
SMTPBadSender�localr3)rr%r&s   r�validateFromzDomainDeliveryBase.validateFromrsO��"��$�$�V�S�2Q�R�R��<�<�3��6�=�=�C�#7��$�$�V�S�2W�X�X��
r)�__name__�
__module__�__qualname__�__doc__rrr#�__annotations__r�DNSNAMErr-r8r<�rrrrs5��
��G�5�L�%�5�+/�<�<�
�#K�J3�2rrc��eZdZdZdZy)�SMTPDomainDeliveryzA
    A domain delivery base class for use in an SMTP server.
    ssmtpN�r=r>r?r@rrCrrrErE�s����LrrEc��eZdZdZdZy)�ESMTPDomainDeliveryzB
    A domain delivery base class for use in an ESMTP server.
    sesmtpNrFrCrrrHrH�s����LrrHc�:�eZdZdZej
ZdZdd�Zd�Z	y)�SMTPFactorya;
    An SMTP server protocol factory.

    @ivar service: See L{__init__}
    @ivar portal: See L{__init__}

    @type protocol: no-argument callable which returns a L{Protocol
        <protocol.Protocol>} subclass
    @ivar protocol: A callable which creates a protocol.  The default value is
        L{SMTP}.
    Nc�^�tjj|�||_||_y)z�
        @type service: L{MailService}
        @param service: An email service.

        @type portal: L{Portal <twisted.cred.portal.Portal>} or
            L{None}
        @param portal: A portal to use for authentication.
        N)rrJrr�portal)rrrLs   rrzSMTPFactory.__init__�s&��	
���!�!�$�'������rc��tjd|���tjj	||�}|j
|_|j|_|S)a
        Create an instance of an SMTP server protocol.

        @type addr: L{IAddress <twisted.internet.interfaces.IAddress>} provider
        @param addr: The address of the SMTP client.

        @rtype: L{SMTP}
        @return: An SMTP protocol.
        zConnection from )r
�msgrrJ�
buildProtocolrrL�r�addr�ps   rrOzSMTPFactory.buildProtocol�sK��	���"�4�&�)�*����*�*�4��6���L�L��	��;�;����r)N)
r=r>r?r@r�SMTPr	rLrrOrCrrrJrJ�s!��
��y�y�H�
�F��rrJc�8�eZdZdZej
ZdZd�Zd�Z	y)�ESMTPFactorya
    An ESMTP server protocol factory.

    @type protocol: no-argument callable which returns a L{Protocol
        <protocol.Protocol>} subclass
    @ivar protocol: A callable which creates a protocol.  The default value is
        L{ESMTP}.

    @type context: L{IOpenSSLContextFactory
        <twisted.internet.interfaces.IOpenSSLContextFactory>} or L{None}
    @ivar context: A factory to generate contexts to be used in negotiating
        encrypted communication.

    @type challengers: L{dict} mapping L{bytes} to no-argument callable which
        returns L{ICredentials <twisted.cred.credentials.ICredentials>}
        subclass provider.
    @ivar challengers: A mapping of acceptable authorization mechanism to
        callable which creates credentials to use for authentication.
    Nc�J�tj|g|���dti|_y)zk
        @param args: Arguments for L{SMTPFactory.__init__}

        @see: L{SMTPFactory.__init__}
        sCRAM-MD5N)rJrr�challengers)r�argss  rrzESMTPFactory.__init__�s%��	���T�)�D�)�'�);�<��rc�v�tj||�}|j|_|j|_|S)a
        Create an instance of an ESMTP server protocol.

        @type addr: L{IAddress <twisted.internet.interfaces.IAddress>} provider
        @param addr: The address of the ESMTP client.

        @rtype: L{ESMTP}
        @return: An ESMTP protocol.
        )rJrOrW�context�ctxrPs   rrOzESMTPFactory.buildProtocol�s3��
�%�%�d�D�1���(�(��
�������r)
r=r>r?r@r�ESMTPr	rZrrOrCrrrUrU�s!���(�z�z�H��G�=�
rrUc�*�eZdZdZdZdZd�Zd�Zd�Zy)�VirtualPOP3a[
    A virtual hosting POP3 server.

    @type service: L{MailService}
    @ivar service: The email service that created this server.  This must be
        set by the service.

    @type domainSpecifier: L{bytes}
    @ivar domainSpecifier: The character to use to split an email address into
        local-part and domain. The default is '@'.
    N�@c�:�|j|�\}}	|jj|�}|jt	j
|j||�dtj�S#t$r tjt��cYSwxYw)a1
        Perform APOP authentication.

        Override the default lookup scheme to allow virtual domains.

        @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} which successfully results in 3-L{tuple} of
            (L{IMailbox <pop3.IMailbox>}, L{IMailbox <pop3.IMailbox>}
            provider, 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 logout function. If authentication fails, the
            deferred fails with an L{UnauthorizedLogin
            <twisted.cred.error.UnauthorizedLogin>} error.
        N)�lookupDomainr�lookupPortal�loginr
�APOPCredentials�magic�IMailbox�KeyErrorr�failr)rr�digestr3rLs     r�authenticateUserAPOPz VirtualPOP3.authenticateUserAPOPs���*�(�(��.���f�	��\�\�.�.�v�6�F��<�<��$�$�T�Z�Z��v�>��d�m�m��
���	3��:�:�/�1�2�2�	3�s�A1�1&B�Bc��|j|�\}}	|jj|�}|jt	||�dt
j�S#t$r tjt��cYSwxYw)aY
        Perform authentication for a username/password login.

        Override the default lookup scheme to allow virtual domains.

        @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} which successfully results in 3-L{tuple} of
            (L{IMailbox <pop3.IMailbox>}, L{IMailbox <pop3.IMailbox>}
            provider, 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 logout function. If authentication fails, the
            deferred fails with an L{UnauthorizedLogin
            <twisted.cred.error.UnauthorizedLogin>} error.
        N)rarrbrcrr
rfrgrrhr)rr�passwordr3rLs     r�authenticateUserPASSz VirtualPOP3.authenticateUserPASS+sw��*�(�(��.���f�	W��\�\�.�.�v�6�F��<�<� 0��x� @�$��
�
�V�V���	3��:�:�/�1�2�2�	3�s�A�&B�Bc��	|j|jd�\}}||jjvr3tjdj|jd����||fS#t$rd}Y�\wxYw)a�
        Check whether a domain is among the virtual domains supported by the
        mail service.

        @type user: L{bytes}
        @param user: An email address.

        @rtype: 2-L{tuple} of (L{bytes}, L{bytes})
        @return: The local part and the domain part of the email address if the
            domain is supported.

        @raise POP3Error: When the domain is not supported by the mail service.
        rrzno such domain {}zutf-8)	�split�domainSpecifier�
ValueErrorrr0r
�	POP3Error�format�decode)rrr3s   rrazVirtualPOP3.lookupDomainHsy��	��:�:�d�&:�&:�A�>�L�D�&�����-�-�-��.�.�!4�!;�!;�F�M�M�'�<R�!S�T�T��V�|���	�	��F�	�s�A0�0A>�=A>)	r=r>r?r@rrprjrmrarCrrr^r^�s#��
��G��O��>W�:rr^c�$�eZdZdZeZdZd�Zd�Zy)�POP3Factorya
    A POP3 server protocol factory.

    @ivar service: See L{__init__}

    @type protocol: no-argument callable which returns a L{Protocol
        <protocol.Protocol>} subclass
    @ivar protocol: A callable which creates a protocol.  The default value is
        L{VirtualPOP3}.
    Nc��||_y)zY
        @type service: L{MailService}
        @param service: An email service.
        N)r)rrs  rrzPOP3Factory.__init__ns��
��rc�h�tjj||�}|j|_|S)a
        Create an instance of a POP3 server protocol.

        @type addr: L{IAddress <twisted.internet.interfaces.IAddress>} provider
        @param addr: The address of the POP3 client.

        @rtype: L{POP3}
        @return: A POP3 protocol.
        )r	�
ServerFactoryrOrrPs   rrOzPOP3Factory.buildProtocolus,��
�"�"�0�0��t�<���L�L��	��r)	r=r>r?r@r^r	rrrOrCrrrvrv_s��	��H��G��rrvN)r@�zope.interfacer�twisted.copyrightr�twisted.cred.credentialsrr�twisted.cred.errorr�twisted.internetrr	�twisted.mailr
rr�twisted.pythonr
�IMessageDeliveryrrErHrJrU�POP3r^ryrvrCrr�<module>r�s���
�
'�)�I�0�,�*�*��
�T�
"�
"�#�r�r�$�r�j�+���,��+�$�"�"�+�\.�;�.�bc�$�)�)�c�L"�(�(�(�"r

Zerion Mini Shell 1.0