
    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       ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/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   "  99$))"2"27";;G7$q')Gd1g%.a84?'IGSii   	
   )*  	 tyyUJ!7885@4??CTT 	 x''1B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    " 99++$$(()9)94@Ay&&t||T:$$TYY%5%56A""188T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    " $$VS2QRR<<36==C#7$$VS2W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5L%5+/<< #KJ32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LL	;;r   )rZ   r   )N)rF   rG   rH   rI   rJ   r   SMTPr   rZ   r   r^   rM   rN   r   r   rW   rW      s!    
 yyH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!    ( zzH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6F <<$$TZZ>dmm   	3::/122	3s   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    $ ((.LL$	<;	<$	\\..v6F -d=tT]]S  M  	3::/122	3s   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>LD ||'S)SS'---..!4!;!;FMM'<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&!OU!>%*	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<LL	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   