Ϫf&0jdZddlmZddlmZddlmZmZddlm Z ddl m Z m Z ddl mZmZmZddlmZeej&Gd d ZGd d eZGd deZGddej.ZGddeZGddej2ZGdde j6Zy)z Mail protocol support. ) implementer) longversion)CramMD5CredentialsUsernamePassword)UnauthorizedLogin)deferprotocol)pop3relaysmtp)logcTeZdZUdZdZdZeed<ejfdZ dZ dZ dZ 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)serviceuserhost)selfrrrs 8/usr/lib/python3/dist-packages/twisted/mail/protocols.py__init__zDomainDeliveryBase.__init__%s   cdx}}|jrd|jjdz}|drd|dz}d|dzdz|dzd z|z|z}d |jzd z|jzd zt jd zdz}ddj t t|zdztjz}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 ) rencoderrrjoinmapbytesr rfc822date) rheloorigin recipientsauthStrheloStrfromUserbyforUsers rreceivedHeaderz!DomainDeliveryBase.receivedHeader4s" ' 99$))"2"27";;G 7$q')Gd1g%.a84?'IGS ii        )  *     tyyUJ!78 85 @4??CT T x''1B6@7JJrc|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 } which successfully fires with no-argument callable which returns L{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) rrqueuedomainsgetdestdomainr DomainQueuerr maybeDeferredexists)rrds r validateTozDomainDeliveryBase.validateToYs" 99++ $$(()9)94@Ay&&t||T: $$TYY%5%56A""188T22rc|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. izWho are you? Say HELO first.riz#Sender address must contain domain.)r SMTPBadSenderlocalr3)rr%r&s r validateFromzDomainDeliveryBase.validateFromrsO"$$VS2QR R <<3 6==C#7$$VS2WX X r)__name__ __module__ __qualname____doc__rrr#__annotations__r DNSNAMErr-r8r<rrrrs5 G5L%5+/<< #KJ32rrceZdZdZdZy)SMTPDomainDeliveryzA A domain delivery base class for use in an SMTP server. ssmtpNr=r>r?r@rrCrrrErEsLrrEceZdZdZdZy)ESMTPDomainDeliveryzB A domain delivery base class for use in an ESMTP server. sesmtpNrFrCrrrHrHsLrrHc:eZdZdZej ZdZddZdZ 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 } 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 } or L{None} @param portal: A portal to use for authentication. N)r rJrrportal)rrrLs rrzSMTPFactory.__init__s& !!$'  rctjd|tjj ||}|j |_|j |_|S)a Create an instance of an SMTP server protocol. @type addr: L{IAddress } provider @param addr: The address of the SMTP client. @rtype: L{SMTP} @return: An SMTP protocol. zConnection from )r msgr rJ buildProtocolrrLraddrps rrOzSMTPFactory.buildProtocolsK "4&)*    * *4 6LL ;;r)N) r=r>r?r@r SMTPr rLrrOrCrrrJrJs! yyH F rrJc8eZdZdZej ZdZdZdZ y) ESMTPFactorya An ESMTP server protocol factory. @type protocol: no-argument callable which returns a L{Protocol } subclass @ivar protocol: A callable which creates a protocol. The default value is L{ESMTP}. @type context: L{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 } subclass provider. @ivar challengers: A mapping of acceptable authorization mechanism to callable which creates credentials to use for authentication. NcJtj|g|dti|_y)zk @param args: Arguments for L{SMTPFactory.__init__} @see: L{SMTPFactory.__init__} sCRAM-MD5N)rJrr challengers)rargss rrzESMTPFactory.__init__s% T)D)');<rcvtj||}|j|_|j|_|S)a Create an instance of an ESMTP server protocol. @type addr: L{IAddress } provider @param addr: The address of the ESMTP client. @rtype: L{ESMTP} @return: An ESMTP protocol. )rJrOrWcontextctxrPs rrOzESMTPFactory.buildProtocols3  % %dD 1((  r) r=r>r?r@r ESMTPr rZrrOrCrrrUrUs!(zzHG= rrUc*eZdZdZdZdZdZdZdZy) 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 ||dtjS#t$r tjtcYSwxYw)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 }, L{IMailbox } provider, no-argument callable) @return: A deferred which fires when authentication is complete. If successful, it returns an L{IMailbox } interface, a mailbox and a logout function. If authentication fails, the deferred fails with an L{UnauthorizedLogin } error. N) lookupDomainr lookupPortalloginr APOPCredentialsmagicIMailboxKeyErrorrfailr)rrdigestr3rLs rauthenticateUserAPOPz VirtualPOP3.authenticateUserAPOP s*((. f \\..v6F<<$$TZZv>dmm  3::/12 2 3sA11&BBc|j|\}} |jj|}|jt ||dt j S#t$r tjtcYSwxYw)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 }, L{IMailbox } provider, no-argument callable) @return: A deferred which fires when authentication is complete. If successful, it returns an L{IMailbox } interface, a mailbox and a logout function. If authentication fails, the deferred fails with an L{UnauthorizedLogin } error. N) rarrbrcrr rfrgrrhr)rrpasswordr3rLs rauthenticateUserPASSz VirtualPOP3.authenticateUserPASS+sw*((. f W\\..v6F<< 0x @$ V V 3::/12 2 3sA&BBc |j|jd\}}||jjvr3t j 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) splitdomainSpecifier ValueErrorrr0r POP3Errorformatdecode)rrr3s rrazVirtualPOP3.lookupDomainHsy ::d&:&:A>LD& -- -..!4!;!;FMM'=A>) r=r>r?r@rrprjrmrarCrrr^r^s# GO>W:rr^c$eZdZdZeZdZdZdZy) POP3Factorya A POP3 server protocol factory. @ivar service: See L{__init__} @type protocol: no-argument callable which returns a L{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  rchtjj||}|j|_|S)a Create an instance of a POP3 server protocol. @type addr: L{IAddress } provider @param addr: The address of the POP3 client. @rtype: L{POP3} @return: A POP3 protocol. )r ServerFactoryrOrrPs rrOzPOP3Factory.buildProtocolus,  " " 0 0t <LL r) r=r>r?r@r^r rrrOrCrrrvrv_s HG rrvN)r@zope.interfacertwisted.copyrightrtwisted.cred.credentialsrrtwisted.cred.errorrtwisted.internetrr twisted.mailr r r twisted.pythonr IMessageDeliveryrrErHrJrUPOP3r^ryrvrCrrrs  ')I0,** T " "#rr$rj+,+$""+\.;.bc$))cL"((("r