ó
    Ö›‘h@1  ã                  ó   • S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
JrJr  SSKJr  SSKJrJr  SS	KJrJrJr  SS
KJr  \(       a  SSKJr  \" \R4                  5       " S S5      5       r " S S\5      r " S S\5      r " S S\R<                  5      r " S S\5      r " S S\R@                  5      r! " S S\RD                  5      r#g)z
Mail protocol support.
é    )Úannotations)ÚTYPE_CHECKINGÚCallable)Úimplementer)Úlongversion)ÚCramMD5CredentialsÚUsernamePassword)ÚUnauthorizedLogin)ÚdeferÚprotocol)Úpop3ÚrelayÚsmtp)Úlog)ÚMailServicec                  ó^   • \ rS rSr% SrSrSrS\S'   \R                  4S jr
S rS	 rS
 rSrg)ÚDomainDeliveryBaseé   a.  
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ÚbytesÚprotocolNamec                ó(   • Xl         X l        X0l        g)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       ÚZC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/mail/protocols.pyÚ__init__ÚDomainDeliveryBase.__init__*   s   € ð ŒØŒ	Ø�	ó    c                óÎ  • S=pEU R                   (       a  SU R                   R                  S5      -   nUS   (       a  SUS   -   nSUS   -   S-   US   -   S	-   U-   U-   nS
U R                  -   S-   U R                  -   S-   [        R                  " S5      -   S-   nSSR                  [        [        U5      5      -   S-   [        R                  " 5       -   nSU-   S-   U-   S-   U-   $ )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Úmapr   r   Ú
rfc822date)	r   ÚheloÚoriginÚ
recipientsÚauthStrÚheloStrÚfromUserÚbyÚforUsers	            r   ÚreceivedHeaderÚ!DomainDeliveryBase.receivedHeader9   s  € ð"  ÐˆØ�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ÐJr   c                ó´  • U R                   (       az  U R                  R                  (       a_  U R                  R                  R	                  UR
                  R                  S5      nUc!  [        R                  " U R                  S5      nO-U R                  R                  UR
                  R                     n[        R                  " UR                  U5      $ )aá  
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   Ú
validateToÚDomainDeliveryBase.validateTo^   sŽ   € ð" �9�9˜Ÿ™×+×+Ø—‘×$Ñ$×(Ñ(¨¯©×)9Ñ)9¸4Ó@ˆAØ‰yÜ×&Ò& t§|¡|°TÓ:�øà—‘×$Ñ$ T§Y¡Y×%5Ñ%5Ñ6ˆAÜ×"Ò" 1§8¡8¨TÓ2Ð2r   c                ó´   • U(       d  [         R                  " USS5      eUR                  S:w  a(  UR                  S:X  a  [         R                  " USS5      eU$ )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Úlocalr:   )r   r+   r,   s      r   ÚvalidateFromÚDomainDeliveryBase.validateFromw   sO   € ö" Ü×$Ò$ V¨SÐ2QÓRÐRØ�<‰<˜3Ó 6§=¡=°CÓ#7Ü×$Ò$ V¨SÐ2WÓXÐXØˆr   )r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Ú__annotations__r   ÚDNSNAMEr   r3   r?   rD   Ú__static_attributes__© r   r   r   r      s5   ‡ ñ
ð €GØ5€L�%Ó5à+/¯<©<ô ò#KòJ3õ2r   r   c                  ó   • \ rS rSrSrSrSrg)ÚSMTPDomainDeliveryé�   z9
A domain delivery base class for use in an SMTP server.
s   smtprN   N©rF   rG   rH   rI   rJ   r   rM   rN   r   r   rP   rP   �   s   † ñð ƒLr   rP   c                  ó   • \ rS rSrSrSrSrg)ÚESMTPDomainDeliveryé—   z:
A domain delivery base class for use in an ESMTP server.
s   esmtprN   NrR   rN   r   r   rT   rT   —   s   † ñð ƒLr   rT   c                  óD   • \ rS rSrSr\R                  rSrSS jr	S r
Srg)ÚSMTPFactoryéŸ   a  
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                óZ   • [         R                  R                  U 5        Xl        X l        g)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   rW   r   r   Úportal)r   r   rZ   s      r   r   ÚSMTPFactory.__init__¯   s"   € ô 	×Ñ×!Ñ! $Ô'ØŒØ�r   c                óº   • [         R                  " SU 35        [        R                  R	                  X5      nU R
                  Ul        U R                  Ul        U$ )zÒ
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   rW   ÚbuildProtocolr   rZ   ©r   ÚaddrÚps      r   r^   ÚSMTPFactory.buildProtocol¼   sI   € ô 	�ŠÐ" 4 &Ð)Ô*Ü×Ñ×*Ñ*¨4Ó6ˆØ—L‘LˆŒ	Ø—;‘;ˆŒØˆr   )rZ   r   )N)rF   rG   rH   rI   rJ   r   ÚSMTPr   rZ   r   r^   rM   rN   r   r   rW   rW   Ÿ   s!   † ñ
ð �y‰y€HØ€Fôõr   rW   c                  ó@   • \ rS rSrSr\R                  rSrS r	S r
Srg)ÚESMTPFactoryéÍ   aà  
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                óL   • [         R                  " U /UQ76   S[        0U l        g)zS
@param args: Arguments for L{SMTPFactory.__init__}

@see: L{SMTPFactory.__init__}
s   CRAM-MD5N)rW   r   r   Úchallengers)r   Úargss     r   r   ÚESMTPFactory.__init__å   s%   € ô 	×Ò˜TÐ) DÓ)Ø'Ô);Ð<ˆÕr   c                ót   • [         R                  X5      nU R                  Ul        U R                  Ul        U$ )zÖ
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.
)rW   r^   rh   ÚcontextÚctxr_   s      r   r^   ÚESMTPFactory.buildProtocolî   s1   € ô ×%Ñ% dÓ1ˆØ×(Ñ(ˆŒØ—‘ˆŒØˆr   )rh   )rF   rG   rH   rI   rJ   r   ÚESMTPr   rl   r   r^   rM   rN   r   r   re   re   Í   s!   † ñð( �z‰z€HØ€Gò=õr   re   c                  ó\   • \ rS rSr% SrSrS\S'   SrS\S'   S	 r      SS
 jr	SS jr
Srg)ÚVirtualPOP3éþ   zý
A virtual hosting POP3 server.

@ivar service: The email service that created this server.  This must be
    set by the service.

@ivar domainSpecifier: The character to use to split an email address into
    local-part and domain. The default is '@'.
NzMailService | Noner   ó   @r   ÚdomainSpecifierc                ó<  • U R                  U5      u  p U R                  R                  U5      nUR                  [        R
                  " U R                  X5      S[        R                  5      $ ! [         a!    [        R                  " [        5       5      s $ f = f)a¹  
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   Údigestr:   rZ   s        r   ÚauthenticateUserAPOPÚ VirtualPOP3.authenticateUserAPOP  s‚   € ð* ×(Ñ(¨Ó.‰ˆð	Ø—\‘\×.Ñ.¨vÓ6ˆFð —<‘<Ü×$Ò$ T§Z¡Z°Ó>ÀÄdÇmÁmóð øô ó 	3Ü—:’:Ô/Ó1Ó2Ò2ð	3ús   •A0 Á0(BÂBc                ó<  • U R                  U5      u  pU R                  c   S5       e U R                  R                  U5      nUR                  [	        X5      S[
        R                  5      nU$ ! [         a!    [        R                  " [        5       5      s $ f = f)a  
Perform authentication for a username/password login.

Override the default lookup scheme to allow virtual domains.

@param user: The name of the user attempting to log in.

@param password: The password to authenticate with.

@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.
Nz.must have a service to be able to authenticate)rv   r   rw   rx   r	   r   r{   r|   r   r}   r
   )r   r   Úpasswordr:   rZ   Úresults         r   ÚauthenticateUserPASSÚ VirtualPOP3.authenticateUserPASS.  s•   € ð$ ×(Ñ(¨Ó.‰ˆà�L‰LÑ$ð	<à;ó	<Ø$ð	Ø—\‘\×.Ñ.¨vÓ6ˆFð —‘Ô-¨dÓ=¸tÄTÇ]Á]ÓSð ð ˆMøô ó 	3Ü—:’:Ô/Ó1Ó2Ò2ð	3ús   ©A0 Á0(BÂBc                ó,  •  UR                  U R                  S5      u  pU R                  c   S5       eX R                  R                  ;  a4  [
        R                  " SR                  UR                  S5      5      5      eX4$ ! [         a    Sn Nrf = f)aC  
Check whether a domain part of the given email address is among the
virtual domains supported by the mail service.

@param user: An email address.

@return: a 2-tuple of (local part, 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(cannot look up domain if service not setzno such domain {}zutf-8)	Úsplitrt   Ú
ValueErrorr   r7   r   Ú	POP3ErrorÚformatÚdecode)r   r   r:   s      r   rv   ÚVirtualPOP3.lookupDomainN  s‰   € ð	ØŸ:™: d×&:Ñ&:¸AÓ>‰LˆDð �|‰|Ñ'ÐSÐ)SÓSÐ'ØŸ™×-Ñ-Ó-Ü—.’.Ð!4×!;Ñ!;¸F¿M¹MÈ'Ó<RÓ!SÓTÐTØˆ|Ðøô ó 	ØŠFð	ús   ‚B ÂBÂBrN   )r   r   r‚   r   ÚreturnzMdefer.Deferred[tuple[type[pop3.IMailbox], pop3.IMailbox, Callable[[], None]]])r   r   r�   ztuple[bytes, bytes])rF   rG   rH   rI   rJ   r   rK   rt   r   r„   rv   rM   rN   r   r   rq   rq   þ   sF   ‡ ñð #'€GÐÓ&à!€O�UÓ!òð>ØðØ%*ðà	Vô÷@r   rq   c                  ó,   • \ rS rSrSr\rSrS rS r	Sr
g)ÚPOP3Factoryid  a  
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                ó   • Xl         g)zA
@type service: L{MailService}
@param service: An email service.
N©r   )r   r   s     r   r   ÚPOP3Factory.__init__s  s	   € ð
 �r   c                óf   • [         R                  R                  X5      nU R                  Ul        U$ )zÐ
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   ÚServerFactoryr^   r   r_   s      r   r^   ÚPOP3Factory.buildProtocolz  s*   € ô ×"Ñ"×0Ñ0°Ó<ˆØ—L‘LˆŒ	Øˆr   r‘   )rF   rG   rH   rI   rJ   rq   r   r   r   r^   rM   rN   r   r   r�   r�   d  s   † ñ	ð €HØ€Gòõr   r�   N)$rJ   Ú
__future__r   Útypingr   r   Úzope.interfacer   Útwisted.copyrightr   Útwisted.cred.credentialsr   r	   Útwisted.cred.errorr
   Útwisted.internetr   r   Útwisted.mailr   r   r   Útwisted.pythonr   Útwisted.mail.mailr   ÚIMessageDeliveryr   rP   rT   rW   re   ÚPOP3rq   r”   r�   rN   r   r   Ú<module>r¢      s·   ðñ
õ #ç *å &å )ß IÝ 0ß ,ß *Ñ *Ý æÝ-ñ ˆT×"Ñ"Ó#÷rð ró $ðrôjÐ+ô ôÐ,ô ô+�$×"Ñ"ô +ô\.�;ô .ôbc�$—)‘)ô côL"�(×(Ñ(õ "r   