§
    Ètºf&0  ã                   óz  — d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZ ddlmZ  eej        ¦  «         G d	„ d
¦  «        ¦   «         Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ dej        ¦  «        Z G d„ de¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        ZdS )z
Mail protocol support.
é    )Úimplementer)Úlongversion)ÚCramMD5CredentialsÚUsernamePassword)ÚUnauthorizedLogin)ÚdeferÚprotocol)Úpop3ÚrelayÚsmtp)Úlogc                   óL   — e Zd ZU dZdZdZeed<   ej	        fd„Z
d„ Zd„ Zd„ ZdS )	Ú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.
    Ns   not-implemented-protocolÚprotocolNamec                 ó0   — || _         || _        || _        dS )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)Úselfr   r   r   s       úU/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/mail/protocols.pyÚ__init__zDomainDeliveryBase.__init__%   s   € ð ˆŒØˆŒ	ØˆŒ	ˆ	ˆ	ó    c                 ó¾  — dx}}| j         rd| j                              d¦  «        z   }|d         rd|d         z   }d|d         z   dz   |d         z   d	z   |z   |z   }d
| j        z   dz   | j        z   dz   t	          j        d¦  «        z   dz   }dd                     t          t          |¦  «        ¦  «        z   dz   t          j	        ¦   «         z   }d|z   dz   |z   dz   |z   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.
        r   s    auth=Úxtextr   s    helo=s   from s    ([é   ó   ]s   by s    with s    (Úasciió   )s   for <ó    s   > s
   Received: s   
	)
r   Úencoder   r   r   ÚjoinÚmapÚbytesr   Ú
rfc822date)	r   ÚheloÚoriginÚ
recipientsÚauthStrÚheloStrÚfromUserÚbyÚforUsers	            r   ÚreceivedHeaderz!DomainDeliveryBase.receivedHeader4   s  € ð"  Ðˆ�'ØŒ9ð 	<Ø $¤)×"2Ò"2°7Ñ";Ô";Ñ;ˆGØ�Œ7ð 	*Ø $ q¤'Ñ)ˆGØ˜d 1œgÑ%¨Ñ.°°a´Ñ8¸4Ñ?À'ÑIÈGÑSˆàØŒiñàñð Ôñ ð ñ	õ
 Ô  Ñ)Ô)ñ*ð ñð 	ð �t—y’y¥¥U¨JÑ!7Ô!7Ñ8Ô8Ñ8¸5Ñ@Å4Ä?ÑCTÔCTÑTð 	ð ˜xÑ'¨'Ñ1°BÑ6¸Ñ@À7ÑJÐJr   c                 ó"  — | j         rS| j        j        rG| j        j                             |j        j        d¦  «        }|€t          j        | j        d¦  «        }n| j        j        |j        j                 }t          j
        |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)r   r   ÚqueueÚdomainsÚgetÚdestÚdomainr   ÚDomainQueuerr   ÚmaybeDeferredÚexists)r   r   Úds      r   Ú
validateTozDomainDeliveryBase.validateToY   s|   € ð" Œ9ð 	7˜œÔ+ð 	7Ø”Ô$×(Ò(¨¬Ô)9¸4Ñ@Ô@ˆAØˆyÝÔ& t¤|°TÑ:Ô:�øà”Ô$ T¤YÔ%5Ô6ˆAÝÔ" 1¤8¨TÑ2Ô2Ð2r   c                 óŽ   — |st          j        |dd¦  «        ‚|j        dk    r!|j        dk    rt          j        |dd¦  «        ‚|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÷  zWho are you?  Say HELO first.r   iõ  z#Sender address must contain domain.)r   ÚSMTPBadSenderÚlocalr3   )r   r%   r&   s      r   ÚvalidateFromzDomainDeliveryBase.validateFromr   sW   € ð" ð 	SÝÔ$ V¨SÐ2QÑRÔRÐRØŒ<˜3ÒÐ 6¤=°CÒ#7Ð#7ÝÔ$ V¨SÐ2WÑXÔXÐXØˆr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   Ú__annotations__r   ÚDNSNAMEr   r-   r8   r<   © r   r   r   r      s�   € € € € € € ð
ð 
ð €GØ5€L�%Ð5Ð5Ñ5à+/¬<ð ð ð ð ð#Kð #Kð #KðJ3ð 3ð 3ð2ð ð ð ð r   r   c                   ó   — e Zd ZdZdZdS )ÚSMTPDomainDeliveryzA
    A domain delivery base class for use in an SMTP server.
    s   smtpN©r=   r>   r?   r@   r   rC   r   r   rE   rE   Š   s   € € € € € ðð ð €L€L€Lr   rE   c                   ó   — e Zd ZdZdZdS )ÚESMTPDomainDeliveryzB
    A domain delivery base class for use in an ESMTP server.
    s   esmtpNrF   rC   r   r   rH   rH   ’   s   € € € € € ðð ð €L€L€Lr   rH   c                   ó2   — e Zd ZdZej        ZdZdd„Zd„ Z	dS )Ú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                 ó`   — t           j                             | ¦  «         || _        || _        dS )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   rJ   r   r   Úportal)r   r   rL   s      r   r   zSMTPFactory.__init__ª   s-   € õ 	Ô×!Ò! $Ñ'Ô'Ð'ØˆŒØˆŒˆˆr   c                 ó¤   — t          j        d|› �¦  «         t          j                             | |¦  «        }| 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.
        zConnection from )r   Úmsgr   rJ   ÚbuildProtocolr   rL   ©r   ÚaddrÚps      r   rO   zSMTPFactory.buildProtocol·   sL   € õ 	ŒÐ) 4Ð)Ð)Ñ*Ô*Ð*ÝÔ×*Ò*¨4°Ñ6Ô6ˆØ”LˆŒ	Ø”;ˆŒØˆr   )N)
r=   r>   r?   r@   r   ÚSMTPr	   rL   r   rO   rC   r   r   rJ   rJ   š   sO   € € € € € ð
ð 
ð Œy€HØ€Fðð ð ð ðð ð ð ð r   rJ   c                   ó0   — e Zd ZdZej        ZdZd„ Zd„ Z	dS )Ú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                 óF   — t          j        | g|¢R Ž  dt          i| _        dS )zk
        @param args: Arguments for L{SMTPFactory.__init__}

        @see: L{SMTPFactory.__init__}
        s   CRAM-MD5N)rJ   r   r   Úchallengers)r   Úargss     r   r   zESMTPFactory.__init__à   s1   € õ 	Ô˜TÐ) DÐ)Ð)Ð)Ð)Ø'Õ);Ð<ˆÔÐÐr   c                 ól   — 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.
        )rJ   rO   rW   ÚcontextÚctxrP   s      r   rO   zESMTPFactory.buildProtocolé   s1   € õ ×%Ò% d¨DÑ1Ô1ˆØÔ(ˆŒØ”ˆŒØˆr   )
r=   r>   r?   r@   r   ÚESMTPr	   rZ   r   rO   rC   r   r   rU   rU   È   sJ   € € € € € ðð ð( Œz€HØ€Gð=ð =ð =ðð ð ð ð r   rU   c                   ó,   — e Zd ZdZdZdZd„ Zd„ Zd„ ZdS )Ú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                             |¦  «        }|                     t	          j        | j        ||¦  «        dt          j        ¦  «        S # t          $ r# t          j
        t          ¦   «         ¦  «        cY S w xY w)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   )r   r   Údigestr3   rL   s        r   ÚauthenticateUserAPOPz VirtualPOP3.authenticateUserAPOP  s¡   € ð* ×(Ò(¨Ñ.Ô.‰ˆˆfð	Ø”\×.Ò.¨vÑ6Ô6ˆFð —<’<ÝÔ$ T¤Z°°vÑ>Ô>ÀÅdÄmñô ð øõ ð 	3ð 	3ð 	3Ý”:Õ/Ñ1Ô1Ñ2Ô2Ð2Ð2Ð2ð	3øøøs   šA. Á.*BÂBc                 ó&  — |                       |¦  «        \  }}	 | j                             |¦  «        }|                     t	          ||¦  «        dt
          j        ¦  «        S # t          $ r# t          j	        t          ¦   «         ¦  «        cY S w xY w)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)ra   r   rb   rc   r   r
   rf   rg   r   rh   r   )r   r   Úpasswordr3   rL   s        r   ÚauthenticateUserPASSz VirtualPOP3.authenticateUserPASS+  s•   € ð* ×(Ò(¨Ñ.Ô.‰ˆˆfð	WØ”\×.Ò.¨vÑ6Ô6ˆFð —<’<Õ 0°°xÑ @Ô @À$ÍÌÑVÔVÐVøõ ð 	3ð 	3ð 	3Ý”:Õ/Ñ1Ô1Ñ2Ô2Ð2Ð2Ð2ð	3øøøs   šA# Á#*BÂBc                 óþ   — 	 |                      | j        d¦  «        \  }}n# t          $ r d}Y nw xY w|| j        j        vr:t          j        d                     |                     d¦  «        ¦  «        ¦  «        ‚||fS )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.
        r   r   zno such domain {}zutf-8)	ÚsplitÚdomainSpecifierÚ
ValueErrorr   r0   r
   Ú	POP3ErrorÚformatÚdecode)r   r   r3   s      r   ra   zVirtualPOP3.lookupDomainH  sŒ   € ð	ØŸ:š: dÔ&:¸AÑ>Ô>‰LˆD�&�&øÝð 	ð 	ð 	ØˆFˆFˆFð	øøøà˜œÔ-Ð-Ð-Ý”.Ð!4×!;Ò!;¸F¿MºMÈ'Ñ<RÔ<RÑ!SÔ!SÑTÔTÐTØ�Vˆ|Ðs   ‚! ¡0¯0)	r=   r>   r?   r@   r   rp   rj   rm   ra   rC   r   r   r^   r^   ù   sZ   € € € € € ð
ð 
ð €Gà€Oðð ð ð>Wð Wð Wð:ð ð ð ð r   r^   c                   ó&   — e Zd ZdZeZdZd„ Zd„ ZdS )Ú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                 ó   — || _         dS )zY
        @type service: L{MailService}
        @param service: An email service.
        N)r   )r   r   s     r   r   zPOP3Factory.__init__n  s   € ð
 ˆŒˆˆr   c                 ó^   — t           j                             | |¦  «        }| 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	   ÚServerFactoryrO   r   rP   s      r   rO   zPOP3Factory.buildProtocolu  s*   € õ Ô"×0Ò0°°tÑ<Ô<ˆØ”LˆŒ	Øˆr   )	r=   r>   r?   r@   r^   r	   r   r   rO   rC   r   r   rv   rv   _  sH   € € € € € ð	ð 	ð €HØ€Gðð ð ðð ð ð ð r   rv   N)r@   Úzope.interfacer   Útwisted.copyrightr   Útwisted.cred.credentialsr   r   Útwisted.cred.errorr   Útwisted.internetr   r	   Útwisted.mailr
   r   r   Útwisted.pythonr   ÚIMessageDeliveryr   rE   rH   rJ   rU   ÚPOP3r^   ry   rv   rC   r   r   ú<module>rƒ      s  ðð
ð ð
 'Ð &Ð &Ð &Ð &Ð &à )Ð )Ð )Ð )Ð )Ð )Ø IÐ IÐ IÐ IÐ IÐ IÐ IÐ IØ 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ø Ð Ð Ð Ð Ð ð €ˆTÔ"Ñ#Ô#ðrð rð rð rð rñ rô rñ $Ô#ðrðjð ð ð ð Ð+ñ ô ð ðð ð ð ð Ð,ñ ô ð ð+ð +ð +ð +ð +�$Ô"ñ +ô +ð +ð\.ð .ð .ð .ð .�;ñ .ô .ð .ðbcð cð cð cð c�$”)ñ cô cð cðL"ð "ð "ð "ð "�(Ô(ñ "ô "ð "ð "ð "r   