ϪfUdZddlZddlZddlZddlmZddlmZmZm Z m Z m Z ddl m Z mZddlZddlZddlZddlZddlmZddlmZmZddlmZdd lmZdd lmZmZdd lmZmZmZmZm Z m!Z!m"Z"dd l#m$Z$m%Z%dd l&m'Z'ddl(m)Z)ddl*m+Z+m,Z,ddl-m.Z.ddl/m0Z0e e1e2d< ddl3m4Z4m5Z5dZ6ejpjse!sdZ6dZ:ee'jvGddZ<GddZ=GddZ>dZ?GddZ@Gd d!e@e'jZBGd"d#e@e'jZDGd$d%ZEGd&d'e+jZGGd(d)e0eEZHGd*d+ZIGd,d-ZJGd.d/eJe'jZLGd0d1eJe'jZNGd2d3ZOGd4d5eOe0ZPGd6d7eOe0ZQeejj,Gd8d9ZSee'jGd:d;ZUGd<d=ZVGd>d?e0eEZWGd@dAe0ZXGdBdCeDZYGdDdEe0eEZZGdFdGe0Z[GdHdIe0eEZ\GdJdKe jZ^GdLdMe0Z_GdNdOe0Z`eeGdPdQZaGdRdSZbGdTdUe0ZcGdVdWe0ZdGdXdYe0ZeGdZd[e0ZfGd\d]e0ZgGd^d_e0ZhGd`dae%ZiGdbdce0Zjy#e7$rdZ6Y\wxYw)dz* Test cases for twisted.mail.smtp module. N)BytesIO)AnyListOptionalTupleType)directlyProvides implementer)cred)AllowAnonymousAccessICredentialsChecker) IAnonymous)UnauthorizedLogin)IRealmPortal)addressdefererror interfacesprotocolreactortask) MemoryReactorStringTransport)smtp)LOGINCredentials)basicloopback)LineLog)TestCasesslSkip)ClientTLSContextServerTLSContextzOpenSSL not presentzReactor doesn't support SSLcyN)spameggss =/usr/lib/python3/dist-packages/twisted/mail/test/test_smtp.py spameaterr*/s c(eZdZdZdZdZdZdZy) BrokenMessagez L{BrokenMessage} is an L{IMessage} which raises an unexpected exception from its C{eomReceived} method. This is useful for creating a server which can be used to test client retry behavior. cyr%r&selfusers r)__init__zBrokenMessage.__init__; r+cyr%r&r0lines r) lineReceivedzBrokenMessage.lineReceived>r3r+ctd)Nz"Some problem, delivery is failing.) RuntimeErrorr0s r) eomReceivedzBrokenMessage.eomReceivedAs?@@r+cyr%r&r:s r)connectionLostzBrokenMessage.connectionLostDr3r+N)__name__ __module__ __qualname____doc__r2r7r;r=r&r+r)r-r-3s   A r+r-c"eZdZdZdZdZdZy) DummyMessagez L{BrokenMessage} is an L{IMessage} which saves the message delivered to it to its domain object. @ivar domain: A L{DummyDomain} which will be used to store the message once it is received. c.||_||_g|_yr%)domainr1buffer)r0rEr1s r)r2zDummyMessage.__init__Qs   r+chtjd|s|jj|yy)Ns/Received: From yyy.com \(\[.*\]\) by localhost;)rematchrFappendr5s r)r7zDummyMessage.lineReceivedVs)xxKTR KK  t $Sr+cdj|jdz}|jj|jj j j|tj}|jd|S)N saved) joinrFrEmessagesr1destlocalrJrDeferredcallback)r0messagedeferreds r)r;zDummyMessage.eomReceived[sc**T[[)E1 TYY^^11299'B>>#(#r+N)r>r?r@rAr2r7r;r&r+r)rCrCHs % r+rCceZdZdZdZdZy) DummyDomainzf L{DummyDomain} is an L{IDomain} which keeps track of messages delivered to it in memory. c>i|_|D]}g|j|<yr%)rO)r0namesnames r)r2zDummyDomain.__init__is&  %D"$DMM$  %r+cjjjvrtjfdStj t jS)NctSr%rCr/sr)z$DummyDomain.exists..psdD)Ar+)rPrQrOrsucceedfailr SMTPBadRcptr/s``r)existszDummyDomain.existsnsA 99??dmm +==!AB Bzz$**4011r+N)r>r?r@rAr2rbr&r+r)rWrWcs % 2r+rWsSubject: hello Goodbye c2eZdZddZdZdZdZdZdZy) MyClientNcj|ddgttf}|d|_|d|_|d|_y)Nzmoshez@foo.barr)rmail_sender _recipient_datar0 messageInfos r)r2zMyClient.__init__|s=  +.>-?OK"1~ %a. ^ r+c|jSr%)rir:s r) getMailFromzMyClient.getMailFroms ||r+c|jSr%)rjr:s r) getMailTozMyClient.getMailTos r+c|jSr%)rkr:s r) getMailDatazMyClient.getMailDatas zzr+c||_yr%)_error)r0excs r) sendErrorzMyClient.sendErrors  r+c.d|_d|_d|_yr%)rirjrk)r0coderespnumOk addresseslogs r)sentMailzMyClient.sentMails  r+r%) r>r?r@r2rorqrsrwr~r&r+r)rdrd{s $r+rdceZdZddZy) MySMTPClientNcptjj|dtj||yNsfoo.baz)r SMTPClientr2rdrls r)r2zMySMTPClient.__init__s&   z2$ ,r+r%r>r?r@r2r&r+r)rrs-r+rceZdZddZy) MyESMTPClientNcrtjj|||dtj|yr)r ESMTPClientr2rd)r0secretcontextFactorys r)r2zMyESMTPClient.__init__s* !!$ K$r+)r+Nrr&r+r)rrs r+rceZdZdZy) LoopbackMixinc.tj||Sr%)r loopbackTCP)r0serverclients r)rzLoopbackMixin.loopbacks##FF33r+N)r>r?r@rr&r+r)rrs4r+rc eZdZgdZdZdZy)FakeSMTPServer) 220 hellos250 nice to meet you 250 greatrs354 go on, ladcg|_|jdd|_|jj|j|jj yr%)rF clientDatareversesendLinepopr:s r)connectionMadezFakeSMTPServer.connectionMadesB //!, ! doo))+,r+c|jj||dk(r6|jjd|jj n@|dk(r|jjdn|dk(r|jj |j r*|j |j jyy)NsQUITs221 see ya around .s 250 gotcha RSET)rFrJ transportwriteloseConnectionrrrr5s r)r7zFakeSMTPServer.lineReceiveds 4 7? NN !9 : NN ) ) + T\ NN !2 3 W_ NN ) ) + ?? MM$//--/ 0 r+N)r>r?r@rrr7r&r+r)rrsJ- 1r+rc<eZdZdZdZgdZdZdZdZdZ dZ y ) SMTPClientTestsz' Tests for L{smtp.SMTPClient}. cpg}t}|j|_|jt |j d|j |j|dtj|j|dj|jt|ddy)z L{smtp.SMTPClient.timeoutConnection} calls the C{sendError} hook with a fatal L{SMTPTimeoutError} with the current line log. rrsHTimeout waiting for SMTP server response <<< 220 hello >>> HELO foo.baz N)rrJrwmakeConnectionrr7timeoutConnectionassertIsInstancerSMTPTimeoutError assertTrueisFatal assertEqualbytes)r0errorsrs r)test_timeoutConnectionz&SMTPClientTests.test_timeoutConnections !==o/0L)  " fQi)>)>? q ))*  &)  " r+) s HELO foo.bazsMAIL FROM:sRCPT TO:sDATAsSubject: hellor+sGoodbyerrct}tj|}|jfd|S)z L{smtp.SMTPClient} sends I{HELO}, I{MAIL FROM}, I{RCPT TO}, and I{DATA} commands based on the return values of its C{getMailFrom}, C{getMailTo}, and C{getMailData} methods. cPjjjSr%)rrFexpected_outputxr0rs r)r^z/SMTPClientTests.test_messages..s 0 0@T@T Ur+)rrr addCallback)r0rdrs` @r) test_messageszSMTPClientTests.test_messagess6 ! MM&& ) UVr+cntddgtdf}t}|j||j d|j |j d|j|j|j j|j|jty)z If there is an error while producing the message body to the connection, the C{sendError} callback is invoked. zalice@example.comzbob@example.comfoo(220 Ok 250 Ok 250 Ok 250 Ok 354 Ok N) rrrr dataReceivedassertNotIdenticalproducer assertFalse streaming stopProducingrru Exceptionr0rrs r)test_transferErrorz"SMTPClientTests.test_transferErrors  #4"5wv G $% i(    2 2D9 ,,- ((* fmmY7r+c(tjd}t}|j||j tj ddd|j |jd|j|jy)z If L{smtp.SMTPClient.sendError} is called with an L{SMTPClientError} which is fatal, it disconnects its transport without writing anything more to it. N{fooTrr+) rrrrrwSMTPClientErrorrvaluer disconnectingrs r)test_sendFatalErrorz#SMTPClientTests.test_sendFatalErrorsn &#% i(--c5$GH *C0  //0r+c(tjd}t}|j||j tj ddd|j |jd|j|jy)z If L{smtp.SMTPClient.sendError} is called with an L{SMTPClientError} which is not fatal, it sends C{"QUIT"} and waits for the server to close the connection. NrrFrQUIT ) rrrrrwrrrrrrs r)test_sendNonFatalErrorz&SMTPClientTests.test_sendNonFatalErrorsp &#% i(--c5%HI *K8 001r+ctjd}t}|j||j t d|j |jd|j|jy)z If L{smtp.SMTPClient.sendError} is called with an exception which is not an L{SMTPClientError}, it disconnects its transport without writing anything more to it. Nrr+) rrrrrwrrrrrrs r)test_sendOtherErrorz#SMTPClientTests.test_sendOtherError+sd &#% i(5)* *C0  //0r+N) r>r?r@rArrrrrrrr&r+r)rrs, ( O 88 1 2 1r+rceZdZdZdZdZy)DummySMTPMessagec.||_||_g|_yr%)rusersrF)r0rrs r)r2zDummySMTPMessage.__init__:s    r+c:|jj|yr%)rFrJr5s r)r7zDummySMTPMessage.lineReceived?s 4 r+cdj|jdz}|jdjdt |jdj }}g}|jD]}|j t |||||f|jjt|<tjdS)NrLrrM) rNrFrhelororigrJrrTtuplerr_)r0rTrorigin recipientsr1s r)r;zDummySMTPMessage.eomReceivedBs**T[[)E1zz!}))!,eDJJqM4F4F.Gf JJ +D   eDk * +48&*g3V eJ/0}}X&&r+N)r>r?r@r2r7r;r&r+r)rr9s !'r+rc$eZdZdZdZdZdZy) DummyProtocH|jj|i|_yr%)dummyMixinBaserrTr:s r)rzDummyProto.connectionMadeMs **40 r+cyr%r&)r's r)receivedHeaderzDummyProto.receivedHeaderQr+c2td_fdS)NctgSr%)rr/sr)r^z'DummyProto.validateTo..Vs'tf5r+)SimpleDeliverydeliveryr/s``r) validateTozDummyProto.validateToTs&t, 55r+c|Sr%r&r0rrs r) validateFromzDummyProto.validateFromX r+N)r>r?r@rrrrr&r+r)rrLs6r+rc$eZdZejZy) DummySMTPN)r>r?r@rSMTPrr&r+r)rr\s YYNr+rc$eZdZejZy) DummyESMTPN)r>r?r@rESMTPrr&r+r)rr`s ZZNr+rc eZdZUdZeeejed<dZ eee jed<dddgddgdfddd d gdd d gd fdd d gddgdfgZ gdZ eeeeeefed<e D]a\ZZZZZZe j1dezdzdddfeD]Ze j1dezdzdddfe j1ddedeeeefffcdZy)AnotherTestCaseN serverClass clientClassfoo.comsmoshez@foo.comsmoshez@bar.coms(From: Moshe To: Moshe Hi, how are you? s tttt@rrr.comsuuu@ooosyyy@eeesSubject: pass ..rrrr.. s@this,@is,@ignored:foo@bar.coms@ignore,@this,@too:bar@foo.coms foo@bar.coms bar@foo.coms Subject: apa To: foo 123 . 456 ))r+s220.* $NN)sHELO foo.com 250.* $NN)sRSET rNNdatas MAIL FROM: s250.* s RCPT TO:\}}}}|r|j ||j }|jtj||s t||||dddk(sh|jD]%} | r | dddk(rd| z} |j | d z'|j d |j }|j|\} } tj| |s t| || d D]?} t| dd} | g| d <|j|j| ft| AA|j!dy) a Exercise a lot of the SMTP client code. This is a "shotgun" style unit test. It does a lot of things and hopes that something will go really wrong if it is going to go wrong. This test should be replaced with a suite of nicer tests. ceZdZdZy)/AnotherTestCase.test_buffer..fooFactoryrN)r>r?r@rEr&r+r) fooFactoryrsFr+rNs354rrfr s. rg)rrfactoryrrrrclearrHrIAssertionError splitlineslistrrTr setTimeout)r0rarsendexpectmsg msgexpectrr6rzmsgdatarecipexpecteds r) test_bufferzAnotherTestCase.test_buffers$%      L  #,0II K (D&#yt$??$D OO 88FD)$T6488BQx6!NN,3DQq T 1#d{NN4'>23x(!(! ) gxxd+(t44$QZKE#GAJ/H#('HQK$$QYYx%8%/JK) K0 Tr+)r>r?r@rrrrProtocol__annotations__rrrrOrrrrrhelo_from_to_realfromrealtorrJrcptr r&r+r)rrdsc59K$x0012937K$t/07             $   $    - . /      7*HX1D$uUE3+, - 5=  0uc8VS ^e+h6 dDQR TD KK,x7tTR S T x=>    'r+rceZdZeZeZy)AnotherESMTPTestsN)r>r?r@rrrrr&r+r)rrs KKr+rceZdZeZeZy)AnotherSMTPTestsN)r>r?r@rrrrr&r+r)rrs KKr+rcxeZdZddiZej j ej jfZdZ dZ y) DummyCheckertestuser testpasswordctj|j|j|jj |j |jSr%)r maybeDeferred checkPasswordrusernamer_cbCheckr0 credentialss r)requestAvatarIdzDummyChecker.requestAvatarIdsE""  % %tzz+2F2F'G +dmm[%9%9 : ;r+cF|r|Stjjr%)r rr)r0resultrs r)r zDummyChecker._cbChecks Ojj**,,r+N) r>r?r@rr r"IUsernamePasswordIUsernameHashedPasswordcredentialInterfacesr#r r&r+r)rrs> / *E ** 00 ; -r+rc(eZdZdZdZdZdZdZy)rz[ L{SimpleDelivery} is a message delivery factory with no interesting behavior. c||_yr%_messageFactory)r0messageFactorys r)r2zSimpleDelivery.__init__s -r+cyr%r&r0rrrs r)rzSimpleDelivery.receivedHeaderrr+c|Sr%r&rs r)rzSimpleDelivery.validateFromrr+cfdS)Nc&jSr%r+r/sr)r^z+SimpleDelivery.validateTo..st++D1r+r&r/s``r)rzSimpleDelivery.validateTos 11r+N)r>r?r@rAr2rrrr&r+r)rrs .2r+rceZdZdZy) DummyRealmc<tjtddfS)Ncyr%r&r&r+r)r^z*DummyRealm.requestAvatar..r+)rIMessageDeliveryr)r0avatarIdmindrs r) requestAvatarzDummyRealm.requestAvatars$$nT&:LHHr+N)r>r?r@r;r&r+r)r4r4sIr+r4ceZdZdZdZdZy) AuthTestsct}tjj|}|j t t dtjji|_td}tjd}|j|j|}|jfd|S)z L{ESMTPClient} can authenticate using the I{CRAM-MD5} SASL mechanism. @see: U{http://tools.ietf.org/html/rfc2195} sCRAM-MD5rrc<jjdS)Nrf)r authenticatedrs r)r^z,AuthTests.test_crammd5Auth..s 0 01E1Eq Ir+)r4r portalrregisterCheckerrrr"CramMD5CredentialsrrCramMD5ClientAuthenticatorregisterAuthenticatorrrr0realmprcAuthrrs` @r)test_crammd5AuthzAuthTests.test_crammd5Auth s   KK  u % ,.)[$*:*:*M*MNO /// <$$U+ MM&& ) IJr+cnt}tjj|}|j t t dti|_td}tjd}|j|j|}|jfd|S)z L{ESMTPClient} can authenticate using the I{LOGIN} SASL mechanism. @see: U{http://sepp.oetiker.ch/sasl-2.1.19-ds/draft-murchison-sasl-login-00.txt} LOGINrrc:jjSr%rr@rs r)r^z*AuthTests.test_loginAuth..00D0D Er+)r4r rArrBrrrrrLOGINAuthenticatorrErrrFs` @r)test_loginAuthzAuthTests.test_loginAuths   KK  u % ,.)X'789 /'' 4$$U+ MM&& ) EFr+ct}tjj|}|j t t dtji|_td}tjd}|j|j|}|jfd|S)a When communicating with a server which implements the I{LOGIN} SASL mechanism using C{"Username:"} as the challenge (rather than C{"User Name\0"}), L{ESMTPClient} can still authenticate successfully using the I{LOGIN} mechanism. rLrrc:jjSr%rNrs r)r^z8AuthTests.test_loginAgainstWeirdServer..FrOr+)r4r rArrBrrrrrrPrErrrFs` @r)test_loginAgainstWeirdServerz&AuthTests.test_loginAgainstWeirdServer3s  KK  u % ,.)Xt'<'<=> /'' 4$$U+ MM&& ) EFr+N)r>r?r@rJrQrTr&r+r)r=r=s**r+r=c0eZdZdZdZdZdZdZdZy)SMTPHelperTestsci}tdD]/}tjd}|j||vd||<1y)Nitestcase)ranger messageidr)r0rims r) testMessageIDzSMTPHelperTests.testMessageIDKsC t Az*A   Q!V $AaD r+cddgddgtjddgddgtjddgg}|D]*\}}|jtj||,y)Nsuser@host.namess"User Name" ssomeguy@someplacesr+s<>)rAddressr quoteaddr)r0casesces r) testQuoteAddrzSMTPHelperTests.testQuoteAddrRst  3 4 ,.A B \\. /1G H %L \\#  &   3DAq   T^^A. 2 3r+cjtjdddd}|jt|dy)Ns user@hostshelo.host.namez user@host)rUserrstr)r0us r)testUserzSMTPHelperTests.testUser^s+ IIl$5tT B Q-r+cdgd}|D]\}}|jtj||t|f|j|j d||jtj ||t|f|j|j d|y)N)) Hello worlds Hello+20world)z Hello+worlds Hello+2Bworld)zs+00+01+02+03+04+05)ze=mc2@example.comse+3Dmc2@example.comxtext)rr xtext_encodelenencode xtext_decodedecode)r0racaser s r)testXtextEncodingz!SMTPHelperTests.testXtextEncodingbs $ =ND(   T..t4xT6K L   T[[18 <   T..x84X:O P   X__W5t <  =r+cd}|jtj|d|jdt |f|j|jdd|jdy)z Specifying an error policy to C{unicode.encode} with the I{xtext} codec should produce the same result as not specifying the error policy. rkstrictrlN)rrrmrorn)r0texts r)test_encodeWithErrorsz%SMTPHelperTests.test_encodeWithErrorspsa     dH - G0Dc$i/P  Wh7W9MNr+cd}|jtj|d|jdt |f|j|jdd|jdy)zO Similar to L{test_encodeWithErrors}, but for C{bytes.decode}. s Hello worldrurlN)rrrprqrn)r0rs r)test_decodeWithErrorsz%SMTPHelperTests.test_decodeWithErrors|sa    eX .g1FE 0S  gx8%,,w:OPr+N) r>r?r@r]rdrirsrwryr&r+r)rVrVJs" 3. = OQr+rVceZdZdZdZy)NoticeTLSClientFc@tj|||d|_yNT)resmtpState_starttlstls)r0ryrzs r)r~z#NoticeTLSClient.esmtpState_starttlss))$d;r+N)r>r?r@rr~r&r+r)r{r{s Cr+r{ceZdZeZdZy)TLSTestsct}t}t|t|fd}j j |S)N)rcvjjdjjdyr})rr startedTLS)ignoredrr0rs r)checkzTLSTests.testTLS..checks-   VZZ .   V.. 5r+)r"r#r{rrr)r0 clientCTX serverCTXrrrs` @@r)testTLSzTLSTests.testTLSsJ$& $&  :95 6}}VV,88??r+N)r>r?r@r!skiprr&r+r)rrs D @r+rceZdZdZy)EmptyLineTestsctj}t}|j||j d|j d|j j}|jt|d|j|djd|j|ddy)z If L{smtp.SMTP} receives an empty line, it responds with a 500 error response code and a message about a syntax error. r+Nrgrs220rfs500 Error: bad syntax) rrrrr7rrrrrnr startswith)r0protorouts r)test_emptyLineSyntaxErrorz(EmptyLineTests.test_emptyLineSyntaxErrors  #%  Y' 3 oo**, S1% A))&12 Q!9:r+N)r>r?r@rr&r+r)rrs;r+rc4eZdZdZdZdZdZdZdZdZ y) TimeoutTestszE Check that SMTP client factories correctly use the timeout. ctj|jtjddd}j |_t }|j|||_fd}j|tjj|}jdjd|S)zR Connect the clientFactory, and check the timeout on the request. TCP example.netcFjjdy)N?)rseconds)ignclockr0s r)rz(TimeoutTests._timeoutTest..checks   U]]_c 2r+g?g?)rClock buildProtocolr IPv4Address callLaterrrr assertFailurerrradvance)r0onDone clientFactoryrtrrrs` @r) _timeoutTestzTimeoutTests._timeoutTests ,,   }b 9 !??  a   3   vt'<'< = I I% P c cr+ctj}tjddt d|dd}|j ||S)z Test timeout for L{smtp.SMTPSenderFactory}: the response L{Deferred} should be errback with a L{smtp.SMTPTimeoutError}. source@addresssrecipient@address Message bodyrrretriestimeoutrrRrSMTPSenderFactoryrrr0rrs r)test_SMTPClientRecipientBytesz*TimeoutTests.test_SMTPClientRecipientBytessL !..  O $     77r+ctj}tjddt d|dd}|j ||S)z- Use a L{unicode} recipient. rrecipient@addressrrrrrrs r)test_SMTPClientRecipientUnicodez,TimeoutTests.test_SMTPClientRecipientUnicodesL!..   O $     77r+ctj}tjddt d|dd}|j ||S)z. Use a L{list} of recipients. r)zrecipient1@addresssrecipient2@addressrrrrrrs r)test_SMTPClientRecipientListz)TimeoutTests.test_SMTPClientRecipientListsL!..  9 O $     77r+c tj}tjddddt d|dd}|j ||S) z Test timeout for L{smtp.ESMTPSenderFactory}: the response L{Deferred} should be errback with a L{smtp.SMTPTimeoutError}. rpasswordrrrrrr)rrRrESMTPSenderFactoryrrrs r)test_ESMTPClientzTimeoutTests.test_ESMTPClientsR !//     O $     77r+cGdd}g}tj}|j|jt j dd|d|dd}d |_tj}|jtjd d d }|j|_ t}|j||jd |j!|j"d|j%|j&|j)d|j+|g|j"j-|j)d|j+|g|j"j-|jd|j+|g|j+|j/dy)z The timeout is not allowed to expire after the server has accepted a DATA command and the client is actively sending data to it. ceZdZdZdZddZy).SlowFilez A file-like which returns one byte from each read call until the specified number of bytes have been returned. c||_yr%_size)r0sizes r)r2zETimeoutTests.test_resetTimeoutWhileSending..SlowFile.__init__s ! r+NcH|jr|xjdzc_yy)Nrfxr+r)r0maxs r)readzATimeoutTests.test_resetTimeoutWhileSending..SlowFile.reads::JJ!OJr+r%)r>r?r@rAr2rr&r+r)SlowFilers   " r+rrrrfrrr example.orgrrrrNrgs250 Ok s]HELO example.org MAIL FROM: RCPT TO: DATA x . RSET )rrR addErrbackrJrrrErrrrrrrrrrrrrrrresumeProducingr)r0rfailedrrrrrs r)test_resetTimeoutWhileSendingz*TimeoutTests.test_resetTimeoutWhileSendings  !&--(..   QK    .  ,,   }b 9 !??#% i(    2 2D9 ,,-  a $ **, a $ **,M* $  OO   r+N) r>r?r@rArrrrrrr&r+r)rrs&.8 8 88$W r+rceZdZdZdZdZy)(MultipleDeliveryFactorySMTPServerFactorya L{MultipleDeliveryFactorySMTPServerFactory} creates SMTP server protocol instances with message delivery factory objects supplied to it. Each factory is used for one connection and then discarded. Factories are used in the order they are supplied. c||_yr%)_messageFactories)r0messageFactoriess r)r2z1MultipleDeliveryFactorySMTPServerFactory.__init__ps !1r+ctjj||}t|jj d|_|S)Nr)r ServerFactoryrrrrr)r0addrrHs r)rz6MultipleDeliveryFactorySMTPServerFactory.buildProtocolss<  " " 0 0t <#D$:$:$>$>q$AB r+N)r>r?r@rAr2rr&r+r)rrhs2r+rceZdZdZdZdZy)SMTPSenderFactoryTestsz. Tests for L{smtp.SMTPSenderFactory}. cNt}tj}tjddt d|}|j dd|}|jd|j|tjd|j|jdy)zt L{smtp.SMTPSenderFactory} removes the current protocol when the client connection is lost. rrmessage localhostrNBye.) rrrRrrr connectTCPrclientConnectionLostrConnectionDonercurrentProtocolr0r sentDeferredr connectors r)2test_removeCurrentProtocolWhenClientConnectionLostzISMTPSenderFactoryTests.test_removeCurrentProtocolWhenClientConnectionLost~s  /~~' .. 17:3F  'G&&{B F ##D)**9e6J6J66RS 66=r+cNt}tj}tjddt d|}|j dd|}|jd|j|tjd|j|jdy)zv L{smtp.SMTPSenderFactory} removes the current protocol when the client connection is failed. rrrrrNr) rrrRrrrrrclientConnectionFailedrrrrrs r)4test_removeCurrentProtocolWhenClientConnectionFailedzKSMTPSenderFactoryTests.test_removeCurrentProtocolWhenClientConnectionFaileds  /~~' .. 17:3F  'G&&{B F ##D),,Y8L8LV8TU 66=r+N)r>r?r@rArrr&r+r)rrys > >r+rceZdZdZdZy)SMTPSenderFactoryRetryTestszD Tests for the retry behavior of L{smtp.SMTPSenderFactory}. c\ d d t g Gfddtj}tt fdg}||_t jd|d}|j}j|jtj}tjd d zt |}d |_t j |j"|j$|}j|j& fd }|j)||S) z If the protocol created by L{SMTPSenderFactory} loses its connection before receiving confirmation of message delivery, it reconnects and tries to deliver the message again. salicessome message textceZdZdZfdZy)HSMTPSenderFactoryRetryTests.test_retryAfterDisconnect..CleanSMTPz An SMTP subclass which ensures that its transport will be disconnected before the test ends. c|j|jtjj ||yr%) addCleanuprrrr) innerSelfrr0s r)rzWSMTPSenderFactoryRetryTests.test_retryAfterDisconnect..CleanSMTP.makeConnections) 8 89 ((I>r+N)r>r?r@rArr:sr) CleanSMTPrs    ?r+rct|Sr%r])r1rEs r)r^zGSMTPSenderFactoryRetryTests.test_retryAfterDisconnect..sfd)Cr+r 127.0.0.1) interfacesbob@example.orgs @example.comrcjjdzdzgijtjtdy)z Verify that the message was successfully delivered and flush the error which caused the first attempt to fail. rLrfN)rrOrnflushLoggedErrorsr9)rrErT recipientr0s r)cbSentzESMTPSenderFactoryRetryTests.test_retryAfterDisconnect..cbSentsJ   V__y57?U;R:S.T U   S!7!7 !EF Jr+)rWrrrr-rr listenTCPgetHostr stopListeningrrRrrrErhostport disconnectr) r0r serverFactory serverPort serverHostrrclientConnectorrrErTrs ` @@@r)test_retryAfterDisconnectz5SMTPSenderFactoryRetryTests.test_retryAfterDisconnects   &i[) ?  ?A C D "+ &&q-;O '')   001~~' ..   ' G    . !,, OOZ__m  223 K   (r+N)r>r?r@rArr&r+r)rrs 8r+rceZdZdZdZdZy)SingletonRealmz Trivial realm implementation which is constructed with an interface and an avatar and returns that avatar when asked for that interface. c ||_||_yr%ravatar)r0rrs r)r2zSingletonRealm.__init__s" r+cR|D]"}||jus||jdfcSy)Ncyr%r&r&r+r)r^z.SingletonRealm.requestAvatar..r7r+r)r0r9r:rifaces r)r;zSingletonRealm.requestAvatars. 8E&dkk<77 8r+N)r>r?r@rAr2r;r&r+r)rrs 8r+rc"eZdZdZdZdZdZy)NotImplementedDeliveryz Non-implementation of L{smtp.IMessageDelivery} which only has methods which raise L{NotImplementedError}. Subclassed by various tests to provide the particular behavior being tested. ctdNz3This oughtn't be called in the course of this test.NotImplementedErrorrs r)rz#NotImplementedDelivery.validateFrom!"WXXr+ctdr r r/s r)rz!NotImplementedDelivery.validateTor r+ctdr r r/s r)rz%NotImplementedDelivery.receivedHeaderr r+N)r>r?r@rArrrr&r+r)rrs YYYr+rcteZdZdZej fdZdZdZdZ dZ dZ dZ e ed Zd Zy ) SMTPServerTestsza Test various behaviors of L{twisted.mail.smtp.SMTP} and L{twisted.mail.smtp.ESMTP}. c|}d|_t}|j||jt j |j d|jy)zb Test that the specified hostname shows up in the SMTP server's greeting. s example.comN)rrrr=rrassertInr)r0rsrs r)testSMTPGreetingHostz$SMTPServerTests.testSMTPGreetingHostsS M    --/0 naggi0r+ctj}t}|j||j t j |jd|jy)z Test that the string "ESMTP" does not appear in the SMTP server's greeting since that string strongly suggests the presence of support for various SMTP extensions which are not supported by L{smtp.SMTP}. ESMTPN) rrrrr=rr assertNotInrr0rrs r)testSMTPGreetingNotExtendedz+SMTPServerTests.testSMTPGreetingNotExtendedsR IIK    --/0 1779-r+cB|jtjy)zS Similar to testSMTPGreetingHost, but for the L{smtp.ESMTP} class. N)rrrr:s r)testESMTPGreetingHostz%SMTPServerTests.testESMTPGreetingHosts !!$**-r+ctj}t}|j||j t j |jd|jy)z Test that the string "ESMTP" does appear in the ESMTP server's greeting since L{smtp.ESMTP} does support the SMTP extensions which that advertises to the client. rN) rrrrr=rrrrrs r)testESMTPGreetingExtendedz)SMTPServerTests.testESMTPGreetingExtended#sP JJL    --/0 h *r+c tj}t}|j||j d|j t j|jd|jy)zN Sending an unimplemented command is responded to with a 500. s DOAGOODTHINGs500 Command not implementedN) rrrrr7r=rrrrrs r)test_SMTPUnknownCommandz'SMTPServerTests.test_SMTPUnknownCommand/s] IIK    ' --/0 4aggi@r+cGddt}ttj|}t |t g}tj }||_t}|j||jd|j|jd|jtj|j|j!dy)z Test that a C{MAIL FROM} command with an acceptable address is responded to with the correct success code. ceZdZdZdZy)DSMTPServerTests.test_acceptSenderAddress..AcceptanceDeliveryzM Delivery object which accepts all senders as valid. c|Sr%r&rs r)rzQSMTPServerTests.test_acceptSenderAddress..AcceptanceDelivery.validateFromEs r+Nr>r?r@rArr&r+r)AcceptanceDeliveryr#@s   r+r&HELO example.com MAIL FROM: s250 Sender address accepted Nrrrr8rr rrArrrrr=rConnectionLostrr)r0r&rGrArtranss r)test_acceptSenderAddressz(SMTPServerTests.test_acceptSenderAddress:s  !7 t446H6JK 4 678  ! U# 23  ?@ U1134 (JKr+cGddt}ttj|}t |t g}tj }||_t}|j||jd|j|jd|jtj|j|j!dy)z Test that a C{MAIL FROM} command with an address rejected by a L{smtp.IMessageDelivery} instance is responded to with the correct error code. ceZdZdZdZy)MSMTPServerTests.test_deliveryRejectedSenderAddress..RejectionDeliveryzO Delivery object which rejects all senders as invalid. c,tj|r%)r SMTPBadSenderrs r)rzZSMTPServerTests.test_deliveryRejectedSenderAddress..RejectionDelivery.validateFromis((00r+Nr%r&r+r)RejectionDeliveryr/ds   1r+r2r'r(V550 Cannot receive from specified address : Sender not acceptable Nr))r0r2rGrArr+s r)"test_deliveryRejectedSenderAddressz2SMTPServerTests.test_deliveryRejectedSenderAddress]s 1 6 1t446G6IJ 4 678  ! U# 23  ?@ U1134  KKM > r+cGdd}ttjt}t ||g}tj }||_t}|j||jd|j|jd|jtj|j|jdy)z Test that a C{MAIL FROM} command with an address rejected by an L{smtp.SMTP} instance's portal is responded to with the correct error code. ceZdZdZefZdZy)QSMTPServerTests.test_portalRejectedSenderAddress..DisallowAnonymousAccesszZ Checker for L{IAnonymous} which rejects authentication attempts. c<tjtSr%)rr`rr!s r)r#zaSMTPServerTests.test_portalRejectedSenderAddress..DisallowAnonymousAccess.requestAvatarIdszz"3"566r+N)r>r?r@rArr(r#r&r+r)DisallowAnonymousAccessr7s %/=  7r+r9r'r(r3Nrrr8rrrrArrrrr=rr*rr)r0r9rGrArr+s r) test_portalRejectedSenderAddressz0SMTPServerTests.test_portalRejectedSenderAddresss 7 7t446L6NO 7 9:;  ! U# 23  ?@ U1134  KKM > r+cttjt}t |g}tj }||_t}|j||jd|j|jd|jtj|j|jdy)z Test that a C{MAIL FROM} command issued without first authenticating when a portal has been configured to disallow anonymous logins is responded to with the correct error code. r'r(sd550 Cannot receive from specified address : Unauthenticated senders not allowed Nr:)r0rGrArr+s r)"test_portalRejectedAnonymousSenderz2SMTPServerTests.test_portalRejectedAnonymousSenders t446L6NOr"  ! U# 23  ?@ U1134  KKM L r+N)r>r?r@rArrrrrrr r,r4r r r;r=r&r+r)rrsW 04yy 1 .. + A!LF& P$%( &( T r+rc^eZdZdZ ddZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zy)ESMTPAuthenticationTestsc|jj|jj||j ||jj j y)z Assert that when the given bytes are delivered to the ESMTP server instance, it responds with the indicated lines. @type bytes: str @type response: list of str N)rrrrrrr)r0rresponses r)assertServerResponsez-ESMTPAuthenticationTests.assertServerResponsesL    ' 4>>#7#7#9#D#D#FGr+c|j\}}}}|j|g|jtjj j j||j|j||j|j||jtj||jtj||jtjddf|jdg|jj!j#y)a Assert that a login attempt has been made, that the credentials and interfaces passed to it are correct, and that when the login request is satisfied, a successful response is sent by the ESMTP server instance. @param loginArgs: A C{list} previously passed to L{portalFactory}. @param username: The login user. @param password: The login password. Ncyr%r&r&r+r)r^zDESMTPAuthenticationTests.assertServerAuthenticated..r7r+s235 Authentication successful.)rrrtwistedr r"r& providedByrrrrIMessageDeliveryFactoryr8rSrrr)r0 loginArgsrrrr"r:rs r)assertServerAuthenticatedz2ESMTPAuthenticationTests.assertServerAuthenticateds,5==?(;j B'  LL $ $ 6 6 A A+ N  --x8  11(;< d22J? d++Z8 D00$ EF  . /1E1E1G1R1R1T r+ctjdti|_d|j_t t jddd|_|jj|jy)zI Create an ESMTP instance attached to a StringTransport. rLs localhostrri90) peerAddressN) rrrrrrrrrrr:s r)setUpzESMTPAuthenticationTests.setUps\jj(, ' (++E;F  ""4>>2r+c^|jjtjy)zT Disconnect the ESMTP instance to clean up its timeout DelayedCall. N)rr=rrr:s r)tearDownz!ESMTPAuthenticationTests.tearDowns ""5#7#7#9:r+c*Gfdd}|S)NceZdZfdZy);ESMTPAuthenticationTests.portalFactory..DummyPortalcZtj}j||||f|Sr%)rrRrJ)r0r"r:rr loginLists r)loginzAESMTPAuthenticationTests.portalFactory..DummyPortal.login s+NN$  ![$ !CDr+N)r>r?r@rT)rSsr) DummyPortalrQ s r+rUr&)r0rSrUs ` r) portalFactoryz&ESMTPAuthenticationTests.portalFactory s   }r+cH|jj|jjd|jj j }|j |dd|j |dd|j t|dy)zV Test that AUTH is advertised to clients which issue an EHLO command. EHLO rs/250-localhost Hello 127.0.0.1, nice to meet yourfs250 AUTH LOGINrgN)rrrrrrrrn)r0 responseLiness r)'test_authenticationCapabilityAdvertisedz@ESMTPAuthenticationTests.test_authenticationCapabilityAdvertiseds    -,,.99;   ! P  q)+<= ]+Q/r+cHg}|j||j_|jjd|jj |j ddtjdjzg|j tjddzdtjdjzg|j tjdjdzg|j|y ) zJ Test that the LOGIN authentication mechanism can be used rX AUTH LOGIN 334 User Nameusernamer PasswordpasswordN rVrrArrrrBbase64 b64encodestriprIr0rHs r)test_plainAuthenticationz1ESMTPAuthenticationTests.test_plainAuthentication s !// :    -  !! &*:*:>*J*P*P*R RS  !!   [ )G 3 v'' 6<<> > ? !!&"2"2;"?"E"E"G'"QSUV &&y1r+cg}|j||j_|jjd|jj |j ddtjdjzg|j tjddzdtjdjzg|j dg|j|d y ) zM Test that giving an empty password for plain auth succeeds. rXr\r]r^r_rr`r+)rNrbrfs r)%test_plainAuthenticationEmptyPasswordz>ESMTPAuthenticationTests.test_plainAuthenticationEmptyPassword7s !// :    -  !! &*:*:>*J*P*P*R RS  !!   [ )G 3 v'' 6<<> > ? !!'2. &&y3&?r+cg}|j||j_|jjd|jj |j dtjdjzdzdtjdjzg|j tjdjdzg|j|y) z The response to the first challenge may be included on the AUTH command line. Test that this is also supported. rX AUTH LOGIN r_rr]r`raNrbrfs r)'test_plainAuthenticationInitialResponsez@ESMTPAuthenticationTests.test_plainAuthenticationInitialResponseMs  !// :    -  !! V--k:@@B BW L v'' 6<<> > ? !!&"2"2;"?"E"E"G'"QSUV &&y1r+cg}|j||j_|jjd|jjd|j ddgy)zW Test that a challenge/response sequence can be aborted by the client. rXr\s* s501 Authentication abortedN)rVrrArrBrfs r)test_abortAuthenticationz1ESMTPAuthenticationTests.test_abortAuthenticationasY !// :    -   !23 !!(-J,KLr+cg}|j||j_|jjd|jjd|j ddg|j |gy)zz Test that a response which is not properly Base64 encoded results in the appropriate error code. rXr\sx +501 Syntax error in parameters or argumentsNrVrrArrBrrfs r)!test_invalidBase64EncodedResponsez:ESMTPAuthenticationTests.test_invalidBase64EncodedResponsemsn  !// :    -   !23 !! EF  B'r+cg}|j||j_|jjd|j ddg|j |gy)z Like L{test_invalidBase64EncodedResponse} but for the case of an initial response included with the C{AUTH} command. rXsAUTH LOGIN x rpNrqrfs r)(test_invalidBase64EncodedInitialResponsezAESMTPAuthenticationTests.test_invalidBase64EncodedInitialResponse~s[  !// :    - !! "P!Q  B'r+cg}|j||j_|jjd|jj |j dtjdjzdzdtjdjzg|j tjdjdzg|j\}}}}|jtd|jd |jj|jt|j!td y ) z If the L{Deferred} returned by L{Portal.login} fires with an exception of any type other than L{UnauthorizedLogin}, the exception is logged and the client is informed that the authentication attempt has failed. rXrkr_rr]r`razSomething wrong with the servers9451 Requested action aborted: local error in processing rfN)rVrrArrrrBrcrdrererrbackr9rrrnr)r0rHrr"r:rs r)test_unexpectedLoginFailurez4ESMTPAuthenticationTests.test_unexpectedLoginFailures% !// :    -  !! V--k:@@B BW L v'' 6<<> > ?  !!&"2"2;"?"E"E"G'"QSUV+4==?(;j ,@AB  J NN " T33LABAFr+N)r_ra)r>r?r@rBrIrLrNrVrZrgrirlrnrrrtrwr&r+r)r?r?sM H9D 8 3;  02.@,2( M(" (Gr+r?c"eZdZdZdZdZdZy)SMTPClientErrorTestsz, Tests for L{smtp.SMTPClientError}. cftjdd}|jt|dy)z The string representation of a L{SMTPClientError} instance includes the response code and response string. rz some textz 123 some textNrrrrgr0errs r)test_strzSMTPClientErrorTests.test_strs* ""3 4 S?3r+cftjdd}|jt|dy)z If the response code supplied to L{SMTPClientError} is negative, it is excluded from the string representation. sfoo barzfoo barNr{r|s r)test_strWithNegativeCodez-SMTPClientErrorTests.test_strWithNegativeCodes* ""2z2 S9-r+ctd}|jd|jdtjdd|j }|j t |dy) z If a line log is supplied to L{SMTPClientError}, its contents are included in the string representation of the exception instance. stestlogs secondlinedz test error)r}z"100 test error testlog secondline N)rrJrrrgr)r0r}r}s r)test_strWithLogz$SMTPClientErrorTests.test_strWithLogsT bk : =!""3 #'')D S#PQr+N)r>r?r@rAr~rrr&r+r)ryrys4. Rr+ryceZdZdZdZy)SenderMixinSentMailTestsz Tests for L{smtp.SenderMixin.sentMail}, used in particular by L{smtp.SMTPSenderFactory} and L{smtp.ESMTPSenderFactory}. cnjtjtj}|j fdtj ddtd|dd}|jtjdd d }d d g}|jd dd||j|S)z L{smtp.SenderMixin.sentMail} adds only the addresses with failing SMTP response codes to the log passed to the factory's errback. c<j|jdS)Ns'bob@example.com: 199 Error in sending. )rr})rcr0s r)r^zFSenderMixinSentMailTests.test_onlyLogFailedAddresses..sd&&Br+rrrrrrrrr)salice@example.comsNo errors here!)sbob@example.comsError in sending.rs Test responserf) rrrRrSMTPDeliveryErrorrrrrrrr~r})r0rrrr|s` r)test_onlyLogFailedAddressesz4SenderMixinSentMailTests.test_onlyLogFailedAddressess ##ENN$4d6L6LM  ..   O $   ,,   }b 9  < ;  -q)VZZH r+N)r>r?r@rArr&r+r)rrs  r+rc.eZdZdZdZdZdZdZdZy)ESMTPDowngradeTestCasezU Tests for the ESMTP -> SMTP downgrade functionality in L{smtp.ESMTPClient}. c<tjddd|_y)Nrr)rrclientProtocolr:s r)rLzESMTPDowngradeTestCase.setUps"..kRr+ct}d|j_d|j_d|j_|jj ||jj d|j|jj d|jd|jy)z If both authentication and transport security are not required, and it is asked for, it will fall back to allowing HELO. FT220 localhost 500 not an esmtp server HELO testuser N rrrequireAuthenticationrequireTransportSecurity heloFallbackrrrrrr0rs r) test_requireHELOFallbackOperatesz7ESMTPDowngradeTestCase.test_requireHELOFallbackOperatess $% 4917<4+/( **95 (()=> (()GH -y/@Ar+ct}d|j_d|j_d|j_|jj ||jj d|j|jj d|jd|jy)z If authentication is required, and HELO fallback is on, HELO fallback must not be honoured, as authentication requires EHLO to succeed. TFrrrNrrs r)!test_requireAuthFailsHELOFallbackz8ESMTPDowngradeTestCase.test_requireAuthFailsHELOFallback s $% 4817<4+/( **95 (()=> (()GH ioo&78r+ct}d|j_d|j_d|j_|jj ||jj d|j|jj d|jd|jy)z If TLS is required and the connection is insecure, HELO fallback must not be honoured, as STARTTLS requires EHLO to succeed. FTrrrNrrs r) test_requireTLSFailsHELOFallbackz7ESMTPDowngradeTestCase.test_requireTLSFailsHELOFallbacks $% 4917;4+/( **95 (()=> (()GH ioo&78r+ct}t|tjd|j_d|j_d|j_|jj||jjd|j|jjd|jd|jy)z If TLS is provided at the transport level, we can honour the HELO fallback if we're set to require TLS. FTrrrN) rr r ISSLTransportrrrrrrrrrrs r)/test_requireTLSAndHELOFallbackSucceedsIfOverTLSzFESMTPDowngradeTestCase.test_requireTLSAndHELOFallbackSucceedsIfOverTLS,s $% J$<$<=4917;4+/( **95 (()=> (()GH -y/@Ar+N) r>r?r@rArLrrrrr&r+r)rrs#SB 9 9 Br+rcReZdZdZeZdZdZdZdZ dZ dZ dZ d Z d Zd Zd Zy ) SSLTestCasezD Tests for the TLS negotiation done by L{smtp.ESMTPClient}. s3220 localhost NO UCE NO UBE NO RELAY PROBES ESMTP s1250-localhost Hello 127.0.0.1, nice to meet you ctjdtd|_d|j_d|j_y)NrrTcy)Nztest@example.orgr&r&r+r)r^z#SSLTestCase.setUp..Mr7r+)rrr"rrror:s r)rLzSSLTestCase.setUpHs>".. -/ 8<4*D'r+c|t}t|tj|jj ||jj |j|j|jj |j|z|jd|jy)a Verify that when L{smtp.ESMTPClient} connects to a server over a transport providing L{ISSLTransport}, C{requireTransportSecurity} is C{True}, and it is presented with the given capabilities, it will try to send its mail and not first attempt to negotiate TLS using the I{STARTTLS} protocol action. @param capabilities: Bytes to include in the test server's capability response. These must be formatted exactly as required by the protocol, including a line which ends the capability response. @type param: L{bytes} @raise: C{self.failureException} if the behavior of C{self.clientProtocol} is not as described. sMAIL FROM: N) rr rrrrrSERVER_GREETINGr EHLO_RESPONSErr)r0 capabilitiesrs r)$_requireTransportSecurityOverSSLTestz0SSLTestCase._requireTransportSecurityOverSSLTestOs $% J$<$<= **95 (()=)=> ((););l)JK OPr+c&|jdy)z When C{requireTransportSecurity} is C{True} and the client is connected over an SSL transport, mail may be delivered. 250 AUTH LOGIN Nrr:s r)$test_requireTransportSecurityOverSSLz0SSLTestCase.test_requireTransportSecurityOverSSLns 112GHr+cHt}|jj||jj|j|j |jj|j dz|jd|jy)z When C{requireTransportSecurity} is C{True} and the client is connected over a non-SSL transport, if the server offers the I{STARTTLS} extension, it is used before mail is delivered. 250-AUTH LOGIN 250 STARTTLS s STARTTLS N rrrrrrrrrrs r)'test_requireTransportSecurityTLSOfferedz3SSLTestCase.test_requireTransportSecurityTLSOfferedus $%  **95 (()=)=> ((   !J J )//*; ((););>S)ST ioo&78r+c |jj}~|j|jg}|j t |d|j |ddt|j |dddy)< L{smtp.ESMTPClient.tlsMode} is deprecated. offendingFunctionsrfrcategoryrTStlsMode attribute of twisted.mail.smtp.ESMTPClient is deprecated since Twisted 13.0N)rtlsMode flushWarnings%test_esmtpClientTlsModeDeprecationGetrrnassertIdenticalDeprecationWarning)r0val warningsShowns r)rz1SSLTestCase.test_esmtpClientTlsModeDeprecationGets!!)) ** $ J JK+  ]+Q/ ]1-j9;MN  ! Y ' / r+c8jtfdy)z L{smtp.ESMTPClient.__getattr__} raises an attribute error for other attribute names which do not exist. c0jjSr%)r doesNotExistr:sr)r^zQSSLTestCase.test_esmtpClientTlsModeDeprecationGetAttributeError..s$2E2E2R2Rr+N) assertRaisesAttributeErrorr:s`r)3test_esmtpClientTlsModeDeprecationGetAttributeErrorz?SSLTestCase.test_esmtpClientTlsModeDeprecationGetAttributeErrors .*RSr+cd|j_|j|jg}|j t |d|j |ddt|j |dddy) rFrrfrrrTrN)rrr%test_esmtpClientTlsModeDeprecationSetrrnrr)r0rs r)rz1SSLTestCase.test_esmtpClientTlsModeDeprecationSets',#** $ J JK+  ]+Q/ ]1-j9;MN  ! Y ' / r+N)r>r?r@rAr!rrrrLrrrrrrrrr&r+r)rr>sI DNOJMEQ>I=* 9& "T r+rceZdZdZdZdZy)AbortableStringTransportzK A version of L{StringTransport} that supports C{abortConnection}. Fc2d|_|jy)z A testable version of the C{ITCPTransport.abortConnection} method. Since this is a special case of closing the connection, C{loseConnection} is also called. TN)abortingrr:s r)abortConnectionz(AbortableStringTransport.abortConnections  r+N)r>r?r@rArrr&r+r)rrs Hr+rcFeZdZdZdZdZdZdZdZdZ dZ d Z d Z y ) SendmailTestsz2 Tests for L{twisted.mail.smtp.sendmail}. ctjtj}|d}|j t |dy)z{ The default C{reactor} parameter of L{twisted.mail.smtp.sendmail} is L{twisted.internet.reactor}. rrgN)inspectgetfullargspecrsendmailrr)r0fullSpecdefaultss r)"test_defaultReactorIsGlobalReactorz0SendmailTests.test_defaultReactorIsGlobalReactors5 ))$--8A; (1+.r+c Xt}tjdddd|||dd |jdd}|j |j d|j |j d|j |jd |j |jd y ) zk L{twisted.mail.smtp.sendmail} creates the ESMTP factory with the ESMTP arguments. rrrrT)rrrrrrrgrbarN) rrr tcpClientsr_requireTransportSecurity_requireAuthenticationrr)r0rrrrs r)_honorsESMTPArgumentsz#SendmailTests._honorsESMTPArgumentss  /    %)"& $$Q'* ::DA 77> ))62 ))62r+c(|jddS)zw L{twisted.mail.smtp.sendmail} should accept C{username} and C{password} which are L{unicode}. rbarrrrr:s r)&test_honorsESMTPArgumentsUnicodeUserPWz4SendmailTests.test_honorsESMTPArgumentsUnicodeUserPWs ))55)IIr+c(|jddS)zu L{twisted.mail.smtp.sendmail} should accept C{username} and C{password} which are L{bytes}. rrrrr:s r)$test_honorsESMTPArgumentsBytesUserPWz2SendmailTests.test_honorsESMTPArgumentsBytesUserPWs ))6F)KKr+ct}td}tjddd|||jdd}|j |j |y) z| L{twisted.mail.smtp.sendmail} will pass through the message untouched if it is a file-like object. sFile!rrrrrrgN)rrrrrassertIsfile)r0r messageFilers r)test_messageFilePassthroughz)SendmailTests.test_messageFilePassthroughsY  /h'       $$Q'* gllK0r+ct}tjdddd||jdd}|j}|j d|j |jdy) z L{twisted.mail.smtp.sendmail} will turn non-file-like objects (eg. strings) into file-like objects before sending. rrrrrrrgN)rrrrrseekrr)r0rrrs r)test_messageStringMadeFilez(SendmailTests.test_messageStringMadeFile(sm  /      $$Q'*ll  ))+Z8r+ct}tjdddd|d|jdd}|j |j d y ) zk L{twisted.mail.smtp.sendmail} passes through the sender domain name, if provided. rrrrr)rsenderDomainNamerrgrN)rrrrrrE)r0rrs r)test_senderDomainNamez#SendmailTests.test_senderDomainName:sT  /    "  $$Q'* 0r+ct}tjdddd|}|j|j |j dj d|j|}|jtjy) z When a user cancels L{twisted.mail.smtp.sendmail} before the connection is made, the connection is closed by L{twisted.internet.interfaces.IConnector.disconnect}. rrrrrrTN) rrrcancelr connectors _disconnectedfailureResultOftraprCancelledError)r0rrfailures r)test_cancelBeforeConnectionMadez-SendmailTests.test_cancelBeforeConnectionMadeKsv  / MM         ++A.<r?r@rArrrrrrrrrr&r+r)rrs6/3.JL1$9$1"+&+r+r)krArcrrHiortypingrrrrrzope.interfacer r twisted.cred.checkersrEtwisted.cred.credentialstwisted.cred.errortwisted.cred.portalr r r rrrrtwisted.internetrrrrrrrtwisted.internet.testingrr twisted.mailrtwisted.mail._credrtwisted.protocolsrrtwisted.python.utilrtwisted.trial.unittestr rgr twisted.test.ssl_helpersr"r#r! ImportError IReactorSSLrFr*IMessager-rCrWrhrdrrrrr LineReceiverrrrrrrrrrrrcheckersrr8rr4r=rVr{rrrrrrrrrrr?ryrrrrrr&r+r)rs  338K/0.WWWC/-'+ #KG((1+G T]]   (622"6-8T__-  Hd.. 44 1U''1:r1h r1j''&    DII TZZ jjZ    T]] . ./--0-& T " "#22$2&II ?-?D:Qh:Qzm@x@";X;$s 8]s lx/E/E"!>X!>H=(=@ V 8 8 8 YY"N hN bXGxXGvR8RB%x%PGBXGBTO (O d&Q+HQ+}5$#G$s!K==LL