+
    Dfjyf                   0	   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIt^ RIt^ RI t^ RI!t^ RI"t^ RI#t^ RI$t^ RI%t^ RI&t^ RIH't'H(t( ^ R	I)H*t*H+t+H,t,H-t-H.t.H/t/ ^ R
I0H1t1 ^ RI2H3t3H4t4H5t5H6t6 ^ RI7H8t8H9t9H:t: ^ RI;H<t<H=t= ^ RI#H>t> ^ RI&H?t? ^ RI@HAtA ^ RIBHCtCHDtDHEtE ^ RIFHGtG ^ RIHHItIHJtJ ^ RIKHLtL ^ RIMHNtN ^ RIOHPtP ]! ]NR8g  R4       ! R R]P4      4       tQ]! ]NR8g  R4       ! R R]P4      4       tR]! ]NR8g  R4       ! R R]P4      4       tS]! ]NR8g  R4       ! R R ]P4      4       tT]! ]NR8g  R4       ! R! R"]P4      4       tU]! ]NR8g  R4       ! R# R$]P4      4       tV]! ]NR8g  R4       ! R% R&]P4      4       tW]! ]NR8g  R4       ! R' R(](P                  P                  4      4       tZ ! R) R*4      t[]! ]NR8g  R4       ! R+ R,]P][4      4       t\]! ]NR8g  R4       ! R- R.]P][4      4       t]]! ]NR8g  R4       ! R/ R0]P4      4       t^]! ]NR8g  R4       ! R1 R2]P4      4       t_]! ]NR8g  R4       ! R3 R4]P4      4       t`]! ](PP                  P                  4       ! R5 R64      4       tb]! ]NR8g  R4       ! R7 R8]P4      4       tc]! ]NR8g  R4       ! R9 R:]P4      4       td ! R; R<]=P                  4      tf]! ]NR8g  R4       ! R= R>]P4      4       tg]! ]NR8g  R4       ! R? R@]P4      4       th ! RA RB4      ti]! ]NR8g  R4       ! RC RD]P4      4       tj]! ]NR8g  R4       ! RE RF]P4      4       tk^ RGI@HltlHmtmHntn  ! RH RI]mP                  4      tpRJ tqRK tr]! ]NR8g  R4       ! RL RM]P4      4       ts]! ]NR8g  R4       ! RN RO]P4      4       tt ! RP RQ4      tu]! ]NR8g  R4       ! RR RS]P4      4       tv ! RT RU4      tw]! ]NR8g  R4       ! RV RW]P4      4       tx ! RX RY4      ty ! RZ R[](P                  P                  4      t| ! R\ R]](P                  P                  4      t~ ! R^ R_4      t]! ]NR8g  R4       ! R` Ra]P4      4       t ! Rb Rc4      t ! Rd Re4      t ! Rf Rg4      t]! ]NR8g  R4       ! Rh Ri]P4      4       tR# )jz.
Tests for large portions of L{twisted.mail}.
)annotationsN)md5)AnyNoReturn)skipIf)	Interfaceimplementer)verifyClass)credmail)addressdefer
interfacesprotocolreactortask)Deferred)CannotListenErrorDNSLookupErrorProcessDoneProcessTerminated)LineSendingProtocolMemoryReactorClockStringTransport)pop3smtp)MaildirMailbox)_AttemptManager)dns)Record_CNAME	Record_MXRRHeader)DNSNameError)failurelog)FilePath)platformType)TestCaseposixz twisted.mail only works on posixc                  f    ] tR t^@t]! ]P                  R	8  R4      R 4       tR tR t	R t
R tRtR# )
DomainWithDefaultsTestsnot ported to Python 3c           	     	   \        ^
4       Uu/ uF  qV^
,           bK  	  pp\        P                  P                  VR4      pV P                  \	        V4      ^
4       V P                  \        \        V4      4      \        \        ^
4      4      4       V P                  \        VP                  4       4      \        \        V4      4      4       \        VP                  4       4      pVP                  4        T P                  T\        ^
4       Uu. uF  qV^
,           3NK  	  up4       \        VP                  4       4      pVP                  4        V P                  V\        \        ^
^4      4      4       VP                  4       pVP                  4        T P                  T\        ^
4       Uu. uF  qV^
,           3NK  	  up4       VP                  4       pVP                  4        V P                  V\        \        ^
^4      4      4       \        ^
4       F]  pV P                  W!,          V^
,           4       V P                  VP                  V4      V^
,           4       V P                  W9   4       K_  	  V^ V^ V^ V P                  \	        V4      ^4       V P                  V^,          R4       V P                  V^,          R4       V P                  V^,          R4       VP                  RRRR	RR/4       V P                  \	        V4      ^
4       V P                  VR,          R4       V P                  VR,          R	4       V P                  VR,          R4       VP!                  4        V P                  \	        V4      ^ 4       V P                  VP#                  RR4      R4       V P                  VR,          R4       V P                  VP%                  4       R
4       V P                  \	        V4      ^ 4       VP'                  4       pV P                  VP(                  VP(                  4       V P                  VP*                  VP*                  4       R# u upi u upi u upi )
   DefaultaNbc*keyvalue )r3   r4   )ranger   DomainWithDefaultDictassertEquallenlistiteriterkeys	iteritemssort
itervaluesitemsvaluesget
assertTrueupdateclear
setdefaultpopitemcopydomainsdefault)selfxdr@   rA   dcopys   &     =/usr/lib/python3/dist-packages/twisted/mail/test/test_mail.pytestMethods#DomainWithDefaultsTests.testMethodsB   sO    %b	*	1BY	*II++Ay9Q$d1gU2Y8ajjl+T$q'];Q[[]#

eBi @iQVi @Aalln%eBm!45	

eBi @iQVi @AeBm!45rAQT1r6*QUU1Xq2v.OOAF# 
 aD!A$!Q#1y)1y)1y)	#tS"c3/0Q$3&3$3%		Q#eW5w?57+&67Q#EMM2EMM2i + !A !As   Q'Q,
1Q1
c                    \         P                   P                  / R4      pV P                  VP                  P                  V! V4      4       RVR&   V P                  \        RR/4      V! V4      4       R# )aa  
Assert that the class name of a L{mail.mail.DomainWithDefaultDict}
instance and the string-formatted underlying domain dictionary both
appear in the string produced by the given string-returning function.

@type stringifier: one-argument callable
@param stringifier: either C{str} or C{repr}, to be used to get a
    string to make assertions against.
r.   r4   r3   N)r   r7   assertIn	__class____name__str)rK   stringifierdomains   && rO   _stringificationTest,DomainWithDefaultsTests._stringificationTestz   s_     00Y?f&&//V1DEuc5'*+[-@A    c                0    V P                  \        4       R# )z
L{DomainWithDefaultDict.__str__} should return a string including
the class name and the domain mapping held by the instance.
N)rY   rV   rK   s   &rO   test_str DomainWithDefaultsTests.test_str   s    
 	!!#&r[   c                0    V P                  \        4       R# )z
L{DomainWithDefaultDict.__repr__} should return a string including
the class name and the domain mapping held by the instance.
N)rY   reprr]   s   &rO   	test_repr!DomainWithDefaultsTests.test_repr   s    
 	!!$'r[   c                `   \         P                   P                  / R4      pVP                  R4       RpV P                  V P                  .4      pV P                  ^\        V4      4       V P                  \        V^ ,          R,          4       V P                  W#^ ,          R,          4       R# )z
has_key is now deprecated.
r.   anythingzotwisted.mail.mail.DomainWithDefaultDict.has_key was deprecated in Twisted 16.3.0. Use the `in` keyword instead.categorymessageN)r   r7   has_keyflushWarningstest_has_keyDeprecationr8   r9   DeprecationWarning)rK   sutrg   warningss   &   rO   rj   /DomainWithDefaultsTests.test_has_keyDeprecation   s     ii--b)<J? 	 %%t'C'C&DECM*+Xa[-DE1+i"89r[   r5   N   )rU   
__module____qualname____firstlineno__r   sysversion_inforP   rY   r^   rb   rj   __static_attributes__r5   r[   rO   r*   r*   @   s>    C$&>?53 @53nB'(:r[   r*   c                  .    ] tR t^tR tR tR tR tRtR# )BounceTestsc                	L    \         P                   P                  4       V n        R # N)r   BounceDomainrX   r]   s   &rO   setUpBounceTests.setUp   s    ii,,.r[   c                	p    V P                  \        P                  V P                  P                  R 4       R# )zany userN)assertRaisesr   AddressErrorrX   existsr]   s   &rO   
testExistsBounceTests.testExists   s$    $++T[[-?-?Lr[   c                	^    V P                  V P                  P                  R R4      R4       R# )zrandom q emailerr   FN)r8   rX   	willRelayr]   s   &rO   	testRelayBounceTests.testRelay   s%    ../A:NPUVr[   c                	    V P                   P                  R R4       V P                  \        P                  V P                   P
                  R 4       R# )bobpasswordN)rX   addUserr   r   SMTPBadRcptr   r]   s   &rO   testAddUserBounceTests.testAddUser   s8    E:.$**DKK,>,>Fr[   )rX   N)	rU   rq   rr   rs   r|   r   r   r   rv   r5   r[   rO   rx   rx      s    /MWGr[   rx   c                       ] tR t^tRtR tRtR# )BounceWithSMTPServerTestszS
Tests for L{twisted.mail.mail.BounceDomain} with
L{twisted.mail.smtp.SMTPServer}.
c                   \         P                   P                  4       p\         P                   P                  4       pVP                  RV4       \         P                  P                  V4      pVP                  R4      p\         P                  P                  VRR4      pWTn        \        4       pVP                  ! V4       VP                  ! R4       VP                  ! R4       VP                  ! R4       VP                  ! R4       V P                  VP                  4       VP                  ! R4       V P                  VP!                  4       P#                  4       P%                  R4      R	,          R4       R# )
zW
Incoming emails to a SMTP server with L{twisted.mail.mail.BounceDomain}
are rejected.
s   foo.comNs   HELO baz.nets   MAIL FROM:<a@baz.net>s   RCPT TO:<any@foo.com>s   QUITs   
s(   550 Cannot receive for specified address)r   MailServicer{   	addDomain	protocolsSMTPFactorybuildProtocolSMTPDomainDeliverydeliveryr   makeConnectionlineReceivedrC   disconnectingconnectionLostr8   r4   stripsplit)rK   servicerX   factoryr   	deliverer	transports   &      rO   test_rejected'BounceWithSMTPServerTests.test_rejected   s   
 ))'')'')*f-..,,W5((.NN55gtTJ	%#%		*o.6767g&	//0%OO##%++G4R87	
r[   r5   N)rU   rq   rr   rs   __doc__r   rv   r5   r[   rO   r   r      s    

r[   r   c                  4    ] tR t^tR tR tR tR tR tRt	R# )FileMessageTestsc                	b   V P                  4       V n        V P                  4       V n        \        V P                  R 4      V n        V P                  V P                  P                  4       \        P                  P                  V P                  V P                  V P                  4      V n	        R# )wbN)
mktempnamefinalopenf
addCleanupcloser   FileMessagefpr]   s   &rO   r|   FileMessageTests.setUp   sh    KKM	[[]
dii&%))''		4::Fr[   c                	h    V P                   P                  4       P                  V P                  4      # rz   )r   eomReceivedaddCallback_cbFinalNamer]   s   &rO   testFinalNameFileMessageTests.testFinalName   s&    ww""$001B1BCCr[   c                	    V P                  WP                  4       V P                  V P                  P                  4       V P                  \        P                  P                  V P                  4      4       R # rz   )
r8   r   rC   r   closedassertFalseospathr   r   rK   results   &&rO   r   FileMessageTests._cbFinalName   sG    ,&		23r[   c                	X   R pVP                  4        F  pV P                  P                  V4       K   	  V P                  P                  4        \	        V P
                  R4      ;_uu_ 4       pV P                  VP                  4       V4       RRR4       R#   + '       g   i     R# ; i)"   first line
second line
third line
rbN)
splitlinesr   r   r   r   r   r8   read)rK   contentsliner   s   &   rO   testContentsFileMessageTests.testContents   st    ;'')DGG  & *$**d##qQVVXx0 $###s   -!BB)	c                	   R pVP                  4        F  pV P                  P                  V4       K   	  V P                  P                  4        V P	                  \
        P                  P                  V P                  4      4       V P	                  \
        P                  P                  V P                  4      4       R# )   first line
second line
N)
r   r   r   r   r   r   r   r   r   r   rK   r   r   s   &  rO   testInterrupted FileMessageTests.testInterrupted   sz    /'')DGG  & * 		23

34r[   )r   r   r   r   N)
rU   rq   rr   rs   r|   r   r   r   r   rv   r5   r[   rO   r   r      s    GD4
15r[   r   c                  8    ] tR tRtRtR tR tR tR tR t	Rt
R	# )
MaildirMessageTestsi  zD
Tests for the file creating by the L{mail.maildir.MaildirMessage}.
c                   V P                  4       V n        V P                  4       V n        RV n        \	        V P                  R4      V n        V P                  V P
                  P                  4       \        P                  P                  V P                  V P
                  V P                  V P                  4      V n        R# )z#
Create and open a temporary file.
s   user@example.comr   N)r   r   r   r   r   r   r   r   r   maildirMaildirMessager   r]   s   &rO   r|   MaildirMessageTests.setUp  sz     KKM	[[]
*dii&%,,--LL$&&$))TZZ
r[   c                V    \         P                   ! V P                   R24      ^ ,          # )zK
Search for the final file path.

@rtype: L{str}
@return: Final file path.
z	,S=[0-9]*)globr   r]   s   &rO   
_finalNameMaildirMessageTests._finalName  s#     yyDJJ<y12155r[   c                   V P                  V P                  P                  4       4      pV P                  WP                   R\
        P                  P                  V4       24       V P                  V P                  P                  4       V P                  \
        P                  P                  V P                  4      4       R# )z
Send the EOM to the message and check that the final file name contains
the correct file size and the temporary file has been closed and removed.
z,S=N)successResultOfr   r   r8   r   r   r   getsizerC   r   r   r   r   r   )rK   r   s   & rO   test_finalName"MaildirMessageTests.test_finalName  s    
 $$TWW%8%8%:;::,c"''//%2H1I JK&		23r[   c                   RpVP                  4        F  pV P                  P                  V4       K   	  V P                  V P                  P	                  4       4      p\        VR4      ;_uu_ 4       pV P                  VP                  4       RV P                  V3,          4       RRR4       R#   + '       g   i     R# ; i)z
Send a message contents and the EOM to the message and check that the
final file contains the correct header and the message contents.
r   r   s   Delivered-To: %s
%sN)	r   r   r   r   r   r   r8   r   r   )rK   r   r   r   r   s   &    rO   test_contents!MaildirMessageTests.test_contents(  s    
 <'')DGG  & *$$TWW%8%8%:;%!1T\\84LL s   24B00C	c                R   RpVP                  4        F  pV P                  P                  V4       K   	  V P                  P                  4        V P	                  \
        P                  P                  V P                  4      4       V P                  \        V P                  4       R# )zk
Check that the interrupted message transfer removes the temporary file
and a doesn't create a final file.
r   N)r   r   r   r   r   r   r   r   r   r   
IndexErrorr   r   s   &  rO   test_interrupted$MaildirMessageTests.test_interrupted6  sq    
 0'')DGG  & * 		23*doo6r[   )r   r   r   r   r   N)rU   rq   rr   rs   r   r|   r   r   r   r   rv   r5   r[   rO   r   r     s     
64
7r[   r   c                  (    ] tR tRtR tR tR tRtR# )MailServiceTestsiC  c                	L    \         P                   P                  4       V n        R # rz   )r   r   r   r]   s   &rO   r|   MailServiceTests.setUpE  s    yy,,.r[   c                	   V P                   P                  4       pV P                  \        V\        P
                  4      4       V P                  VP                  R4      \        P                  4       V P                   P                  4       pV P                  \        V\        P
                  4      4       V P                  VP                  R4      \        P                  4       V P                   P                  4       pV P                  \        V\        P
                  4      4       V P                  VP                  R4      \        P                  4       R# )	127.0.0.1N)r   90  )r   getPOP3FactoryrC   
isinstancer   ServerFactoryr   r   POP3getSMTPFactoryr   SMTPgetESMTPFactoryESMTP)rK   r   s   & rO   testFactoriesMailServiceTests.testFactoriesH  s    LL'')
1h&<&<=>(<=tyyILL'')
1h&<&<=>(<=tyyILL((*
1h&<&<=>(<=tzzJr[   c                	<   \        4       p\        4       pWP                  P                  R &   W P                  P                  R&   V P                  V P                  P	                  R 4      VJ 4       V P                  V P                  P                  4       VJ 4       R# )rX    N)objectr   portalsrC   lookupPortaldefaultPortal)rK   o1o2s   &  rO   testPortalsMailServiceTests.testPortalsU  sr    XX)+X&#%R 11(;rAB224:;r[   )r   N)rU   rq   rr   rs   r|   r   r   rv   r5   r[   rO   r   r   C  s    /K<r[   r   c                      ] tR tRtRtR tR t]! ]P                  R8  R4      R 4       t
]! ]P                  R8  R4      R 4       tR tR	 tR
 tRtR# )StringListMailboxTestsi_  zW
Tests for L{StringListMailbox}, an in-memory only implementation of
L{pop3.IMailbox}.
c                   \         P                  P                  . RO4      pV P                  VP	                  ^ 4      ^4       V P                  VP	                  ^4      ^4       V P                  VP	                  ^4      ^4       R# )zr
L{StringListMailbox.listMessages} returns the length of the message at
the offset into the mailbox passed to it.
N)abcabr/   r   r   StringListMailboxr8   listMessagesrK   mailboxs   & rO   test_listOneMessage*StringListMailboxTests.test_listOneMessagef  sj    
 ,,001CD--a0!4--a0!4--a0!4r[   c                    \         P                  P                  . RO4      pV P                  VP	                  4       . RO4       R# )zi
L{StringListMailbox.listMessages} returns a list of the lengths of all
messages if not passed an index.
N)r/   r  r  )   rp      r  r
  s   & rO   test_listAllMessages+StringListMailboxTests.test_listAllMessagesp  s2    
 ,,001CD--/;r[   r+   c                    \         P                  P                  RR.4      pV P                  VP	                  ^4      P                  4       R4       R# )z
L{StringListMailbox.getMessage} returns a file-like object from which
the contents of the message at the given offset into the mailbox can be
read.
foozreal contentsN)r   r   r  r8   
getMessager   r
  s   & rO   test_getMessage&StringListMailboxTests.test_getMessagex  sA     ,,00%1IJ++A.335Gr[   c                    \         P                  P                  RR.4      pV P                  VP	                  ^ 4      VP	                  ^4      4       R# )zp
L{StringListMailbox.getUidl} returns a unique identifier for the
message at the given offset into the mailbox.
r  barN)r   r   r  assertNotEqualgetUidlr
  s   & rO   test_getUidl#StringListMailboxTests.test_getUidl  s>     ,,00%@GOOA.0BCr[   c                    \         P                  P                  R.4      pVP                  ^ 4       V P	                  VP                  ^ 4      ^ 4       V P	                  VP                  4       ^ .4       R# )zv
L{StringListMailbox.deleteMessage} marks a message for deletion causing
further requests for its length to return 0.
r  N)r   r   r  deleteMessager8   r	  r
  s   & rO   test_deleteMessage)StringListMailboxTests.test_deleteMessage  s^    
 ,,00%9a --a0!4--/!5r[   c                   \         P                  P                  R.4      pVP                  ^ 4       VP	                  4        V P                  VP                  ^ 4      ^4       V P                  VP                  4       ^.4       R# )zw
L{StringListMailbox.undeleteMessages} causes any messages marked for
deletion to be returned to their original state.
r  N)r   r   r  r  undeleteMessagesr8   r	  r
  s   & rO   test_undeleteMessages,StringListMailboxTests.test_undeleteMessages  sj    
 ,,00%9a   "--a0!4--/!5r[   c                ,   \         P                  P                  R.4      pVP                  ^ 4       VP	                  4        VP                  4        V P                  VP                  ^ 4      ^ 4       V P                  VP                  4       ^ .4       R# )za
L{StringListMailbox.sync} causes any messages as marked for deletion to
be permanently deleted.
r  N)r   r   r  r  syncr#  r8   r	  r
  s   & rO   	test_sync StringListMailboxTests.test_sync  ss    
 ,,00%9a   "--a0!4--/!5r[   r5   Nro   )rU   rq   rr   rs   r   r  r  r   rt   ru   r  r  r   r$  r(  rv   r5   r[   rO   r  r  _  st    
5< C$&>?H @H C$&>?D @D6	6
6r[   r  c                  4    ] tR tRtRtRtRtR tR tR t	Rt
R# )&FailingMaildirMailboxAppendMessageTaski  Tc                	    V P                   '       d   \        P                  ! WV4      # \        \        P
                  R 4      hzFaked Permission Problem)
_openstater   r   OSErrorerrnoEPERM)rK   fnattrmodes   &&&&rO   osopen-FailingMaildirMailboxAppendMessageTask.osopen  s.    ???772T**%++'ABBr[   c                	    V P                   '       d   \        P                  ! W4      # \        \        P
                  R 4      h)zFaked Space problem)_writestater   writer/  r0  ENOSPC)rK   fhdatas   &&&rO   oswrite.FailingMaildirMailboxAppendMessageTask.oswrite  s/    88B%%%,,(=>>r[   c                	    V P                   '       d   \        P                  ! W4      # \        \        P
                  R 4      hr-  )_renamestater   renamer/  r0  r1  )rK   oldnamenewnames   &&&rO   osrename/FailingMaildirMailboxAppendMessageTask.osrename  s/    99W..%++'ABBr[   r5   N)rU   rq   rr   rs   r.  r8  r@  r5  r=  rD  rv   r5   r[   rO   r+  r+    s$     JKLC?Cr[   r+  c                  &    ] tR tRtRtR R ltRtR# )_AppendTestMixini  z
Mixin for L{MaildirMailbox.appendMessage} test cases which defines a helper
for serially appending multiple messages to a mailbox.
c               $    V ^8  d   QhRRRRRR/# )r  mboxz#twisted.mail.maildir.MaildirMailboxmessageszlist[bytes]returnzDeferred[list[None]]r5   )formats   "rO   __annotate___AppendTestMixin.__annotate__  s$     0 070CN0	0r[   c                P   aa R VV3R llp\         P                  ! V! 4       4      # )z
Deliver the given messages one at a time.  Delivery is serialized to
guarantee a predictable order in the mailbox (overlapped message deliver
makes no guarantees about which message which appear first).
c                   V ^8  d   QhRR/# )r  rK  z
list[None]r5   )rL  s   "rO   rM  6_AppendTestMixin._appendMessages.<locals>.__annotate__  s     	 	j 	r[   c                 ~   <"   . p S F-  pSP                  V4      G R j  xL
  V P                  R 4       K/  	  V #  L5irz   )appendMessageappend)resultsmrI  rJ  s     rO   rT  0_AppendTestMixin._appendMessages.<locals>.append  sA     "$G((+++t$  N ,s   =;=r   fromCoroutine)rK   rI  rJ  rT  s   &ff rO   _appendMessages _AppendTestMixin._appendMessages  s"    	 	 %%fh//r[   r5   N)rU   rq   rr   rs   r   rZ  rv   r5   r[   rO   rG  rG    s    
0 0r[   rG  c                  Z    ] tR tRtRtR R ltR R ltRR ltR	 R
 ltR R lt	R t
RtR# )MaildirAppendStringTestsi  G
Tests for L{MaildirMailbox.appendMessage} when invoked with a C{str}.
c                   V ^8  d   QhRR/# r  rK  Noner5   )rL  s   "rO   rM  %MaildirAppendStringTests.__annotate__  s     / /t /r[   c                	    \         P                  ! V P                  4       4      V n        \        P
                  P                  V P                  4       R # rz   )r   fsencoder   rM   r   r   initializeMaildirr]   s   &rO   r|   MaildirAppendStringTests.setUp  s.    T[[]+&&tvv.r[   c               $    V ^8  d   QhRRRRRR/# )r  ignoredr   rI  r   rK  zDeferred[None]r5   )rL  s   "rO   rM  rb    s!     0 0v 0^ 0 0r[   c                	P    VP                  R 4      pV P                  V\        4      # )s   TEST)rS  assertFailure	Exception)rK   rh  rI  rM   s   &&& rO   _append MaildirAppendStringTests._append  s%    w'!!!Y//r[   Nc                   VeG   V P                  \        VP                  RVP                  P                  4       W2P                  n        VeG   V P                  \        VP                  RVP                  P                  4       WBP                  n        VeI   V P                  \        VP                  RVP                  P
                  4       WRP                  n        R# R# )a  
Change the behavior of future C{rename}, C{write}, or C{open} calls made
by the mailbox C{mbox}.

@param rename: If not L{None}, a new value for the C{_renamestate}
    attribute of the mailbox's append factory.  The original value will
    be restored at the end of the test.

@param write: Like C{rename}, but for the C{_writestate} attribute.

@param open: Like C{rename}, but for the C{_openstate} attribute.
Nr@  r8  r.  )r   setattrAppendFactoryr@  r8  r.  )rK   rh  rI  rA  r9  r   s   &&&&&&rO   	_setState"MaildirAppendStringTests._setState  s     OO""""//	 /5+OO""""..	 .3*OO++\4;M;M;X;X -1)	 r[   c                   V ^8  d   QhRR/# r  rK  r   r5   )rL  s   "rO   rM  rb    s      S r[   c                ^   \         P                  P                  V P                  4      p\        Vn        T P                  T\        ^^4       Uu. uF  pRV,          NK  	  up4      pVP                  V P                  R.^
,          4       VP                  V P                  V4       V# u upi )~
L{MaildirMailbox.appendMessage} returns a L{Deferred} which fires when
the message has been added to the end of the mailbox.
   XN)r   r   r   rM   r+  rp  rZ  r6   r   r8   _cbTestAppend)rK   rI  irM   s   &   rO   test_append$MaildirAppendStringTests.test_append  s    
 ||**4662C  %2,'G,Qq,'GH	d&&4	d(($/ (Hs   B*
c                   V ^8  d   QhRR/# rt  r5   )rL  s   "rO   rM  rb    s     , ,C ,r[   c                L   a  R V 3R llp\         P                  ! V! 4       4      # )z
Appending a message, then re-opening the mailbox by creating a new
MaildirMailbox, should result in seeing the message as loadable.
c                   V ^8  d   QhRR/# r`  r5   )rL  s   "rO   rM  AMaildirAppendStringTests.test_reopenMailbox.<locals>.__annotate__%  s     		J 		J$ 		Jr[   c                   <"   \         P                  P                  SP                  4      p R pV P	                  V4      G Rj  xL
  \         P                  P                  SP                  4      pVP                  4       pSP                  \        V4      ^4       Vw  pSP                  V\        V4      4       SP                  VP                  ^ 4      P                  4       VP                  4       4       R#  L5i)s   xyzzyN)r   r   r   rM   rS  r	  r8   r9   r  r   decode)mbox1samplembox2listedmessageSizerK   s        rO   go7MaildirAppendStringTests.test_reopenMailbox.<locals>.go%  s     LL//7EF%%f---LL//7E'')FS[!,"M[[#f+6U--a0557I .s   A C<C:B7C<rX  )rK   r  s   f rO   test_reopenMailbox+MaildirAppendStringTests.test_reopenMailbox  s$    		J 		J %%bd++r[   c           
        V P                  \        VP                  4       4      ^
4       T P                  \        ^
4       Uu. uF+  p\        VP	                  V4      P                  4       4      NK-  	  up\        \        ^^4      4      4       V P                  RVRR7       V P                  RV4      pVP                  V P                  VRRR7       VP                  V P                  V4       VP                  V P                  VRRR7       VP                  V P                  V4       VP                  V P                  VRR7       V# u upi )
Check that the mailbox has the expected number (ten) of messages in it,
and that each has the expected contents, and that they are in the same
order as that in which they were appended.
NF)rA  T)rA  r9  )r9  r   )r   )
r8   r9   r	  r6   r  r   r:   rq  rl  r   )rK   rh  rI  ry  rM   s   &&&  rO   rx  &MaildirAppendStringTests._cbTestAppend2  s    	T..01265:2Y?YS#((*+Y?eArlAS	
 	tT%0LLt$	dnnd4uE	dllD)	dnnd$UC	dllD)	dnnd6 @s   1E
rM   )NNN)rU   rq   rr   rs   r   r|   rl  rq  rz  r  rx  rv   r5   r[   rO   r]  r]    s&    /0!1F,&r[   r]  c                  ^    ] tR tRtRtR t]! ]P                  R	8  R4      R 4       t	R t
RtR# )
MaildirAppendFileTestsiG  r^  c                	    V P                  4       V n        \        P                  P	                  V P                  4       R # rz   r   rM   r   r   re  r]   s   &rO   r|   MaildirAppendFileTests.setUpM  %    &&tvv.r[   r+   c                   \         P                  P                  V P                  4      p. p\	        ^^4       Fn  p\
        P                  ! 4       pVP                  RV,          4       VP                  ^ ^ 4       VP                  V4       V P                  VP                  4       Kp  	  V P                  W4      pVP                  V P                  V4       V# )rv  X)r   r   r   rM   r6   tempfileTemporaryFiler9  seekrT  r   r   rZ  r   rx  )rK   rI  rJ  ry  temprM   s   &     rO   rz  "MaildirAppendFileTests.test_appendQ  s     ||**4662q"A))+DJJsQwIIaOOOD!OODJJ'    0	d(($/r[   c           
     *   V P                  \        VP                  4       4      ^
4       T P                  \        ^
4       Uu. uF+  p\        VP	                  V4      P                  4       4      NK-  	  up\        \        ^^4      4      4       R# u upi )r  N)r8   r9   r	  r6   r  r   r:   )rK   r   rI  ry  s   &&& rO   rx  $MaildirAppendFileTests._cbTestAppendd  sm     	T..01265:2Y?YS#((*+Y?eArlAS	
?s   1Br  Nro   )rU   rq   rr   rs   r   r|   r   rt   ru   rz  rx  rv   r5   r[   rO   r  r  G  s9    / C$&>? @$	
r[   r  c                  f    ] tR tRtR tR tR tR t]! ]	P                  R
8  R4      R 4       tRtR	# )MaildirTestsip  c                	    V P                  4       V n        \        P                  P	                  V P                  4       R # rz   r  r]   s   &rO   r|   MaildirTests.setUpr  r  r[   c                	F    \         P                  ! V P                  4       R # rz   )shutilrmtreerM   r]   s   &rO   tearDownMaildirTests.tearDownv  s    dffr[   c                	(   V P                   p\        P                  P                  VR 4      pT P	                  \        P                  P                  V4      ;'       d     \        P                  P                  V4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       V P	                  \        P                  P                  \        P                  P                  VR4      4      4       R# ).TrashnewcurtmpN)rM   r   r   joinrC   r   isdir)rK   rM   trashs   &  rO   testInitializerMaildirTests.testInitializery  s-   FFQ)q)>>bggmmA.>?rww||Au'=>?rww||Au'=>?rww||Au'=>?bggll1e&<=>bggll1e&<=>bggll1e&<=>rww||E5'ABCrww||E5'ABCrww||E5'ABCbggll5%&@ABbggll5%&@ABbggll5%&@ABr[   c                   \         P                  ! 4       pVP                  R4       \        P                  P                  V4      pVP                  4       pVP                  R4       VP                  4       pV P                  W48  4       R# )z
Each call to L{_MaildirNameGenerator.generate} returns a unique
string suitable for use as the basename of a new message file.  The
names are ordered such that those generated earlier sort less than
those generated later.
g?N)r   Clockadvancer   r   _MaildirNameGeneratorgeneraterC   )rK   clock	generator	firstName
secondNames   &    rO   test_nameGeneratorMaildirTests.test_nameGenerator  sf     

dLL66u=	&&(	d'')
	./r[   r+   c           
     V   \         P                  P                  p\        P                  P
                  pR UUu. uF!  p\        ^4       F  qA! W2! 4       4      NK  	  K#  	  ppp^pV FR  p\        V! V P                  V4      R4      ;_uu_ 4       pVP                  RV,          4       RRR4       V^,           pKT  	  \        P                  P                  V P                  4      p	V P                  V	P                  4       \        \        ^^4      4      4       V P                  V	P                  ^4      ^4       V P                  V	P                  ^4      ^4       V P                  V	P                  ^4      P                  4       R4       V P                  V	P                  ^4      P                  4       R4       / p
\        ^
4       F+  pV	P!                  V4      pV P#                  W9   4       RW&   K-  	  \         P                  P%                  V^,          4      w  rV	P'                  ^4       V P                  V	P                  ^4      ^ 4       V P)                  \         P                  P+                  V! V P                  RRV4      4      4       V P#                  \         P                  P+                  V! V P                  V^,          4      4      4       V	P-                  4        V P                  V	P                  ^4      ^4       V P#                  \         P                  P+                  V! V P                  RRV4      4      4       V P)                  \         P                  P+                  V! V P                  V^,          4      4      4       R# u uppi   + '       g   i     EL; i)	zJ
Exercise the methods of L{IMailbox} as implemented by
L{MaildirMailbox}.
r  wrL   Nr  )r  r  xxxxxxxxx)r   r   r  r   r   _generateMaildirNamer6   r   rM   r9  r   r8   r	  r:   r  r   r  r   r   r  rC   r   r#  )rK   jnr0   rL   msgsry  r   fObjmbrM   ups   &            rO   test_mailboxMaildirTests.test_mailbox  s    GGLLLL--#1D>a58a!QS	8	>D AalC((D

37# )AA 
 \\((0*Dq",>?+Q/+Q/q)..0':q)..0':rA

1AQV$AD 
 ww}}T!W%
+Q/q5!'DEF$&&$q'(:;<
+Q/$&&(E1(EFGqa'9:;C E
 )((s   'NNN(r  Nro   )rU   rq   rr   rs   r|   r  r  r  r   rt   ru   r  rv   r5   r[   rO   r  r  p  s?    /C&0" C$&>?(< @(<r[   r  c                       ] tR tRtRtR tRtR# )AbstractMaildirDomainTestsi  z:
Tests for L{twisted.mail.maildir.AbstractMaildirDomain}.
c                ~    \        \        P                  P                  \        P                  P                  4       R# )zG
L{maildir.AbstractMaildirDomain} implements L{mail.IAliasableDomain}.
N)r	   r   IAliasableDomainr   AbstractMaildirDomainr]   s   &rO   test_interface)AbstractMaildirDomainTests.test_interface  s"     	DII..0R0RSr[   r5   N)rU   rq   rr   rs   r   r  rv   r5   r[   rO   r  r    s    Tr[   r  c                      ] tR tRtRtR R ltR t]! ]P                  R8  R4      R 4       t
R t]! ]P                  R8  R4      R	 4       t]! ]P                  R8  R4      R
 4       tR R ltRtR# )MaildirDirdbmDomainTestsi  z#
Tests for L{MaildirDirdbmDomain}.
c                   V ^8  d   QhRR/# r`  r5   )rL  s   "rO   rM  %MaildirDirdbmDomainTests.__annotate__  s     B Bt Br[   c                    V P                  4       V n        \        P                  P                  4       V n        \        P
                  P                  V P                  V P                  4      V n        R# )z_
Create a temporary L{MaildirDirdbmDomain} and parent
L{MailService} before running each test.
N)r   Pr   r   Sr   MaildirDirdbmDomainDr]   s   &rO   r|   MaildirDirdbmDomainTests.setUp  sE    
 &&(11$&&$&&Ar[   c                F    \         P                  ! V P                  4       R# )zG
Remove the temporary C{maildir} directory when the test has
finished.
N)r  r  r  r]   s   &rO   r  !MaildirDirdbmDomainTests.tearDown  s    
 	dffr[   r+   c           	        RpV F   w  r#V P                   P                  W#4       K"  	  V F  w  r#V P                  W P                   P                  9   4       V P	                  V P                   P                  V,          V4       V P                  \
        P                  P                  \
        P                  P                  V P                  V4      4      4       K  	  R# )z
L{MaildirDirdbmDomain.addUser} accepts a user and password
argument. It stores those in a C{dbm} dictionary
attribute and creates a directory for each user.
N))user1pwd1)user2pwd2)user3pwd3)
r  r   rC   dbmr8   r   r   r   r  r  )rK   toAddr  r  s   &   rO   test_addUser%MaildirDirdbmDomainTests.test_addUser  s     JDAFFNN1   DAOOAO,TVVZZ]A.OOBGGNN277<<+BCD r[   c                h   V P                   P                  4       pV P                  \        V4      ^4       V P	                  \
        P                  P                  P                  V^ ,          4      4       V P	                  \
        P                  P                  V^ ,          P                  9   4       R# )zv
L{MaildirDirdbmDomain.getCredentialsCheckers} initializes and
returns one L{ICredentialsChecker} checker by default.
N)r  getCredentialsCheckersr8   r9   rC   r
   checkersICredentialsChecker
providedBycredentialsIUsernamePasswordcredentialInterfaces)rK   credss   & rO   test_credentials)MaildirDirdbmDomainTests.test_credentials  sy    
 --/UQ'99DDU1XNO..%(2O2OO	
r[   c                    ! R R\         4      pV P                  P                  RR4       V P                  \        V P                  P
                  RRV4       V P                  P                  RR\        P                  4      pV P                  \        V4      ^4       V P                  V^ ,          \        P                  J 4       V P                  \        P                  P                  V^,          4      4       V^,          ! 4        R# )a  
L{MaildirDirdbmDomain.requestAvatar} raises L{NotImplementedError}
unless it is supplied with an L{pop3.IMailbox} interface.
When called with an L{pop3.IMailbox}, it returns a 3-tuple
containing L{pop3.IMailbox}, an implementation of that interface
and a NOOP callable.
c                      ] tR tRtRtR# )?MaildirDirdbmDomainTests.test_requestAvatar.<locals>.ISomethingi  r5   N)rU   rq   rr   rs   rv   r5   r[   rO   
ISomethingr    s    r[   r  userr   N)r   r  r   r   NotImplementedErrorrequestAvatarr   IMailboxr8   r9   rC   r  )rK   r  ts   &  rO   test_requestAvatar+MaildirDirdbmDomainTests.test_requestAvatar	  s    	 	 	vz*!5!5vtZ	
 FF  t}}=Q#!-.00167	!r[   c                   V P                   P                  RR4       V P                   P                  4       ^ ,          p\        P                  P                  RR4      pV P                  \        P                  P                  VP                  V4       \        P                  P                  RR4      pV P                  VP                  V4      R4       R# )z
L{DirdbmDatabase.requestAvatarId} raises L{UnauthorizedLogin} if
supplied with invalid user credentials.
When called with valid credentials, L{requestAvatarId} returns
the username associated with the supplied credentials.
r  r   zwrong passwordN)r  r   r  r
   r  UsernamePasswordr   errorUnauthorizedLoginrequestAvatarIdr8   )rK   databaser  s   &  rO   test_requestAvatarId-MaildirDirdbmDomainTests.test_requestAvatarId"  s     	vz*6600215  11&:JK$**668P8PRWX  11&*E11%8&Ar[   c                   V ^8  d   QhRR/# r`  r5   )rL  s   "rO   rM  r  3  s     
 
D 
r[   c                L   V P                   P                  RR4       V P                  V P                   P                  R4      \        P
                  P                  V P                   P                  R4      4       RV P                   n        V P                  V P                   P                  R4      R4       RV P                   n        V P                  V P                   P                  R4      \        P
                  P                  V P                   P                  R4      4       R# )a-  
L{MaildirDirdbmDomain.userDirectory} is supplied with a user name
and returns the path to that user's maildir subdirectory.
Calling L{MaildirDirdbmDomain.userDirectory} with a
non-existent user returns the 'postmaster' directory if there
is a postmaster or returns L{None} if there is no postmaster.
   user   passwordFs   nouserNTs
   postmaster)
r  r   r8   userDirectoryr   r   r  root
postmasterassertIdenticalr]   s   &rO   test_userDirectory+MaildirDirdbmDomainTests.test_userDirectory3  s     	w,FF  )277<<W+M	
 "TVV11)<dC FF  +GGLLm4	
r[   )r  r  r  Nro   )rU   rq   rr   rs   r   r|   r  r   rt   ru   r  r  r  r  r  rv   r5   r[   rO   r  r    s    B C$&>?E @E
 C$&>? @0 C$&>?B @B 
 
r[   r  c                  B    ] tR tRtRtRR ltR tR tR tR R	 lt	R
t
R# )StubAliasableDomainiJ  z6
Minimal testable implementation of IAliasableDomain.
Nc                    \        4       hzc
No test coverage for invocations of this method on domain objects,
so we just won't implement it.
r  rK   r  memos   &&&rO   r   StubAliasableDomain.existsP      
 "##r[   c                    \        4       hr  r  )rK   r  r   s   &&&rO   r   StubAliasableDomain.addUserW  r  r[   c                    . # )z
This needs to succeed in order for other tests to complete
successfully, but we don't actually assert anything about its
behavior.  Return an empty list.  Sometime later we should return
something else and assert that a portal got set up properly.
r5   r]   s   &rO   r  *StubAliasableDomain.getCredentialsCheckers^  s	     	r[   c                    Wn         R# )z7
Just record the value so the test can check it later.
N
aliasGroup)rK   aliasess   &&rO   setAliasGroup!StubAliasableDomain.setAliasGroupg  s	     "r[   c               (    V ^8  d   QhRRRRRRRR/# )	r  avatarIdzbytes | tuple[()]mindr   r   ztype[Interface]rK  r   r5   )rL  s   "rO   rM   StubAliasableDomain.__annotate__m  s,     $ $)$17$FU$	$r[   c                    \        4       h)z)
Stub domains cannot authenticate users.
r  )rK   r$  r%  r   s   &&&*rO   r  !StubAliasableDomain.requestAvatarm  s     "##r[   r  rz   )rU   rq   rr   rs   r   r   r   r  r!  r  rv   r5   r[   rO   r  r  J  s%    $$"$ $r[   r  c                      ] tR tRtR tR tR t]! ]P                  R8  R4      R 4       t
]! ]P                  R8  R4      R 4       tR tR	 tR
 tR tRtR# )ServiceDomainTestsiv  c                	   \         P                   P                  4       V n        \         P                  P	                  V P                  R 4      V n        V P                  V P
                  n        RV P
                  n        RV P
                  n        V P                  4       V n
        \         P                  P                  V P                  V P                  4      pVP                  RR4       V P                  P                  RV4       R # )NTESThostnamer  r	  test.domain)r   r   r  r   DomainDeliveryBaser  r   protocolNamehostr   tmpdirr   r  r   r   rK   rX   s   & rO   r|   ServiceDomainTests.setUpx  s    &&(224664@$ kkm11$&&$++Fw,/r[   c                	F    \         P                  ! V P                  4       R # rz   r  r  r2  r]   s   &rO   r  ServiceDomainTests.tearDown      dkk"r[   c                    \        4       p\        4       pWP                  n        V P                  P	                  RV4       V P                  VP                  V4       R# )zj
Test that adding an IAliasableDomain to a mail service properly sets
up alias group references and such.
example.comN)r   r  r  r   r   r  r  )rK   r   rX   s   &  rO   testAddAliasableDomain)ServiceDomainTests.testAddAliasableDomain  sF    
 ($& /V..8r[   r+   c                	j   V P                   P                  R\        P                  ! R4      R.4      p\        P
                  ! V4      p\        P                  P                  4       pVP                  V4      pV P                  \        VP                  4       4      ^4       V P                  RV4       R# )
remotehostz<someguy@someplace>zuser@host.nameReceivedN)r>  z123.232.101.234)r  receivedHeaderr   AddressioBytesIOemailparserParserparser8   r9   r@   rS   )rK   hdrr   emailParserrV  s   &    rO   testReceivedHeader%ServiceDomainTests.testReceivedHeader  s    ff##-LL./

 ZZ_ll))+b!QWWY+j!$r[   c                	    \         P                  ! R RRR4      p\        P                  ! V P                  P
                  V4      P                  V P                  4      # )zuser@test.domainheloNwherever@whatever)r   Userr   maybeDeferredr  
validateTor   _cbValidateTorK   r  s   & rO   testValidateTo!ServiceDomainTests.testValidateTo  sK    yy+VT;NO""466#4#4d;GG
 	
r[   c                	:    V P                  \        V4      4       R # rz   )rC   callabler   s   &&rO   rR   ServiceDomainTests._cbValidateTo  s    ()r[   c                	    \         P                  ! R RRR4      pV P                  \        P                  ! V P
                  P                  V4      \         P                  4      # )zresu@test.domainrM  NrN  r   rO  rj  r   rP  r  rQ  r   rS  s   & rO   testValidateToBadUsername,ServiceDomainTests.testValidateToBadUsername  M    yy+VT;NO!! 1 148$:J:J
 	
r[   c                	    \         P                  ! R RRR4      pV P                  \        P                  ! V P
                  P                  V4      \         P                  4      # )zuser@domain.testrM  NrN  rZ  rS  s   & rO   testValidateToBadDomain*ServiceDomainTests.testValidateToBadDomain  r]  r[   c                	
   Rp\         P                  ! R4      pV P                  V P                  P	                  W4      VJ 4       Rp\         P                  ! R4      pV P                  V P                  P	                  W4      VJ 4       Rp\         P                  ! R4      pV P                  V P                  P	                  W4      VJ 4       V P                  \         P                  V P                  P                  RV4       R# )r-  z<user@hostname>z<>N)r-  r   )r-  1.2.3.4)r   rA  rC   r  validateFromr   SMTPBadSender)rK   rM  origins   &  rO   testValidateFrom#ServiceDomainTests.testValidateFrom  s    (/0++D9VCD&/0++D9VCD&d#++D9VCD$,,dff.A.A4Pr[   )r  r  r2  Nro   )rU   rq   rr   rs   r|   r  r;  r   rt   ru   rJ  rT  rR  r[  r_  rf  rv   r5   r[   rO   r*  r*  v  sv    
0#	9 C$&>?
% @
% C$&>?
 @
*

Qr[   r*  c                      ] tR tRtR R ltR t]! ]P                  R8  R4      R 4       t	R t
]! ]P                  R8  R4      R 4       t]! ]P                  R8  R4      R	 4       tR
 R ltR tR R ltR R ltRtR# )VirtualPOP3Testsi  c                   V ^8  d   QhRR/# r`  r5   )rL  s   "rO   rM  VirtualPOP3Tests.__annotate__  s     	, 	,t 	,r[   c                	V   V P                  4       V n        \        P                  P                  4       V n        \        P
                  P                  V P                  V P                  4      V n        V P                  P                  R R4       V P                  P                  RV P                  4       V P                  P                  RV P                  4       \        P                  P                  4       V n        V P                  V P                  n        RV P                  n        R# )r  r	  s   test.domainr[   s   <unit test magic>N)r   r2  r   r   r  r   r  r  r   r   r   VirtualPOP3r  r   magicr]   s   &rO   r|   VirtualPOP3Tests.setUp  s    kkm&&(11$&&$++Fw,0dff%++-+r[   c                	F    \         P                  ! V P                  4       R # rz   r6  r]   s   &rO   r  VirtualPOP3Tests.tearDown  r8  r[   r+   c                	    \        V P                  P                  R ,           4      P                  4       pV P                  P	                  RV4      P                  V P                  4      # )r   r  )r   r  rn  	hexdigestauthenticateUserAPOPr   _cbAuthenticateAPOPrK   resps   & rO   testAuthenticateAPOP%VirtualPOP3Tests.testAuthenticateAPOP  sO    466<<*,-779vv**648DD$$
 	
r[   c                	   V P                  \        V4      ^4       V P                  V^ ,          \        P                  4       V P	                  \        P                  P                  V^,          4      4       V^,          ! 4        R# rp   Nr8   r9   r   r  rC   r  r   s   &&rO   ru  $VirtualPOP3Tests._cbAuthenticateAPOP  V    Va(DMM200;<q	r[   c                	    \        V P                  P                  R ,           4      P                  4       pV P	                  V P                  P                  RV4      \        P                  P                  4      # )r   resu)	r   r  rn  rs  rj  rt  r
   r   r  rv  s   & rO   !testAuthenticateIncorrectUserAPOP2VirtualPOP3Tests.testAuthenticateIncorrectUserAPOP  sU    466<<*,-779!!FF''5tzz7S7S
 	
r[   c                	    \        R 4      P                  4       pV P                  V P                  P	                  RV4      \
        P                  P                  4      # )zwrong digestr  )r   rs  rj  r  rt  r
   r   r  rv  s   & rO   %testAuthenticateIncorrectResponseAPOP6VirtualPOP3Tests.testAuthenticateIncorrectResponseAPOP  sH    >",,.!!FF''5tzz7S7S
 	
r[   c                   V ^8  d   QhRR/# )r  rK  zDeferred[object]r5   )rL  s   "rO   rM  rk    s     
 
&6 
r[   c                	l    V P                   P                  R R4      P                  V P                  4      # )r  r	  )r  authenticateUserPASSr   _cbAuthenticatePASSr]   s   &rO   testAuthenticatePASS%VirtualPOP3Tests.testAuthenticatePASS  s/    vv**7K@LL$$
 	
r[   c                	   V P                  \        V4      ^4       V P                  V^ ,          \        P                  4       V P	                  \        P                  P                  V^,          4      4       V^,          ! 4        R# r{  r|  r   s   &&rO   r  $VirtualPOP3Tests._cbAuthenticatePASS  r~  r[   c                   V ^8  d   QhRR/# rt  r5   )rL  s   "rO   rM  rk    s     
 
S 
r[   c                	    V P                  V P                  P                  R R4      \        P                  P
                  4      # )s   resur	  rj  r  r  r
   r   r  r]   s   &rO   testAuthenticateBadUserPASS,VirtualPOP3Tests.testAuthenticateBadUserPASS  s6    !!FF''=JJ((
 	
r[   c                   V ^8  d   QhRR/# rt  r5   )rL  s   "rO   rM  rk    s     
 
 
r[   c                	    V P                  V P                  P                  R R4      \        P                  P
                  4      # )r  s   wrong passwordr  r]   s   &rO   testAuthenticateBadPasswordPASS0VirtualPOP3Tests.testAuthenticateBadPasswordPASS  s7    !!FF''1BCJJ((
 	
r[   )r  r  r  r2  Nro   )rU   rq   rr   rs   r|   r  r   rt   ru   rx  ru  r  r  r  r  r  r  rv   r5   r[   rO   ri  ri    s    	,# C$&>?
 @
 C$&>?
 @
 C$&>?
 @




 
r[   ri  c                      ] tR tRtR tRtR# )emptyi  c                	    R # rz   r5   r]   s   &rO   __init__empty.__init__	  s    r[   r5   N)rU   rq   rr   rs   r  rv   r5   r[   rO   r  r    s    r[   r  c                  N    ] tR tRt]! ]P                  R8  R4      R 4       tRtR# )
RelayTestsi  r+   c                	  a \         P                   P                  4       p\         P                  P                  V4      p\        P
                  ! R 4      \        P                  ! RRR4      .p\        P                  ! RR^>4      \        P                  ! RRR4      .pV F  o\        4       pRVn        RVn	        \        4       Vn
        \        4       VP                  n        V3R	 lVP                  P                  n        V P                  \        VP                  V4      4      4       K  	  V F  o\        4       pR
Vn        \        4       Vn
        \        4       VP                  n        V3R lVP                  P                  n        RVn	        V P!                  \"        P$                  VP                  V4       K  	  R# )z/var/run/mail-relayTCPr   r   z192.168.2.1rb  i  z	user@hostz	tsoh@resuc                    < S # rz   r5   peers   rO   <lambda>'RelayTests.testExists.<locals>.<lambda>$      dr[   z
some@placec                    < S # rz   r5   r  s   rO   r  r  -  r  r[   z	who@caresN)r   r   relayDomainQueuerr   UNIXAddressIPv4Addressr  origdestr   r   getPeerrC   rW  r   r   r   r   )rK   r   rX   doRelay	dontRelayr  r  s   &     @rO   r   RelayTests.testExists  sJ   ))'')((1  56{E:
 }b9y$7
	
 D7D#DI#DI!GDM&+gDMM#.:DMM##+OOHV]]4%89:  D7D$DI!GDM&+gDMM#.:DMM##+#DId..tD r[   r5   Nro   )	rU   rq   rr   rs   r   rt   ru   r   rv   r5   r[   rO   r  r    s*    C$&>? E @ Er[   r  c                  4    ] tR tRtR tR tR tR tR tRt	R# )	RelayerTestsi3  c                	   V P                  4       V n        \        P                  ! V P                  4       . V n        \        ^
4       F  p\        P                  P                  V P                  RV3,          4      p\        VR,           R4      ;_uu_ 4       p\        P                  ! RV3,          RV3,          .V4       RRR4       \        VR,           R4      pVP                  V4       VP                  ^ ^ 4       V P                  P                  V4       K  	  \        P                  P!                  4       V n        V P"                  P%                  V P                  4       R#   + '       g   i     L; i)	r-   body-%d-Hr   from-%dto-%dN-Dr  )r   r2  r   mkdirmessageFilesr6   r   r  r   pickledumpr9  r  rT  r   r  RelayerMixinRloadMessages)rK   ry  r   r   s   &   rO   r|   RelayerTests.setUp5  s   kkm
rA77<<Y!-=>DdTk4((AY!-w!~>B ) TD[#&AGGDMFF1aL$$T*  ((*D--. )(s   *E))E9c                	F    \         P                  ! V P                  4       R # rz   r6  r]   s   &rO   r  RelayerTests.tearDownF  r8  r[   c                	    \        ^
4       FT  pV P                  V P                  P                  4       RV3,          4       V P                  P	                  ^RRRR4       KV  	  V P                  V P                  P                  4       R4       R# )r-   r  N)r6   r8   r  getMailFromsentMailrK   ry  s   & rO   testMailFromRelayerTests.testMailFromI  sk    rATVV//19t3CDFFOOCtT48  	++-t4r[   c                	"   \        ^
4       FU  pV P                  V P                  P                  4       RV3,          .4       V P                  P	                  ^RRRR4       KW  	  V P                  V P                  P                  4       R4       R# )r-   r  N)r6   r8   r  	getMailTor  r  s   & rO   
testMailToRelayerTests.testMailToO  sm    rATVV--/'QD.1ABFFOOCtT48  	))+T2r[   c                	   \        ^
4       F  p\        P                  P                  V P                  RV3,          4      pV P                  V P                  P                  4       P                  4       V4       V P                  P                  ^RRRR4       K  	  V P                  V P                  P                  4       R4       R# )r-   r  N)
r6   r   r   r  r2  r8   r  getMailDatar   r  )rK   ry  r   s   &  rO   testMailDataRelayerTests.testMailDataU  s    rA77<<Y!-=>DTVV//1668$?FFOOCtT48  	++-t4r[   )r  r  r2  N)
rU   rq   rr   rs   r|   r  r  r  r  rv   r5   r[   rO   r  r  3  s    /"#535r[   r  c                  .    ] tR tRtR tR tR tR tRtR# )Manageri]  c                	0    . V n         . V n        . V n        R # rz   )successr#   doner]   s   &rO   r  Manager.__init__^  s    	r[   c                	>    V P                   P                  W34       R # rz   )r  rT  rK   r   rg   s   &&&rO   notifySuccessManager.notifySuccessc      W./r[   c                	>    V P                   P                  W34       R # rz   )r#   rT  r  s   &&&rO   notifyFailureManager.notifyFailuref  r  r[   c                	<    V P                   P                  V4       R # rz   )r  rT  )rK   r   s   &&rO   
notifyDoneManager.notifyDonei  s    		!r[   )r  r#   r  N)	rU   rq   rr   rs   r  r  r  r  rv   r5   r[   rO   r  r  ]  s    
00"r[   r  c                  .    ] tR tRtR tR tR tR tRtR# )ManagedRelayerTestsim  c                	   \        4       V n        \        \        ^ ^^4      4      V n        \        4       V n        \        P                  P                  V P                  4      V n
        V P                  R,          V P                  n        V P                  R,          V P                  n        V P                  V P                  n        R# )    :NNNN)r  managerr:   r6   rJ  r   r   r   relaymanagerManagedRelayerMixinr  namesr]   s   &rO   r|   ManagedRelayerTests.setUpo  s~    yU1b!_-x&&::4<<H
"mmA.

==+

!\\

r[   c                	
   V P                    F"  pV P                  P                  ^RRRR4       K$  	  T P                  V P                  P
                  V P                    Uu. uF  q P                  V3NK  	  up4       R# u upi )   N)rJ  r  r  r8   r  r  r   rK   ry  rV  s   &  rO   testSuccessfulSentMail*ManagedRelayerTests.testSuccessfulSentMailx  f    AJJT4t<  	LL  dmm"LmLL!#4m"L	
"L   !B 
c                	
   V P                    F"  pV P                  P                  R RRRR4       K$  	  T P                  V P                  P
                  V P                    Uu. uF  q P                  V3NK  	  up4       R# u upi )i&  N)rJ  r  r  r8   r  r#   r   r  s   &  rO   testFailedSentMail&ManagedRelayerTests.testFailedSentMail  r  r  c                	    V P                   P                  \        P                  ! \	        4       4      4       V P                  V P                  P                  V P                  .4       R # rz   )	r  r   r#   Failurerk  r8   r  r  r   r]   s   &rO   testConnectionLost&ManagedRelayerTests.testConnectionLost  s?    

!!'//)+">?**T\\N;r[   )r   r  rJ  r  N)	rU   rq   rr   rs   r|   r  r  r  rv   r5   r[   rO   r  r  m  s    *

<r[   r  c                      ] tR tRtR tR t]! ]P                  R8  R4      R 4       t	]! ]P                  R8  R4      R 4       t
]! ]P                  R8  R4      R 4       tR tR	tR
# )DirectoryQueueTestsi  c                	N   V P                  4       V n        \        P                  ! V P                  4       \        P
                  P                  V P                  4      V n        R V P                  n        \        ^4       Ft  pV P                  P                  4       w  r#V;_uu_ 4        \        P                  ! RV.V4       RRR4       VP                  RV3,          4       VP                  4        Kv  	  V P                  P                  4        R#   + '       g   i     LY; i)FheaderNs   body: %d)r   r2  r   r  r   r  Queuequeuenoisyr6   createNewMessager  r  r   r   readDirectory)rK   rV  hdrFmsgFs   &   rO   r|   DirectoryQueueTests.setUp  s    kkm
&&,,T[[9
 

rA446JDXqM40 kQD01  	

  "	 s   )DD$c                	F    \         P                  ! V P                  4       R # rz   r6  r]   s   &rO   r  DirectoryQueueTests.tearDown  r8  r[   r+   c                	F   V P                  V P                  P                  4       4       V P                  \	        V P                  P                  4       4      ^4       V P                  P                  4       pV P                  P                  V^ ,          4       V P                  \	        V P                  P                  4       4      ^4       V P                  P                  V^ ,          4       V P                  \	        V P                  P                  4       4      ^4       R#    N)rC   r  
hasWaitingr8   r9   
getWaitingsetRelaying
setWaiting)rK   waitings   & rO   testWaitingDirectoryQueueTests.testWaiting  s    

--/0TZZ2245r:**'')

wqz*TZZ2245r:

gaj)TZZ2245r:r[   c           	     	   V P                   P                  4        Fy  pV P                   P                  V4       V P                  \	        V P                   P                  4       4      ^\	        V P                   P                  4       4      ,
          4       K{  	  V P                  V P                   P                  4       4       V P                   P                  4       pV P                   P                  V^ ,          4       V P                  \	        V P                   P                  4       4      ^4       V P                  \	        V P                   P                  4       4      ^4       R# r  )	r  r  r  r8   r9   
getRelayedr   r
  r  )rK   rV  relayeds   &  rO   testRelaying DirectoryQueueTests.testRelaying  s    &&(AJJ""1%DJJ))+,b3tzz7L7L7N3O.O ) 	..01**'')

gaj)TZZ2245q9TZZ2245r:r[   c                	,   V P                   P                  4       ^ ,          pV P                   P                  V4       V P                   P                  V4       V P	                  \        V P                   P                  4       4      ^4       V P	                  \        V P                   P                  4       4      ^ 4       V P                  WP                   P                  4       9   4       V P                  WP                   P                  4       9   4       R# )r  N)r  r  r  r  r8   r9   r  r   )rK   msgs   & rO   testDoneDirectoryQueueTests.testDone  s    jj##%a(

s#

TZZ2245r:TZZ2245q9

 5 5 778

 5 5 778r[   c                	*   . pV P                   P                  4        F-  pVP                  V P                   P                  V4      4       K/  	  VP	                  4        \        ^4       F&  pV P                  VP                  ^ 4      RV.4       K(  	  R# )r	  r  N)r  r  rT  getEnveloper>   r6   r8   pop)rK   	envelopesr  ry  s   &   rO   testEnvelope DirectoryQueueTests.testEnvelope  sr    	::((*CTZZ33C89 + 	rAY]]1-!}= r[   )r  r2  Nro   )rU   rq   rr   rs   r|   r  r   rt   ru   r  r  r  r  rv   r5   r[   rO   r  r    s    ## C$&>?	; @	; C$&>?; @; C$&>?	9 @	9>r[   r  )clientcommonserverc                  &    ] tR tRtR tRR ltRtR# )TestAuthorityi  c                	R    \         P                  P                  V 4       / V n        R # rz   )r!  ResolverBaser  	addressesr]   s   &rO   r  TestAuthority.__init__  s    $$T*r[   Nc                	   WP                   9   d   V\        P                  8X  d   . pV P                   V,           F_  p\        P                  ! V\        P                  \        P                  ^<\        P
                  ! ^ V4      4      pVP                  V4       Ka  	  \        P                  ! V. . 34      # \        P                  ! \        P                  ! \        P                  ! V4      4      4      # )<   )r'  r   MXr!   INr    rT  r   succeedfailr#   r  DomainError)rK   r   clstypetimeoutrU  r/   rH  s   &&&&&   rO   _lookupTestAuthority._lookup  s    >>!dcffnG^^D))ll4S]]1a=PQs# * =='2r!233zz'//#//$*?@AAr[   )r'  rz   )rU   rq   rr   rs   r  r3  rv   r5   r[   rO   r$  r$    s    B Br[   r$  c                   \        4       V n        \        P                  ! V P                  .4      p\        P
                  ! V4      p \        P                  ! ^ VRR7      V n        V P                  P                  4       P                  p \        P                  ! W2RR7      V n         \        P                  ! RT3.R7      T n        R#   \         d    T P                  P                  4         K  i ; i)r  r   	interface)serversN)r$  authr"  DNSServerFactoryr   DNSDatagramProtocolr   	listenTCPportgetHost	listenUDPudpPortr   stopListeningr   Resolverresolver)rK   r   r   
portNumbers   &   rO   setUpDNSrE    s    DI%%tyyk2G&&w/H
%%aKH	YY&&(--
	",,DL OOk:-F,GHDM	 ! 	&II##%	&s   C
 
%C32C3c                   . pVP                  \        P                  ! V P                  P                  4      4       VP                  \        P                  ! V P
                  P                  4      4        V P                  P                  P                  4        \        P                  ! V4      #   \         d     L#i ; irz   )rT  r   rP  r=  rA  r@  rC  
_parseCallcancelBaseExceptionDeferredList)rK   dls   & rO   tearDownDNSrL    s    	BIIe!!$))"9"9:;IIe!!$,,"<"<=>  '') b!!  s   6$B0 0B>=B>c                     ] tR tRtRtR tR tR t]! ]	P                  R8  R4      R 4       tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR t]! ]	P                  R8  R4      R 4       tR tR tR tR tRt R# )MXTestsi  z.
Tests for L{mail.relaymanager.MXCalculator}.
c                	    \        V 4       \        P                  ! 4       V n        \        P
                  P                  V P                  V P                  4      V n        R # rz   )	rE  r   r  r  r   r  MXCalculatorrC  mxr]   s   &rO   r|   MXTests.setUp  s8    ZZ\
##00

Kr[   c                	    \        V 4      # rz   )rL  r]   s   &rO   r  MXTests.tearDown  s    4  r[   c                    V P                  \        P                  P                  V P                  4      P
                  \        4       R# )zA
L{MXCalculator}'s default clock is C{twisted.internet.reactor}.
N)r  r   r  rP  rC  r  r   r]   s   &rO   test_defaultClockMXTests.test_defaultClock  s2     	**4==9??	
r[   r+   c                	    R .V P                   P                  R&   V P                  P                  R4      P	                  V P
                  4      # )the.email.test.domainr.  )r9  r'  rQ  getMXr   _cbSimpleSuccessr]   s   &rO   testSimpleSuccessMXTests.testSimpleSuccess  s=    .E-F		M*ww}}]+778M8MNNr[   c                	    V P                  VP                  ^ 4       V P                  \        VP                  4      R4       R# )r  rY  N)r8   
preferencerV   r   rK   rQ  s   &&rO   r[  MXTests._cbSimpleSuccess  s/    *RWW'>?r[   c                	    R V P                   n        V P                  V P                   P                  R4      \        4      # )Fr.  )rQ  fallbackToDomainrj  rZ  IOErrorr]   s   &rO   testSimpleFailureMXTests.testSimpleFailure!  s.    #( !!$''--">HHr[   c                	`    V P                  V P                  P                  R 4      \        4      # r.  )rj  rQ  rZ  r   r]   s   &rO   testSimpleFailureWithFallback%MXTests.testSimpleFailureWithFallback%  s"    !!$''--">OOr[   c                   a aaa  ! VV3R lR4      pV! 4       S P                   n        S P                   P                  S4      pVV 3R lpVP                  V4       V# )a  
Issue an MX request for the given domain and arrange for it to be
responded to with the given records.  Verify that the resulting mail
exchange is the indicated host.

@type domain: C{str}
@type records: C{list} of L{RRHeader}
@type correctMailExchange: C{str}
@rtype: L{Deferred}
c                  &   < ] tR tRtV V3R ltRtR# ),MXTests._exchangeTest.<locals>.DummyResolveri4  c                	   < VS8X  d   \         P                  ! S. . 34      # \         P                  ! \        S4      4      # rz   )r   r-  r.  r"   )rK   r   rX   recordss   &&rO   lookupMailExchange?MXTests._exchangeTest.<locals>.DummyResolver.lookupMailExchange5  s4    6> =='2r):;;zz,v"677r[   r5   NrU   rq   rr   rs   rp  rv   )rX   ro  s   rO   DummyResolverrm  4  s    8 8r[   rs  c                R   < SP                  \        V P                  4      S4       R # rz   r8   rV   r   )recordcorrectMailExchangerK   s   &rO   gotMailExchange.MXTests._exchangeTest.<locals>.gotMailExchange=  s    S-/BCr[   )rQ  rC  rZ  r   )rK   rX   ro  rw  rs  rM   rx  s   ffff   rO   _exchangeTestMXTests._exchangeTest(  sH    	8 	8 )?GGMM&!	D 	
o&r[   c           
        RpRpRp\        V\        P                  \        ^V4      R7      \        V\        P                  \        ^ V4      R7      \        V\        P                  \        ^V4      R7      .pV P                  WV4      # )zP
The MX record with the lowest preference is returned by
L{MXCalculator.getMX}.
r:  good.example.combad.example.comr   r1  payload)r!   r    TYPErz  rK   rX   goodbadro  s   &    rO   test_mailExchangePreference#MXTests.test_mailExchangePreferenceC  sv    
 ! &y~~yC?PQ&y~~yD?QR&y~~yC?PQ

 !!&488r[   c           	         RpRpRp\        V\        P                  \        ^ V4      R7      \        V\        P                  \        ^V4      R7      .pV P                  P	                  V4       V P                  WV4      # )zi
L{MXCalculator.getMX} returns the MX record with the lowest preference
which is not also marked as bad.
r:  r}  r~  r  r!   r    r  rQ  markBadrz  r  s   &    rO   test_badExchangeExcluded MXTests.test_badExchangeExcludedS  so    
 ! &y~~yC?PQ&y~~yD?QR
 	!!&488r[   c           	     6   RpRpRp\        V\        P                  \        ^ V4      R7      \        V\        P                  \        ^V4      R7      .pV P                  P	                  V4       V P                  P	                  V4       V P                  WV4      # )z
L{MXCalculator.getMX} returns the MX record with the lowest preference
if all the MX records in the response have been marked bad.
r:  r~  zworse.example.comr  r  )rK   rX   r  worsero  s   &    rO   test_fallbackForAllBadExchanges'MXTests.test_fallbackForAllBadExchangesc  s    
 # &y~~yC?PQ&y~~yE?RS
 	!!&377r[   c           	     ^   RpRpRp\        V\        P                  \        ^ V4      R7      \        V\        P                  \        ^V4      R7      .pV P                  P	                  V4       V P
                  P                  V P                  P                  4       V P                  WV4      # )z
L{MXCalculator.getMX} returns the MX record with the lowest preference
if it was last marked bad longer than L{MXCalculator.timeOutBadMX}
seconds ago.
r:  r}  r~  r  )	r!   r    r  rQ  r  r  r  timeOutBadMXrz  rK   rX   r  previouslyBadro  s   &    rO   test_badExchangeExpiresMXTests.test_badExchangeExpirest  s     !) )..)A}:U &y~~yD?QR	
 	&

477//0!!&=AAr[   c           	        RpRpRp\        V\        P                  \        ^ V4      R7      \        V\        P                  \        ^V4      R7      .pV P                  P	                  V4       V P                  P                  V4       V P                  P                  V P                  P                  4       V P                  WV4      # )zw
L{MXCalculator.getMX} returns the MX record with the lowest preference
if it was marked good after it was marked bad.
r:  r}  r~  r  )
r!   r    r  rQ  r  markGoodr  r  r  rz  r  s   &    rO   test_goodExchangeUsedMXTests.test_goodExchangeUsed  s    
 !) )..)A}:U &y~~yD?QR	
 	&'

477//0!!&=AAr[   c                   aa RoRo ! VV3R lR4      pV! 4       V P                   n        V P                   P                  S4      pVP                  V P                  \        SR7      4       V# )z
If an MX lookup succeeds but the result set is empty,
L{MXCalculator.getMX} should try to look up an I{A} record for the
requested name and call back its returned Deferred with that
address.
rb  zexample.orgc                  D   < ] tR tRtRt Z . . . 3/t Z  Z/tR tR tRt	R# )9MXTests.test_successWithoutResults.<locals>.DummyResolveri  a  
Fake resolver which will respond to an MX lookup with an empty
result set.

@ivar mx: A dictionary mapping hostnames to three-tuples of
    results to be returned from I{MX} lookups.

@ivar a: A dictionary mapping hostnames to addresses to be
    returned from I{A} lookups.
c                	P    \         P                  ! V P                  V,          4      # rz   )r   r-  rQ  r3  s   &&rO   rp  LMXTests.test_successWithoutResults.<locals>.DummyResolver.lookupMailExchange  s    }}TWWV_55r[   c                	P    \         P                  ! V P                  V,          4      # rz   )r   r-  r/   r3  s   &&rO   getHostByNameGMXTests.test_successWithoutResults.<locals>.DummyResolver.getHostByName  s    }}TVVF^44r[   r5   N)
rU   rq   rr   rs   r   rQ  r/   rp  r  rv   )rX   ips   rO   rs  r    s-    	 2r2,'BA65r[   rs  r   rQ  rC  rZ  r   r8   r    )rK   rs  rM   rX   r  s   &  @@rO   test_successWithoutResults"MXTests.test_successWithoutResults  sY     	5 	5* )?GGMM&!	d&&	r(:;r[   c                     ! R R4      pV! 4       V P                   n        V P                   P                  R4      pVP                  V P                  \        RR7      4       V# )z
Test that if the MX record lookup fails, fallback is enabled, and an A
record is available for the name, then the Deferred returned by
L{MXCalculator.getMX} ultimately fires with a Record_MX instance which
gives the address in the A record for the name.
c                  &    ] tR tRtRtR tR tRtR# )AMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolveri  zS
Fake resolver which will fail an MX lookup but then succeed a
getHostByName call.
c                	>    \         P                  ! \        4       4      # rz   )r   r.  r"   r3  s   &&rO   rp  TMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolver.lookupMailExchange  s    zz,.11r[   c                	.    \         P                  ! R 4      # )rb  )r   r-  r3  s   &&rO   r  OMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolver.getHostByName  s    }}Y//r[   r5   N)rU   rq   rr   rs   r   rp  r  rv   r5   r[   rO   rs  r    s    
20r[   rs  rX   rb  r  r  )rK   rs  rM   s   &  rO   "test_failureWithSuccessfulFallback*MXTests.test_failureWithSuccessfulFallback  sL    
	0 
	0 )?GGMM(#	d&&	y(ABr[   c                   aaa RoRoRo ! VVV3R lR4      pV! 4       V P                   n        V P                   P                  S4      pVP                  V P                  \        SR7      4       V# )z
If an MX lookup returns a single CNAME record as a result, MXCalculator
will perform an MX lookup for the canonical name indicated and return
the MX record which results.
alias.example.comcanonical.example.commail.example.comc                  ,   < ] tR tRtRtV VV3R ltRtR# );MXTests.test_cnameWithoutGlueRecords.<locals>.DummyResolveri  z
Fake resolver which will return a CNAME for an MX lookup of a name
which is an alias and an MX for an MX lookup of the canonical name.
c           
     	T  < VS8X  d>   \         P                  ! \        V\        P                  \        S4      R 7      .. . 34      # VS8X  d?   \         P                  ! \        V\
        P                  \        ^ S4      R 7      .. . 34      # \         P                  ! \        V4      4      # r  )r   r-  r!   r   r  r    r.  r"   )rK   rX   alias	canonicalexchanges   &&rO   rp  NMXTests.test_cnameWithoutGlueRecords.<locals>.DummyResolver.lookupMailExchange  s    U? == !))/)5):):,8,C!" 
  y( == !))/)2,5a,B!" 
  !::l6&:;;r[   r5   N)rU   rq   rr   rs   r   rp  rv   )r  r  r  s   rO   rs  r    s    
< <r[   rs  r  r  )rK   rs  rM   r  r  r  s   &  @@@rO   test_cnameWithoutGlueRecords$MXTests.test_cnameWithoutGlueRecords  s_     $+	%$	< $	<L )?GGMM% 	d&&	x(@Ar[   c                  a a  ! R R4      p^oV! 4       S P                   n        S P                   P                  RS4      pS P                  V\        P
                  P                  P                  4       VV 3R lpVP                  V4       V# )z
If L{MXCalculator.getMX} encounters a CNAME chain which is longer than
the length specified, the returned L{Deferred} should errback with
L{CanonicalNameChainTooLong}.
c                  $    ] tR tRtRt^ tR tRtR# ).MXTests.test_cnameChain.<locals>.DummyResolveri  z[
Fake resolver which generates a CNAME chain of infinite length in
response to MX lookups.
c           	     	    V ;P                   ^,          un         RV P                   3,          p\        P                  ! \        V\        P
                  \	        V4      R7      .. . 34      # )r  x-%d.example.comr  )chainCounterr   r-  r!   r   r  )rK   rX   r   s   && rO   rp  AMXTests.test_cnameChain.<locals>.DummyResolver.lookupMailExchange  sg    !!Q&!)T->->,@@}} %%+%1%6%6(4T(: 
 r[   r5   N)rU   rq   rr   rs   r   r  rp  rv   r5   r[   rO   rs  r    s    
 Lr[   rs  r  c                   < SP                  V P                  ^ ,          \        RS^,           3,          4      4       SP                  SP                  P                  P
                  S^,           4       R# )r  r  N)r8   argsr   rQ  rC  r  )r   
cnameLimitrK   s   &rO   cbChainTooLong/MXTests.test_cnameChain.<locals>.cbChainTooLong3  sV    

1|,>*q.AR,RS TWW--::JNKr[   )	rQ  rC  rZ  rj  twistedr   r  CanonicalNameChainTooLongr   )rK   rs  rM   r  r  s   f   @rO   test_cnameChainMXTests.test_cnameChain  sp    	 	2 
(?GGMM,j91gll77QQR	L 	
n%r[   c                   aaaa . oRoRoRo ! VVVV3R lR4      pV! 4       V P                   n        V P                   P                  S4      pVP                  V P                  \        SR7      4       V# )z
If an MX lookup returns a CNAME and the MX record for the CNAME, the
L{Deferred} returned by L{MXCalculator.getMX} should be called back
with the name from the MX record without further lookups being
attempted.
r  r  r  c                  *   < ] tR tRtV VVV3R ltRtR# )8MXTests.test_cnameWithGlueRecords.<locals>.DummyResolveriH  c                	   < VS8w  g	   S'       d   . . . 3# \         P                  ! \        S\        P                  \        S4      R 7      \        S\
        P                  \        SR7      R 7      .. . 34      # )r  r  )r   r-  r!   r   r  r    )rK   rX   r  r  r  lookedUps   &&rO   rp  KMXTests.test_cnameWithGlueRecords.<locals>.DummyResolver.lookupMailExchangeI  sw    U?h B<'}} %%*%1%6%6(4Y(?
 %%.%.^^(1x(@  r[   r5   Nrr  )r  r  r  r  s   rO   rs  r  H  s     r[   rs  r  r  )rK   rs  rM   r  r  r  r  s   &  @@@@rO   test_cnameWithGlueRecords!MXTests.test_cnameWithGlueRecords<  sc     #+	%	 	2 )?GGMM% 	d&&	x(@Ar[   c                   aa RoRo ! VV3R lR4      pV! 4       V P                   n        V P                   P                  S4      pV P                  V\        P
                  P                  P                  4       V# )z
If an MX lookup returns two CNAME records which point to each other,
the loop should be detected and the L{Deferred} returned by
L{MXCalculator.getMX} should be errbacked with L{CanonicalNameLoop}.
zcname1.example.comzcname2.example.comc                  &   < ] tR tRtV V3R ltRtR# )<MXTests.test_cnameLoopWithGlueRecords.<locals>.DummyResolverio  c           
     	   < \         P                  ! \        S\        P                  \        S4      R 7      \        S\        P                  \        S4      R 7      .. . 34      # r  )r   r-  r!   r   r  )rK   rX   
firstAliassecondAliass   &&rO   rp  OMXTests.test_cnameLoopWithGlueRecords.<locals>.DummyResolver.lookupMailExchangep  sb    }} %%/%1%6%6(4[(A
 %%0%1%6%6(4Z(@  r[   r5   Nrr  )r  r  s   rO   rs  r  o  s     r[   rs  )rQ  rC  rZ  rj  r  r   r  CanonicalNameLoop)rK   rs  rM   r  r  s   &  @@rO   test_cnameLoopWithGlueRecords%MXTests.test_cnameLoopWithGlueRecordsf  s`     *
*	 	* )?GGMM*%1gll77IIJr[   c                	    . ROV P                   P                  R&   V P                  P                  R4      P	                  V P
                  4      # )mx1.test.domainr.  )r  zmx2.test.domainzmx3.test.domain)r9  r'  rQ  rZ  r   _cbManyRecordsSuccessfulLookupr]   s   &rO   testManyRecordsMXTests.testManyRecords  sC    .
		M*
 ww}}]+77//
 	
r[   c                	D   V P                  \        VP                  4      P                  R ^4      ^ ,          R9   4       V P                  P                  \        VP                  4      4       V P                  P                  R4      P                  V P                  V4      # ).r.  )mx1mx2mx3)	rC   rV   r   r   rQ  r  rZ  r   _cbManyRecordsDifferentResultr`  s   &&rO   r  &MXTests._cbManyRecordsSuccessfulLookup  sq    BGG**32159NNOBGG%ww}}]+77..
 	
r[   c                	8   V P                  \        VP                  4      \        VP                  4      4       V P                  P	                  \        VP                  4      4       V P                  P                  R 4      P                  V P                  W!4      # rh  )r  rV   r   rQ  r  rZ  r   _cbManyRecordsLastResult)rK   nextMXrQ  s   &&&rO   r  %MXTests._cbManyRecordsDifferentResult  sg    CL#fkk*:;FKK()ww}}]+77))2
 	
r[   c                	   V P                  \        VP                  4      \        VP                  4      4       V P                  \        VP                  4      \        VP                  4      4       V P                  P	                  \        VP                  4      4       V P                  P                  \        VP                  4      4       V P                  P                  R 4      P                  V P                  V4      # rh  )	r  rV   r   rQ  r  r  rZ  r   "_cbManyRecordsRepeatSpecificResult)rK   lastMXrQ  r  s   &&&&rO   r   MXTests._cbManyRecordsLastResult  s    CL#fkk*:;C,c&++.>?FKK()V[[)*ww}}]+7733V
 	
r[   c                	v    V P                  \        VP                  4      \        VP                  4      4       R # rz   ru  )rK   againMXr  s   &&&rO   r  *MXTests._cbManyRecordsRepeatSpecificResult  s$    W\\*C,<=r[   )r  rQ  Nro   )!rU   rq   rr   rs   r   r|   r  rV  r   rt   ru   r\  r[  re  ri  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rv   r5   r[   rO   rN  rN    s    L
!
 C$&>?O @O@IP69 9 8"B(B("H23j,\(T!F C$&>?
 @


	
>r[   rN  c                      ] tR tRt]P
                  ! ]R4      f   RtR tR t	]
! ]P                  R
8  R4      R 4       t]
! ]P                  R
8  R4      R 4       tR	tR# )LiveFireExerciseTestsi  Nz1UDP support is required to determining MX recordsc                	.    \        V 4       . ROV n        R# )	domainDirN)r  insertionDomaininsertionQueuedestinationDomaindestinationQueue)rE  tmpdirsr]   s   &rO   r|   LiveFireExerciseTests.setUp  s    
r[   c                	    V P                    F@  p\        P                  P                  V4      '       g   K*  \        P
                  ! V4       KB  	  \        V 4      # rz   )r  r   r   r   r  r  rL  )rK   rM   s   & rO   r  LiveFireExerciseTests.tearDown  s<    Aww~~a  a   4  r[   r+   c                	  a aaa \         P                   P                  4       pVP                  P                  \        P
                  P                  4       4       \         P                  P                  VR 4      oSP                  RR4       VP                  RS4       VP                  R,          VP                  R&   \        VP                  R,          P                  SP                  4       4       VP                  \         P                  P!                  V4      4       VP#                  4       p\$        P&                  ! ^ VRR7      S n        \+        . R
O4      o\-        4       o\.        P0                  ! 4       pV3R lVn        V3R lVn        \$        P4                  ! RS P(                  P7                  4       P8                  V4       VV 3R	 lpSP;                  V4       S# )r  r  r   r.  r   r   r6  c                    < S # rz   r5   r   s   rO   r  9LiveFireExerciseTests.testLocalDelivery.<locals>.<lambda>      Vr[   c                 &   < SP                  R 4      # rz   callbackr  r  s   *rO   r  r        t}}T/Br[   c                  < SP                  R R\        P                  4      ^,          pVP                  ^ 4      P	                  4       pSP                  VP                  R4      R4       SP                  P                  4       # r  NThis is the message)	r  r   r  r  r   r  find
smtpServerrA  )ignrI  r  rX   rK   s   &  rO   finished9LiveFireExerciseTests.testLocalDelivery.<locals>.finished  sd    ''dmmDQGD//!$))+C)> ?D??0022r[   )
HELO mesonzMAIL FROM: <user@hostname>zRCPT TO: <user@test.domain>DATAr  r  QUIT)r   r   
smtpPortalregisterCheckerr
   r  AllowAnonymousAccessr   r  r   r   r   mapr  setQueuer  r  r   r   r<  r  r   r   r   ClientFactoryclientConnectionLost
connectTCPr>  r=  r   )rK   r   r   r  r   rX   r  s   f   @@@rO   testLocalDelivery'LiveFireExerciseTests.testLocalDelivery  sX   ))'')**4==+M+M+OP11';Gvz*-0%oom<GOOB//1N1N1PQ009:""$!++AqKH$

 z""$#
!B;(?(?(A(F(FJ	3 	"r[   c                	  a aaaaa	 \         P                   P                  4       pVP                  P                  \        P
                  P                  4       4       \         P                  P                  VR 4      oVP                  RS4       \        P                  ! R4       VP                  \         P                  P                  R4      4       VP                  P!                  \         P"                  P%                  V4      4       \         P                  P'                  VP(                  4      o	S	;P*                  R,          un        \         P                  P-                  S	^4      o\         P                  P/                  S P0                  4      S	n        R.S P4                  P6                  R&   VP9                  4       p\:        P<                  ! ^ VRR7      S n        \         P                   P                  4       pVP                  P                  \        P
                  P                  4       4       \         P                  P                  VR4      oSPA                  RR4       VP                  RS4       \        P                  ! R	4       VP                  \         P                  P                  R	4      4       \         P                  P-                  S	^4      oSPC                  4        VP9                  4       p\:        P<                  ! ^ VRR7      S n"        S PD                  PG                  4       PH                  S	n%        \M        . RO4      o\O        4       o\P        PR                  ! 4       pV3R
 lVn(        V3R lVn*        \:        PV                  ! RS P>                  PG                  4       PH                  V4       VVV	V 3R lpSPY                  V4       S# )r  zinsertion.domainr  r   zdestination.domainr6  r  r  r   r  c                    < S # rz   r5   r  s   rO   r  9LiveFireExerciseTests.testRelayDelivery.<locals>.<lambda>)  r  r[   c                 &   < SP                  R 4      # rz   r	  r  s   *rO   r  r%  *  r  r[   c                Z   < SP                  4       pVVV3R  lpVP                  V4       V# )c                `  < SP                  R R\        P                  4      ^,          pVP                  ^ 4      P	                  4       pSP                  VP                  R4      R4       SP                  P                  4        SP                  P                  4        SP                  4        R# r  )r  r   r  r  r   r  r  	insServerrA  
destServerstopService)r  rI  r  rX   helperrK   s   &  rO   	deliveredLLiveFireExerciseTests.testRelayDelivery.<locals>.finished.<locals>.delivered2  s}    ++FD$--HKooa(--/##CHH-B$CRH,,.--/""$r[   )
checkStater   )r  r   r-  rX   r,  r  rK   s   &  rO   r  9LiveFireExerciseTests.testRelayDelivery.<locals>.finished-  s-     ))+H%   +Or[   )ztest.identity.hostname)r  zMAIL FROM: <user@wherever>z"RCPT TO: <user@destination.domain>r  r  r  r  )-r   r   r  r  r
   r  r  r   r  r   r   r  r  r  r  rI   setDefaultDomainr  r  SmartHostSMTPRelayingManagerr  fArgsRelayStateHelperrP  rC  mxcalcr9  r'  r   r   r<  r)  r   startServicer*  r>  r=  PORTr   r   r   r  r  r   r   )
rK   insServr   destServr  r   rX   r  r,  r  s
   f    @@@@@rO   testRelayDelivery'LiveFireExerciseTests.testRelayDelivery  s    ))'')**4==+M+M+OP11';LM,f5
!"**001ABC(()@)@)IJ##@@O44""33GQ?**77F5@M		01""$ **1a;G 99((*++DMM,N,N,PQ11(<OPvz*/8
#$$++112DEF""33GQ?##%!++AqKH ..055$

 z""$#
!B;(>(>(@(E(EqI	 	" 	"r[   )r*  r)  r  r  ro   )rU   rq   rr   rs   r   IReactorUDPr   skipr|   r  r   rt   ru   r!  r:  rv   r5   r[   rO   r  r    sw    gt,4B
! C$&>?) @)V C$&>?K @Kr[   r  c                  .    ] tR tRtR tR tR tR tRtR# )LineBufferMessageiB  c                	0    . V n         R V n        R V n        R# )FN)lineseomlostr]   s   &rO   r  LineBufferMessage.__init__C  s    
	r[   c                	<    V P                   P                  V4       R # rz   )rA  rT  )rK   r   s   &&rO   r   LineBufferMessage.lineReceivedH  s    

$r[   c                	<    R V n         \        P                  ! R4      # )Tz
<Whatever>)rB  r   r-  r]   s   &rO   r   LineBufferMessage.eomReceivedK  s    }}\**r[   c                	    R V n         R# )TN)rC  r]   s   &rO   r    LineBufferMessage.connectionLostO  s	    	r[   )rB  rA  rC  N)	rU   rq   rr   rs   r  r   r   r   rv   r5   r[   rO   r?  r?  B  s    
 +r[   r?  c                      ] tR tRt. ROtR t]! ]P                  R8  R4      R 4       t	R t
R t]! ]P                  R8  R4      R 4       tR tR	tR
# )
AliasTestsiS  c                	:   / p. ROpV F$  p\         P                  P                  WRR4       K&  	  V P                  VR,          RR.4       V P                  VR,          R.4       V P                  VR,          R	.4       V P                  VR
,          . RO4       R# )user:  another@host
r'   Nr  zanother@hostzme@againnextuserz|/bin/program	moreusersz:/etc/include/filename	multiuser)rN  znextuser:  |/bin/program
zuser:  me@again
z"moreusers: :/etc/include/filename
z3multiuser: first@host, second@host,last@anotherhost)z
first@hostzsecond@hostzlast@anotherhost)r   r  handler8   )rK   r   rA  ls   &   rO   
testHandleAliasTests.testHandleW  s    
 AJJfT:  	.*)EF
+o->?,/G.HI;!R	
r[   r+   c                	j   R \        4       /p\        P                  P                  V\        P
                  ! \        P                  ! R4      P                  4       4      R7      pV P                  \        V4      ^4       VR,          p\        V4      pR	 F$  pV P                  VP                  V4      R
4       K&  	  V P                  \        V4      ^4       VR,          p\        V4      pR F$  pV P                  VP                  V4      R
4       K&  	  V P                  \        V4      ^4       VR,          p\        V4      pV P                  VP                  R4      R
4       R F,  pV P                  VP                  V4      R
RV,          4       K.  	  V P                  \        V4      ^4       R# )r   a                      # Here's a comment
                       # woop another one
                    testuser:                   address1,address2, address3,
                        continuation@address, |/bin/process/this

                    usertwo:thisaddress,thataddress, lastaddress
                    lastuser:       :/includable, /filename, |/program, address
                    )r   testuserusertwolastuserz/includablez%s not foundN)address1address2address3zcontinuation@addressz/bin/process/thisr  )thisaddressthataddresslastaddress)z	/filenameprogramr   )r   r   r  loadAliasFilerB  rC  textwrapdedentencoder8   r9   rV   r  r  )rK   rI   r   groupsr/   s   &     rO   testFileLoaderAliasTests.testFileLoaderk  sf   vx.))zz
 &( * 
" 	Va(z"J
A q	2.
 	UQ'y!J>Aq	2. ?UQ'z"J.34Aq	2~/AB 5UQ'r[   c                	   \        4       \        4       \        4       3p\        P                  P                  V4      pV P                   F  pVP                  V4       K  	  VP                  4       P                  V P                  V4      # rz   )	r?  r   r  MultiWrapperrA  r   r   r   _cbMultiWrapper)rK   r  r  Ls   &   rO   testMultiWrapperAliasTests.testMultiWrapper  si     "$5$79J9LLjj%%d+AQ  ,,T-A-A4HHr[   c                	    V F_  pV P                  VP                  4       V P                  VP                  4       V P	                  V P
                  VP
                  4       Ka  	  R # rz   )rC   rB  r   rC  r8   rA  )rK   rh  r  rV  s   &&& rO   rk  AliasTests._cbMultiWrapper  sF    AOOAEE"QVV$TZZ1 r[   c                	    V P                  4       p\        P                  P                  VR R 4      pVP	                  4       pV P
                   F  pVP                  V4       K  	  VP                  4       P                  V P                  V4      # rz   )
r   r   r  	FileAliascreateMessageReceiverrA  r   r   r   _cbTestFileAlias)rK   tmpfiler/   rV  rS  s   &    rO   testFileAliasAliasTests.testFileAlias  sl    ++-JJ  $5##%ANN1 }}**4+@+@'JJr[   c                	    \        V4      ;_uu_ 4       pVP                  4       pR R R 4       T P                  X Uu. uF  qUR R NK	  	  upV P                  4       R #   + '       g   i     L@; iu upi )Nr  r   	readlinesr8   rA  )rK   rh  ru  r   rA  rl  s   &&&   rO   rt  AliasTests._cbTestFileAlias  sN    ']]aKKME %0%QCR&%0$**= ]0s   AA0A-	r5   Nz
First linez	Next liner   zAfter a blank linez	Last linero   )rU   rq   rr   rs   rA  rT  r   rt   ru   rg  rm  rk  rv  rt  rv   r5   r[   rO   rL  rL  S  so    NE
( C$&>?,( @,(\I2 C$&>?K @K>r[   rL  c                  *    ] tR tRtRtR tRR ltRtR# )DummyDomaini  z'
Test domain for L{AddressAliasTests}.
c                	    Wn         R # rz   r   )rK   r   s   &&rO   r  DummyDomain.__init__  s    r[   Nc                b   a a V'       d    \         P                  P                  R4      hV V3R l# )z
@returns: When a C{memo} is passed in this will raise a
    L{smtp.SMTPBadRcpt} exception, otherwise a boolean
    indicating if the C{user} and string version of
    L{self.address} are equal or not.
@rtype: C{bool}
hamc                 4   < S\        S P                  4      8H  # rz   )rV   r   rS  s   rO   r  $DummyDomain.exists.<locals>.<lambda>  s    ts4<<00r[   )r   r   r   r  s   ff&rO   r   DummyDomain.exists  s#     ))''..00r[   r  rz   )rU   rq   rr   rs   r   r  r   rv   r5   r[   rO   r~  r~    s    1 1r[   r~  c                  8    ] tR tRtRtR tR tR tR tR t	Rt
R	# )
AddressAliasTestsi  z/
Tests for L{twisted.mail.alias.AddressAlias}.
c                   \         P                  P                  R4      V n        V P                  P                  \        V P                  4      /p\         P                  P                  V P                  WP                  4      V n        R# )z
Setup an L{AddressAlias}.
zfoo@barN)r   r   rA  r   rX   r~  r  AddressAlias)rK   rI   s   & rO   r|   AddressAliasTests.setUp  sW     yy((3<<&&DLL(ABZZ,,T\\7LLQ
r[   c                X    V P                  V P                  P                  4       4       R# )z|
L{createMessageReceiever} calls C{exists()} on the domain object
which key matches the C{alias} passed to L{AddressAlias}.
N)rC   r  rs  r]   s   &rO   test_createMessageReceiver,AddressAliasTests.test_createMessageReceiver  s    
 	

88:;r[   c                P    V P                  \        V P                  4      R4       R# )z@
The string presentation of L{AddressAlias} includes the alias.
z<Address foo@bar>N)r8   rV   r  r]   s   &rO   r^   AddressAliasTests.test_str  s     	TZZ*=>r[   c                t    V P                  V P                  P                  V P                  R/4      R4       R# )z
L{resolve} will look for additional aliases when an C{aliasmap}
dictionary is passed, and returns L{None} if none were found.
r  N)r8   r  resolver   r]   s   &rO   test_resolveAddressAliasTests.test_resolve  s,    
 	++T\\5,ABDIr[   c                \    V P                  V P                  P                  / 4      R4       R# )z
L{resolve} returns L{None} when the alias could not be found in the
C{aliasmap} and no L{mail.smtp.User} with this alias exists either.
N)r8   r  r  r]   s   &rO   test_resolveWithoutAliasmap-AddressAliasTests.test_resolveWithoutAliasmap  s#    
 	++B/6r[   )r   r  N)rU   rq   rr   rs   r   r|   r  r^   r  r  rv   r5   r[   rO   r  r    s"    R<?J7r[   r  c                      ] tR tRtR.tRtR# )DummyProcessi  onEndr5   N)rU   rq   rr   rs   	__slots__rv   r5   r[   rO   r  r    s	    	Ir[   r  c                       ] tR tRtRtR tRtR# )MockProcessAliasi  z<
An alias processor that doesn't actually launch processes.
c                    R# )z
Don't spawn a process.
Nr5   )rK   protor`  r   s   &&&&rO   spawnProcessMockProcessAlias.spawnProcess      r[   r5   N)rU   rq   rr   rs   r   r  rv   r5   r[   rO   r  r    s    r[   r  c                      ] tR tRtRt]tRtR# )MockAliasGroupi  z+
An alias group using C{MockProcessAlias}.
r5   N)rU   rq   rr   rs   r   r  processAliasFactoryrv   r5   r[   rO   r  r    s     +r[   r  c                  ,    ] tR tRtRtR tR tR tRtR# )StubProcessi  z
Fake implementation of L{IProcessTransport}.

@ivar signals: A list of all the signals which have been sent to this fake
    process.
c                	    . V n         R # rz   signalsr]   s   &rO   r  StubProcess.__init__  s	    r[   c                    R# )z(
No-op implementation of disconnection.
Nr5   r]   s   &rO   loseConnectionStubProcess.loseConnection  r  r[   c                <    V P                   P                  V4       R# )z<
Record a signal sent to this process for later inspection.
N)r  rT  )rK   signals   &&rO   signalProcessStubProcess.signalProcess  s     	F#r[   r  N)	rU   rq   rr   rs   r   r  r  r  rv   r5   r[   rO   r  r    s    
$r[   r  c                  .   ] tR tRtRt]P                  ! ]R4      f   Rt. ROt	R t
R tR tR t]! ]P                   R8  R	4      R
 4       tR tR tR tR tR t]! ]P                   R8  R	4      R 4       t]! ]P                   R8  R	4      R 4       tRtR# )ProcessAliasTestsi&  z
Tests for alias resolution.
NzIReactorProcess not supportedc                   V^,          ^ ,          pV P                  \        P                  ! V4      4       V P                  \        P                  ! V4      V4       V P                  \        P                  ! V4      4       V# )z
Construct a status from the given exit code.

@type code: L{int} between 0 and 255 inclusive.
@param code: The exit status which the code will represent.

@rtype: L{int}
@return: A status integer for the given exit code.
)rC   r   	WIFEXITEDr8   WEXITSTATUSr   WIFSIGNALED)rK   codestatuss   && rO   
exitStatusProcessAliasTests.exitStatus1  s]     !)q 	V,-/6/0r[   c                    TpV P                  \        P                  ! V4      4       V P                  \        P                  ! V4      V4       V P                  \        P                  ! V4      4       V# )z
Construct a status from the given signal.

@type signal: L{int} between 0 and 255 inclusive.
@param signal: The signal number which the status will represent.

@rtype: L{int}
@return: A status integer for the given signal.
)rC   r   r  r8   WTERMSIGr   r  )rK   r  r  s   && rO   signalStatusProcessAliasTests.signalStatusF  sU      	v./V,f5f-.r[   c                F    \         P                  V n        R\         n        R# )z2
Replace L{smtp.DNSNAME} with a well-known value.
r   N)r   DNSNAMEr]   s   &rO   r|   ProcessAliasTests.setUp^  s     ||r[   c                0    V P                   \        n         R# )z0
Restore the original value of L{smtp.DNSNAME}.
N)r  r   r]   s   &rO   r  ProcessAliasTests.tearDowne  s     ||r[   r+   c                  a  \        S P                  4       4      pVP                  R4       \        P                  ! VP
                  R4       \        P                  P                  VP
                  RR4      pVP                  4       pS P                   F  pVP                  V4       K  	  V 3R lpVP                  4       P                  V4      # )z
Standard call to C{mail.alias.ProcessAlias}: check that the specified
script is called, and that the input is correctly transferred to it.
zX#!/bin/sh
rm -f process.alias.out
while read i; do
    echo $i >> process.alias.out
donei  Nc                   < \        R 4      ;_uu_ 4       pVP                  4       pRRR4       SP                  X Uu. uF  q3RR NK	  	  upSP                  4       R#   + '       g   i     L@; iu upi )zprocess.alias.outNr  ry  )rh  r   rA  rl  rK   s   &   rO   _cbProcessAlias<ProcessAliasTests.test_processAlias.<locals>._cbProcessAlias  sS    )**a +e4efe4djjA +*4s   AA1A.	)r%   r   
setContentr   chmodr   r   r  ProcessAliasrs  rA  r   r   r   )rK   shr/   rV  rS  r  s   f     rO   test_processAlias#ProcessAliasTests.test_processAliask  s     dkkm$
	
 	% JJ##BGGT48##%ANN1 	B
 }}**?;;r[   c                  a aa \         P                  ! 4       p\        4       o\        P                  P                  4       oSP                  S4       \        P                  P                  SRV4      pVP                  4       pVP                  ! VP                  4       VV V3R lpS P                  V\        P                  P                  4       VP                  V4       V# )z
If the alias child process does not exit within a particular period of
time, the L{Deferred} returned by L{MessageWrapper.eomReceived} should
fail with L{ProcessAliasTimeout} and send the I{KILL} signal to the
child process..
Nc                   < SP                  SP                  R .4       SP                  \        SP	                  \
        P                  4      4      4       R# )KILLN)r8   r  processEndedr   r  r  SIGKILL)rh  r  rK   r   s   &rO   timedOut<ProcessAliasTests.test_processAliasTimeout.<locals>.timedOut  s@    Y..9 01B1B6>>1RSTr[   )r   r  r  r   r  ProcessAliasProtocolr   MessageWrapperr   r  completionTimeoutrj  ProcessAliasTimeoutr   )rK   r   receiverrM   r  r  r   s   f    @@rO   test_processAliasTimeout*ProcessAliasTests.test_processAliasTimeout  s     **,M	

//1Y'::,,UD'B  "223	U 	1djj<<=	hr[   c                ^   \        4       p\        P                  P                  4       pVP                  ! V4       \        P                  P                  VRR4      pVP                  ! \        P                  ! \        ^ 4      4      4       V P                  VP                  4       \        4      # )z
If the process associated with an L{mail.alias.MessageWrapper} exits
before I{eomReceived} is called, the L{Deferred} returned by
I{eomReceived} should fail.
N)r  r   r  r  r   r  r  r#   r  r   rj  r   )rK   r   r   r  s   &   rO   test_earlyProcessTermination.ProcessAliasTests.test_earlyProcessTermination  sz      M	::224	*::,,XtTBgook!n=>!!("6"6"8+FFr[   c                ^   \        4       p\        P                  P                  4       pVP                  ! V4       \        P                  P                  VRR4      pVP                  ! \        P                  ! \        V4      4      4       V P                  VP                  4       \        4      # )z
Verify that if the process associated with an
L{mail.alias.MessageWrapper} exits with the given status, the
L{Deferred} returned by I{eomReceived} fails with L{ProcessTerminated}.
N)r  r   r  r  r   r  r  r#   r  r   rj  r   )rK   r  r   r   r  s   &&   rO   _terminationTest"ProcessAliasTests._terminationTest  s}      M	::224	*::,,XtTBgoo.?.GHI!!("6"6"8:KLLr[   c                B    V P                  V P                  ^4      4      # )z
If the process associated with an L{mail.alias.MessageWrapper} exits
with a non-zero exit code, the L{Deferred} returned by I{eomReceived}
should fail.
)r  r  r]   s   &rO   test_errorProcessTermination.ProcessAliasTests.test_errorProcessTermination  s     $$T__Q%788r[   c                ^    V P                  V P                  \        P                  4      4      # )z
If the process associated with an L{mail.alias.MessageWrapper} exits
because it received a signal, the L{Deferred} returned by
I{eomReceived} should fail.
)r  r  r  SIGHUPr]   s   &rO   test_signalProcessTermination/ProcessAliasTests.test_signalProcessTermination  s$     $$T%6%6v}}%EFFr[   c           	     r   / pR\        V. RO4      /p\        . ROVR4      p\        RR.VR4      p\        P                  P	                  RVR4      pVP                  RVRVRV/4       VP                  V4      p\        \        VP                  4      pVP                  4        \        \        \        P                  P	                  RR	R	4      \        P                  P                  \        4       R
4      \        P                  P                  R4      .4      pVP                  4        V P                  Wx4       VP                  V4      p	\        \        V	P                  4      p
V
P                  4        \        \        \        P                  P	                  RR	R	4      \        P                  P	                  RR	R	4      .4      pVP                  4        V P                  W4       VP                  V4      p\        \        VP                  4      pVP                  4        \        \        \        P                  P	                  RR	R	4      \        P                  P                  \        4       R
4      \        P                  P                  R4      .4      pVP                  4        V P                  W4       R	# )a  
Check that the C{resolve} method of alias processors produce the correct
set of objects:
    - direct alias with L{mail.alias.AddressAlias} if a simple input is passed
    - aliases in a file with L{mail.alias.FileWrapper} if an input in the format
      '/file' is given
    - aliases resulting of a process call wrapped by L{mail.alias.MessageWrapper}
      if the format is '|process'
r   r  r  r  /filealias1alias2alias3Necho)r  r  r  )r  |echor  )
TestDomainr  r   r  r  rD   r  r  rV   objsr>   r  r  FileWrapperr8   )rK   r   rX   A1A2A3res1r1expectedres2r2res3r3s   &            rO   test_aliasResolution&ProcessAliasTests.test_aliasResolution  s    j*EFG7JWg.AZZ$$Xvx@"""	
 zz'"dii 
	

''t<

)),.&A

&&w/
 	&zz'"dii 
	

''t<

''t<
 	&zz'"dii 
	

''t<

)),.&A

&&w/
 	&r[   c                V   / pR\        V. 4      /p\        P                  P                  RVR4      p\        P                  P                  RVR4      p\        P                  P                  RVR4      pVP	                  RVRVRV/4       V P                  VR,          P                  V4      R4       V P                  VR,          P                  V4      R4       V P                  VR,          P                  V4      R4       \        RR.VR4      pWaR&   VP                  V4      p\        \        VP                  4      pVP                  4        \        \        \        P                  P                  \        4       R4      .4      p	V	P                  4        V P                  W4       R# )	z>
Check that a cycle in alias resolution is correctly handled.
r   r  r  r  Nr  alias4r  )r  r   r  r  rD   r8   r  r  r  rV   r  r>   r  r  )
rK   r   rX   r  r  r  A4resrr  s
   &         rO   test_cyclicAlias"ProcessAliasTests.test_cyclicAlias	  sV   
 j"-.ZZ$$Xvx@ZZ$$Xvx@ZZ$$Xvx@"hHbAB*227;TB*227;TB*227;TBWh/Bjj!SXX	sTZZ66|~vNOP%r[   )r  r|  ro   )rU   rq   rr   rs   r   r   IReactorProcessr   r=  rA  r  r  r|   r  r   rt   ru   r  r  r  r  r  r  r  r  rv   r5   r[   rO   r  r  &  s     !!'408.NE*0$ C$&>?< @<84GM9G C$&>?>' @>'@ C$&>?& @&r[   r  c                  &    ] tR tRtR tRR ltRtR# )r  i(	  c                	    Wn         W n        R # rz   r   users)rK   r   r  s   &&&rO   r  TestDomain.__init__)	  s    
r[   Nc                	R  aa SP                   P                  oSV P                  9   d   V3R  l#  V P                  S,          pVP	                  V P                  V4      oS'       d   V3R l# \
        P                  ! S4      h  \         d    \
        P                  ! S4      hi ; i)c                 F   < \         P                  P                  S R R 4      # rz   )r   r  r  )r  s   rO   r  #TestDomain.exists.<locals>.<lambda>0	  s    4::224tDr[   c                    < S # rz   r5   )r   s   rO   r  r  8	  s    wr[   )r  localr  r   r  r   r   rI  )rK   r  r  r/   r   s   &f& @rO   r   TestDomain.exists-	  s    yy4::DD	)T"A iid3G&&""4((  	)""4((	)s   B "B&r  rz   )rU   rq   rr   rs   r  r   rv   r5   r[   rO   r  r  (	  s    ) )r[   r  c                  >    ] tR tRtRtR tR tR tR tR t	R t
R	tR
# )
DummyQueuei<	  z
A fake relay queue to use for testing.

This queue doesn't keep track of which messages are waiting to be relayed
or are in the process of being relayed.

@ivar directory: See L{__init__}.
c                    Wn         R# )zn
@type directory: L{bytes}
@param directory: The pathname of the directory holding messages in the
    queue.
N	directory)rK   r  s   &&rO   r  DummyQueue.__init__F	  s	     #r[   c                    \         P                  P                  V4      p\         P                  ! V P	                  V4      R,           4       \         P                  ! V P	                  V4      R,           4       R# )zk
Remove a message from the queue.

@type message: L{bytes}
@param message: The base filename of a message.
r  r  N)r   r   basenameremovegetPathrK   rg   s   &&rO   r  DummyQueue.doneN	  sL     ''""7+
		$,,w'$./
		$,,w'$./r[   c                x    \        \        P                  P                  V P                  VR,           4      R4      # )z
Get the envelope file for a message in the queue.

@type message: L{bytes}
@param message: The base filename of a message.

@rtype: L{file}
@return: The envelope file for the message.
r  r   )r   r   r   r  r  r  s   &&rO   getEnvelopeFileDummyQueue.getEnvelopeFileY	  s(     BGGLL4@$GGr[   c                V    \         P                  P                  V P                  V4      # )z
Return the full base pathname of a message in the queue.

@type message: L{bytes}
@param message: The base filename of a message.

@rtype: L{bytes}
@return: The full base pathname of the message.
)r   r   r  r  r  s   &&rO   r  DummyQueue.getPathe	  s     ww||DNNG44r[   c                   \         P                   ! 4        R\        V 4       2p\        \        P                  P                  V P                  VR,           4      R4      p\        P                  P                  V P                  VR,           4      p\        P                  P                  V P                  VR,           4      p\        VR4      pV\        P                  P                  WSV4      3# )z
Create a new message in the queue.

@rtype: 2-L{tuple} of (E{1}) L{file}, (E{2}) L{FileMessage}
@return: The envelope file and a message receiver for a new message in
    the queue.
_r  r   z-Cr  )	timeidr   r   r   r  r  r   r   )rK   fname
headerFiletempFilenamefinalFilenamemessageFiles   &     rO   r   DummyQueue.createNewMessageq	  s     99;-qD
+"'',,t~~ut|DdK
ww||DNNEDLAT^^UT\B<.49900}
 
 	
r[   c                    R# )z
Ignore the request to mark a message as waiting to be relayed.

@type message: L{bytes}
@param message: The base filename of a message.
Nr5   r  s   &&rO   r  DummyQueue.setWaiting	  s     	r[   r  N)rU   rq   rr   rs   r   r  r  r!  r  r   r  rv   r5   r[   rO   r  r  <	  s&    #	0
H
5
$r[   r  c                       ] tR tRtRtR tRtR# )!DummySmartHostSMTPRelayingManageri	  a  
A fake smart host to use for testing.

@type managed: L{dict} of L{bytes} -> L{list} of
    L{list} of L{bytes}
@ivar managed: A mapping of a string identifying a managed relayer to
    filenames of messages the managed relayer is responsible for.

@ivar queue: See L{__init__}.
c                     / V n         Wn        R# )z
Initialize the minimum necessary members of a smart host.

@type queue: L{DummyQueue}
@param queue: A queue that can be used for testing purposes.
Nmanagedr  )rK   r  s   &&rO   r  *DummySmartHostSMTPRelayingManager.__init__	  s     
r[   r4  N)rU   rq   rr   rs   r   r  rv   r5   r[   rO   r2  r2  	  s    	r[   r2  c                      ] tR tRtRtR tR tR tR tR t	R t
R	 tR
 tR tR t]! ]P"                  R8  R4      R 4       t]! ]P"                  R8  R4      R 4       tR tR tR tR tRtR# )_AttemptManagerTestsi	  a  
Test the behavior of L{_AttemptManager}.

@type tmpdir: L{bytes}
@ivar tmpdir: The path to a temporary directory holding the message files.

@type reactor: L{MemoryReactorClock}
@ivar reactor: The reactor used for test purposes.

@type eventLog: L{None} or L{dict} of L{bytes} -> L{object}
@ivar eventLog: Information about the last informational log message
    generated or none if no log message has been generated.

@type noisyAttemptMgr: L{_AttemptManager}
@ivar noisyAttemptMgr: An attempt manager which generates informational
    log messages.

@type quietAttemptMgr: L{_AttemptManager}
@ivar quietAttemptMgr: An attempt manager which does not generate
    informational log messages.

@type noisyMessage: L{bytes}
@ivar noisyMessage: The full base pathname of the message to be used with
    the noisy attempt manager.

@type quietMessage: L{bytes}
@ivar quietMessage: The full base pathname of the message to be used with
    the quiet.
c                &   V P                  4       V n        \        P                  ! V P                  4       \	        4       V n        RV n        \        P                  ! V P                  4       \        \        \        V P                  4      4      RV P
                  4      V n        \        \        \        V P                  4      4      RV P
                  4      V n        RpRp\        P                  P!                  V P                  V4      V n        \        P                  P!                  V P                  V4      V n        \'        V P"                  R,           R4      P)                  4        \'        V P$                  R,           R4      P)                  4        V.V P                  P*                  P,                  R&   V.V P                  P*                  P,                  R	&   \'        V P"                  R
,           R4      ;_uu_ 4       p\.        P0                  ! RR.V4       RRR4       \'        V P$                  R
,           R4      ;_uu_ 4       p\.        P0                  ! RR.V4       RRR4       R#   + '       g   i     LY; i  + '       g   i     R# ; i)z
Set up a temporary directory for the queue, attempt managers with the
noisy flag on and off, message files for use with each attempt manager,
and a reactor.  Also, register to be notified when log messages are
generated.
NTFnoisyMessagequietMessager  r  noisyRelayerquietRelayerr  r   zfrom-noisy@domainzto-noisy@domainzfrom-quiet@domainzto-quiet@domain)r   r2  r   r  r   r   eventLogr$   addObserver_logObserverr   r2  r  noisyAttemptMgrquietAttemptMgrr   r  r:  r;  r   r   r  r5  r  r  )rK   noisyBaseNamequietBaseNameenvelopes   &   rO   r|   _AttemptManagerTests.setUp	  s    kkm
)+))*.-j.EFLL 

  /-j.EFLL 
 '&GGLLmDGGLLmDT%s+113T%s+113@M$$,,^<@M$$,,^<$##d*D11XKK,.?@(K 2 $##d*D11XKK,.?@(K 21 21 211s   I,I?,I<	?J	c                    \         P                  ! V P                  4       \        P                  ! V P
                  4       R# )z?
Unregister for log events and remove the temporary directory.
N)r$   removeObserverr@  r  r  r2  r]   s   &rO   r  _AttemptManagerTests.tearDown	  s(     	4,,-dkk"r[   c                    Wn         R# )z
A log observer.

@type eventDict: L{dict} of L{bytes} -> L{object}
@param eventDict: Information about the last informational log message
    generated.
N)r>  )rK   	eventDicts   &&rO   r@  !_AttemptManagerTests._logObserver	  s	     "r[   c                    \        \        \        V P                  4      4      4      pV P	                  VP
                  4       R# )zu
When an attempt manager is created without the noisy parameter, the
noisy instance variable should default to true.
N)r   r2  r  r2  rC   r  rK   ams   & rO   test_initNoisyDefault*_AttemptManagerTests.test_initNoisyDefault
  s-    
 >z$++?VWX!r[   c                P    V P                  V P                  P                  4       R# )z}
When an attempt manager is created with the noisy parameter set to
true, the noisy instance variable should be set to true.
N)rC   rA  r  r]   s   &rO   test_initNoisy#_AttemptManagerTests.test_initNoisy

  s    
 	,,223r[   c                P    V P                  V P                  P                  4       R# )z
When an attempt manager is created with the noisy parameter set to
false, the noisy instance variable should be set to false.
N)r   rB  r  r]   s   &rO   test_initQuiet#_AttemptManagerTests.test_initQuiet
  s    
 	--334r[   c                    \        \        \        V P                  4      4      4      pV P	                  VP
                  \
        4       R# )z
When an attempt manager is created without the reactor parameter, the
reactor instance variable should default to the global reactor.
N)r   r2  r  r2  r8   r   rN  s   & rO   test_initReactorDefault,_AttemptManagerTests.test_initReactorDefault
  s1    
 >z$++?VWXW-r[   c                f    V P                  V P                  P                  V P                  4       R# )z{
When an attempt manager is created with a reactor provided, the
reactor instance variable should default to that reactor.
N)r8   rA  r   r]   s   &rO   test_initReactor%_AttemptManagerTests.test_initReactor 
  s$    
 	--55t||Dr[   c                    V P                   P                  RV P                  4       V P                  V P                  4       R# )z_
For an attempt manager with the noisy flag set, notifySuccess should
result in a log message.
r<  N)rA  r  r:  rC   r>  r]   s   &rO   test_notifySuccessNoisy,_AttemptManagerTests.test_notifySuccessNoisy'
  s0    
 	**>4;L;LM&r[   c                    V P                   P                  RV P                  4       V P                  V P                  4       R# )zd
For an attempt manager with the noisy flag not set, notifySuccess
should result in no log message.
r=  N)rB  r  r;  r   r>  r]   s   &rO   test_notifySuccessQuiet,_AttemptManagerTests.test_notifySuccessQuiet/
  s2    
 	**>4;L;LM'r[   r+   c                    V P                   P                  RV P                  4       V P                  V P                  4       R# )z_
For an attempt manager with the noisy flag set, notifyFailure should
result in a log message.
r<  N)rA  r  r:  rC   r>  r]   s   &rO   test_notifyFailureNoisy,_AttemptManagerTests.test_notifyFailureNoisy7
  s0     	**>4;L;LM&r[   c                    V P                   P                  RV P                  4       V P                  V P                  4       R# )zd
For an attempt manager with the noisy flag not set, notifyFailure
should result in no log message.
r=  N)rB  r  r;  r   r>  r]   s   &rO   test_notifyFailureQuiet,_AttemptManagerTests.test_notifyFailureQuiet@
  s2     	**>4;L;LM'r[   c                r    V P                   P                  R4       V P                  V P                  4       R# )z\
For an attempt manager with the noisy flag set, notifyDone should
result in a log message.
r<  N)rA  r  rC   r>  r]   s   &rO   test_notifyDoneNoisy)_AttemptManagerTests.test_notifyDoneNoisyI
  s(    
 	''7&r[   c                r    V P                   P                  R4       V P                  V P                  4       R# )za
For an attempt manager with the noisy flag not set, notifyDone
should result in no log message.
r=  N)rB  r  r   r>  r]   s   &rO   test_notifyDoneQuiet)_AttemptManagerTests.test_notifyDoneQuietQ
  s*    
 	''7'r[   c                    V P                   P                  R4       V P                  V P                  4       V P                  P                  ^<4       R# )zd
For an attempt manager with the noisy flag set, notifyNoConnection
should result in a log message.
r<  N)rA  notifyNoConnectionrC   r>  r   r  r]   s   &rO   test_notifyNoConnectionNoisy1_AttemptManagerTests.test_notifyNoConnectionNoisyY
  s:    
 	//?&R r[   c                    V P                   P                  R4       V P                  V P                  4       V P                  P                  ^<4       R# )zi
For an attempt manager with the noisy flag not set, notifyNoConnection
should result in no log message.
r=  N)rB  rq  r   r>  r   r  r]   s   &rO   test_notifyNoConnectionQuiet1_AttemptManagerTests.test_notifyNoConnectionQuietb
  s<    
 	//?'R r[   )r>  rA  r:  rB  r;  r   r2  Nro   )rU   rq   rr   rs   r   r|   r  r@  rP  rS  rV  rY  r\  r_  rb  r   rt   ru   re  rh  rk  rn  rr  ru  rv   r5   r[   rO   r8  r8  	  s    <+LZ#""45.E'( C$&>?' @' C$&>?( @('(!!r[   r8  )r   
__future__r   email.messagerD  email.parserr0  r   rB  r   r  r  r  rt   r  rb  r'  hashlibr   typingr   r   unittestr   zope.interfacer   r   zope.interface.verifyr	   twisted.cred.checkersr  twisted.cred.credentialstwisted.cred.portaltwisted.mail.aliastwisted.mail.mailtwisted.mail.maildirtwisted.mail.protocolstwisted.mail.relaytwisted.mail.relaymanagerr
   r   twisted.internetr   r   r   r   r   r   twisted.internet.deferr   twisted.internet.errorr   r   r   r   twisted.internet.testingr   r   r   twisted.mailr   r   r   r   twisted.namesr   twisted.names.dnsr   r    r!   twisted.names.errorr"   twisted.pythonr#   r$   twisted.python.filepathr%   twisted.python.runtimer&   twisted.trial.unittestr'   r*   rx   r   r   r   r   r  r    _MaildirMailboxAppendMessageTaskr+  rG  r]  r  r  r  r  r  r  r*  ri  rO  r  r  r  r  r  r  r   r!  r"  r&  r$  rE  rL  rN  r  r?  rL  r~  r  r  r  r  r  
AliasGroupr  r  r  r  r  r2  r8  r5   r[   rO   <module>r     s   #     	 	    
        1 -            P P +  
 $ / 5  ? ? , ' , / + !CDe:h e: Ee:P !CDG( G EG !CD#
 #
 E#
L !CD5x 5 E5B !CD=7( =7 E=7@ !CD<x < E<6 !CDJ6X J6 EJ6Z !CDCLL11C EC40 02 !CDbx)9 b EbJ !CD%
X'7 %
 E%
P !CDU<8 U< EU<p !CD	T 	T E	T !CDp
x p
 Ep
f TYY''(($ ($ )($V !CDKQ KQ EKQ\ !CD?
x ?
 E?
DDII 
 !CD"E "E E"EJ !CD&58 &5 E&5R" "  !CD<( < E<> !CDA>( A> EA>H 1 0BF'' BI&" !CDl>h l> El>^ !CDLH L EL^ " !CDa> a> Ea>H1 1, !CD&7 &7 E&7R tzz.. +TZZ** +$ $. !CD~& ~& E~&B) )(N Nb . !CDD!8 D! ED!r[   