HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/mail/__pycache__/protocols.cpython-38.pyc
U


W[d1�@sdZddlmZmZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZmZdd
lmZddlmZddlmZeej�Gd
d�d��ZGdd�de�ZGdd�de�ZGdd�dej�ZGdd�de�ZGdd�dej�ZGdd�dej�ZdS)z
Mail protocol support.
�)�absolute_import�division)�pop3)�smtp)�protocol)�defer)�longversion)�log)�CramMD5Credentials�UsernamePassword)�UnauthorizedLogin)�relay)�implementerc@s>eZdZdZdZdZejfdd�Zdd�Z	dd�Z
d	d
�ZdS)�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.
    NcCs||_||_||_dS)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)�selfrrr�r�8/usr/lib/python3/dist-packages/twisted/mail/protocols.py�__init__+szDomainDeliveryBase.__init__c	Cs�d}}|jrd|j�d�}|dr2d|d}d|dd|dd	||}d
|jd|jdt�d
�d}dd�tt|��dt�	�}d|d|d|S)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.
        �s auth=Zxtextrs helo=sfrom s ([��]sby s with s (�ascii�)sfor <� s> s
Received: s
	)
r�encoder�protocolNamer�join�map�bytesrZ
rfc822date)	r�helo�originZ
recipientsZauthStrZheloStrZfromUserZbyZforUserrrr�receivedHeader;s2��������z!DomainDeliveryBase.receivedHeadercCsX|jr:|jjr:|jj�|jjd�}|dkrJt�|jd�}n|jj|jj}t	�
|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)rrZqueue�domains�get�dest�domainr
ZDomainQueuerrZ
maybeDeferred�exists)rr�drrr�
validateTo[szDomainDeliveryBase.validateTocCs8|st�|dd��|jdkr4|jdkr4t�|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.)rZ
SMTPBadSenderZlocalr()rr"r#rrr�validateFromus��zDomainDeliveryBase.validateFrom)�__name__�
__module__�__qualname__�__doc__rrrZDNSNAMErr$r+r,rrrrrs rc@seZdZdZdZdS)�SMTPDomainDeliveryzA
    A domain delivery base class for use in an SMTP server.
    ssmtpN�r-r.r/r0rrrrrr1�sr1c@seZdZdZdZdS)�ESMTPDomainDeliveryzB
    A domain delivery base class for use in an ESMTP server.
    sesmtpNr2rrrrr3�sr3c@s,eZdZdZejZdZddd�Zdd�Z	dS)�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}.
    NcCstj�|�||_||_dS)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)rr4rr�portal)rrr5rrrr�s	zSMTPFactory.__init__cCs2t�d|f�tj�||�}|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 %s)r	�msgrr4�
buildProtocolrr5�rZaddr�prrrr7�s

zSMTPFactory.buildProtocol)N)
r-r.r/r0rZSMTPrr5rr7rrrrr4�s

r4c@s*eZdZdZejZdZdd�Zdd�Z	dS)�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.
    NcGstj|f|��dti|_dS)zk
        @param args: Arguments for L{SMTPFactory.__init__}

        @see: L{SMTPFactory.__init__}
        sCRAM-MD5N)r4rr
�challengers)r�argsrrrr�s�zESMTPFactory.__init__cCs t�||�}|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.
        )r4r7r;�contextZctxr8rrrr7�s
zESMTPFactory.buildProtocol)
r-r.r/r0rZESMTPrr=rr7rrrrr:�s
r:c@s0eZdZdZdZdZdd�Zdd�Zdd	�ZdS)
�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�@cCs`|�|�\}}z|j�|�}Wn tk
r>t�t��YSX|�t�	|j
||�dtj�SdS)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�KeyErrorr�failr�loginrZAPOPCredentials�magic�IMailbox)rrZdigestr(r5rrr�authenticateUserAPOPs�z VirtualPOP3.authenticateUserAPOPcCsZ|�|�\}}z|j�|�}Wn tk
r>t�t��YSX|�t||�dt	j
�SdS)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)r@rrArBrrCrrDrrrF)rrZpasswordr(r5rrr�authenticateUserPASS7s�z VirtualPOP3.authenticateUserPASScCsZz|�|jd�\}}Wntk
r.d}YnX||jjkrRt�d�|�d����||fS)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�
ValueErrorrr%rZ	POP3Error�format�decode)rrr(rrrr@Ys
�zVirtualPOP3.lookupDomain)	r-r.r/r0rrJrGrHr@rrrrr>s""r>c@s(eZdZdZeZdZdd�Zdd�ZdS)�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}.
    NcCs
||_dS)zY
        @type service: L{MailService}
        @param service: An email service.
        N)r)rrrrrr�szPOP3Factory.__init__cCstj�||�}|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�
ServerFactoryr7rr8rrrr7�s
zPOP3Factory.buildProtocol)	r-r.r/r0r>rrrr7rrrrrNrs

rNN) r0Z
__future__rrZtwisted.mailrrZtwisted.internetrrZtwisted.copyrightrZtwisted.pythonr	Ztwisted.cred.credentialsr
rZtwisted.cred.errorrr
Zzope.interfacerZIMessageDeliveryrr1r3r4r:ZPOP3r>rOrNrrrr�<module>s&t/4o