+
    Dfjg$                      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	H
t
 ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RIHtHtHt ^ RIH t  ^ RI!H"t"H#t# ^ RI$H%t%H&t&H't'H(t( ^ RI)H*t* ^ RI+H,t, ^ RI-H.t.H/t/ ^ RI0H1t1 ^ RI2H3t3 ^ RI4H5t5H6t6H7t7 ^ RI8H9t9 ^ RI:H;t;H<t<H=t= ^ RI>H?t?H@t@HAtA ^ RIBHCtCHDtD  ^ RIEHFtFHGtG R tI ! R R]D4      tJ ! R R4      tK ! R R ]C4      tL ! R! R"]C4      tM ! R# R$]D4      tN]! ]1P                  ]1P                  ]1P                  4       ! R% R&4      4       tR]! ]1P                  ]1P                  4       ! R' R(4      4       tS ! R) R*]1P                  4      tU ! R+ R,]U]1P                  4      tW ! R- R.]1P                  4      tY ! R/ R0]1P                  4      t[ ! R1 R24      t\ ! R3 R4]\]D4      t] ! R5 R6]C4      t^ ! R7 R8]\]D4      t_]! ]"4       ! R9 R:4      4       t` ! R; R<4      ta ! R= R>]\]D4      tb ! R? R@]D4      tc ! RA RB]\]D4      td ! RC RD]D4      te ! RE RF]1P                  4      tf ! RG RH]\]D4      tg ! RI RJ4      th ! RK RL]h4      ti ! RM RN]i]C4      tj ! RO RP]i]C4      tk ! RQ RR]h]C4      tl ! RS RT]h]C4      tm ! RU RV]h]C4      tn ! RW RX]h]D4      to ! RY RZ]h]C4      tp ! R[ R\]h]C4      tq ! R] R^]1P                  4      tr]! ]1P                  4       ! R_ R`]=P                  4      4       tu ! Ra Rb]D]\4      tv ! Rc Rd]D4      tw ! Re Rf]D]\4      tx ! Rg Rh]\]D4      ty]! ]1P                  4       ! Ri Rj]D]\4      4       t{ ! Rk Rl4      t|]! ]1P                  4       ! Rm Rn4      4       t~]! ]1P                  4       ! Ro Rp4      4       t ! Rq Rr]D4      t]! ]F'       * Rs4      ]! ]'EP                  ! ](R4      '       * Rt4       ! Ru Rv]\]D4      4       4       t ! Rw Rx]R4      t ! Ry Rz]\]D4      t ! R{ R|]D4      t ! R} R~4      t ! R R]D4      t ! R R]D4      t ! R R4      t ! R R]]C4      t ! R R]]D4      t ! R R]C4      tR#   ]H d	    RtFRtG ELi ; i)z"
Test case for twisted.mail.imap4
)annotationsN)OrderedDictBytesIO)chain)OptionalType)skipIf)implementer)verifyClassverifyObject)'InMemoryUsernamePasswordDatabaseDontUse)CramMD5CredentialsIUsernameHashedPasswordIUsernamePasswordUnauthorizedLogin)IRealmPortal)defererror
interfacesreactor)Deferred)Clock)StringTransport StringTransportWithDisconnection)imap4)
MessageSet)IChallengeResponseIClientAuthenticationICloseableMailboxIMAP)loopback)failurelogutil)	iterbytesnativeStringnetworkString)SynchronousTestCaseTestCase)ClientTLSContextServerTLSContextc                    V 3R  l# )c                    V! 4       # N )resultfs   &&=/usr/lib/python3/dist-packages/twisted/mail/test/test_imap.py<lambda>strip.<locals>.<lambda>:   s    qs    r0   )r2   s   &r3   stripr7   9   s    ""r6   c                  n    ] tR t^=tRR.RR.RR.RR.R	R
..tR tR tR tR tR t	R t
R tR tR tRtR# )IMAP4UTF7TestsHello world   Hello worldzHello & worlds   Hello &- world   Helloÿworld   Hello&AP8-worldu   ÿþýüs   &AP8A,gD9APw-u   ~peter/mail/日本語/台北s   ~peter/mail/&ZeVnLIqe-/&U,BTFw-c                l    RpV P                  VP                  RR4      VP                  R4      4       R# )z
Specifying an error policy to C{unicode.encode} with the
I{imap4-utf-7} codec should produce the same result as not
specifying the error policy.
r:   imap4-utf-7strictNassertEqualencodeselftexts   & r3   test_encodeWithErrors$IMAP4UTF7Tests.test_encodeWithErrorsI   s0     KKx0$++m2L	
r6   c                l    RpV P                  VP                  RR4      VP                  R4      4       R# )z?
Similar to L{test_encodeWithErrors}, but for C{bytes.decode}.
r;   r?   r@   NrB   decoderE   bytess   & r3   test_decodeWithErrors$IMAP4UTF7Tests.test_decodeWithErrorsT   s0     LL15<<3N	
r6   c                L    RpV P                  VP                  R4      R4       R# )zi
Unicode strings that contain an ampersand (C{&}) can be
encoded to bytes with the I{imap4-utf-7} codec.
u
   &Hello&½&r?   s   &-Hello&-&AL0-&-NrA   rD   s   & r3   test_encodeAmpersand#IMAP4UTF7Tests.test_encodeAmpersand]   s&    
 6KK&	
r6   c                H    V P                  RP                  R4      R4       R# )zr
An I{imap4-utf-7} encoded string that does not shift back to
ASCII (i.e., it lacks a final C{-}) can be decoded.
s   &AL0r?      ½NrJ   rE   s   &r3   !test_decodeWithoutFinalASCIIShift0IMAP4UTF7Tests.test_decodeWithoutFinalASCIIShifth   s!    
 	NN=)*	
r6   c                    \         P                  ! R4      ! \        R4      4      pV P                  VP	                  4       R4       R# )zT
C{codecs.getreader('imap4-utf-7')} returns the I{imap4-utf-7} stream
reader class.
r?   r=   r<   N)codecs	getreaderr   rB   read)rE   readers   & r3   test_getreaderIMAP4UTF7Tests.test_getreaderr   s6    
 !!-09K1LM(89r6   c                    \        4       p\        P                  ! R4      ! V4      pVP                  R4       V P	                  VP                  4       R4       R# )zT
C{codecs.getwriter('imap4-utf-7')} returns the I{imap4-utf-7} stream
writer class.
r?   r<   r=   N)r   rY   	getwriterwriterB   getvalue)rE   outputwriters   &  r3   test_getwriterIMAP4UTF7Tests.test_getwriterz   sE    
 !!-08%&*,>?r6   c                r    V P                    F&  w  rV P                  VP                  R4      V4       K(  	  R# )z
The I{imap4-utf-7} can be used to encode a unicode string into a byte
string according to the IMAP4 modified UTF-7 encoding rules.
r?   N)testsrB   rC   rE   inputrc   s   &  r3   test_encodeIMAP4UTF7Tests.test_encode   s-    
 "ZZMEU\\-8&A (r6   c                p    V P                    F%  w  rV P                  WP                  R4      4       K'  	  R# )z
The I{imap4-utf-7} can be used to decode a byte string into a unicode
string according to the IMAP4 modified UTF-7 encoding rules.
r?   N)rh   rB   rK   ri   s   &  r3   test_decodeIMAP4UTF7Tests.test_decode   s+    
 "ZZMEUMM-$@A (r6   c                   \        \        ^ ^&4      \        ^'^4      4       Fp  p\        V4      P                  4       pV P	                  V\        V4      P                  R4      4       V P	                  \        V4      VP                  R4      4       Kr  	  V P	                  RP                  R4      R4       V P	                  RP                  R4      R4       R# )z
The IMAP4 modified UTF-7 implementation encodes all printable
characters which are in ASCII using the corresponding ASCII byte.
r?   &s   &-N)r   rangechrrC   rB   rK   )rE   ocharbytes   &  r3   test_printableSingletons'IMAP4UTF7Tests.test_printableSingletons   s     uT4(%d*;<A1v}}HXs1v}}]'CDSVX__]%CD = 	M2E:m4c:r6   r0   N)__name__
__module____qualname____firstlineno__rh   rG   rN   rQ   rV   r]   re   rk   rn   rv   __static_attributes__r0   r6   r3   r9   r9   =   sg    	'	+,	-.	-.9.	
	E	

	

:@BB;r6   r9   c                  .    ] tR t^tR tR tR tR tRtR# )BufferingConsumerc                	    . V n         R # r/   )bufferrU   s   &r3   __init__BufferingConsumer.__init__   s	    r6   c                	    V P                   P                  V4       V P                  '       d   V P                  P                  4        R # R # r/   )r   appendconsumerresumeProducingrL   s   &&r3   ra   BufferingConsumer.write   s2    5!===MM))+ r6   c                	F    Wn         V P                   P                  4        R # r/   )r   r   )rE   r   	streamings   &&&r3   registerProducer"BufferingConsumer.registerProducer   s     %%'r6   c                	    R V n         R # r/   )r   rU   s   &r3   unregisterProducer$BufferingConsumer.unregisterProducer   s	    r6   )r   r   N)	rx   ry   rz   r{   r   ra   r   r   r|   r0   r6   r3   r~   r~      s    ,
(r6   r~   c                  4    ] tR t^tR tR tR tR tR tRt	R# )MessageProducerTestsc                	   a aaa R o\        4       pRVR&   RVR&   RVR&   RVR&   \        VRR	S^{R	4      p\        4       o\        P                  ! V4      oSP                  S4      pVVVV 3R
 lpVP                  V4      # )s   This is body text.  Rar.sender@hostfromrecipient@domaintobooga booga boosubject
text/plaincontent-typeNc                   < SP                  V S4       SP                  R P                  SP                  4      RS,           4       R# )r6   sf   {119}
From: sender@host
To: recipient@domain
Subject: booga booga boo
Content-Type: text/plain

N)assertIdenticalrB   joinr   )r1   bodycprE   s   &r3   
cbProduced7MessageProducerTests.testSinglePart.<locals>.cbProduced   s@      +"
 r6   r0   r   FakeyMessager~   r   MessageProducerbeginProducingaddCallback)rE   headersmsgdr   r   r   r   s   f    @@@r3   testSinglePart#MessageProducerTests.testSinglePart   s    *-'*.	".7BdC>!!#&Q
	 
	 }}Z((r6   c                	J  a aaa	 R pRo\        4       pRVR&   RVR&   RVR&   RVR	&   \        4       pR
VR&   RVR	&   \        VRRV^{\        VRRSRR4      .4      p\        4       o\        P                  ! V4      o	S	P                  S4      pVVV	V 3R lpVP                  V4      # )r6   &   Contained body message text.  Squarge.r   r   r   r   r   r   %multipart/alternative; boundary="xyz"r   this is subject textr   Nc                   < SP                  V S4       SP                  R P                  SP                  4      RS,           R,           4       R# )r6   s   {239}
From: sender@host
To: recipient@domain
Subject: booga booga boo
Content-Type: multipart/alternative; boundary="xyz"


--xyz
Subject: this is subject text
Content-Type: text/plain

   
--xyz--
NfailUnlessIdenticalrB   r   r   r1   r   	innerBodyr   rE   s   &r3   r   <MessageProducerTests.testSingleMultiPart.<locals>.cbProduced   sJ    $$VQ/"
 $
$ '9
9r6   r0   r   
rE   	outerBodyr   innerHeadersr   r   r   r   r   r   s
   f      @@@r3   testSingleMultiPart(MessageProducerTests.testSingleMultiPart   s    	=	-'*.	"I"}"8Y'3^$,D)T4HI
 !!#&Q	 	$ }}Z((r6   c                	  a aa	a
a R pRo	Ro
\        4       pRVR&   RVR&   RVR&   R	VR
&   \        4       pRVR&   RVR
&   \        4       pRVR&   RVR
&   \        VRRV^{\        VRRS	RR4      \        VRRS
RR4      .4      p\        4       o\        P                  ! V4      oSP                  S4      pVV	V
VV 3R lpVP                  V4      # )r6   r   .   Secondary <i>message</i> text of squarge body.r   r   r   r   r   r   r   r   r   r   <b>this is subject</b>	text/htmlNc                   < SP                  V S4       SP                  R P                  SP                  4      RS,           R,           S,           R,           4       R# )r6   s   {354}
From: sender@host
To: recipient@domain
Subject: booga booga boo
Content-Type: multipart/alternative; boundary="xyz"


--xyz
Subject: this is subject text
Content-Type: text/plain

sE   
--xyz
Subject: <b>this is subject</b>
Content-Type: text/html

r   Nr   )r1   r   
innerBody1
innerBody2r   rE   s   &r3   r   >MessageProducerTests.testMultipleMultiPart.<locals>.cbProduced  s^    $$VQ/"
 %
%( %% (::r6   r0   r   )rE   r   r   r   innerHeaders2r   r   r   r   r   r   r   s   f       @@@@r3   testMultipleMultiPart*MessageProducerTests.testMultipleMultiPart   s    	>
F
-'*.	"I"}"8Y'3^$##;i (3n%\2tZtL]Bj$M

 !!#&Q	 	* }}Z((r6   c                Z  a aaa	 RpRo\        4       pRVR&   RVR&   RVR&   R	VR
&   \        4       pRVR&   RVR
&   \        VRRV^{\        VRRSRR4      .4      p\        4       o\        P                  ! V4      o	R S	n        S	P                  S4      pVVV	V 3R lpVP                  V4      # )z.
A boundary is generated if none is provided.
r6   r   r   r   r   r   r   r   multipart/alternativer   r   r   Nc                 .    \         P                  ! R 4      # )z$aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)uuidUUIDr0   r6   r3   r4   ?MessageProducerTests.test_multiPartNoBoundary.<locals>.<lambda>M  s    499%KLr6   c                   < SP                  V S4       SP                  R P                  SP                  4      RS,           R,           4       R# )r6   s	  {341}
From: sender@host
To: recipient@domain
Subject: booga booga boo
Content-Type: multipart/alternative; boundary="----=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"


------=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Subject: this is subject text
Content-Type: text/plain

s-   
------=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa--
Nr   r   s   &r3   r   AMessageProducerTests.test_multiPartNoBoundary.<locals>.cbProducedQ  sL    $$VQ/"  GGr6   r0   )r   r   r~   r   r   _uuid4r   r   r   s
   f      @@@r3   test_multiPartNoBoundary-MessageProducerTests.test_multiPartNoBoundary3  s     	=	-'*.	"9"}"8Y'3^$,D)T4HI
 !!#&LQ	 	* }}Z((r6   c                J  a aaa	 RpRo\        4       pRVR&   RVR&   RVR&   R	VR
&   \        4       pRVR&   RVR
&   \        VRRV^{\        VRRSRR4      .4      p\        4       o\        P                  ! V4      o	S	P                  S4      pVVV	V 3R lpVP                  V4      # )z.
A boundary without does not have them added.
r6   r   r   r   r   r   r   r   z#multipart/alternative; boundary=xyzr   r   r   Nc                   < SP                  V S4       SP                  R P                  SP                  4      RS,           R,           4       R# )r6   s   {237}
From: sender@host
To: recipient@domain
Subject: booga booga boo
Content-Type: multipart/alternative; boundary=xyz


--xyz
Subject: this is subject text
Content-Type: text/plain

r   Nr   r   s   &r3   r   ?MessageProducerTests.test_multiPartNoQuotes.<locals>.cbProduced  sJ    $$VQ/" $$ '99r6   r0   r   r   s
   f      @@@r3   test_multiPartNoQuotes+MessageProducerTests.test_multiPartNoQuotesh  s     	=	-'*.	"G"}"8Y'3^$,D)T4HI
 !!#&Q	 	& }}Z((r6   r0   N)
rx   ry   rz   r{   r   r   r   r   r   r|   r0   r6   r3   r   r      s    )8+)Z4)l3)j/)r6   r   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R tR tR tR tR tR tR tR tRtR# )MessageSetTestsi  z
Tests for L{MessageSet}.
c                8   \        4       p\        4       pV P                  W4       V P                  VR4       V^,           pV P                  \        V4      ^4       V P                  \	        V4      ^.4       VR,           pV P                  \        V4      ^4       V P                  \	        V4      . RO4       VR,           pV P                  W4       V P                  \	        W,           4      . RO4       VP                  ^4       V P                  \        V4      ^4       V P                  \	        V4      . RO4       V P                  W4       VP                  ^^4       V P                  \        V4      ^4       V P                  \	        V4      . RO4       R# )a  
Test the following properties of L{MessageSet} addition and
equality:

    1. Two empty L{MessageSet}s are equal to each other;

    2. A L{MessageSet} is not equal to any other object;

    2. Adding a L{MessageSet} and another L{MessageSet} or an
       L{int} representing a single message or a sequence of
       L{int}s representing a sequence of message numbers
       produces a new L{MessageSet} that:

    3. Has a length equal to the number of messages within
       each sequence of message numbers;

    4. Yields each message number in ascending order when
       iterated over;

    6. L{MessageSet.add} with a single message or a start and
       end message satisfies 3 and 4 above.
Nr0         r      r   )r   r   r      )r   r   r   r            )r   rB   assertNotEquallenlistadd)rE   m1m2s   &  r3   !test_equalityIterationAndAddition1MessageSetTests.test_equalityIterationAndAddition  s8   . \\ B#!VR!$bA3'&[R!$b9-&[ bg	2
q	R!$b<0B#
q!R!$b#89r6   c                P    V P                  \        \        \        ^R4      4       R# )zm
A L{MessageSet} that has a range that ends with L{None} raises
a L{TypeError} when its length is requested.
N)assertRaises	TypeErrorr   r   rU   s   &r3   test_lengthWithWildcardRange,MessageSetTests.test_lengthWithWildcardRange  s    
 	)S*Q*=>r6   c                0    \        \        ^^4      4       R# )z4
L{MessageSet.__repr__} does not raise an exception
N)reprr   rU   s   &r3   test_reprSanityMessageSetTests.test_reprSanity  s     	Z1r6   c                   \         P                  ! R4      \         P                  ! R4      \         P                  ! R^4      \         P                  ! R^4      .p. ROp\        W4       F   w  r4V P                  \	        V4      V4       K"  	  R# )z
In a L{MessageSet}, in the presence of wildcards, if the
highest message id is known, the wildcard should get replaced
by that high value.
   *   1:*s   3:*s   *:2N)*1:*z3:6z2:6r   parseIdListziprB   strrE   inputsoutputsirt   s   &    r3   &test_stringRepresentationWithWildcards6MessageSetTests.test_stringRepresentationWithWildcards  su     d#f%fa(fa(	

 (DASVQ' )r6   c                    \         P                  ! R4      \         P                  ! R4      .pRR.p\        W4       F   w  r4V P                  \	        V4      V4       K"  	  R# )z
In a L{MessageSet}, inverting the high and low numbers in a
range doesn't affect the meaning of the range.  For example,
3:2 displays just like 2:3, because according to the RFC they
have the same meaning.
   2:3s   3:22:3Nr   r   s   &    r3   &test_stringRepresentationWithInversion6MessageSetTests.test_stringRepresentationWithInversion  s]     f%f%
 

 (DASVQ' )r6   c                    \        ^4      pV P                  \        V4      R4       V P                  \        V4      ^4       V P                  \	        V4      ^.4       R# )z
Creating a L{MessageSet} with a single message number adds
only that message to the L{MessageSet}; its serialized form
includes only that message number, its length is one, and it
yields only that message number.
1Nr   rB   r   r   r   rE   ms   & r3   "test_createWithSingleMessageNumber2MessageSetTests.test_createWithSingleMessageNumber
  sK     qMQ%Q#a1#&r6   c                    \        ^^
4      pV P                  \        V4      R4       V P                  \        V4      ^
4       V P                  \	        V4      . RO4       R# )a  
Creating a L{MessageSet} with both a start and end message
number adds the sequence between to the L{MessageSet}; its
serialized form consists that range, its length is the length
of the sequence, and it yields the message numbers inclusively
between the start and end.
z1:10N)
r   r   r      r   r   r   r   	   
   r
  r  s   & r3   test_createWithSequence'MessageSetTests.test_createWithSequence  sM     q"Q(Q$a"ABr6   c                    \        R4      pV P                  \        V4      R4       V P                  \        V4      ^4       V P	                  \
        \        V4       R# )z
Creating a L{MessageSet} with a single L{None}, representing
C{*}, adds C{*} to the range; its serialized form includes
only C{*}, its length is one, but it cannot be iterated over
because its endpoint is unknown.
Nr   )r   rB   r   r   r   r   r   r  s   & r3   test_createWithSingleWildcard-MessageSetTests.test_createWithSingleWildcard#  sH     tQ%Q#)T1-r6   c                    \        R4      p^
Vn        V P                  \        V4      ^
.4       \        ^R4      p^Vn        V P                  \        V4      . RO4       R# )zw
Setting L{MessageSet.last} replaces L{None}, representing
C{*}, with that number, making that L{MessageSet} iterable.
Nr   )r   lastrB   r   )rE   singleMessageReplacedrangeReplaceds   &  r3   test_setLastSingleWildcard*MessageSetTests.test_setLastSingleWildcard/  sY    
 !+4 0%'"34rd;"1d+m,i8r6   c                    \        ^R4      pVP                  ^R4       ^Vn        V P                  \	        V4      . RO4       R# )z<
Setting L{MessageSet.last} replaces L{None} in all ranges.
Nr   r   r   r  r   )r   r   r  rB   r   r  s   & r3   test_setLastWithWildcardRange-MessageSetTests.test_setLastWithWildcardRange<  s8     q$	aa/2r6   c                    \        ^R4      p^Vn        V P                  \        4      ;_uu_ 4        ^Vn        RRR4       R#   + '       g   i     R# ; i)z)
L{MessageSet.last} cannot be set twice.
N)r   r  r   
ValueErrorr  s   & r3   test_setLastTwiceFails&MessageSetTests.test_setLastTwiceFailsE  s>     q$z**AF +***s   AA	c                ,   \        ^4      p^Vn        VP                  R4       V P                  \	        V4      ^^.4       V P                  \	        VR,           4      . RO4       VP                  ^R4       V P                  \	        V4      . RO4       R# )z
Adding a L{None}, representing C{*}, or a sequence that
includes L{None} to a L{MessageSet} whose
L{last<MessageSet.last>} property has been set replaces all
occurrences of L{None} with the value of
L{last<MessageSet.last>}.
N)Nr   )r   r  r   )r   r   r  )r   r  r   rB   r   )rE   hasLasts   & r3   test_lastOverridesNoneInAdd+MessageSetTests.test_lastOverridesNoneInAddN  st     Q-DgA/g	12I>Atg	2r6   c                d    \        ^R4      p^Vn        V P                  VP                  ^4       R# )z6
Accessing L{MessageSet.last} returns the last value.
N)r   r  rB   r  s   & r3   test_getLastMessageSetTests.test_getLasta  s+     q$#r6   c                @   \        4       pVP                  ^4       V P                  \        V4      ^.4       \        4       pVP                  R4       V P                  \	        V4      R4       \        4       pVP                  R4       V P                  \        V4      . RO4       \        4       pVP                  R4       V P                  \	        V4      R4       \        4       pVP                  \        ^^4      4       V P                  \        V4      . RO4       R# )z
L{MessageSet.extend} accepts as its arugment an L{int} or
L{None}, or a sequence L{int}s or L{None}s of length two, or
another L{MessageSet}, combining its argument with its
instance's existing ranges.
Nr   r   r   NN)r   extendrB   r   r   )rE   extendWithIntextendWithNoneextendWithSequenceOfIntsextendWithSequenceOfNonesextendWithMessageSets   &     r3   test_extendMessageSetTests.test_extendi  s     #Qm,qc2#d#^,c2#-<  ''/67C$.L!!((667=)|##Jq!$4523Y?r6   c                   \        ^^4      p\        ^^4      \        ^^4      ,           pV P                  ^V4       V P                  ^V4       VR,           pV P                  \        4      ;_uu_ 4        ^V9    RRR4       VR,           pVP                  ^R4       V P                  \        4      ;_uu_ 4        ^V9    RRR4       R#   + '       g   i     LX; i  + '       g   i     R# ; i)z
A L{MessageSet} contains a number if the number falls within
one of its ranges, and raises L{TypeError} if any range
contains L{None}.
N)r     )r   assertInassertNotInr   r   r   )rE   hasFivedoesNotHaveFivehasFiveButHasNonehasFiveButHasNoneInSequences   &    r3   test_containsMessageSetTests.test_contains  s     Q"$Q*Z1-==a!O,#dNy))"" * '.&8##''40y)),, *) *)
 *))s   4C
:C
C	C.	c                .   \        ^^4      p\        ^^4      pW,           pV\        ^^4      ,           pV P                  \        VR,           4      . RO4       V P                  \        VR,           4      . RO4       V P                  \        VR,           4      . RO4       V P                  \        VR,           4      . R	O4       V P                  \        VR,           4      . R
O4       V P                  \        V\        ^4      ,           4      . RO4       R# )z
Adding a sequence of message numbers to a L{MessageSet} that
begins or ends immediately before or after an existing
sequence in that L{MessageSet}, or overlaps one, merges the two.
N)r   r  )r   r   r   r  )r   r   r  )r   r   )r   r   r   r   )r  r   )r  r   r   r   r   )r   r   r   r  r   r   r   r   )r   r   r   r  r   r   r   )r   rB   r   )rE   
mergeAftermergeBeforemergeBetweenSequencemergeBetweenNumbers   &    r3   test_rangesMerged!MessageSetTests.test_rangesMerged  s      1%
 A&)7'*Q*::j612LAj612ODkF23\BkF23_E2V;<>VW#jm346K	
r6   c                    V P                  \        ^^4      \        ^^4      4       V P                  \        \        ^^4      4      . RO4       \        RR4      pRVn        V P                  \        V4      RR.4       R# )a  
Test the C{seq-range} examples from Section 9, "Formal Syntax"
of RFC 3501::

    Example: 2:4 and 4:2 are equivalent and indicate values
             2, 3, and 4.

    Example: a unique identifier sequence range of
             3291:* includes the UID of the last message in
             the mailbox, even if that value is less than 3291.

@see: U{http://tools.ietf.org/html/rfc3501#section-9}
i  Ni  r   r   r  )rB   r   r   r  r  s   & r3   test_seq_rangeExamples&MessageSetTests.test_seq_rangeExamples  si     	Aq):a+;<jA./;tT"a4,/r6   c                v   \        ^4      \        ^^4      ,           \        ^	4      ,           \        ^R4      ,           p^Vn        V P                  RP                  R V 4       4      R4       \        R^4      \        ^^4      ,           p^
Vn        V P                  RP                  R V 4       4      R4       R# )aI  
Test the C{sequence-set} examples from Section 9, "Formal
Syntax" of RFC 3501.  In particular, L{MessageSet} reorders
and coalesces overlaps::

    Example: a message sequence number set of
             2,4:7,9,12:* for a mailbox with 15 messages is
             equivalent to 2,4,5,6,7,9,12,13,14,15

    Example: a message sequence number set of *:4,5:7
             for a mailbox with 10 messages is equivalent to
             10,9,8,7,6,5,4,5,6,7 and MAY be reordered and
             overlap coalesced to be 4,5,6,7,8,9,10.

@see: U{http://tools.ietf.org/html/rfc3501#section-9}
N,c              3  8   "   T F  p\        V4      x  K  	  R # 5ir/   r   .0r   s   & r3   	<genexpr><MessageSetTests.test_sequence_setExamples.<locals>.<genexpr>  s     9%8SVV%8   z2,4,5,6,7,9,12,13,14,15c              3  8   "   T F  p\        V4      x  K  	  R # 5ir/   rO  rP  s   & r3   rR  rS    s     !B/Q#a&&/rT  z4,5,6,7,8,9,10)r   r  rB   r   )rE   fromFifteenMessagesfromTenMessagess   &  r3   test_sequence_setExamples)MessageSetTests.test_sequence_setExamples  s    $ qMJq!,,z!}<z"d?SS 	 $& HH9%899;T	
 %T1-
1a0@@!!B/!BBDTUr6   r0   N)rx   ry   rz   r{   __doc__r   r   r   r  r  r  r  r  r  r   r$  r(  r+  r5  r?  rF  rJ  rX  r|   r0   r6   r3   r   r     se    1:f?(.((
'C
.933&$@6-*
00,Vr6   r   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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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,R+ t-R,t.R-# ).IMAP4HelperTestsi  z9
Tests for various helper utilities in the IMAP4 module.
c                J    \        \        P                  ! RR.R4      4       R# )z9
L{imap4.Command}'s C{repr} does not raise an exception.
s   COMMANDs   arg   extraN)r   r   CommandrU   s   &r3   test_commandRepr!IMAP4HelperTests.test_commandRepr  s     	U]]:x(<=r6   c                	
  a aaa Ro\        4       o\        S4      p\        P                  ! V4      oSP	                  S4      pVVVV 3R lpV3R lpVP                  V4       VP                  V4       VP                  V4      # )   xc                   < SP                  V S4       SP                  R \        S4      S3,          RP                  SP                  4      4       V # )s   {%d}
%br6   )r   rB   r   r   r   )r1   br   r   rE   s   &r3   r   6IMAP4HelperTests.test_fileProducer.<locals>.cbProduced  sB    $$VQ/]c!fa[8#((188:LMMr6   c                (   < SP                  4        V # r/   )r   )r1   r   s   &r3   cbResume4IMAP4HelperTests.test_fileProducer.<locals>.cbResume  s     Mr6   s   xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz)r~   r   r   FileProducerr   r   )rE   r2   r   r   rh  re  r   r   s   f    @@@r3   test_fileProducer"IMAP4HelperTests.test_fileProducer  ss    7AJq!Q	 	
	 	
j!	h }}Z((r6   c                	$   R . RORR..R. RO. R	O.R. R
O. RO..pV Fo  w  r#p\         P                  ! VR4      pV F#  pV P                  VP                  V4      4       K%  	  V F#  pV P	                  VP                  V4      4       K%  	  Kq  	  R# )foo/%gum/barfoo/xgum/barfoo/gum/barfoo/x%x/barfoo/xyz*abc/bar/Nzfoo/barzoo/lalagum/barzfoo/gumx/barzfoo/gum/bazfoobarzfuz fuz fuzz	foo/*/barfoo/xyz/barz
foo/xx/baz)foo/xyx/bar
foo/xx/barfoo/xxxxxxxxxxxxxx/barrx  zfoo/abc/barzfoo/xyzab/cbarzfoo/xyza/bcbarzfoo/xyzabc/barzfoo/xyz/abc/barzfoo/xyz/123/abc/barr   wildcardToRegexpassertFalsematch
assertTruerE   caseswildcardfailsucceedxs   &     r3   test_wildcardIMAP4HelperTests.test_wildcard  s     L/ WG "RL
$ (-#HG--h<H  !23 q 12 	 (-r6   c                	(   R . RO. RO.R. RO. RO.R. RO. R	O..pV Fq  w  r#p\         P                  ! VR4      pV F$  pV P                  VP                  V4      V4       K&  	  V F$  pV P	                  VP                  V4      V4       K&  	  Ks  	  R# )
rn  rq  rr  Nrt  )ro  rp  zfoo/x/gum/barru  )ry  rz  r{  zfoo/x/x/barr|  r}  r~  r  s   &     r3   test_wildcardNoDelim%IMAP4HelperTests.test_wildcardNoDelim"  s     L@ WV "RL
$ (-#HG--h=H  !2A6 q 115 	 (-r6   c           	         RRRR/R3.pV F]  w  r#\         P                  ! V4      pV P                  \        VP	                  R4      4      \        VP	                  R4      4      4       K_  	  R# )z
L{imap4._formatHeaders} accepts a C{dict} of header name/value pairs and
returns a string representing those headers in the standard multiline,
C{":"}-separated format.
Header1Value1Header2Value2s"   Header2: Value2
Header1: Value1
TN)r   _formatHeadersrB   sorted
splitlines)rE   r  rj   expectedrc   s   &    r3   test_headerFormatter%IMAP4HelperTests.test_headerFormatter<  sp     Hi:9
  %OE))%0Fv((./8K8KD8Q1R  %r6   c                	f   . R
OpRR.RR.. RO. RO. RO. RO. RO. RO. RO. ROR	.RR.R.. ROR.. ROR.. ROR..p. ROpV F2  pV P                  \        P                  \        P                  V4       K4  	  \	        W4       F+  w  rVV P                  \        P                  ! V4      V4       K-  	  R# )   Hello World   oo 	 oo   oo \t oo   oo \o oo   Hello   Worlds   World!N   oo
   oo "oo" oo)r  s   Hello "World!"s   World "Hello" "How are you?"s   "Hello world" How "are you?"s   foo bar "baz buz" NILs   foo bar "baz buz" "NIL"s   foo NIL "baz buz" bars   foo "NIL" "baz buz" bars   "NIL" bar "baz buz" foos   oo \"oo\" oos   "oo \"oo\" oo"r  s	   "oo 	 oo"r  s
   "oo \t oo"r  
   "oo \o oo"r  r  )r  r  s   How are you?)r;   s   Hows   are you?)   foo   bar   baz buzN)r  r  r     NIL)r  Nr  r  )r  r  r  r  )r  r  r  r  )r  s   "oo"r  )r  s   \tr  )r     \or  )s   "mismatched quotes   mismatched quote"s   mismatched"quotes   "oops here is" another")r   r   MismatchedQuotingsplitQuotedr   rB   )rE   r  answerserrorsscaser  s   &      r3   test_quotedSplitter$IMAP4HelperTests.test_quotedSplitterO  s    
. x y!11.0.00#OENM"N"N"N'
,
 Ae55u7H7H!L  "%1NDU..t4h? 2r6   c                	   . RO. RO. RORR.R . ROR.R R. RO.RR RR. RORRRR.	R . RORR..pR.. ROR.R.R R	.R.R
R..RR	.R.R R.R..p\        W4       F+  w  r4V P                  \        P                  ! V4      V4       K-  	  R# )   a   b   d   e       "s   abcde   des   abcs   bcds   abs   cdes   a s    es    bc  N)r  r     cr  r  )
r  r  r  r  r  r  r  r  r  r  )r  r  r  )r  r  r  )r  r  r  )r  r  r  r  r  r  r  )r  s   bc r  )r   rB   r   collapseStrings)rE   r  r  r  r  s   &    r3   test_stringCollapser%IMAP4HelperTests.test_stringCollapser  s    *Ht,%t,4+,4t%7tT4P=tTJ
 J!XuF8T"VHVHe$H:u%
 "%1NDU2248(C 2r6   c                	  a  R P                  R.^,          4      pV 3R lpV! R\        V4      V3,          RR. R%O.V.4       V! RRR.R	R
RRRRR. R&O.. R&O.. R&O.. R'O.. R(O. R)O.RRR.
RRRRR.RRRRR..
4       V! RR.4       V! RR.4       V! RR.4       V! R R!.4       V! R R!.4       V! R"R#R$.4       V! R"R#R$.4       R# )*   
s   xxc                X   < \         P                  ! V 4      pSP                  W!.4       R # r/   )r   parseNestedParensrB   )r  r  parsedrE   s   && r3   check0IMAP4HelperTests.test_parenParser.<locals>.check  s#    ,,T2FVZ0r6   s8   (BODY.PEEK[HEADER.FIELDS.NOT (subject bcc cc)] {%d}
%b)	   BODY.PEEKs   HEADER.FIELDS.NOTs  (FLAGS (\Seen) INTERNALDATE "17-Jul-1996 02:44:25 -0700" RFC822.SIZE 4286 ENVELOPE ("Wed, 17 Jul 1996 02:23:25 -0700 (PDT)" "IMAP4rev1 WG mtg summary and minutes" (("Terry Gray" NIL gray cac.washington.edu)) (("Terry Gray" NIL gray cac.washington.edu)) (("Terry Gray" NIL gray cac.washington.edu)) ((NIL NIL imap cac.washington.edu)) ((NIL NIL minutes CNRI.Reston.VA.US) ("John Klensin" NIL KLENSIN INFOODS.MIT.EDU)) NIL NIL <B27397-0100000@cac.washington.edu>) BODY (TEXT PLAIN (CHARSET US-ASCII) NIL NIL 7BIT 3028 92))   FLAGSs   \Seens   INTERNALDATEs   17-Jul-1996 02:44:25 -0700s   RFC822.SIZEs   4286s   ENVELOPEs%   Wed, 17 Jul 1996 02:23:25 -0700 (PDT)s$   IMAP4rev1 WG mtg summary and minutesNs#   <B27397-0100000@cac.washington.edu>   BODYs   TEXT   PLAIN   CHARSETs   US-ASCIIs   7BITs   3028s   92s   ("oo \"oo\" oo")r  s   ("oo \\ oo")s   oo \\ oos   ("oo \ oo")s   oo \ oos	   ("oo \o")s   oo \os   (oo \o)r  r  )s   subjects   bccs   cc)s
   Terry GrayNs   gray   cac.washington.edu)NNs   imapr  )NNs   minutess   CNRI.Reston.VA.US)s   John KlensinNs   KLENSINs   INFOODS.MIT.EDU)r   r   )rE   r  r  s   f  r3   test_parenParser!IMAP4HelperTests.test_parenParser  s5   LL%1%	1 	ISQRVUVKW02MNPQR	
 	J -<;JKJKJKABFO : -	1"0	
d 	#m_5-1o}-mi[)mi[)kE6?+kE6?+r6   c           
     	   . RO. RO. RO. RO. RO. RO. R	O. R
O. RO.	pV F  w  r#pVP                  R4      p\        P                  ! 4       pVP                  V4       V P	                  \        VP                  4      ^4       V P                  \        VP                  ^ ,          \        WS4      4      4       V P	                  \        VP                  ^ ,          4      V4       K  	  R# )ENVELOPEasciiN)r  Envelopeenvelope)FLAGSFlagsflags)INTERNALDATEInternalDateinternaldate)RFC822.HEADERRFC822Headerzrfc822.header)RFC822.SIZE
RFC822Sizezrfc822.size)RFC822.TEXT
RFC822Textzrfc822.text)RFC822r  rfc822)UIDr  uid)BODYSTRUCTUREBodyStructurebodystructure)rC   r   _FetchParserparseStringrB   r   r1   r  
isinstancegetattrr   )rE   r  inpoutpasStringr   s   &     r3   test_fetchParserSimple'IMAP4HelperTests.test_fetchParserSimple  s    0'<>88*!?

 $)Cx**W%C""$AMM#S]A.OOJqxx{GA4DEFS!-x8 $)r6   c                	   R ^. RO3.R^. RO3.R^. RO3..pV F  w  r#\         P                  ! 4       pVP                  V4       V P                  \	        VP
                  4      V^ ,          4       VP
                   Uu. uF+  p\        V4      P                  4       P                  R4      NK-  	  ppVP                  4        V^,          P                  4        V P                  Wc^,          4       K  	  R# u upi )s   ALLs   FULLs   FASTr  N)   flags   internaldate   rfc822.size   envelope)r  r  r  r  s   body)r  r  r  )
r   r  r  rB   r   r1   r   lowerrC   sort)rE   r  r  r  r   tokenexpectedResults   &      r3   test_fetchParserMacros'IMAP4HelperTests.test_fetchParserMacros  s    aQRSUV qEFG
 IC""$AMM#S]DG4NOhhWhUc%j..077@hNW!GLLN^!W5  Xs   ?1C7c                	L   \         P                  pV! 4       pVP                  R 4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          4      R4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          4      R4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          4      R4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          P                  VP                  4      4       V P                  VP
                  ^ ,          P                  P                  R4       V P                  VP
                  ^ ,          P                  P                  R4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          4      R	4       V! 4       pVP                  R
4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          P                  VP                  4      4       V P                  VP
                  ^ ,          P                  P                  R4       V P                  VP
                  ^ ,          P                  P                  R4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          4      R	4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          P                  VP                  4      4       V P                  VP
                  ^ ,          P                  P                  R4       V P                  VP
                  ^ ,          P                  P                  . RO4       V P                  VP
                  ^ ,          P                  R4       V P                  \!        VP
                  ^ ,          4      R4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          P                  VP                  4      4       V P                  VP
                  ^ ,          P                  P                  R4       V P                  VP
                  ^ ,          P                  P                  . RO4       V P                  VP
                  ^ ,          P                  R4       V P                  \!        VP
                  ^ ,          4      R4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          P                  VP                  4      4       V P                  VP
                  ^ ,          P                  P                  R4       V P                  VP
                  ^ ,          P                  P                  . RO4       V P                  VP
                  ^ ,          P                  R4       V P                  \!        VP
                  ^ ,          4      R4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          P"                  VP$                  4      4       V P                  VP
                  ^ ,          P&                  R4       V P                  VP
                  ^ ,          P(                  ^
4       V P                  VP
                  ^ ,          P*                  ^24       V P                  VP
                  ^ ,          P                  R4       V P                  \!        VP
                  ^ ,          4      R4       V! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  \        VP
                  ^ ,          P                  VP                  4      4       V P                  VP
                  ^ ,          P&                  R4       V P                  VP
                  ^ ,          P                  P                  RR.4       V P                  VP
                  ^ ,          P(                  ^g4       V P                  VP
                  ^ ,          P*                  ^E4       V P                  VP
                  ^ ,          P                  R4       V P                  \!        VP
                  ^ ,          4      R4       R# )r  FNBODYr  Ts   BODY[]zBODY[]s   BODY[HEADER]zBODY[HEADER]s   BODY.PEEK[HEADER]s+   BODY[HEADER.FIELDS (Subject Cc Message-Id)]
   MESSAGE-IDs0   BODY.PEEK[HEADER.FIELDS (Subject Cc Message-Id)]s4   BODY.PEEK[HEADER.FIELDS.NOT (Subject Cc Message-Id)]s/   BODY[HEADER.FIELDS.NOT (Subject Cc Message-Id)]s   BODY[1.MIME]<10.50>s?   BODY.PEEK[1.3.9.11.HEADER.FIELDS.NOT (Message-Id Date)]<103.69>s   DATEs:   BODY[1.3.9.11.HEADER.FIELDS.NOT (Message-Id Date)]<103.69>r0   )s   SUBJECTs   CCr      )r  r   r   r  )r   r  r  rB   r   r1   r  r  Bodypeekheaderr   emptyHeadernegatefieldsrM   mimeMIMEpartpartialBeginpartialLength)rE   Pr   s   &  r3   test_fetchParserBody%IMAP4HelperTests.test_fetchParserBody  s	   C	gQXX*
188A;78!))51!++T2QXXa[)62C	l#QXX*
188A;78!))40QXXa[)62C	i QXX*
188A;78!**D1QXXa[)84C	o&QXX*
188A;78!))51
188A;#5#5qxx@A!++22D9!++22B7!**E2QXXa[)>:C	*+QXX*
188A;78!))40
188A;#5#5qxx@A!++22D9!++22B7!**E2QXXa[)>:C	DEQXX*
188A;78!))51
188A;#5#5qxx@A!++22E:!++224VW!**E2!((1+ N	
 C	IJQXX*
188A;78!))40
188A;#5#5qxx@A!++22E:!++224VW!**E2!((1+ N	
 C	MNQXX*
188A;78!))40
188A;#5#5qxx@A!++22D9!++224VW!**E2!((1+ R	
 C	,-QXX*
188A;78!))51
188A;#3#3QVV<=!))40!1126!22B7!**E2qxx{+-CDC	N	
 	QXX*
188A;78!))40
188A;#5#5qxx@A!))=9!++22]G4LM!1137!22B7!**E2!((1+I	
r6   c                   \         P                  ! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  \        VP
                  ^ ,          VP                  4      4       V P                  VP
                  ^ ,          P                  R4       V P                  VP
                  ^ ,          P                  ^ 4       V P                  VP
                  ^ ,          P                  R4       V P                  VP
                  ^ ,          P                  R4       V P                  VP
                  ^ ,          P                  ^dR7      R4       R# )zT
Partial requests starting at 0 and longer than the message
return the entire body.
s   BODY.PEEK[]<0.393216>Ti   )lengths	   BODY[]<0>N)r   r  r  rB   r   r1   r  r  r  r  r  r  r  getBytesrE   r   s   & r3   "test_fetchParserParseStringPartial3IMAP4HelperTests.test_fetchParserParseStringPartial  s    
  	./QXX*
188A;78!))40!1115!22F;!**D1HHQK   ,	
r6   c                   \         P                  ! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  VP
                  ^ ,          P                  R4       V P                  VP
                  ^ ,          VP                  4       V P                  VP
                  ^ ,          P                  VP                  4       V P                  \        VP
                  ^ ,          4      R4       R# )z{
Parsing a C{BODY} whose C{HEADER} values require quoting
results in a object that perserves that quoting when
serialized.
s   BODY[HEADER.FIELDS ((Quoted)]Fs   BODY[HEADER.FIELDS ("(Quoted")]N)r   r  r  rB   r   r1   r  assertIsInstancer  r  r   rM   r  s   & r3   test_fetchParserQuotedHeader-IMAP4HelperTests.test_fetchParserQuotedHeader  s      	67QXX*!))51ahhqk1662ahhqk00!((;qxx{+-OPr6   c                    \         P                  ! 4       pVP                  R4       V P                  \	        VP
                  4      4       R# )z-
Parsing an empty string results in no data.
r6   N)r   r  r  r  r   r1   r  s   & r3   test_fetchParserEmptyString,IMAP4HelperTests.test_fetchParserEmptyString  s4      	cQXX'r6   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zD
Parsing a string with an unknown attribute raises an
L{Exception}.
s   UNKNOWNNr   r  r   	Exceptionr  r  s   & r3    test_fetchParserUnknownAttribute1IMAP4HelperTests.test_fetchParserUnknownAttribute  s(    
  )Q]]J?r6   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zN
Parsing a string that prematurely ends in whitespace raises an
L{Exception}.
s   BODY[HEADER.FIELDS  Nr  r  s   & r3   0test_fetchParserIncompleteStringEndsInWhitespaceAIMAP4HelperTests.test_fetchParserIncompleteStringEndsInWhitespace  )    
  )Q]]4KLr6   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zg
Parsing a string that contains an unexpected character rather
than whitespace raises an L{Exception}.
s   BODY[HEADER.FIELDS!]Nr  r  s   & r3   "test_fetchParserExpectedWhitespace3IMAP4HelperTests.test_fetchParserExpectedWhitespace  r   r6   c                   \         P                  ! 4       pVP                  R4       V P                  \	        VP
                  4      ^4       V P                  VP
                  ^ ,          VP                  4       V P                  VP
                  ^ ,          P                  R4       V P                  VP
                  ^ ,          P                  VP                  4       V P                  \        VP
                  ^ ,          4      R4       R# )z*
A C{BODY} can contain a C{TEXT} section.
s
   BODY[TEXT]FN)r   r  r  rB   r   r1   r  r  r  rF   TextrM   r  s   & r3   test_fetchParserTextSection,IMAP4HelperTests.test_fetchParserTextSection  s      	m$QXX*ahhqk1662!))51ahhqk..7qxx{+];r6   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zC
Parsing a C{BODY} with an unknown section raises an
L{Exception}.
s   BODY[UNKNOWN]Nr  r  s   & r3   test_fetchParserUnknownSection/IMAP4HelperTests.test_fetchParserUnknownSection  s)    
  )Q]]4DEr6   c                    \         P                  ! 4       pV P                  \        VP                  R4       \         P                  ! 4       pV P                  \        VP                  R4       R# )zM
Parsing a C{BODY} with an unterminated section list raises an
L{Exception}.
s   BODY[HEADERs   BODY[HEADER.FIELDS (SUBJECT)Nr  r  s   & r3   #test_fetchParserMissingSectionClose4IMAP4HelperTests.test_fetchParserMissingSectionClose  sM    
  )Q]]NC )Q]]4STr6   c                    \         P                  ! 4       pV P                  \        VP                  R4       \         P                  ! 4       pV P                  \        VP                  R4       R# )z
Parsing a C{BODY} whose C{HEADER.FIELDS} list does not begin
with an open parenthesis (C{(}) or end with a close
parenthesis (C{)}) raises an L{Exception}.
s   BODY[HEADER.FIELDS Missing)]s   BODY[HEADER.FIELDS (Missing]Nr  r  s   & r3   (test_fetchParserHeaderMissingParentheses9IMAP4HelperTests.test_fetchParserHeaderMissingParentheses  sN      )Q]]4ST )Q]]4STr6   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zS
Parsing a C{BODY} with a range that lacks a period (C{.})
raises an L{Exception}.
s   BODY<01>Nr  r  s   & r3   test_fetchParserDotlessPartial/IMAP4HelperTests.test_fetchParserDotlessPartial  s(    
  )Q]]K@r6   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zt
Parsing a C{BODY} with a partial range that's missing its
closing greater than sign (C{>}) raises an L{EXCEPTION}.
s   BODY<0Nr  r  s   & r3   test_fetchParserUnclosedPartial0IMAP4HelperTests.test_fetchParserUnclosedPartial  s(    
  )Q]]I>r6   c                	x    R RR\        R4      RR.pRpV P                  \        P                  ! V4      V4       R# )rv  rw  baz   this is a file
buzbizs4   "foo" "bar" "baz" {16}
this is a file
 "buz" "biz"N)r   rB   r   collapseNestedLists)rE   inputStructurerc   s   &  r3   
test_filesIMAP4HelperTests.test_files  sD    )*
 M22>BFKr6   c                	    R \         P                  ! R4      R\        R4      R\         P                  ! R4      R.pRpV P                  \         P                  ! V4      V4       R# )	r  r  s   bazr9  s   this is
quoteds   buzr6   sC   "foo" bar "baz" {16}
this is a file
 {15}
this is
quoted buz ""N)r   DontQuoteMer   rB   r<  ri   s   &  r3   test_quoteAvoider"IMAP4HelperTests.test_quoteAvoider  sa    f%)* f%
 	 	22596Br6   c                	v    R R..3.pV F+  w  r#V P                  \        P                  ! V4      V4       K-  	  R# )s   ({10}
0123456789)s
   0123456789N)rB   r   r  )rE   r  r  r  s   &   r3   test_literalsIMAP4HelperTests.test_literals'  s?    $&78
 $NDU44T:HE $r6   c                	   \         P                  ! ^R7      \         P                  ! ^^^R7      \         P                  ! \         P                  ! ^R7      \         P                  ! ^R7      4      \         P                  ! RR7      \         P                  ! \         P                  ! ^R7      \         P                  ! ^R7      \         P                  ! ^R7      4      \         P                  ! \         P                  ! \         P                  ! \         P                  ! ^RR	R
7      \         P                  ! ^RRR7      \         P                  ! ^^^RR7      \         P                  ! \         P                  ! RR7      4      4      4      \         P                  ! \         P                  ! RR7      4      4      .p. ROp\	        W4       F  w  r4V P                  W44       K  	  R# )r   )flagged)r  	unflaggeddeleted)rJ  today)before)unseen)new	yesterdayi  )r  sincesmallertuesdayi'  )r  rL  larger)r  rM  rJ  rL  spam)r   z1:5r  N)FLAGGEDz(DELETED UNFLAGGED)z(OR FLAGGED DELETED)z(BEFORE "today")z(OR DELETED (OR UNSEEN NEW))z(OR (NOT (OR (SINCE "yesterday" SMALLER 1000) (OR (BEFORE "tuesday" LARGER 10000) (OR (BEFORE "today" DELETED UNSEEN) (NOT (SUBJECT "spam")))))) (NOT (UID 1:5))))r   QueryOrNotr   rB   )rE   r   r   queryr  s   &    r3   test_queryBuilder"IMAP4HelperTests.test_queryBuilder/  s'   KK"KKqAq9HHU[[+U[[-CDKKw'HHU[[+U[[-BEKKTUDVWHH		HH1KN1YuM1Q'R		%++f"=>	 		%++%01

&

  #63OEU-  4r6   c                X    \         P                  ! RR7      pV P                  RV4       R# )z
When passed the C{keyword} argument, L{imap4.Query} returns an unquoted
string.

@see: U{http://tools.ietf.org/html/rfc3501#section-9}
@see: U{http://tools.ietf.org/html/rfc3501#section-6.4.4}
twisted)keywordz(KEYWORD twisted)Nr   rW  rB   rE   rZ  s   & r3   test_queryKeywordFlagWithQuotes0IMAP4HelperTests.test_queryKeywordFlagWithQuotesR  s#     I.,e4r6   c                X    \         P                  ! RR7      pV P                  RV4       R# )z
When passed the C{unkeyword} argument, L{imap4.Query} returns an
unquoted string.

@see: U{http://tools.ietf.org/html/rfc3501#section-9}
@see: U{http://tools.ietf.org/html/rfc3501#section-6.4.4}
r^  )	unkeywordz(UNKEYWORD twisted)Nr`  ra  s   & r3   !test_queryUnkeywordFlagWithQuotes2IMAP4HelperTests.test_queryUnkeywordFlagWithQuotes]  s#     i0.6r6   c                    \         P                  ! \         P                  ! ^R4      R7      pV P                  VR4       R# )zv
When passed a L{MessageSet}, L{imap4.Query} returns a query
containing a quoted string representing the ID sequence.
Nmessagesz(MESSAGES "1:*"))r   rW  r   rB   ra  s   & r3   test_queryWithMesssageSet*IMAP4HelperTests.test_queryWithMesssageSeth  s0    
 U%5%5a%>? 23r6   c                X    \         P                  ! ^R7      pV P                  VR4       R# )zT
When passed an L{int}, L{imap4.Query} returns a query
containing a quoted integer.
ri  z(MESSAGES "1")Nr`  ra  s   & r3   test_queryWithInteger&IMAP4HelperTests.test_queryWithIntegerp  s#    
 Q' 01r6   c                    V P                  \        P                  \        P                  \        P                  ! ^R7      4       R# )zY
An L{imap4.Or} query with less than two arguments raises an
L{imap4.IllegalQueryError}.
ri  N)r   r   IllegalQueryErrorrX  rW  rU   s   &r3   test_queryOrIllegalQuery)IMAP4HelperTests.test_queryOrIllegalQueryx  s*    
 	%11588U[[RS=TUr6   c                6   V P                  RVP                  4        R2\        P                  ! R	/ VR/B 4       V P                  RVP                  4        R2\        P                  ! R	/ VRRP	                  R \        ^!4       4       4      : R2/B 4       R# )
z
Helper to implement tests for value filtering of KEYWORD and UNKEYWORD
queries.

@param keyword: A native string giving the name of the L{imap4.Query}
    keyword argument to test.
(z twistedrocks)ztwisted (){%*"\] rocksztwisted  c              3  8   "   T F  p\        V4      x  K  	  R # 5ir/   )rs   )rQ  chs   & r3   rR  9IMAP4HelperTests._keywordFilteringTest.<locals>.<genexpr>  s     ;2s2wwrT  z rocksNr0   )rB   upperr   rW  r   rr   )rE   r_  s   &&r3   _keywordFilteringTest&IMAP4HelperTests._keywordFilteringTest  s     	 /KK?7$=>?	
 	 /KK ww;r;;>	
r6   c                (    V P                  R4       R# )a  
When passed the C{keyword} argument, L{imap4.Query} returns an
C{atom} that consists of one or more non-special characters.

List of the invalid characters:

    ( ) { % * " \ ] CTL SP

@see: U{ABNF definition of CTL and SP<https://tools.ietf.org/html/rfc2234>}
@see: U{IMAP4 grammar<http://tools.ietf.org/html/rfc3501#section-9>}
@see: U{IMAP4 SEARCH specification<http://tools.ietf.org/html/rfc3501#section-6.4.4>}
r_  Nr{  rU   s   &r3   test_queryKeywordFlag&IMAP4HelperTests.test_queryKeywordFlag  s     	""9-r6   c                (    V P                  R4       R# )a  
When passed the C{unkeyword} argument, L{imap4.Query} returns an
C{atom} that consists of one or more non-special characters.

List of the invalid characters:

    ( ) { % * " \ ] CTL SP

@see: U{ABNF definition of CTL and SP<https://tools.ietf.org/html/rfc2234>}
@see: U{IMAP4 grammar<http://tools.ietf.org/html/rfc3501#section-9>}
@see: U{IMAP4 SEARCH specification<http://tools.ietf.org/html/rfc3501#section-6.4.4>}
re  Nr~  rU   s   &r3   test_queryUnkeywordFlag(IMAP4HelperTests.test_queryUnkeywordFlag  s     	"";/r6   c                    . ROpV F3  pV P                  \        P                  \        P                  VR4       K5  	  R# )zd
Trying to parse an invalid representation of a sequence range raises an
L{IllegalIdentifierError}.
90  N)s   *:*r  s   4:s   bar:5r   r   IllegalIdentifierErrorr   rE   r   rj   s   &  r3   test_invalidIdListParser)IMAP4HelperTests.test_invalidIdListParser  s6    
 3E,,e.?.? r6   c                    . ROpV F3  pV P                  \        P                  \        P                  VR4       K5  	  R# )z
Zeroes and negative values are not accepted in id range expressions. RFC
3501 states that sequence numbers and sequence ranges consist of
non-negative numbers (RFC 3501 section 9, the seq-number grammar item).
r  N)s   0:5s   0:0s   *:0   0s   -3:5s   1:-2s   -1r  r  s   &  r3   #test_invalidIdListParserNonPositive4IMAP4HelperTests.test_invalidIdListParserNonPositive  s7     IE,,e.?.? r6   c                   . ROp\        ^R4      \        ^R4      \        ^R4      \        ^^4      ,           \        RR4      \        ^4      \        ^^4      \        ^4      \        ^4      ,           \        ^4      ,           \        ^^
4      \        ^^4      \        ^^4      \        ^
^4      ,           \        ^4      \        ^^
4      ,           \        ^4      \        ^^
4      ,           \        ^^4      ,           \        ^^
4      \        ^4      ,           \        ^^4      ,           \        ^^4      .p. ROp\        W4       F+  w  rEV P                  \        P                  ! V4      V4       K-  	  \        W4       Fw  w  rEVf2   V P                  \        \        \        P                  ! V4      4       K:  \        \        P                  ! V4      4      pV P                  WeRV: RV: RV: 24       Ky  	  R# )zQ
The function to parse sequence ranges yields appropriate L{MessageSet}
objects.
Nzlen(z) = z != )r   s   5:*s   1:2,5:*r      1s   1,2s   1,3,5s   1:10s   1:10,11s	   1:5,10:20s   1,5:10s   1,5:10,15:20s   1:10,15,20:25   4:2)NNNr   r   r   r   r        r         r   )r   r   rB   r   r   r   r   r   )rE   r   r   lengthsrj   r  Ls   &      r3   test_parseIdList!IMAP4HelperTests.test_parseIdList  s   

$ q$q$q$*Q"22tT"qMq!qMJqM)JqM9q"q"q!z"b11qMJq"--qMJq"--
2r0BBq"
2.B1CCq!
" K"63OEU..u5x@  4  #63OE!!)S%2C2CE2JK))%01  UIT!d8,.WX  4r6   c                P    V P                  \        \        P                  R4       R# )z]
L{imap4.parseTime} raises L{ValueError} when given a a time
string whose format is invalid.
invalidNr   r#  r   	parseTimerU   s   &r3   test_parseTimeInvalidFormat,IMAP4HelperTests.test_parseTimeInvalidFormat  s    
 	*eooyAr6   c                j    . ROpV F(  pV P                  \        \        P                  V4       K*  	  R# )z^
L{imap4.parseTime} raises L{ValueError} when given a time
string composed of invalid values.
N)zinvalid-July-2017z2-invalid-2017z2-July-invalidr  )rE   invalidStringsr  s   &  r3   test_parseTimeInvalidValues,IMAP4HelperTests.test_parseTimeInvalidValues	  s+    


 &Gj%//7C &r6   c                (   \        4       pRVP                  4       RVP                  4       RVP                  4       RVP	                  4       RVP                  4       /p\        P                  ! WP                  4       4      pV P                  W#4       R# )z
L{imap4.statusRequestHelper} builds a L{dict} mapping the
requested status names to values extracted from the provided
L{IMailboxIMAP}'s.
MESSAGESRECENTUIDNEXTUIDVALIDITYUNSEENN)
SimpleMailboxgetMessageCountgetRecentCount
getUIDNextgetUIDValiditygetUnseenCountr   statusRequestHelperkeysrB   )rE   mboxr  r1   s   &   r3   test_statusRequestHelper)IMAP4HelperTests.test_statusRequestHelper  s~      ,,.d))+t(4..0d))+
 **4A*r6   r0   N)/rx   ry   rz   r{   rZ  r`  rk  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r"  r&  r)  r,  r/  r2  r5  r>  rB  rE  r[  rb  rf  rk  rn  rr  r{  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r\  r\    s    >)03464&8@tD0M,^9*6&r
h
$Q(@MM
<FU	UA?LC(F!.F	5	742V
2.0
1YfBD+r6   r\  c                      ] tR tRt$ Rt. tR]R&   ^ t^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R ltR tR tR tR tR tRtR# )r  i+  +list[tuple[bytes, list[bytes], bytes, int]]rj  Fc                	    . V n         V P                   P                  V n        V P                   P                  V n        R # r/   	listenersr   addListenerremoveremoveListenerrU   s   &r3   r   SimpleMailbox.__init__3  -    >>00"nn33r6   c                	    V P                   # r/   r  rU   s   &r3   getFlagsSimpleMailbox.getFlags8      zzr6   c                	    ^*# )*   r0   rU   s   &r3   r  SimpleMailbox.getUIDValidity;  s    r6   c                	:    \        V P                  4      ^,           # r   r   rj  rU   s   &r3   r  SimpleMailbox.getUIDNext>  s    4==!A%%r6   c                	    ^	# )r  r0   rU   s   &r3   r  SimpleMailbox.getMessageCountA      r6   c                	    ^# )r   r0   rU   s   &r3   r  SimpleMailbox.getRecentCountD  r  r6   c                	    ^# )r  r0   rU   s   &r3   r  SimpleMailbox.getUnseenCountG  r  r6   c                	    V P                   # r/   rwrU   s   &r3   isWriteableSimpleMailbox.isWriteableJ  s    wwr6   c                	    R # r/   r0   rU   s   &r3   destroySimpleMailbox.destroyM      r6   c                	    R # )rs  r0   rU   s   &r3   getHierarchicalDelimiter&SimpleMailbox.getHierarchicalDelimiterP  s    r6   c                	D   / pR V9   d   V P                  4       VR &   RV9   d   V P                  4       VR&   RV9   d   V P                  4       ^,           VR&   RV9   d   V P                  4       VR&   RV9   d   V P                  4       VR&   \        P
                  ! V4      # )r  r  r  r  r  r  r  getUIDr  r   r  rE   namesrs   && r3   requestStatusSimpleMailbox.requestStatusS  s     002AjMu--/AhK//1A5AiLE!#{{}Amu--/AhK}}Qr6   Nc                	    V P                   P                  WW0P                  34       V ;P                  ^,          un        \        P                  ! R4      # r   Nrj  r   mUIDr   r  rE   messager  dates   &&&&r3   
addMessageSimpleMailbox.addMessagea  s9    gdII>?		Q	}}T""r6   c                	    . pV P                    F$  pR V^,          9   g   K  VP                  V4       K&  	  V F  pV P                   P                  V4       K   	  V Uu. uF  q"^,          NK  	  up# u upi \Deletedrj  r   r  rE   deleter   s   &  r3   expungeSimpleMailbox.expungef  sg    Aad"a   AMM  # $%f!f%%%   A3c                	    R V n         R# TN)closedrU   s   &r3   closeSimpleMailbox.closeo  s	    r6   c                	    R # r/   r0   rE   rj  r  s   &&&r3   fetchSimpleMailbox.fetchr      r6   c                	    R # r/   r0   rE   r  s   &&r3   r  SimpleMailbox.getUIDv  r  r6   c                	    R # r/   r0   rE   rj  r  moder  s   &&&&&r3   storeSimpleMailbox.storez  r  r6   )r  r  r  r  z\Flag1Flag2z\AnotherSysFlagLastFlagr/   )rx   ry   rz   r{   r  rj  __annotations__r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r  +  sv    @E<>H9>D	
BF4
& #
&r6   r  c                      ] tR tRt$ RtRt. tR]R&   ^ t^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R ltR tR tR tR tRtR# )UncloseableMailboxi  z"
A mailbox that cannot be closed.
r  rj  Fc                	    . V n         V P                   P                  V n        V P                   P                  V n        R # r/   r  rU   s   &r3   r   UncloseableMailbox.__init__  r  r6   c                    V P                   # )z*
The flags

@return: A sequence of flags.
r  rU   s   &r3   r  UncloseableMailbox.getFlags  s     zzr6   c                    ^*# )z.
The UID validity value.

@return: The value.
r0   rU   s   &r3   r  !UncloseableMailbox.getUIDValidity  s     r6   c                :    \        V P                  4      ^,           # )z"
The next UID.

@return: The UID.
r  rU   s   &r3   r  UncloseableMailbox.getUIDNext  s     4==!A%%r6   c                    ^	# )z/
The number of messages.

@return: The number.
r0   rU   s   &r3   r  "UncloseableMailbox.getMessageCount       r6   c                    ^# z,
The recent messages.

@return: The number.
r0   rU   s   &r3   r  !UncloseableMailbox.getRecentCount  r  r6   c                    ^# r  r0   rU   s   &r3   r  !UncloseableMailbox.getUnseenCount  r  r6   c                    V P                   # )zH
The recent messages.

@return: Whether or not the mailbox is writable.
r  rU   s   &r3   r  UncloseableMailbox.isWriteable  s     wwr6   c                    R# )z
Destroy this mailbox.
Nr0   rU   s   &r3   r  UncloseableMailbox.destroy  s     	r6   c                    R# )z=
Return the hierarchical delimiter.

@return: The delimiter.
rs  r0   rU   s   &r3   r  +UncloseableMailbox.getHierarchicalDelimiter  s     r6   c                D   / pRV9   d   V P                  4       VR&   RV9   d   V P                  4       VR&   RV9   d   V P                  4       ^,           VR&   RV9   d   V P                  4       VR&   RV9   d   V P                  4       VR&   \        P
                  ! V4      # )zn
Return the mailbox's status.

@param names: The status items to include.

@return: A L{dict} of status data.
r  r  r  r  r  r  r  s   && r3   r   UncloseableMailbox.requestStatus  s      002AjMu--/AhK//1A5AiLE!#{{}Amu--/AhK}}Qr6   Nc                    V P                   P                  WW0P                  34       V ;P                  ^,          un        \        P                  ! R4      # )z
Add a message to the mailbox.

@param message: The message body.

@param flags: The message flags.

@param date: The message date.

@return: A L{Deferred} that fires when the message has been
    added.
Nr  r  s   &&&&r3   r  UncloseableMailbox.addMessage  s;     	gdII>?		Q	}}T""r6   c                    . pV P                    F$  pRV^,          9   g   K  VP                  V4       K&  	  V F  pV P                   P                  V4       K   	  V Uu. uF  q"^,          NK  	  up# u upi )zR
Delete messages marked for deletion.

@return: A L{list} of deleted message IDs.
r  r  r  s   &  r3   r  UncloseableMailbox.expunge  si     Aad"a   AMM  # $%f!f%%%r  c                	    R # r/   r0   r  s   &&&r3   r  UncloseableMailbox.fetch
  r  r6   c                	    R # r/   r0   r  s   &&r3   r  UncloseableMailbox.getUID  r  r6   c                	    R # r/   r0   r  s   &&&&&r3   r  UncloseableMailbox.store  r  r6   )r  r  r  r
  r/   )rx   ry   rz   r{   rZ  r  rj  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r    sy     AE<>H9>D	
BF4
& *#"&r6   r  c                  .    ] tR tRtRt]tR tRR ltRt	R# )AccountWithoutNamespacesi  zD
An in-memory account that does not provide L{INamespacePresenter}.
c                	"    V P                  4       # r/   )mailboxFactory)rE   nameids   &&&r3   _emptyMailbox&AccountWithoutNamespaces._emptyMailbox  s    ""$$r6   c                	X    \         P                  P                  W4      pVe   W#n        V# r/   )r   MemoryAccountselectr  )rE   r6  r  r  s   &&& r3   r<  AccountWithoutNamespaces.select!  s(    ""))$5Gr6   r0   Nr  )
rx   ry   rz   r{   rZ  r  r5  r8  r<  r|   r0   r6   r3   r3  r3    s     #N% r6   r3  c                      ] tR tRtRtRtR# )Accounti(  z<
An in-memory account that provides L{INamespacePresenter}.
r0   Nrx   ry   rz   r{   rZ  r|   r0   r6   r3   r?  r?  (  s    r6   r?  c                  2    ] tR tRt]! R4      tR tR tRtR# )SimpleServeri.     testuserc                	    \         P                  P                  ! V .VO5/ VB  \        V R 7      p\	        V4      p\        4       pVP                  RR4       WPn        W@n        VP                  V4       RV n
        R# )accountHolderrC     password-testFN)r   IMAP4Serverr   	TestRealmr   r   addUsercheckerportalregisterCheckertimeoutTest)rE   argskwrealmrL  r   s   &*,   r3   r   SimpleServer.__init__1  sj    ""45$5"5-35			+/0q! r6   c                	l    V P                   '       d   R # \        P                  P                  W4       R # r/   )rN  r   rH  lineReceivedrE   lines   &&r3   rT  SimpleServer.lineReceived<  s%    &&t2r6   )rK  rL  rN  N)	rx   ry   rz   r{   r?  
theAccountr   rT  r|   r0   r6   r3   rB  rB  .  s    %J	!3r6   rB  c                  8    ] tR tRtR	R ltR tR tR tR tRt	R# )
SimpleClientiD  Nc                	^    \         P                  P                  W4       Wn        . V n        R # r/   )r   IMAP4Clientr   deferredevents)rE   r]  contextFactorys   &&&r3   r   SimpleClient.__init__E  s"    ""48 r6   c                	<    V P                   P                  R 4       R # r/   )r]  callback)rE   capss   &&r3   serverGreetingSimpleClient.serverGreetingJ  s    t$r6   c                	t    V P                   P                  R V.4       V P                  P                  4        R# modeChangedNr^  r   	transportloseConnection)rE   	writeables   &&r3   rh  SimpleClient.modeChangedM  s)    M956%%'r6   c                	t    V P                   P                  R V.4       V P                  P                  4        R# )flagsChangedNri  rE   newFlagss   &&r3   ro  SimpleClient.flagsChangedQ  s)    NH56%%'r6   c                	t    V P                   P                  R W.4       V P                  P                  4        R# )newMessagesNri  )rE   existsrecents   &&&r3   rt  SimpleClient.newMessagesU  s)    M6:;%%'r6   )r]  r^  r/   )
rx   ry   rz   r{   r   rd  rh  ro  rt  r|   r0   r6   r3   rZ  rZ  D  s    
%(((r6   rZ  c                  X    ] tR tRt$ RtR]R&   RtR]R&   R tR tR	 t	R
 t
R tR tRtR# )IMAP4HelperMixiniZ  NzOptional[ServerTLSContext]	serverCTXzOptional[ClientTLSContext]	clientCTXc                	    \         P                  ! 4       p\        V P                  R 7      V n        \        WP                  R 7      V n        Wn        . \        n
        \        R4      p\        Vn        V\        n        R# )r_  rC  N)r   r   rB  rz  serverrZ  r{  client	connectedr  rj  r?  mboxTyperX  )rE   r   rX  s   &  r3   setUpIMAP4HelperMixin.setUp^  sU    NN"$..A"1^^D!#[)
+
",r6   c                	    V = V =V =R # r/   )r~  r  r  rU   s   &r3   tearDownIMAP4HelperMixin.tearDowni  s    KKNr6   c                	N    V P                   P                  P                  4        R # r/   )r  rj  rk  )rE   ignores   &&r3   _cbStopClientIMAP4HelperMixin._cbStopClientn  s    ,,.r6   c                	    V P                   P                  P                  4        V P                  P                  P                  4        \        P
                  ! VR \        V 4      ,           4       R# )Problem with N)r  rj  rk  r~  r$   errr   )rE   r#   s   &&r3   
_ebGeneralIMAP4HelperMixin._ebGeneralq  sE    ,,.,,.3t945r6   c                	X    \         P                  ! V P                  V P                  4      # r/   )r"   loopbackAsyncr~  r  rU   s   &r3   r"   IMAP4HelperMixin.loopbackv  s    %%dkk4;;??r6   c                    VP                   ! \        P                  4       \        VP                  4      p\        V4      pV P                  W24       R# )z
Assert that the provided failure is an L{IMAP4Exception} with
the given message.

@param failure: A failure whose value L{IMAP4Exception}
@type failure: L{failure.Failure}

@param expected: The expected failure message.
@type expected: L{bytes}
N)trapr   IMAP4Exceptionr   valuer   rB   )rE   r#   r  r  s   &&& r3   assertClientFailureMessage+IMAP4HelperMixin.assertClientFailureMessagey  s;     	U))*gmm$>+r6   )r  r  r~  )rx   ry   rz   r{   rz  r  r{  r  r  r  r  r"   r  r|   r0   r6   r3   ry  ry  Z  s7    ,0I)0,0I)0	-
/6
@,r6   ry  c                  H   ] 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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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.R- t/R. t0R/ t1R0 t2R1 t3R2 t4R3 t5R4 t6R5t7R6# )7IMAP4ServerTestsi  c                	  a aa / oVV 3R  lpS P                   P                  \        V4      4      P                  S P                  4      p\
        P                  ! S P                  4       V.4      pRRRRRR/oVP                  VVV 3R l4      # )c                 d   < VV3R  lp SP                   P                  4       P                  V 4      # )c                r   < SP                  V 4       SP                  P                  P                  4        R # r/   updater~  rj  rk  r   rc  rE   s   &r3   gotCapsAIMAP4ServerTests.testCapability.<locals>.getCaps.<locals>.gotCaps  $    A%%446r6   r  getCapabilitiesr   r  rc  rE   s    r3   getCaps0IMAP4ServerTests.testCapability.<locals>.getCaps  (    7 ;;..0<<WEEr6   	   IMAP4rev1N	   NAMESPACE   IDLEc                (   < SP                  SS4      # r/   rB   )_rc  r  rE   s   &r3   r4   1IMAP4ServerTests.testCapability.<locals>.<lambda>  s    t'7'7$'Gr6   )r  r   r7   
addErrbackr  r   gatherResultsr"   )rE   r  d1r   rc  r  s   f   @@r3   testCapabilityIMAP4ServerTests.testCapability  st    	F ^^''g7BB4??S" 56 $dGTJ}}GHHr6   c                	^  a aa / o\         S P                  P                  R &   VV 3R lpS P                  P	                  \        V4      4      P                  S P                  4      p\        P                  ! S P                  4       V.4      pRRRRRRRR ./oVP	                  VVV 3R l4      # )   CRAM-MD5c                 d   < VV3R  lp SP                   P                  4       P                  V 4      # )c                r   < SP                  V 4       SP                  P                  P                  4        R # r/   r  r  s   &r3   r  IIMAP4ServerTests.testCapabilityWithAuth.<locals>.getCaps.<locals>.gotCaps  r  r6   r  r  s    r3   r  8IMAP4ServerTests.testCapabilityWithAuth.<locals>.getCaps  r  r6   r  Nr  r     AUTHc                (   < SP                  SS4      # r/   r  )r  rc  expCaprE   s   &r3   r4   9IMAP4ServerTests.testCapabilityWithAuth.<locals>.<lambda>  s    t'7'7'Er6   )r   r~  challengersr  r   r7   r  r  r   r  r"   )rE   r  r  r   rc  r  s   f   @@r3   testCapabilityWithAuth'IMAP4ServerTests.testCapabilityWithAuth  s    /A,	F ^^''g7BB4??S" 56 $$Tk]	
 }}EFFr6   c                	   a  ^ S n         V 3R lpS P                  P                  \        V4      4      P	                  S P
                  4       S P                  4       pVP                  V 3R l4      # )r  c                 x   < V3R  lp SP                   P                  4       P                  \        V 4      4       R# )c                    < ^S n         R# r  )	loggedOutrU   s   r3   setLoggedOutAIMAP4ServerTests.testLogout.<locals>.logout.<locals>.setLoggedOut  s
    !"r6   N)r  logoutr   r7   )r  rE   s    r3   r  +IMAP4ServerTests.testLogout.<locals>.logout  s*    # KK ,,U<-@Ar6   c                <   < SP                  SP                  ^4      # r  )rB   r  r  rE   s   &r3   r4   -IMAP4ServerTests.testLogout.<locals>.<lambda>  s    t'7'7'Jr6   )r  r  r   r7   r  r  r"   )rE   r  r   s   f  r3   
testLogoutIMAP4ServerTests.testLogout  sR    	B 	""5=1<<T__MMMO}}JKKr6   c                	   a  R S n         V 3R lpS P                  P                  \        V4      4      P	                  S P
                  4       S P                  4       pVP                  V 3R l4      # )Nc                 f   < V3R  lp SP                   P                  4       P                  V 4       R# )c                ^   < V Sn         SP                  P                  P                  4        R # r/   )	responsesr~  rj  rk  )r  rE   s   &r3   setResponses=IMAP4ServerTests.testNoop.<locals>.noop.<locals>.setResponses  s     !*%%446r6   N)r  noopr   )r  rE   s    r3   r  'IMAP4ServerTests.testNoop.<locals>.noop  s%    7 KK**<8r6   c                <   < SP                  SP                  . 4      # r/   )rB   r  r  s   &r3   r4   +IMAP4ServerTests.testNoop.<locals>.<lambda>  s    t'7'7'Kr6   )r  r  r   r7   r  r  r"   )rE   r  r   s   f  r3   testNoopIMAP4ServerTests.testNoop  sQ    	9 	""5;/::4??KMMO}}KLLr6   c                	  a  V 3R  lpS P                   P                  \        V4      4      P                  S P                  4      p\
        P                  ! VS P                  4       .4      pVP                  S P                  4      # )c                 v   < SP                   P                  R R4      p V P                  SP                  4       R# rC  rG  N)r  loginr   r  r   rE   s    r3   r  )IMAP4ServerTests.testLogin.<locals>.login  s,    !!+/?@AMM$,,-r6   )	r  r   r7   r  r  r   r  r"   _cbTestLoginrE   r  r  r   s   f   r3   	testLoginIMAP4ServerTests.testLogin  sa    	. ^^''e5@@QT]]_ 56}}T..//r6   c                	    V P                  V P                  P                  \        P                  4       V P                  V P                  P
                  R 4       R# authNrB   r~  accountrB  rX  staterE   ignoreds   &&r3   r  IMAP4ServerTests._cbTestLogin  <    ,,l.E.EF**F3r6   c                	  a  V 3R  lpS P                   P                  \        V4      4      P                  S P                  4      pS P                  4       p\        P                  ! W#.4      pVP                  S P                  4      # )c                 v   < SP                   P                  R R4      p V P                  SP                  4       R# rC  s   wrong-passwordNr  r  addBothr  r  s    r3   r  /IMAP4ServerTests.testFailedLogin.<locals>.login  ,    !!+/@AAIId(()r6   )	r  r   r7   r  r  r"   r   r  _cbTestFailedLoginrE   r  r  d2r   s   f    r3   testFailedLogin IMAP4ServerTests.testFailedLogin  sc    	* ^^''e5@@Q]]_)}}T4455r6   c                	    V P                  V P                  P                  R 4       V P                  V P                  P                  R4       R # )Nunauth)rB   r~  r  r  r  s   &&r3   r  #IMAP4ServerTests._cbTestFailedLogin  s6    ,,d3**H5r6   c                0  a  RS P                   n        V 3R lpS P                  P                  \	        V4      4      P                  S P                  4      pS P                  4       p\        P                  ! W#.4      pVP                  S P                  4      # )zR
Attempting to log into a server that has no L{Portal} results
in a failed login.
Nc                 v   < SP                   P                  R R4      p V P                  SP                  4       R# r  r  r  s    r3   r  7IMAP4ServerTests.test_loginWithoutPortal.<locals>.login  r  r6   )r~  rL  r  r   r7   r  r  r"   r   r  r  r  s   f    r3   test_loginWithoutPortal(IMAP4ServerTests.test_loginWithoutPortal  sq    
 "	* ^^''e5@@Q]]_)}}T4455r6   c                ^  a  R pVS P                   P                  P                  n        V 3R lpS P                  P                  \        V4      4      P                  S P                  4      pS P                  4       p\        P                  ! W4.4      pVP                  S P                  4      # )z
The server responds with a C{BAD} response when its portal
attempts to log a user in with checker that claims to support
L{IAccount} but returns an an avatar interface that is not
L{IAccount}.
c                     R RR 3# )zNot IAccountzNot an accountc                     R # r/   r0   r0   r6   r3   r4   VIMAP4ServerTests.test_nonIAccountAvatar.<locals>.brokenRequestAvatar.<locals>.<lambda>  s    dr6   r0   )r  __s   *,r3   brokenRequestAvatarDIMAP4ServerTests.test_nonIAccountAvatar.<locals>.brokenRequestAvatar   s    "$4lCCr6   c                 v   < SP                   P                  R R4      p V P                  SP                  4       R# r  r  r  s    r3   r  6IMAP4ServerTests.test_nonIAccountAvatar.<locals>.login  s,    !!+/?@AIId(()r6   )r~  rL  rQ  requestAvatarr  r   r7   r  r  r"   r   r  r  )rE   r	  r  r  r  r   s   f     r3   test_nonIAccountAvatar'IMAP4ServerTests.test_nonIAccountAvatar  s    	D 2E  .	* ^^''e5@@Q]]_)}}T4455r6   c                  a a  ! R R\         4      oV3R lpVS P                  n        V 3R lpS P                  P	                  \        V4      4      pVP                  S P                  R4       VP                  VV 3R l4       pVP                  S P                  4       VP                  S P                  4       S P                  4       p\        P                  ! W5.4      pVP	                  S P                  4      # )z
Any exception raised by L{IMAP4Server.authenticateLogin} that
is not L{UnauthorizedLogin} is logged results in a C{BAD}
response.
c                      ] tR tRtRtRtR# )AIMAP4ServerTests.test_loginException.<locals>.UnexpectedExceptioni  
An unexpected exception.
r0   Nr@  r0   r6   r3   UnexpectedExceptionr        r6   r  c                   < S! R 4      h)Whoopsr0   )userpasswdr  s   &&r3   raisesUnexpectedExceptionGIMAP4ServerTests.test_loginException.<locals>.raisesUnexpectedException  s    %h//r6   c                 <   < S P                   P                  R R4      # rC  rG  r  r  rU   s   r3   r  3IMAP4ServerTests.test_loginException.<locals>.login      ;;$$[2BCCr6   s   Server error: Whoopsc                H   < SP                  SP                  S4      4       R # r/   r  flushLoggedErrors)r  r  rE   s   &r3   assertErrorLogged?IMAP4ServerTests.test_loginException.<locals>.assertErrorLogged&  s    OOD223FGHr6   )r  r~  authenticateLoginr  r   r7   r  r  r  r  r  r"   r   r  r  )rE   r  r  r  r$  r  r   r  s   f      @r3   test_loginException$IMAP4ServerTests.test_loginException  s    	) 	
	0 )B%	D ^^''e5
d557NO		I 
	I 	doo&


4%%&]]_)}}T4455r6   c                	F  a  R R/S P                   P                  n        V 3R lpS P                  P	                  \        V4      4      P                  S P                  4      p\        P                  ! S P                  4       V.4      pVP	                  S P                  4      # )
   {test}user   {test}passwordc                    < SP                   P                  R R4      p V P                  \        P                  R\        S4      ,           4       V P                  SP                  4       R# )r*  r+  r  N)r  r  r  r$   r  r   r   r  r  s    r3   r  9IMAP4ServerTests.testLoginRequiringQuoting.<locals>.login4  sG    !!-1BCALL/CI"=>MM$,,-r6   )r~  rK  usersr  r   r7   r  r  r   r  r"   _cbTestLoginRequiringQuotingr  s   f   r3   testLoginRequiringQuoting*IMAP4ServerTests.testLoginRequiringQuoting1  sy    %24E$F!	.
 ^^''e5@@Q" 56}}T>>??r6   c                	    V P                  V P                  P                  \        P                  4       V P                  V P                  P
                  R 4       R# r  r  r  s   &&r3   r/  -IMAP4ServerTests._cbTestLoginRequiringQuoting=  r  r6   c                	  a  R S n         V 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      4       VP	                  S P
                  4       S P                  4       p\        P                  ! W4.4      pVP                  V 3R l4       pVP                  S P                  RR... . .4       V# )Nc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  -IMAP4ServerTests.testNamespace.<locals>.loginD  r   r6   c                 b   < V3R  lp SP                   P                  4       P                  V 4      # )c                8   < V Sn         SP                  R 4       R # r/   namespaceArgsr  rO  rE   s   &r3   gotNamespaceGIMAP4ServerTests.testNamespace.<locals>.namespace.<locals>.gotNamespaceH      %)"""4(r6   r  	namespacer   r<  rE   s    r3   r@  1IMAP4ServerTests.testNamespace.<locals>.namespaceG  (    ) ;;((*66|DDr6   c                   < SP                    F+  pV F"  pV F  pSP                  V\        4       K  	  K$  	  K-  	  SP                   # r/   )r:  r  r   )r  
namespacespairr  rE   s   &   r3   assertAllPairsNativeStringsCIMAP4ServerTests.testNamespace.<locals>.assertAllPairsNativeStringsT  sE    "00
&D!%--eS9 "& ' 1 %%%r6   rv  rs  )
r:  r  r   r7   r  r  r"   r   r  rB   )rE   r  r@  r  r  r   rG  s   f      r3   testNamespaceIMAP4ServerTests.testNamespaceA  s    !	D	E ^^''e5
uY'(
doo&]]_)	
	& 
	& 	
d&&2s)b"(=>r6   c                  a  \        R4      S P                  n        RS n        V 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      4       VP                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP                  V 3R l4       VP                  S P                  . . . .4       V# )z~
A mailbox that does not provide L{INamespacePresenter} returns
empty L{list}s for its personal, shared, and user namespaces.
rC  Nc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  <IMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.loging  r   r6   c                 b   < V3R  lp SP                   P                  4       P                  V 4      # )c                8   < V Sn         SP                  R 4       R # r/   r9  r;  s   &r3   r<  VIMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.namespace.<locals>.gotNamespacek  r>  r6   r?  rA  s    r3   r@  @IMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.namespacej  rC  r6   c                   < SP                   # r/   )r:  r  s   &r3   r4   ?IMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.<lambda>v  s     2 2r6   )r3  r~  rX  r:  r  r   r7   r  r  r"   r   r  rB   )rE   r  r@  r  r  r   s   f     r3   test_mailboxWithoutNamespace-IMAP4ServerTests.test_mailboxWithoutNamespace_  s    
 ":+!F!	D	E ^^''e5
uY'(
doo&]]_)	23	d&&R5r6   c                	  a  \         P                  P                  R 4       RS n        V 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      4       VP                  S P                  4       S P                  4       p\        P                  ! W4.4      P                  S P                  4      # )test-mailboxNc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  *IMAP4ServerTests.testSelect.<locals>.login~  r   r6   c                 l   < V3R  lp SP                   P                  R4      pVP                  V 4       V# )c                8   < V Sn         SP                  R 4       R # r/   )selectedArgsr  r;  s   &r3   selected=IMAP4ServerTests.testSelect.<locals>.select.<locals>.selected      $(!""4(r6   rW  )r  r<  r   )r]  r   rE   s     r3   r<  +IMAP4ServerTests.testSelect.<locals>.select  s/    ) "">2AMM(#Hr6   )rB  rX  
addMailboxr\  r  r   r7   r  r  r"   r   r  _cbTestSelect)rE   r  r<  r  r  s   f    r3   
testSelectIMAP4ServerTests.testSelectz  s    **>: 	D	 ^^''e5
uV}%
doo&]]_""B8,889K9KLLr6   c                  a  V 3R lpV 3R lpS P                   P                  \        V4      4       S P                   P                  \        V4      4       S P                   P                  S P                  R4       S P                   P                  S P
                  4       S P                   P                  S P                  4       \        P                  ! S P                   S P                  4       .4      pVP                  V 3R l4       pV# )zP
A client that selects a mailbox that does not exist receives a
C{NO} response.
c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  9IMAP4ServerTests.test_selectWithoutMailbox.<locals>.login  r   r6   c                 :   < S P                   P                  R 4      # )rW  r  r<  rU   s   r3   r<  :IMAP4ServerTests.test_selectWithoutMailbox.<locals>.select      ;;%%n55r6      No such mailboxc                R   < SP                  SP                  P                  4       R # r/   )assertIsNoner~  r  r  s   &r3   assertNoMailboxSelectedKIMAP4ServerTests.test_selectWithoutMailbox.<locals>.assertNoMailboxSelected  s    dkk../r6   )
r  r   r7   r  r  r  r  r   r  r"   )rE   r  r<  connectionCompletero  s   f    r3   test_selectWithoutMailbox*IMAP4ServerTests.test_selectWithoutMailbox  s    	D	6 	""5<0""5=1!!$"A"ACUV""4#5#56!!$//2"00$..$--/1RS		'	'	0 
(	0 "!r6   c                	    \         P                  P                  R ,          pV P                  V P                  P
                  V4       V P                  V P                  R^	R^R^*RRRR/4       R# )	TEST-MAILBOXEXISTSr  r  r  
READ-WRITETNr
  )rB  rX  	mailboxesrB   r~  r  r\  rE   r  r  s   && r3   rb  IMAP4ServerTests._cbTestSelect  sh    &&00@))40!!rMd		
r6   c                  a  \         P                  P                  R4       RS n        V 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      4       VP                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP                  S P                  4      # )a/  
L{IMAP4Client.examine} issues an I{EXAMINE} command to the server and
returns a L{Deferred} which fires with a C{dict} with as many of the
following keys as the server includes in its response: C{'FLAGS'},
C{'EXISTS'}, C{'RECENT'}, C{'UNSEEN'}, C{'READ-WRITE'}, C{'READ-ONLY'},
C{'UIDVALIDITY'}, and C{'PERMANENTFLAGS'}.

Unfortunately the server doesn't generate all of these so it's hard to
test the client's handling of them here.  See
L{IMAP4ClientExamineTests} below.

See U{RFC 3501<http://www.faqs.org/rfcs/rfc3501.html>}, section 6.3.2,
for details.
rW  Nc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  ,IMAP4ServerTests.test_examine.<locals>.login  r   r6   c                 l   < V3R  lp SP                   P                  R4      pVP                  V 4       V# )c                8   < V Sn         SP                  R 4       R # r/   )examinedArgsr  r;  s   &r3   examined@IMAP4ServerTests.test_examine.<locals>.examine.<locals>.examined  r_  r6   rW  )r  examiner   )r  r   rE   s     r3   r  .IMAP4ServerTests.test_examine.<locals>.examine  s/    ) ##N3AMM(#Hr6   )rB  rX  ra  r  r  r   r7   r  r  r"   r   r  _cbTestExamine)rE   r  r  r  r  r   s   f     r3   test_examineIMAP4ServerTests.test_examine  s     	**>: 	D	 ^^''e5
uW~&
doo&]]_)}}T0011r6   c                	    \         P                  P                  R ,          pV P                  V P                  P
                  V4       V P                  V P                  R^	R^R^*RRRR/4       R# )	ru  rv  r  r  r  rw  FNr
  )rB  rX  rx  rB   r~  r  r  ry  s   && r3   r  IMAP4ServerTests._cbTestExamine  sh    &&00@))40!!rMe		
r6   c                	Z  a aaaa	 Ro	RoV 3R loV 3R loV 3R lpVVVV V	3R lp. S n         S P                  P                  \        V4      4      P                  \        V4      4      pS P	                  4       p\
        P                  ! W4.4      pVP                  S P                  S	S4      # )testboxc                 >   < S P                   P                  ^4       R# r  r1   r   rU   s   r3   cb'IMAP4ServerTests.testCreate.<locals>.cb      KKq!r6   c                >   < SP                   P                  ^ 4       R# r  Nr  r#   rE   s   &r3   eb'IMAP4ServerTests.testCreate.<locals>.eb  r  r6   c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  *IMAP4ServerTests.testCreate.<locals>.login  r   r6   c                    < SS,            FG  p SP                   P                  V 4      pVP                  \        S4      4      P	                  S4       KI  	  XP                  SP                  SP                  4       R # r/   )r  creater   r7   r  addCallbacksr  r  )r6  r   r  r  r  rE   r  s     r3   r  +IMAP4ServerTests.testCreate.<locals>.create  s\    $KK&&t,eBi(33B7 ' NN4--t?r6   )r  test/boxztest/test/box/boxINBOX)r  r  )r1   r  r   r7   r"   r   r  _cbTestCreate)
rE   r  r  r  r  r   r  r  r  r  s
   f     @@@@r3   
testCreateIMAP4ServerTests.testCreate  s    K&	"	"	D	@ 	@ ^^''e5AA%-P]]_)}}T//$??r6   c                	V   V P                  V P                  ^.\        V4      ,          ^ .\        V4      ,          ,           4       \        \        P
                  P                  4      p\        . RO4      pT P                  YE Uu. uF  qfP                  4       NK  	  up4       R# u upi )r   N)inboxr  r  testr  )rB   r1   r   r  rB  rX  rx  rz  )rE   r  r  r  r  r  as   &&&&   r3   r  IMAP4ServerTests._cbTestCreate	  sw    qcCL&8A3T?&JKl--778QR7;7a	7;<;s   B&
c                	  a  \         P                  P                  R 4       V 3R lpV 3R lpS P                  P	                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP	                  V 3R l4       V# )	delete/mec                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  *IMAP4ServerTests.testDelete.<locals>.login	  r   r6   c                 :   < S P                   P                  R 4      # r  r  r  rU   s   r3   r  +IMAP4ServerTests.testDelete.<locals>.delete	      ;;%%k22r6   c                j   < SP                  \        \        P                  P                  4      . 4      # r/   )rB   r   rB  rX  rx  r  s   &r3   r4   -IMAP4ServerTests.testDelete.<locals>.<lambda>	  s$    d&&tL,C,C,M,M'NPRSr6   rB  rX  ra  r  r   r7   r  r  r  r"   r   r  )rE   r  r  r  r  r   s   f     r3   
testDeleteIMAP4ServerTests.testDelete
	  s    **;7	D	3 ^^''e5
ft7
**DOO<]]_)	S	
 r6   c                
  a  \         P                  P                  R4       \         P                  P                  R4       V 3R lpV 3R lpV 3R lpS P                  P	                  \        V4      4      pVP                  \        V4      S P                  4       VP                  V4       VP                  S P                  4       S P                  4       p\        P                  ! WE.4      pVP	                  V 3R l4       V# )z
Attempting to delete a mailbox with hierarchically inferior
names fails with an informative error.

@see: U{https://tools.ietf.org/html/rfc3501#section-6.3.4}

@return: A L{Deferred} with assertions.
r  r  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  GIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.login)	  r   r6   c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  HIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.delete,	      ;;%%h//r6   c                   < V P                   ! \        P                  4       SP                  \	        V P
                  4      \	        R 4      4       R# )s-   Name "DELETE" has inferior hierarchical namesN)r  r   r  rB   r   r  r  s   &r3   assertIMAPExceptionUIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.assertIMAPException/	  s8    LL--.GMM"DEr6   c                n   < SP                  \        \        P                  P                  4      R R.4      # )DELETEz	DELETE/ME)rB   r  rB  rX  rx  r  s   &r3   r4   JIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.<lambda>>	  s+    d&&|..889Hk;Rr6   )rB  rX  ra  r  r   r7   r  r  r  r  r"   r   r  )rE   r  r  r  loggedIn
loopedBackr   s   f      r3   'testDeleteWithInferiorHierarchicalNames8IMAP4ServerTests.testDeleteWithInferiorHierarchicalNames	  s     	**84**;7	D	0	 >>--eEl;eFmT__=/0d001]]_
 67		

 r6   c                	  a  R S n         V 3R lpV 3R lpV 3R lpS P                  P                  \        V4      4      pVP	                  \        V4      S P
                  4       VP                  V4       VP	                  S P                  S P
                  4       S P                  4       p\        P                  ! WE.4      pVP                  V 3R l4       V# )Nc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  6IMAP4ServerTests.testIllegalInboxDelete.<locals>.loginG	  r   r6   c                 :   < S P                   P                  R 4      # )r  r  rU   s   r3   r  7IMAP4ServerTests.testIllegalInboxDelete.<locals>.deleteJ	  s    ;;%%g..r6   c                   < V Sn         R # r/   stashedr1   rE   s   &r3   stash6IMAP4ServerTests.testIllegalInboxDelete.<locals>.stashM	  s
    !DLr6   c                j   < SP                  \        SP                  \        P                  4      4      # r/   r  r  r  r#   Failurer  s   &r3   r4   9IMAP4ServerTests.testIllegalInboxDelete.<locals>.<lambda>W	      doojw&OPr6   r  r  r   r7   r  r  r  r  r"   r   r  )rE   r  r  r  r  r  r   s   f      r3   testIllegalInboxDelete'IMAP4ServerTests.testIllegalInboxDeleteD	  s    	D	/	" ^^''e5
ft7


5
**DOO<]]_)	P	
 r6   c                	  a  V 3R  lpV 3R lpV 3R lpRS n         S P                  P                  \        V4      4      pVP                  \        V4      4      P	                  V4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! WE.4      pVP                  V 3R l4       V# )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  5IMAP4ServerTests.testNonExistentDelete.<locals>.login\	  r   r6   c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  6IMAP4ServerTests.testNonExistentDelete.<locals>.delete_	  r  r6   c                   < V Sn         R # r/   r#   r  s   &r3   deleteFailed<IMAP4ServerTests.testNonExistentDelete.<locals>.deleteFailedb	  
    "DLr6   Nc                t   < SP                  \        SP                  P                  4      \        R 4      4      # )rl  rB   r   r#   r  r  s   &r3   r4   8IMAP4ServerTests.testNonExistentDelete.<locals>.<lambda>l	  s'    d&&s4<<+=+='>DV@WXr6   )r#   r  r   r7   r  r  r  r  r"   r   r  )rE   r  r  r  r  r  r   s   f      r3   testNonExistentDelete&IMAP4ServerTests.testNonExistentDelete[	  s    	D	3	# ^^''e5
uV}%00>
**DOO<]]_)	X	
 r6   c                	R  a a \        4       pR	Vn        \        P                  P	                  RV4       \        P                  P	                  R4       V 3R lpV 3R lpV 3R lpRS n        S P                  P                  \        V4      4      pVP                  \        V4      4      P                  V4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! WV.4      p\!        R4      oVP                  VV 3R l4       V# )
	\Noselectr  r  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  1IMAP4ServerTests.testIllegalDelete.<locals>.loginv	  r   r6   c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  2IMAP4ServerTests.testIllegalDelete.<locals>.deletey	  r  r6   c                   < V Sn         R # r/   r  r  s   &r3   r  8IMAP4ServerTests.testIllegalDelete.<locals>.deleteFailed|	  r  r6   Ns<   Hierarchically inferior mailboxes exist and \Noselect is setc                b   < SP                  \        SP                  P                  4      S4      # r/   r  )r  r  rE   s   &r3   r4   4IMAP4ServerTests.testIllegalDelete.<locals>.<lambda>	  s!     0 0T\\5G5G1H( Sr6   )r  )r  r  rB  rX  ra  r#   r  r   r7   r  r  r  r  r"   r   r  r   )	rE   r  r  r  r  r  r  r   r  s	   f       @r3   testIllegalDelete"IMAP4ServerTests.testIllegalDeletep	  s    O!**8Q7**;7	D	0	# ^^''e5
uV}%00>
**DOO<]]_)P
 	
STr6   c                	  a  \         P                  P                  R 4       V 3R lpV 3R lpS P                  P	                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP	                  V 3R l4       V# )oldmboxc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  *IMAP4ServerTests.testRename.<locals>.login	  r   r6   c                 <   < S P                   P                  R R4      # )s   oldmboxs   newnamer  renamerU   s   r3   r  +IMAP4ServerTests.testRename.<locals>.rename	  s    ;;%%j*==r6   c                   < SP                  \        \        P                  P                  P                  4       4      R .4      # )NEWNAME)rB   r   rB  rX  rx  r  r  s   &r3   r4   -IMAP4ServerTests.testRename.<locals>.<lambda>	  s1    d&&\,,66;;=>r6   r  rE   r  r  r  r  r   s   f     r3   
testRenameIMAP4ServerTests.testRename	  s    **95	D	> ^^''e5
ft7
**DOO<]]_)		

 r6   c                	  a  R S n         V 3R lpV 3R lpV 3R lpS P                  P                  \        V4      4      pVP	                  \        V4      S P
                  4       VP                  V4       VP	                  S P                  S P
                  4       S P                  4       p\        P                  ! WE.4      pVP                  V 3R l4       V# )Nc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  6IMAP4ServerTests.testIllegalInboxRename.<locals>.login	  r   r6   c                 <   < S P                   P                  R R4      # )r  frotzr  rU   s   r3   r  7IMAP4ServerTests.testIllegalInboxRename.<locals>.rename	  s    ;;%%gw77r6   c                   < V Sn         R # r/   r  )stuffrE   s   &r3   r  6IMAP4ServerTests.testIllegalInboxRename.<locals>.stash	  s
     DLr6   c                j   < SP                  \        SP                  \        P                  4      4      # r/   r  r  s   &r3   r4   9IMAP4ServerTests.testIllegalInboxRename.<locals>.<lambda>	  r  r6   r  )rE   r  r  r  r  r  r   s   f      r3   testIllegalInboxRename'IMAP4ServerTests.testIllegalInboxRename	  s    	D	8	! ^^''e5
ft7


5
**DOO<]]_)	P	
 r6   c                	  a  \         P                  P                  R 4       \         P                  P                  R4       V 3R lpV 3R lpS P                  P	                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP	                  S P                  4      # )z
oldmbox/m1z
oldmbox/m2c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  6IMAP4ServerTests.testHierarchicalRename.<locals>.login	  r   r6   c                 <   < S P                   P                  R R4      # )r  newnamer  rU   s   r3   r  7IMAP4ServerTests.testHierarchicalRename.<locals>.rename	  s    ;;%%i;;r6   )rB  rX  r  r  r   r7   r  r  r  r"   r   r  _cbTestHierarchicalRenamer  s   f     r3   testHierarchicalRename'IMAP4ServerTests.testHierarchicalRename	  s    &&|4&&|4	D	< ^^''e5
ft7
**DOO<]]_)}}T;;<<r6   c                	    \         P                  P                  P                  4       p. ROp\	        \        V4      4      pT P                  Y# Uu. uF  qDP                  4       NK  	  up4       R# u upi )r  N)r  z
newname/m1z
newname/m2)rB  rX  rx  r  r   r  rB   rz  )rE   r  mboxesr  r  s   &&   r3   r  *IMAP4ServerTests._cbTestHierarchicalRename	  sU    ((22779:fVn%X!>X'')X!>?!>s   A1
c                	v  a  V 3R  lpV 3R lpS P                   P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P
                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP                  V 3R l4       V# )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  -IMAP4ServerTests.testSubscribe.<locals>.login	  r   r6   c                 :   < S P                   P                  R 4      # z	this/mbox)r  	subscriberU   s   r3   r   1IMAP4ServerTests.testSubscribe.<locals>.subscribe	  s    ;;((55r6   c                Z   < SP                  \        P                  P                  R .4      # )	THIS/MBOXrB   rB  rX  subscriptionsr  s   &r3   r4   0IMAP4ServerTests.testSubscribe.<locals>.<lambda>	  #    d&&''55}r6   )	r  r   r7   r  r  r  r"   r   r  )rE   r  r   r  r  r   s   f     r3   testSubscribeIMAP4ServerTests.testSubscribe	  s    	D	6 ^^''e5
i($//:
**DOO<]]_)		

 r6   c                	  a  R R.\         P                  n        V 3R lpV 3R lpS P                  P	                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP	                  V 3R l4       V# )r#  	THAT/MBOXc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  /IMAP4ServerTests.testUnsubscribe.<locals>.login	  r   r6   c                 :   < S P                   P                  R 4      # r  )r  unsubscriberU   s   r3   r/  5IMAP4ServerTests.testUnsubscribe.<locals>.unsubscribe	  s    ;;**;77r6   c                Z   < SP                  \        P                  P                  R .4      # )r+  r$  r  s   &r3   r4   2IMAP4ServerTests.testUnsubscribe.<locals>.<lambda>	  r'  r6   )rB  rX  r%  r  r   r7   r  r  r  r"   r   r  )rE   r  r/  r  r  r   s   f     r3   testUnsubscribe IMAP4ServerTests.testUnsubscribe	  s    1<k0J-	D	8 ^^''e5
k*DOO<
**DOO<]]_)		

 r6   c                	n  a  \         P                  P                  R 4       \         P                  P                  R4       \         P                  P                  R4       V 3R lpV 3R lpRS n        S P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  VS P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! WE.4      P                  V 3R l4      # )root/subthingzroot/another-thingznon-root/subthingc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  *IMAP4ServerTests._listSetup.<locals>.login	  r   r6   c                   < V Sn         R # r/   listed)r  rE   s   &r3   r;  +IMAP4ServerTests._listSetup.<locals>.listed	  s
    !DKr6   Nc                   < SP                   # r/   r:  r  s   &r3   r4   -IMAP4ServerTests._listSetup.<locals>.<lambda>
  s	    4;;r6   )rB  rX  ra  r;  r  r   r7   r  r  r  r"   r   r  )rE   r2   r  r;  r  r  s   f&    r3   
_listSetupIMAP4ServerTests._listSetup	  s    **?;**+?@**+>?	D	" ^^''e5
a$//2
0
**DOO<]]_""B8,889NOOr6   c                    V F?  pV P                  V^,          \        R4       V P                  V^,          \        R4       KA  	  V# )z
Assert a C{LIST} response's delimiter and mailbox are native
strings.

@param results: A list of tuples as returned by
    L{IMAP4Client.list} or L{IMAP4Client.lsub}.
zdelimiter %r is not a strzmailbox %r is not a str)r  r   )rE   resultsr1   s   && r3   'assertListDelimiterAndMailboxAreStrings8IMAP4ServerTests.assertListDelimiterAndMailboxAreStrings	
  sC     F!!&)S2MN!!&)S2KL  r6   c                	`   a  V 3R  lpS P                  V4      pVP                  V 3R l4       pV# )c                 <   < S P                   P                  R R4      # root%)r  r   rU   s   r3   mailboxList.IMAP4ServerTests.testList.<locals>.mailboxList
      ;;##FC00r6   c                *  < \        \        P                  4      R R3\        \        P                  4      R R3.p\        ^4       F4  pV P	                  ^ 4      w  r4pSP                  \        V4      WE3V4       K6  	  SP                  V RV : 24       R# )rs  ROOT/SUBTHINGzROOT/ANOTHER-THINGzMore results than expected: N)r  r  r  rr   popr9  r  )r;  expectedContentsr  r  	delimitermailboxrE   s   &     r3   assertListContents5IMAP4ServerTests.testList.<locals>.assertListContents
  s     ++,c?C++,c3GH 
 1X,2JJqM)'E]I7$  V'CF:%NOr6   )r?  r   )rE   rJ  r   rS  s   f   r3   testListIMAP4ServerTests.testList
  s7    	1 OOK(	
	P 
	P r6   c                	  a  \         P                  P                  R 4       V 3R lpS P                  V4      pVP	                  S P
                  4       VP	                  S P                  \        P                  RR 3.4       V# )rN  c                 <   < S P                   P                  R R4      # rG  )r  lsubrU   s   r3   rY  'IMAP4ServerTests.testLSub.<locals>.lsub1
  rL  r6   rs  )	rB  rX  r   r?  r   rC  rB   r  r  )rE   rY  r   s   f  r3   testLSubIMAP4ServerTests.testLSub.
  sg    ))/:	1 OOD!	dBBC	d&&-*=*=sO)T(UVr6   c                	  a  \         P                  P                  R 4       V 3R lpV 3R lpV 3R lpRS n        S P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  VS P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! WE.4      pVP                  V 3R l4       V# )r6  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  *IMAP4ServerTests.testStatus.<locals>.login<
  r   r6   c                 @   < S P                   P                  R RRR4      # )r6  r  r  r  r  statusrU   s   r3   rb  +IMAP4ServerTests.testStatus.<locals>.status?
  s    ;;%%oz9hWWr6   c                   < V Sn         R # r/   statusedr  s   &r3   rf  -IMAP4ServerTests.testStatus.<locals>.statusedB
  
    "DMr6   Nc           	     H   < SP                  SP                  R ^	RRR^/4      # )r  r  s   10r  )rB   rf  r  s   &r3   r4   -IMAP4ServerTests.testStatus.<locals>.<lambda>M
  s&    d&&
Ay%1Mr6   )rB  rX  ra  rf  r  r   r7   r  r  r  r"   r   r  )rE   r  rb  rf  r  r  r   s   f      r3   
testStatusIMAP4ServerTests.testStatus9
  s    **?;	D	X	# ^^''e5
ft7
$//2
**DOO<]]_)		

 r6   c                	  a  V 3R  lpV 3R lpV 3R lpV 3R lpR;S n         S n        S P                  P                  \	        V4      4      pVP                  \	        V4      S P                  4       VP                  W44       VP                  S P                  S P                  4       S P                  4       p\        P                  ! WV.4      P                  S P                  4      # )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  0IMAP4ServerTests.testFailedStatus.<locals>.loginT
  r   r6   c                 @   < S P                   P                  R RRR4      # )zroot/nonexistentr  r  r  ra  rU   s   r3   rb  1IMAP4ServerTests.testFailedStatus.<locals>.statusW
  s#    ;;%%"J	8 r6   c                   < V Sn         R # r/   re  r  s   &r3   rf  3IMAP4ServerTests.testFailedStatus.<locals>.statused\
  rh  r6   c                   < V Sn         R # r/   r  r  s   &r3   failed1IMAP4ServerTests.testFailedStatus.<locals>.failed_
  r  r6   N)rf  r#   r  r   r7   r  r  r  r"   r   r  _cbTestFailedStatus)rE   r  rb  rf  ru  r  r  s   f      r3   testFailedStatus!IMAP4ServerTests.testFailedStatusS
  s    	D	
	#	# (,+^^''e5
ft7
)
**DOO<]]_""B8,889Q9QRRr6   c                	    V P                  V P                  R 4       V P                  V P                  P                  P                  R4       R # )N)s   Could not open mailbox)rB   rf  r#   r  rO  r  s   &&r3   rw  $IMAP4ServerTests._cbTestFailedStatusj
  s7    -++002NOr6   c                	  a a \         P                  ! \        R 4      o\        P                  P                  R4       V 3R lp\        P                  VV 3R l4       pS P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP                  S P                   S4      # )rfc822.messager6  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  .IMAP4ServerTests.testFullAppend.<locals>.loginr
  r   r6   c               3     <"   \        SR 4      ;_uu_ 4       p SP                  P                  RV RR4      x pVuuRRR4       #   + '       g   i     R# ; i5i)rbr6  z%Tue, 17 Jun 2003 11:22:16 -0600 (MDT)N)\SEEN\DELETED)openr  r   r  r1   infilerE   s     r3   r   /IMAP4ServerTests.testFullAppend.<locals>.appendu
  sM     fd##w#{{11#+;	    $###s   A"AAA		A)r%   sibpath__file__rB  rX  ra  r   inlineCallbacksr  r   r7   r  r  r  r"   r  _cbTestFullAppendrE   r  r   r  r  r   r  s   f     @r3   testFullAppendIMAP4ServerTests.testFullAppendn
  s    h(89**?;	D 
			 
	 ^^''e5
ft7
**DOO<]]_)}}T33V<<r6   c                	   \         P                  P                  R ,          pV P                  ^\	        VP
                  4      4       V P                  RR.R^ 3VP
                  ^ ,          R,          4       \        VR4      ;_uu_ 4       pV P                  VP                  4       VP
                  ^ ,          ^ ,          P                  4       4       RRR4       R#   + '       g   i     R# ; i)rN  r  r  s%   Tue, 17 Jun 2003 11:22:16 -0600 (MDT)r   NNr  N	rB  rX  rx  rB   r   rj  r  r[   rb   rE   r  r  mbr2   s   &&&  r3   r  "IMAP4ServerTests._cbTestFullAppend
  s    $$..?C,-$&NPQRKKN2	
 &$1QVVXr{{1~a'8'A'A'CD  s   
ACC,	c                	  a a \         P                  ! \        R 4      o\        P                  P                  R4       V 3R lp\        P                  VV 3R l4       pS P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! W4.4      pVP                  S P                   S4      # )r}  PARTIAL/SUBTHINGc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  1IMAP4ServerTests.testPartialAppend.<locals>.login
  r   r6   c               3  d  <"   \        SR 4      ;_uu_ 4       p SP                  P                  \        P                  ! R\        R\        P                  P                  S4      3,          4      RSP                  P                  V 4      4      x pVuuRRR4       #   + '       g   i     R# ; i5i)r  s   APPENDz)PARTIAL/SUBTHING (\SEEN) "Right now" {%d}Nr0   )
r  r  sendCommandr   r_  r(   ospathgetsize_IMAP4Client__cbContinueAppendr  s     r3   r   2IMAP4ServerTests.testPartialAppend.<locals>.append
  s     fd##w#{{66MM!
 &#&(ggoof&=%?@
 BB  " % $###s   B0A9BB0B-	'	B0)r%   r  r  rB  rX  ra  r   r  r  r   r7   r  r  r  r"   r  _cbTestPartialAppendr  s   f     @r3   testPartialAppend"IMAP4ServerTests.testPartialAppend
  s    h(89**+=>	D 
			 
	* ^^''e5
ft7
**DOO<]]_)}}T66??r6   c                	   \         P                  P                  R ,          pV P                  ^\	        VP
                  4      4       V P                  R.R^ 3VP
                  ^ ,          R,          4       \        VR4      ;_uu_ 4       pV P                  VP                  4       VP
                  ^ ,          ^ ,          P                  4       4       RRR4       R#   + '       g   i     R# ; i)r  r  s	   Right nowr  r  Nr  r  s   &&&  r3   r  %IMAP4ServerTests._cbTestPartialAppend
  s    $$../ABC,-8*lA6Ar8JK&$1QVVXr{{1~a'8'A'A'CD  s   	ACC+	c                	  a  \         P                  P                  R 4       V 3R lpV 3R lpV 3R lpS P                  P	                  \        V4      4      pVP                  \        V4      S P                  4       VP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       # )   root/subthingc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  *IMAP4ServerTests._testCheck.<locals>.login
  r   r6   c                 :   < S P                   P                  R 4      # )r  ri  rU   s   r3   r<  +IMAP4ServerTests._testCheck.<locals>.select
  s    ;;%%&677r6   c                 8   < S P                   P                  4       # r/   )r  r  rU   s   r3   r  *IMAP4ServerTests._testCheck.<locals>.check
      ;;$$&&r6   )
rB  rX  ra  r  r   r7   r  r  r  r"   )rE   r  r<  r  r   s   f    r3   
_testCheckIMAP4ServerTests._testCheck
  s    **+;<	D	8	' NN&&uU|4	uV}doo6	uU|T__5	t))4??;}}r6   c                "    V P                  4       # )zN
Trigger the L{imap.IMAP4Server._cbSelectWork} callback
by selecting an mbox.
)r  rU   s   &r3   
test_checkIMAP4ServerTests.test_check
  s    
   r6   c                   a  RR lpV 3R lpS P                  \        RV4       S P                  4       pVP                  V4      # )zZ
Trigger the L{imap.IMAP4Server._ebSelectWork} errback
by failing when we select an mbox.
c                .    \         P                  ! R 4      h)encoding)r   IllegalMailboxEncoding)rE   r6  r  s   &&&r3   
failSelect3IMAP4ServerTests.test_checkFail.<locals>.failSelect
  s    ..z::r6   c                   < SP                  4       pSP                  V^,          P                  P                  ^ ,          R4       R# )r   s   SELECT failed: Server errorN)r#  rB   r  rO  )r  failuresrE   s   & r3   checkResponse6IMAP4ServerTests.test_checkFail.<locals>.checkResponse
  s7    --/HXa[..33A68VWr6   r<  r  )patchr?  r  r   )rE   r  r  r   s   f   r3   test_checkFailIMAP4ServerTests.test_checkFail
  s;    	;	X 	

7Hj1OO}}]++r6   c                	8  a  \        4       p. ROVn        \        P                  P	                  RV4       V 3R lpV 3R lpV 3R lpS P
                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! WV.4      P                  S P                  V4      # )	   Message 1rR  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  )IMAP4ServerTests.testClose.<locals>.login
  r   r6   c                 :   < S P                   P                  R 4      # )s   mailboxri  rU   s   r3   r<  *IMAP4ServerTests.testClose.<locals>.select
      ;;%%j11r6   c                 8   < S P                   P                  4       # r/   )r  r  rU   s   r3   r  )IMAP4ServerTests.testClose.<locals>.close
  r  r6   )r  )r  AnotherFlagNr  s	   Message 2)r  Nr   )s	   Message 3r  Nr   )r  rj  rB  rX  ra  r  r   r7   r  r  r  r"   r   r  _cbTestClose)rE   r  r  r<  r  r   r  s   f      r3   	testCloseIMAP4ServerTests.testClose
  s    O


 	**9a8	D	2	' NN&&uU|4	uV}doo6	uU|T__5	t))4??;]]_""A7+778I8I1MMr6   c                	    V P                  \        VP                  4      ^4       V P                  VP                  ^ ,          R4       V P                  VP                  4       R# r   Nr  )rB   r   rj  r  r  rE   r  r  s   &&&r3   r  IMAP4ServerTests._cbTestClose  sC    QZZ!,A(QR!r6   c                	  a  \        4       p. ROVn        \        P                  P	                  RV4       V 3R lpV 3R lpV 3R lpV 3R lpRS n        S P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  \        V4      S P                  4       VP                  VS P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! Wg.4      pVP                  S P                  V4      # )r  NrR  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  +IMAP4ServerTests.testExpunge.<locals>.login  r   r6   c                 :   < S P                   P                  R 4      # )rR  ri  rU   s   r3   r<  ,IMAP4ServerTests.testExpunge.<locals>.select  s    ;;%%i00r6   c                 8   < S P                   P                  4       # r/   )r  r  rU   s   r3   r  -IMAP4ServerTests.testExpunge.<locals>.expunge  s    ;;&&((r6   c                d   < SP                  SP                  P                  R J 4       V Sn        R # r/   )r  r~  r  rB  )rB  rE   s   &r3   expunged.IMAP4ServerTests.testExpunge.<locals>.expunged  s'    T[[--56"DLr6   r  )r  rj  rB  rX  ra  rB  r  r   r7   r  r  r  r"   r   r  _cbTestExpunge)	rE   r  r  r<  r  r  r  r  r   s	   f        r3   testExpungeIMAP4ServerTests.testExpunge  s    O


 	**9a8	D	1	)	# ^^''e5
ft7
g8
$//2
**DOO<]]_)}}T00!44r6   c                	    V P                  \        VP                  4      ^4       V P                  VP                  ^ ,          R4       V P                  V P                  ^ ^.4       R# r  )rB   r   rj  rB  r  s   &&&r3   r  IMAP4ServerTests._cbTestExpunge&  sK    QZZ!,A(QR1v.r6   )r  r#   r;  r  r:  r  r1   rB  r\  r  rf  N)8rx   ry   rz   r{   r  r  r  r  r  r  r  r  r  r  r'  r0  r/  rI  rT  rc  rr  rb  r  r  r  r  r  r  r  r  r  r   r  r  r  r(  r3  r?  rC  rU  r[  rk  rx  rw  r  r  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r    s   IG.LM04666 6,!6F
@4<6M,"4
#2J
@2=&%N.*6*.="@&*P&0	4S.P=6E"@HE$!,"N2"
5@/r6   r  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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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,R+# ),IMAP4ServerParsingTestsi-  z.
Test L{imap4.IMAP4Server}'s command parsing.
c                	    \        4       V n        \        P                  ! 4       V n        V P                  P                  V P                  4       V P                  P                  4        R # r/   )r   rj  r   rH  r~  makeConnectionclearrU   s   &r3   r  IMAP4ServerParsingTests.setUp2  sB    (*'')""4>>2r6   c                	    V P                   P                  \        P                  ! \        P
                  ! 4       4      4       R # r/   r~  connectionLostr#   r  r   ConnectionDonerU   s   &r3   r   IMAP4ServerParsingTests.tearDown8  &    ""7??53G3G3I#JKr6   c                   a  ! R R\         4      oV3R lpRV P                  n        WP                  n        V P                  P	                  R4       V P                  V P                  S4      4       R# )z?
L{imap4.IMAP4Server} logs exceptions raised by parse methods.
c                      ] tR tRtRtRtR# )SIMAP4ServerParsingTests.test_parseMethodExceptionLogged.<locals>.UnhandledExceptioni@  
An unhandled exception.
r0   Nr@  r0   r6   r3   UnhandledExceptionr  @  r  r6   r  c                   < Shr/   r0   )rV  r  s   &r3   raisesValueErrorQIMAP4ServerParsingTests.test_parseMethodExceptionLogged.<locals>.raisesValueErrorE  s	    $$r6   command   invalidN)r  r~  
parseStateparse_commandrT  r  r#  )rE   r  r  s   & @r3   test_parseMethodExceptionLogged7IMAP4ServerParsingTests.test_parseMethodExceptionLogged;  sV    
	 	
	% "+$4!  ,../ABCr6   c                   V P                   P                  R4       V P                  V P                  P	                  4       R4       V P                   P                  \        P                  ! \        P                  ! R4      4      4       R# )zj
L{imap4.IMAP4Server.parse_command} sends a C{BAD} response to
a line that includes a tag but no command.
   001s   001 BAD Missing command
DoneN)
r~  r  rB   rj  r  r  r#   r  r   r  rU   s   &r3   test_missingCommand+IMAP4ServerParsingTests.test_missingCommandO  s]    
 	!!&)--/1OP""OOE0089	
r6   c                    V P                   P                  R4       V P                  V P                  P	                  4       R4       R# )zN
L{imap4.IMAP4Server.parse_command} sends a C{BAD} response to
an empty line.
r6   s   * BAD Null command
N)r~  r  rB   rj  r  rU   s   &r3   test_emptyLine&IMAP4ServerParsingTests.test_emptyLine\  s4    
 	!!#&--/1JKr6   c                   a V3R lpW@P                   n        V P                   P                  RP                  VR.4      4       V P	                  V P
                  P                  4       RP                  W#.4      4       R# )a  
Assert that the given exception results in the expected
response.

@param exception: The exception to raise.
@type exception: L{Exception}

@param tag: The IMAP tag.

@type: L{bytes}

@param expectedResponse: The expected bad response.
@type expectedResponse: L{bytes}
c                   < Shr/   r0   )tagcmdrest	exceptions   &&&r3   raisesDIMAP4ServerParsingTests.assertParseExceptionResponse.<locals>.raisesu      Or6   r  r  N)r~  dispatchCommandr  r   rB   rj  r  rE   r	  r  expectedResponser
  s   &f&& r3   assertParseExceptionResponse4IMAP4ServerParsingTests.assertParseExceptionResponsee  s]     	 '-#!!$))S*,=">?--/C;R1STr6   c                T    V P                  \        P                  ! R4      RR4       R# )z\
When a parsing method raises L{IllegalClientResponse}, the
server sends a C{BAD} response.
client responser  %   BAD Illegal syntax: client response
N)r  r   IllegalClientResponserU   s   &r3   'test_parsingRaisesIllegalClientResponse?IMAP4ServerParsingTests.test_parsingRaisesIllegalClientResponse~  s'    
 	))''(9:6	
r6   c                T    V P                  \        P                  ! R4      RR4       R# )zV
When a parsing method raises L{IllegalOperation}, the server
sends a C{NO} response.
	operationr  !   NO Illegal operation: operation
N)r  r   IllegalOperationrU   s   &r3   *test_parsingRaisesIllegalOperationResponseBIMAP4ServerParsingTests.test_parsingRaisesIllegalOperationResponse  s&    
 	))"";/2	
r6   c                T    V P                  \        P                  ! R4      RR4       R# )z\
When a parsing method raises L{IllegalMailboxEncoding}, the
server sends a C{NO} response.
r  r  #   NO Illegal mailbox name: encoding
N)r  r   r  rU   s   &r3   (test_parsingRaisesIllegalMailboxEncoding@IMAP4ServerParsingTests.test_parsingRaisesIllegalMailboxEncoding  s&    
 	))((44	
r6   c                    V P                   P                  R4       V P                  V P                  P	                  4       R4       R# )zQ
L{imap4.IMAP4Server} responds to an unsupported command with a
C{BAD} response.
s   001 HULLABALOOs   001 BAD Unsupported command
N)r~  rT  rB   rj  r  rU   s   &r3   test_unsupportedCommand/IMAP4ServerParsingTests.test_unsupportedCommand  s5    
 	  !23--/1STr6   c                    V P                   P                  R4       V P                  V P                  P	                  4       R\        R4      P                  R4      ,           R,           4       R# )zf
L{imap4.IMAP4Server} responds with a C{BAD} response to a
command with more arguments than expected.
s   001 LOGIN A B C   Czutf-8r  Ns8   001 BAD Illegal syntax: Too many arguments for command: )r~  rT  rB   rj  r  r   rC   rU   s   &r3   test_tooManyArgumentsForCommand7IMAP4ServerParsingTests.test_tooManyArgumentsForCommand  s[    
 	  !34NN  "7t*##G,- 	
r6   c                v  a V3R lpV P                  V P                  P                  R4       V3V P                  P                  R,          ,           V P                  n        V P                  P	                  VRR4       V P                  V P
                  P                  4       RP                  W#.4      4       R# )a
  
Assert that the given exception results in the expected
response.

@param exception: The exception to raise.
@type exception: L{Exception}

@param: The IMAP tag.

@type: L{bytes}

@param expectedResponse: The expected bad response.
@type expectedResponse: L{bytes}
c                   < Shr/   r0   )serverInstancer  r  r  r	  s   &&&&r3   r
  FIMAP4ServerParsingTests.assertCommandExceptionResponse.<locals>.raises  r  r6   r  r     LOGINs   user passwdr  N)rB   r~  r  unauth_LOGINr  rj  r  r   r  s   &f&& r3   assertCommandExceptionResponse6IMAP4ServerParsingTests.assertCommandExceptionResponse  s     	 	**H5$*9t{{/G/G/K#K ##C>B--/C;R1STr6   c                T    V P                  \        P                  ! R4      RR4       R# )zU
When a command raises L{IllegalClientResponse}, the
server sends a C{BAD} response.
r  r  r  N)r/  r   r  rU   s   &r3   'test_commandRaisesIllegalClientResponse?IMAP4ServerParsingTests.test_commandRaisesIllegalClientResponse  s'    
 	++''(9:6	
r6   c                T    V P                  \        P                  ! R4      RR4       R# )zO
When a command raises L{IllegalOperation}, the server sends a
C{NO} response.
r  r  r  N)r/  r   r  rU   s   &r3   *test_commandRaisesIllegalOperationResponseBIMAP4ServerParsingTests.test_commandRaisesIllegalOperationResponse  s&    
 	++"";/2	
r6   c                T    V P                  \        P                  ! R4      RR4       R# )zU
When a command raises L{IllegalMailboxEncoding}, the server
sends a C{NO} response.
r  r  r  N)r/  r   r  rU   s   &r3   (test_commandRaisesIllegalMailboxEncoding@IMAP4ServerParsingTests.test_commandRaisesIllegalMailboxEncoding  s&    
 	++((44	
r6   c                     ! R R\         4      pV P                  V! R4      RR4       V P                  V P                  V4      4       R# )zj
Wehn a command raises an unhandled exception, the server sends
a C{BAD} response and logs the exception.
c                      ] tR tRtRtRtR# )XIMAP4ServerParsingTests.test_commandRaisesUnhandledException.<locals>.UnhandledExceptioni  r  r0   Nr@  r0   r6   r3   r  r<    r  r6   r  	unhandledr  s   BAD Server error: unhandled
N)r  r/  r  r#  )rE   r  s   & r3   $test_commandRaisesUnhandledException<IMAP4ServerParsingTests.test_commandRaisesUnhandledException  sF    	 	
 	++{+.	
 	../ABCr6   c                    ^V P                   n        V P                   P                  R4       V P                  V P                  P                  4       R4       R# )z`
A string literal whose length exceeds the maximum allowed
length results in a C{BAD} response.
s   001 LOGIN {5}
sE   001 BAD Illegal syntax: Literal too long! I accept at most 4 octets
N)r~  _literalStringLimitrT  rB   rj  r  rU   s   &r3   test_stringLiteralTooLong1IMAP4ServerParsingTests.test_stringLiteralTooLong  sF    
 +,'  !56NN  ".	
r6   c                    R F8  pV P                  \        P                  V P                  P                  V4       K:  	  R# )zA
An empty string argument raises L{imap4.IllegalClientResponse}.
N)r6   r  r  r   r   r  r~  arg_astring)rE   r  s   & r3   test_arg_astringEmptyLine1IMAP4ServerParsingTests.test_arg_astringEmptyLine  s3     *E++T[[-D-De *r6   c                p    V P                  \        P                  V P                  P                  R4       R# )zP
An unmatched quote in a string argument raises
L{imap4.IllegalClientResponse}.
s   "openNrE  rU   s   &r3   test_arg_astringUnmatchedQuotes7IMAP4ServerParsingTests.test_arg_astringUnmatchedQuotes  s)    
 	'')@)@(	
r6   c                p    V P                  \        P                  V P                  P                  R4       R# )zV
An unmatched brace in a string literal's size raises
L{imap4.IllegalClientResponse}.
s   {0NrE  rU   s   &r3   &test_arg_astringUnmatchedLiteralBraces>IMAP4ServerParsingTests.test_arg_astringUnmatchedLiteralBraces&  s'    
 	%55t{{7N7NPUVr6   c                p    V P                  \        P                  V P                  P                  R4       R# )zK
A non-integral string literal size raises
L{imap4.IllegalClientResponse}.
   {[object Object]}NrE  rU   s   &r3   "test_arg_astringInvalidLiteralSize:IMAP4ServerParsingTests.test_arg_astringInvalidLiteralSize-  *    
 	'')@)@BV	
r6   c                p    V P                  \        P                  V P                  P                  R4       R# )z0
An empty atom raises L{IllegalClientResponse}.
r6   Nr   r   r  r~  arg_atomrU   s   &r3   test_arg_atomEmptyLine.IMAP4ServerParsingTests.test_arg_atomEmptyLine6  s&     	%55t{{7K7KSQr6   c                p    V P                  \        P                  V P                  P                  R4       R# )z3
A malformed atom raises L{IllegalClientResponse}.
s    not an atom NrU  rU   s   &r3   test_arg_atomMalformedAtom2IMAP4ServerParsingTests.test_arg_atomMalformedAtom<  s*     	'')=)=?O	
r6   c                p    V P                  \        P                  V P                  P                  R4       R# )z>
An empty parenthesized list raises L{IllegalClientResponse}.
r6   Nr   r   r  r~  	arg_plistrU   s   &r3   test_arg_plistEmptyLine/IMAP4ServerParsingTests.test_arg_plistEmptyLineD  s&     	%55t{{7L7LcRr6   c                    V P                  \        P                  V P                  P                  R4       V P                  \        P                  V P                  P                  R4       R# )zM
A parenthesized with unmatched parentheses raises
L{IllegalClientResponse}.
s   (foos   foo)Nr]  rU   s   &r3   "test_arg_plistUnmatchedParentheses:IMAP4ServerParsingTests.test_arg_plistUnmatchedParenthesesJ  sH    
 	%55t{{7L7LgV%55t{{7L7LgVr6   c                p    V P                  \        P                  V P                  P                  R4       R# )z8
An empty file literal raises L{IllegalClientResponse}.
r6   Nr   r   r  r~  arg_literalrU   s   &r3   test_arg_literalEmptyLine1IMAP4ServerParsingTests.test_arg_literalEmptyLineR  s'     	%55t{{7N7NPSTr6   c                    V P                  \        P                  V P                  P                  R4       V P                  \        P                  V P                  P                  R4       R# )zB
A literal with unmatched braces raises
L{IllegalClientResponse}.
s   {10s   10}Nre  rU   s   &r3   test_arg_literalUnmatchedBraces7IMAP4ServerParsingTests.test_arg_literalUnmatchedBracesX  sJ    
 	%55t{{7N7NPVW%55t{{7N7NPVWr6   c                p    V P                  \        P                  V P                  P                  R4       R# )zD
A non-integral literal size raises
L{imap4.IllegalClientResponse}.
rP  Nre  rU   s   &r3   "test_arg_literalInvalidLiteralSize:IMAP4ServerParsingTests.test_arg_literalInvalidLiteralSize`  rS  r6   c                h    RpV P                   P                  V4      w  r#V P                  VR4       R# )z8
A sequence set returns the unparsed portion of a line.
s   1:* blah blah blahs   blah blah blahN)r~  
arg_seqsetrB   )rE   sequencer  r  s   &   r3   test_arg_seqsetReturnsRest2IMAP4ServerParsingTests.test_arg_seqsetReturnsResti  s0     )++((201r6   c                p    V P                  \        P                  V P                  P                  R4       R# )z<
An invalid sequence raises L{imap4.IllegalClientResponse}.
s   x:yN)r   r   r  r~  rp  rU   s   &r3   test_arg_seqsetInvalidSequence6IMAP4ServerParsingTests.test_arg_seqsetInvalidSequenceq  s&     	%55t{{7M7MvVr6   c                    RpV P                   P                  V4      w  r#V P                  W!.4       V P                  V4       R# )z:
A single flag that is not contained in a list is parsed.
s   flagN)r~  arg_flaglistrB   r  )rE   flagr  r  s   &   r3   test_arg_flaglistOneFlag0IMAP4ServerParsingTests.test_arg_flaglistOneFlagw  s=     {{//5(r6   c                p    V P                  \        P                  V P                  P                  R4       R# )zS
A list of flags with unmatched parentheses raises
L{imap4.IllegalClientResponse}.
s   (invalidNr   r   r  r~  rx  rU   s   &r3   &test_arg_flaglistMismatchedParentehses>IMAP4ServerParsingTests.test_arg_flaglistMismatchedParentehses  s+    
 	''KK$$	
r6   c                    V P                  \        P                  V P                  P                  R4       V P                  \        P                  V P                  P                  R4       R# )zW
A list of flags that contains a malformed flag raises
L{imap4.IllegalClientResponse}.
s	   (first  )s   (first  second)Nr}  rU   s   &r3   test_arg_flaglistMalformedFlag6IMAP4ServerParsingTests.test_arg_flaglistMalformedFlag  sQ    
 	'')A)A?	
 	'')A)ACX	
r6   c                    RpV P                   P                  V4      w  r#V P                  V4       V P                  W14       R# )zw
A line that does not begin with an open parenthesis (C{(}) is
parsed as L{None}, and the remainder is the whole line.
s   not (N)r~  	opt_plistrn  rB   )rE   rV  plist	remainders   &   r3   $test_opt_plistMissingOpenParenthesis<IMAP4ServerParsingTests.test_opt_plistMissingOpenParenthesis  s<    
 ;;006% )r6   c                    RpV P                   P                  V4      w  r#V P                  V4       V P                  W14       R# )zr
A line that does not begin with a double quote (C{"}) is
parsed as L{None}, and the remainder is the whole line.
s   not "N)r~  opt_datetimern  rB   )rE   rV  dtr  s   &   r3   !test_opt_datetimeMissingOpenQuote9IMAP4ServerParsingTests.test_opt_datetimeMissingOpenQuote  s;    
 006")r6   c                t    RpV P                  \        P                  V P                  P                  V4       R# )z`
A line that does not have a closing double quote (C{"}) raises
L{imap4.IllegalClientResponse}.
s   "21-Jul-2017 19:37:07 -0700N)r   r   r  r~  r  rU  s   & r3   "test_opt_datetimeMissingCloseQuote:IMAP4ServerParsingTests.test_opt_datetimeMissingCloseQuote  s,    
 .%55t{{7O7OQUVr6   c                t    RpV P                  \        P                  V P                  P                  V4       R# )zh
A line that contains C{CHARSET} but no character set
identifier raises L{imap4.IllegalClientResponse}.
r  N)r   r   r  r~  opt_charsetrU  s   & r3   !test_opt_charsetMissingIdentifier9IMAP4ServerParsingTests.test_opt_charsetMissingIdentifier  s,    
 %55t{{7N7NPTUr6   c                    RpV P                   P                  V4      w  r#V P                  VR4       V P                  VR4       R# )zt
A line that ends with a C{CHARSET} identifier is parsed as
that identifier, and the remainder is the empty string.
s   CHARSET UTF-8   UTF-8r6   Nr~  r  rB   rE   rV  
identifierr  s   &   r3   test_opt_charsetEndOfLine1IMAP4ServerParsingTests.test_opt_charsetEndOfLine  s@    
   $ 7 7 =
X.C(r6   c                    RpV P                   P                  V4      w  r#V P                  VR4       V P                  VR4       R# )z
A line that has additional data after a C{CHARSET} identifier
is parsed as that identifier, and the remainder is that
additional data.
s   CHARSET UTF-8 remainderr  s	   remainderNr  r  s   &   r3   test_opt_charsetWithRemainder5IMAP4ServerParsingTests.test_opt_charsetWithRemainder  s@     * $ 7 7 =
X.L1r6   r~  rj  N)-rx   ry   rz   r{   rZ  r  r  r  r  r  r  r  r  r   r#  r'  r/  r2  r5  r8  r>  rB  rG  rJ  rM  rQ  rW  rZ  r_  rb  rg  rj  rm  rr  ru  rz  r~  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r  -  s    LD(
LU2	
	
	
U
 U6	
	
	
D&

W
R
SWUX
2W	


**WV)	2r6   r  c                  b    ] 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RtR# )IMAP4ServerSearchTestsi  zK
Tests for the behavior of the search_* functions in L{imap4.IMAP4Server}.
c                	    \         P                  V 4       R .V n        R.V n        R.V n        ^ V n        \        RR/. RRRR4      V n        R# )	z10-Dec-2009z13-Dec-2009z16-Dec-2009r  zMon, 13 Dec 2009 21:25:10 GMTz13 Dec 2009 00:00:00 GMTrv    N)ry  r  earlierQuerysameDateQuery
laterQueryseqr   r   rU   s   &r3   r  IMAP4ServerSearchTests.setUp  sX    t$*O+_(/45&
r6   c                .   V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       R# )zi
L{imap4.IMAP4Server.search_SENTBEFORE} returns True if the message date
is earlier than the query date.
N)r  r~  search_SENTBEFOREr  r  r   r  r  rU   s   &r3   test_searchSentBefore,IMAP4ServerSearchTests.test_searchSentBefore  sf    
 	KK))$*;*;TXXtxxP	
 	KK))$//488TXXN	
r6   c                   V P                  V P                  P                  R.V P                  V P                  R4      4       V P                  V P                  P                  R.V P                  V P                  R4      4       V P                  V P                  P                  R.V P                  V P                  R4      4       R# )zY
L{imap4.IMAP4Server.search_UID} returns True if the message UID is in
the search range.
r  s   2:*r   N)r   r  )r  r~  
search_UIDr  r   r  rU   s   &r3   test_searchWildcard*IMAP4ServerSearchTests.test_searchWildcard  s    
 	KK""F8TXXtxxK	
 	..x488YWX..vtxx9UVr6   c                    V P                  V P                  P                  R.V P                  V P                  R4      4       R# )z
L{imap4.IMAP4Server.search_UID} should return True if there is a
wildcard, because a wildcard means "highest UID in the mailbox".
s   1235:*N)r  r   )r  r~  r  r  r   rU   s   &r3   test_searchWildcardHigh.IMAP4ServerSearchTests.test_searchWildcardHigh  s2    
 	KK""I;$((IN	
r6   c                l    \         P                  ! R4      pV P                  \        V4      . RO4       R# )d
L{imap4.IMAP4Server.search_SENTON} returns True if the message date is
the same as the query date.
r  NrI  )r   r   rB   r   )rE   msgsets   & r3   test_reversedSearchTerms/IMAP4ServerSearchTests.test_reversedSearchTerms  s(    
 ""6*fy1r6   c                   V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       R# )r  N)	r  r~  search_SENTONr  r  r   r  r  r  rU   s   &r3   test_searchSentOn(IMAP4ServerSearchTests.test_searchSentOn  s    
 	KK%%d&7&7488L	
 	KK%%d&8&8$((DHHM	
 	224??DHHdhhWXr6   c                .   V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       R# )zf
L{imap4.IMAP4Server.search_SENTSINCE} returns True if the message date
is later than the query date.
N)r  r~  search_SENTSINCEr  r  r   r  r  rU   s   &r3   test_searchSentSince+IMAP4ServerSearchTests.test_searchSentSince  sf    
 	KK(():):DHHdhhO	
 	KK(($((DHHM	
r6   c                   V P                  V P                  P                  R.V P                  ,           R.,           V P                  ,           V P
                  V P                  R4      4       V P                  V P                  P                  R.V P                  ,           R.,           V P                  ,           V P
                  V P                  R4      4       V P                  V P                  P                  R.V P                  ,           R.,           V P                  ,           V P
                  V P                  R4      4       R# )z
L{imap4.IMAP4Server.search_OR} returns true if either of the two
expressions supplied to it returns true and returns false if neither
does.
	SENTSINCENSENTONr.  )r  r~  	search_ORr  r  r  r   r  rU   s   &r3   test_searchOr$IMAP4ServerSearchTests.test_searchOr'  s     	KK!! 1 11[MADOOS		
 	KK!!/;-?$BSBSS		
 	KK!!
T__,}<tN		
r6   c                R   V P                  V P                  P                  R.V P                  ,           V P                  V P
                  R4      4       V P                  V P                  P                  R.V P                  ,           V P                  V P
                  R4      4       R# )zf
L{imap4.IMAP4Server.search_NOT} returns the negation of the result
of the expression supplied to it.
r  Nr  r.  )r  r~  
search_NOTr  r  r   r  r  rU   s   &r3   test_searchNot%IMAP4ServerSearchTests.test_searchNotF  s~    
 	KK"" 1 11488TXX|	

 	KK""
T__,dhh,	
r6   c                   V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       R# )zh
L{imap4.IMAP4Server.search_BEFORE} returns True if the
internal message date is before the query date.
N)	r  r~  search_BEFOREr  r  r   r  r  r  rU   s   &r3   test_searchBefore(IMAP4ServerSearchTests.test_searchBeforeV  s    
 	KK%%d&7&7488L	
 	KK%%d&8&8$((DHHM	
 	11$//488TXXVWr6   c                   V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       R# )zi
L{imap4.IMAP4Server.search_ON} returns True if the
internal message date is the same as the query date.
N)r  r~  	search_ONr  r  r   r  r  rU   s   &r3   test_searchOn$IMAP4ServerSearchTests.test_searchOnc  s    
 	..t/@/@$((DHHUV..t/A/A488TXXVW..t$((STr6   c                   V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       V P                  V P                  P                  V P                  V P                  V P
                  4      4       R# )zm
L{imap4.IMAP4Server.search_SINCE} returns True if the
internal message date is greater than the query date.
N)	r  r~  search_SINCEr  r  r   r  r  r  rU   s   &r3   test_searchSince'IMAP4ServerSearchTests.test_searchSincel  s    
 	001B1BDHHdhhWXKK$$T%7%7488L	
 	11$//488TXXVWr6   )r  r  r   r  r  N)rx   ry   rz   r{   rZ  r  r  r  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r    sH    



W
2Y


>
 XU	Xr6   r  c                  .    ] tR tRtRtRtRR ltR tRtR# )rI  ix  z
A L{IRealm} for tests.

@cvar theAccount: An C{Account} instance.  Tests can set this to
    ensure predictable account retrieval.
Nc                J   a a S'       d   V3R lS n         R# V 3R lS n         R# )a*  
Create a realm for testing.

@param accountHolder: (optional) An object whose C{theAccount}
    attribute will be returned instead of
    L{TestRealm.theAccount}.  Attribute access occurs on every
    avatar request, so any modifications to
    C{accountHolder.theAccount} will be reflected here.
c                    < S P                   # r/   rX  rE  s   r3   r4   $TestRealm.__init__.<locals>.<lambda>  s    }'?'?r6   c                    < S P                   # r/   r  rU   s   r3   r4   r    s	    tr6   N_getAccount)rE   rF  s   ffr3   r   TestRealm.__init__  s     ?D6Dr6   c                	F    \         P                  V P                  4       R  3# )c                     R # r/   r0   r0   r6   r3   r4   )TestRealm.requestAvatar.<locals>.<lambda>  s    4r6   )r   IAccountr  )rE   avatarIdmindr   s   &&&*r3   r  TestRealm.requestAvatar  s    ~~t//1<??r6   r  r/   )	rx   ry   rz   r{   rZ  rX  r   r  r|   r0   r6   r3   rI  rI  x  s     J7@r6   rI  c                  2    ] tR tRt]]3tRR/tR tR t	Rt
R# )TestCheckeri  rC     secretc                	    VP                   V P                  9   da   \        P                  ! VP                  V P                  VP                   ,          4      P                  V P                  VP                   4      # R # r/   )usernamer.  r   maybeDeferredcheckPasswordr   _cbCheck)rE   credentialss   &&r3   requestAvatarIdTestChecker.requestAvatarId  s\    4::-&&))4::k6J6J+Kk$--)=)=>? .r6   c                	*    V'       d   V# \        4       hr/   r   )rE   r1   r  s   &&&r3   r  TestChecker._cbCheck  s    O!!r6   r0   N)rx   ry   rz   r{   r   r   credentialInterfacesr.  r  r  r|   r0   r6   r3   r  r    s"    35FG)$E?"r6   r  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R tR tR tR tR tR tR tR tR tRtR# )AuthenticatorTestsi  c                	0   \         P                  V 4       \        4       p\        R 4      Vn        \        V4      V n        V P                  P                  \        4       4       V P                  V P                  n        ^ V n
        VP                  V n        R# )rC  N)ry  r  rI  r?  rX  r   rL  rM  r  r~  authenticatedr  )rE   rQ  s   & r3   r  AuthenticatorTests.setUp  sh    t$";/Um##KM2![[''r6   c                   \        \        \        4       ! R R4      4       pV! 4       p\        \        V4       \        P
                  ! RV/4      pV P                  Vn        \        4       pVP                  V4       V P                  VP                  \        P                  ! R4      4       V P                  RVP                  4       4       VP                  4        VP!                  R4       V P                  \"        P$                  ! VP'                  4       4      VP                  4       4       VP                  4        VP!                  \"        P$                  ! R4      R,           4       V P)                  VP                  4       R	4       R
# )z
L{imap4.IMAP4Server} accepts a L{dict} mapping challenge type
names to L{twisted.mail.interfaces.IChallengeResponse}
providers.
c                  .    ] tR tRtR tR tR tR tRtR# )>AuthenticatorTests.test_customChallengers.<locals>.SPECIALAuthi  c                	    R # )   SPECIALr0   rU   s   &r3   getChallengeKAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.getChallenge      !r6   c                	D    VP                  R ^4      w  V n        V n        R # r/   )splitr  passwordrE   responses   &&r3   setResponseJAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.setResponse  s    /7~~dA/F,t}r6   c                	    R # )Fr0   rU   s   &r3   moreChallengesMAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.moreChallenges  s    r6   c                	(    V P                   V n         R # r/   )r  )rE   r  s   &&r3   r  LAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.checkPassword  s     $r6   )r  r  N)	rx   ry   rz   r{   r  r  r
  r  r|   r0   r6   r3   SPECIALAuthr    s    "G.r6   r  r  Connection done.s   AUTH=SPECIALs   001 AUTHENTICATE SPECIAL
s   username passwordr  s"   001 OK Authentication successful
N)r
   r   r   r   r   rH  rL  r   r  
addCleanupr  r   r  r9  r  r  dataReceivedbase64	b64encoder  rB   )rE   r  specialr~  rj  s   &    r3   test_customChallengers)AuthenticatorTests.test_customChallengers  s&    
'):	;	. 	. 
<	. -'1""J#<=#%	i(--u/C/CDV/WXoy'89;<f&&w';';'=>	@QRF,,-ABWLM*,STr6   c                j   \         P                  ! 4       pV P                  Vn        \        4       pVP	                  V4       V P                  VP                  \        P                  ! R4      4       VP                  4        VP                  R4       V P                  VP                  4       R4       R# )zG
An unsupported C{AUTHENTICATE} method results in a negative
response.
r  s   001 AUTHENTICATE UNKNOWN
s(   001 NO AUTHENTICATE method unsupported
N)r   rH  rL  r   r  r  r  r   r  r  r  rB   r  )rE   r~  rj  s   &  r3   test_unsupportedMethod)AuthenticatorTests.test_unsupportedMethod  s    
 ""$#%	i(--u/C/CDV/WX;<OOL	
r6   c                  a  \         P                  S P                  P                  R&   \         P                  ! R4      pS P
                  P                  V4       RS P                  n        V 3R lpS P                  P                  \        V4      4      pVP                  S P                  R4       VP                  S P                  S P                  4       \         P"                  ! VS P%                  4       .4      # )z^
An L{imap4.IMAP4Server} that is missing a L{Portal} responds
negatively to an authentication
r-  rC  Nc                 :   < S P                   P                  R 4      # r  r  authenticaterU   s   r3   r  3AuthenticatorTests.test_missingPortal.<locals>.auth      ;;++I66r6   s    Temporary authentication failure)r   LOGINCredentialsr~  r  LOGINAuthenticatorr  registerAuthenticatorrL  r  r   r7   r  r  r  r  r  r   r  r"   )rE   cAuthr  r   s   f   r3   test_missingPortal%AuthenticatorTests.test_missingPortal  s    
 -2,B,B)((5))%0!	7 NN&&uT{3	++-P	
 	
t))4??;""At}}#788r6   c                  a  \        \        4       ! R R4      4       p\        \        4       ! R R4      4       pV! 4       p\        \        V4       VS P                  P
                  R&   S P                  P                  V! 4       4       V 3R lpS P                  P                  \        V4      4      pVP                  S P                  R\        VP                  4      ,           P                  R4      4       VP!                  S P"                  S P$                  4       \&        P(                  ! VS P+                  4       .4      # )	z}
When a challenger's
L{getChallenge<IChallengeResponse.getChallenge>} method raises
any exception, a C{NO} response is sent.
c                  ,    ] tR tRtRtR tR tR tRtR# )RAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallengei  s   A challenge failurec                	,    \        V P                  4      hr/   )r#  r  rU   s   &r3   r  _AuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallenge.getChallenge  s     ..r6   c                    R# zG
Never called.

@param response: See L{IChallengeResponse.setResponse}
Nr0   r  s   &&r3   r  ^AuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallenge.setResponse      r6   c                    R# z
Never called.
Nr0   rU   s   &r3   r
  aAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallenge.moreChallenges  r/  r6   r0   N	rx   ry   rz   r{   r  r  r  r
  r|   r0   r6   r3   ValueErrorAuthChallenger)    s    ,G/r6   r4  c                  "    ] tR tRtR tR tRtR# )RAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthenticatori#  c                	    R # )   ERRORr0   rU   s   &r3   getNameZAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthenticator.getName%  s    r6   c                	    R # )s   IGNOREDr0   )rE   secretchals   &&&r3   challengeResponsedAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthenticator.challengeResponse(  r  r6   r0   N)rx   ry   rz   r{   r9  r>  r|   r0   r6   r3   ValueErrorAuthenticatorr6  #  s     "r6   r@  r8  c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  ?AuthenticatorTests.test_challengerRaisesException.<locals>.auth1  r   r6   zServer error: r  )r
   r   r    r   r~  r  r  r#  r  r   r7   r  r  r   r  rC   r  r  r  r   r  r"   )rE   r4  r@  badr  r   s   f     r3   test_challengerRaisesException1AuthenticatorTests.test_challengerRaisesException	  s	    
'	(	 	 
)	$ 
*	+	" 	" 
,	" &''-,C)))*A*CD	7 NN&&uT{3	++$;$C$C DDLLWU	
 	
t))4??;""At}}#788r6   c                *   \        \        4       ! R R4      4       pV! 4       p\        \        V4       \        P                  ! 4       pV P
                  Vn        WP                  R&   \        4       pVP                  V4       V P                  VP                  \        P                  ! R4      4       V P                  RVP                  4       4       VP                  4        VP!                  R4       V P                  \"        P$                  ! VP'                  4       4      VP                  4       4       VP                  4        VP!                  R4       V P)                  VP                  4       RP+                  R	VP,                  R
.4      4       R# )zq
A client that responds with a challenge that cannot be decoded
as Base 64 receives an L{IllegalClientResponse}.
c                  ,    ] tR tRtRtR tR tR tRtR# )EAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallengeiC  s   Malformed Response - not base64c                	    R # )s   SomeChallenger0   rU   s   &r3   r  RAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallenge.getChallengeG  s    'r6   c                    R# r-  r0   r  s   &&r3   r  QAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallenge.setResponseJ  r/  r6   c                    R# r1  r0   rU   s   &r3   r
  TAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallenge.moreChallengesQ  r/  r6   r0   Nr3  r0   r6   r3   NotBase64AuthChallengerH  C  s    8G(r6   rO  s	   NOTBASE64r  s   AUTH=NOTBASE64s   001 AUTHENTICATE NOTBASE64
s     Not base64
r6   s   001 NO Authentication failed: r  N)r
   r   r   r   rH  rL  r  r   r  r  r  r   r  r9  r  r  r  r  r  r  rB   r   r  )rE   rO  	notBase64r~  rj  s   &    r3   test_authNotBase64%AuthenticatorTests.test_authNotBase64=  s6    
'	(	 	 
)	$ +,	'3""$+A<(#%	i(--u/C/CDV/WX'):;=>f&&y'='='?@)//BST23OOHH79J9JGTU	
r6   c                L  a  \        4       p\        V4      pVS P                  n        \        P
                  ;S P                  P                  R&   p\        \        V4       \        P                  ! R4      pS P                  P                  V4       V 3R lpS P                  P                  \        V4      4      pVP                  S P                   R4       VP#                  S P$                  S P&                  4       \(        P*                  ! S P-                  4       V.4      pV# )z
A challenger that causes the login to fail
L{UnhandledCredentials} results in an C{NO} response.

@return: A L{Deferred} that fires when the authorization has
    failed.
r-  rC  c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  :AuthenticatorTests.test_unhandledCredentials.<locals>.auth  r   r6   s+   Authentication failed: server misconfigured)rI  r   r~  rL  r   r!  r  r   r   r"  r  r#  r  r   r7   r  r  r  r  r  r   r  r"   )rE   rQ  rL  	loginCredr$  r  r  r   s   f       r3   test_unhandledCredentials,AuthenticatorTests.test_unhandledCredentialsp  s      $8=8N8NN)I&	2((5))%0	7 ^^''d4
++:	
 	**DOO<" 56r6   c                  a a
  ! R R\         4      o
 ! V
3R lR4      p\        4       p\        V4      pVP                  V! 4       4       VS P                  n        \        P                  ;S P                  P                  R&   p\        \        V4       \        P                  ! R4      pS P                  P                  V4       V 3R lpV
V 3R lpS P                  P                  \!        V4      4      pVP#                  S P$                  R	4       VP                  \!        V4      4       VP'                  S P(                  S P*                  4       \,        P.                  ! S P1                  4       V.4      p	V	# )
z
If the portal raises an exception other than
L{UnauthorizedLogin} or L{UnhandledCredentials}, the server
responds with a C{BAD} response and the exception is logged.
c                      ] tR tRtRtRtR# )KAuthenticatorTests.test_unexpectedLoginFailure.<locals>.UnexpectedExceptioni  r  r0   Nr@  r0   r6   r3   r  r[    r  r6   r  c                  0   < ] tR tRtRt]]3tV 3R ltRt	R# )FAuthenticatorTests.test_unexpectedLoginFailure.<locals>.FailingCheckeri  zV
A credentials checker whose L{requestAvatarId} method
raises L{UnexpectedException}.
c                	   < S! R 4      h)zUnexpected error.r0   )rE   r  r  s   &&r3   r  VAuthenticatorTests.test_unexpectedLoginFailure.<locals>.FailingChecker.requestAvatarId  s    )*=>>r6   r0   N)
rx   ry   rz   r{   rZ  r   r   r  r  r|   )r  s   r3   FailingCheckerr]    s     
 %<=N#O ? ?r6   r`  r-  rC  c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  <AuthenticatorTests.test_unexpectedLoginFailure.<locals>.auth  r   r6   c                 H   < SP                  SP                  S 4      4       R # r/   r"  )r  rE   s   r3   assertUnexpectedExceptionLoggedWAuthenticatorTests.test_unexpectedLoginFailure.<locals>.assertUnexpectedExceptionLogged  s    OOD223FGHr6   s'   Server error: login failed unexpectedly)r  rI  r   rM  r~  rL  r   r!  r  r   r   r"  r  r#  r  r   r7   r  r  r  r  r  r   r  r"   )rE   r`  rQ  rL  rV  r$  r  rd  r  r   r  s   f         @r3   test_unexpectedLoginFailure.AuthenticatorTests.test_unexpectedLoginFailure  s   	) 	
		? 		? ~/0#8=8N8NN)I&	2((5))%0	7	I ^^''d4
++-W	
 	u<=>
**DOO<" 56r6   c                	  a  \         S P                  P                  R &   \        P                  ! R4      pS P
                  P                  V4       V 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       S P                  4       p\        P                  ! WE.4      pVP                  S P                   4      # )r  rC  c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  ,AuthenticatorTests.testCramMD5.<locals>.auth  r   r6   c                    < ^S n         R# r  r  rU   s   r3   authed.AuthenticatorTests.testCramMD5.<locals>.authed      !"Dr6   )r   r~  r  r   CramMD5ClientAuthenticatorr  r#  r  r   r7   r  r  r  r"   r   r  _cbTestCramMD5)rE   r$  r  rm  r  r  r   s   f      r3   testCramMD5AuthenticatorTests.testCramMD5  s    /A,00=))%0	7	# ^^''d4
ft7
**DOO<]]_)}}T0011r6   c                	    V P                  V P                  ^4       V P                  V P                  P                  V P                  4       R# r  rB   r  r~  r  r  s   &&r3   rq  !AuthenticatorTests._cbTestCramMD5  6    ++Q/,,dll;r6   c                	"  a  \         S P                  P                  R &   \        P                  ! R4      pS P
                  P                  V4       V 3R lpV 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      \        V4      4       VP                  S P                  S P                  4       \        P                  ! S P                  4       V.4      pVP                  S P                   4      # )r  rC  c                 :   < S P                   P                  R 4      # s   not the secretr  rU   s   r3   misauth5AuthenticatorTests.testFailedCramMD5.<locals>.misauth      ;;++,=>>r6   c                    < ^S n         R# r  rl  rU   s   r3   rm  4AuthenticatorTests.testFailedCramMD5.<locals>.authed  ro  r6   c                    < RS n         R# r   Nrl  rU   s   r3   	misauthed7AuthenticatorTests.testFailedCramMD5.<locals>.misauthed      !#Dr6   )r   r~  r  r   rp  r  r#  r  r   r7   r  r  r  r   r  r"   _cbTestFailedCramMD5rE   r$  r{  rm  r  r  r   s   f      r3   testFailedCramMD5$AuthenticatorTests.testFailedCramMD5  s    /A,00=))%0	?	#	$ ^^''g7
fuY'78
**DOO<" 56}}T6677r6   c                	    V P                  V P                  R4       V P                  V P                  P                  R4       R# r  ru  r  s   &&r3   r  'AuthenticatorTests._cbTestFailedCramMD5  2    ++R0,,d3r6   c                	P  a  \         P                  ;S P                  P                  R &   p\	        \
        V4       \         P                  ! R4      pS P                  P                  V4       V 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       \        P                   ! S P#                  4       V.4      pVP                  S P$                  4      # )r-  rC  c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  *AuthenticatorTests.testLOGIN.<locals>.auth  r   r6   c                    < ^S n         R# r  rl  rU   s   r3   rm  ,AuthenticatorTests.testLOGIN.<locals>.authed  ro  r6   )r   r!  r~  r  r   r   r"  r  r#  r  r   r7   r  r  r  r   r  r"   _cbTestLOGIN)rE   rV  r$  r  rm  r  r   s   f      r3   	testLOGINAuthenticatorTests.testLOGIN      8=8N8NN)I&	2((5))%0	7	# ^^''d4
ft7
**DOO<" 56}}T..//r6   c                	    V P                  V P                  ^4       V P                  V P                  P                  V P                  4       R# r  ru  r  s   &&r3   r  AuthenticatorTests._cbTestLOGIN  rw  r6   c                	6  a  \         P                  S P                  P                  R &   \         P                  ! R4      pS P
                  P                  V4       V 3R lpV 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      \        V4      4       VP                  S P                  S P                  4       \        P                  ! S P                  4       V.4      pVP                  S P                   4      # )r-  rC  c                 :   < S P                   P                  R 4      # rz  r  rU   s   r3   r{  3AuthenticatorTests.testFailedLOGIN.<locals>.misauth  r}  r6   c                    < ^S n         R# r  rl  rU   s   r3   rm  2AuthenticatorTests.testFailedLOGIN.<locals>.authed  ro  r6   c                    < RS n         R# r  rl  rU   s   r3   r  5AuthenticatorTests.testFailedLOGIN.<locals>.misauthed  r  r6   )r   r!  r~  r  r"  r  r#  r  r   r7   r  r  r  r   r  r"   _cbTestFailedLOGINr  s   f      r3   testFailedLOGIN"AuthenticatorTests.testFailedLOGIN	      ,1,B,B)((5))%0	?	#	$ ^^''g7
fuY'78
**DOO<" 56}}T4455r6   c                	    V P                  V P                  R4       V P                  V P                  P                  R4       R# r  ru  r  s   &&r3   r  %AuthenticatorTests._cbTestFailedLOGIN  r  r6   c                	P  a  \         P                  ;S P                  P                  R &   p\	        \
        V4       \         P                  ! R4      pS P                  P                  V4       V 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      S P                  4       VP                  S P                  S P                  4       \        P                   ! S P#                  4       V.4      pVP                  S P$                  4      # )r  rC  c                 :   < S P                   P                  R 4      # r  r  rU   s   r3   r  *AuthenticatorTests.testPLAIN.<locals>.auth)  r   r6   c                    < ^S n         R# r  rl  rU   s   r3   rm  ,AuthenticatorTests.testPLAIN.<locals>.authed,  ro  r6   )r   PLAINCredentialsr~  r  r   r   PLAINAuthenticatorr  r#  r  r   r7   r  r  r  r   r  r"   _cbTestPLAIN)rE   	plainCredr$  r  rm  r  r   s   f      r3   	testPLAINAuthenticatorTests.testPLAIN!  r  r6   c                	    V P                  V P                  ^4       V P                  V P                  P                  V P                  4       R# r  ru  r  s   &&r3   r  AuthenticatorTests._cbTestPLAIN5  rw  r6   c                	6  a  \         P                  S P                  P                  R &   \         P                  ! R4      pS P
                  P                  V4       V 3R lpV 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      \        V4      4       VP                  S P                  S P                  4       \        P                  ! S P                  4       V.4      pVP                  S P                   4      # )r  rC  c                 :   < S P                   P                  R 4      # rz  r  rU   s   r3   r{  3AuthenticatorTests.testFailedPLAIN.<locals>.misauth>  r}  r6   c                    < ^S n         R# r  rl  rU   s   r3   rm  2AuthenticatorTests.testFailedPLAIN.<locals>.authedA  ro  r6   c                    < RS n         R# r  rl  rU   s   r3   r  5AuthenticatorTests.testFailedPLAIN.<locals>.misauthedD  r  r6   )r   r  r~  r  r  r  r#  r  r   r7   r  r  r  r   r  r"   _cbTestFailedPLAINr  s   f      r3   testFailedPLAIN"AuthenticatorTests.testFailedPLAIN9  r  r6   c                	    V P                  V P                  R4       V P                  V P                  P                  R4       R# r  ru  r  s   &&r3   r  %AuthenticatorTests._cbTestFailedPLAINM  r  r6   )r  r  rL  N)rx   ry   rz   r{   r  r  r  r%  rD  rQ  rW  rf  rr  rq  r  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r    sl    
()UV
&9.29h1
fB0d2$<8(40(<6(40(<6(4r6   r  c                  ,    ] tR tRtRtR tR tR tRtR# )SASLPLAINTestsiR  z
Tests for I{SASL PLAIN} authentication, as implemented by
L{imap4.PLAINAuthenticator} and L{imap4.PLAINCredentials}.

@see: U{http://www.faqs.org/rfcs/rfc2595.html}
@see: U{http://www.faqs.org/rfcs/rfc4616.html}
c                    RpRpRp\         P                  ! V4      pVP                  W#4      pV P                  VRV,           R,           V,           4       R# )zo
L{PLAINAuthenticator.challengeResponse} returns challenge strings of
the form::

    NUL<authn-id>NUL<secret>
rC  r  s	   challenge    N)r   r  r>  rB   )rE   r  r<  r=  r$  r  s   &     r3   #test_authenticatorChallengeResponse2SASLPLAINTests.test_authenticatorChallengeResponse[  sR     ((2**6858#3e#;f#DEr6   c                    \         P                  ! 4       pVP                  R4       V P                  VP                  R4       V P                  VP
                  R4       R# )zf
L{PLAINCredentials.setResponse} parses challenge strings of the
form::

    NUL<authn-id>NUL<secret>
s    testuser secretrC  r  N)r   r  r  rB   r  r  rE   creds   & r3   test_credentialsSetResponse*SASLPLAINTests.test_credentialsSetResponsei  sI     %%'./4	2r6   c                2   \         P                  ! 4       pV P                  \         P                  VP                  R4       V P                  \         P                  VP                  R4       V P                  \         P                  VP                  R4       R# )zv
L{PLAINCredentials.setResponse} raises L{imap4.IllegalClientResponse}
when passed a string not of the expected form.
s   hellos   hello worlds   hello world Zoom! N)r   r  r   r  r  r  s   & r3   test_credentialsInvalidResponse.SASLPLAINTests.test_credentialsInvalidResponseu  su    
 %%'%55t7G7GR'')9)9?	
 	'')9)9;S	
r6   r0   N)	rx   ry   rz   r{   rZ  r  r  r  r|   r0   r6   r3   r  r  R  s    F
3
r6   r  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R tRtR# )UnsolicitedResponseTestsi  c                	L  a  V 3R  lpV 3R lpS P                   P                  \        V4      4      pVP                  \        V4      4      P                  S P                  4       \
        P                  ! S P                  4       V.4      pVP                  S P                  4      # )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  5UnsolicitedResponseTests.testReadWrite.<locals>.login  r   r6   c                 >   < S P                   P                  ^4       R# r  r~  rh  rU   s   r3   r  8UnsolicitedResponseTests.testReadWrite.<locals>.loggedIn      KK##A&r6   )	r  r   r7   r  r  r   r  r"   _cbTestReadWriterE   r  r  r  r   s   f    r3   testReadWrite&UnsolicitedResponseTests.testReadWrite  sw    	D	' ^^''e5
uX'224??C" 56}}T2233r6   c                	\    V P                   P                  pV P                  VR ^..4       R# rg  r  r^  rB   rE   r  Es   && r3   r  )UnsolicitedResponseTests._cbTestReadWrite  )    KKmQ/01r6   c                	L  a  V 3R  lpV 3R lpS P                   P                  \        V4      4      pVP                  \        V4      4      P                  S P                  4       \
        P                  ! S P                  4       V.4      pVP                  S P                  4      # )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  4UnsolicitedResponseTests.testReadOnly.<locals>.login  r   r6   c                 >   < S P                   P                  ^ 4       R# r  r  rU   s   r3   r  7UnsolicitedResponseTests.testReadOnly.<locals>.loggedIn  r  r6   )	r  r   r7   r  r  r   r  r"   _cbTestReadOnlyr  s   f    r3   testReadOnly%UnsolicitedResponseTests.testReadOnly  sw    	D	' ^^''e5
uX'224??C" 56}}T1122r6   c                	\    V P                   P                  pV P                  VR ^ ..4       R# rg  r  r  s   && r3   r  (UnsolicitedResponseTests._cbTestReadOnly  r  r6   c                	h  a a ^RR.^. ^
R./oV 3R lpVV 3R lpS P                   P                  \        V4      4      pVP                  \        V4      4      P                  S P                  4       \
        P                  ! S P                  4       V.4      pVP                  S P                  S4      # )r   	\Answeredr  \Recentc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  6UnsolicitedResponseTests.testFlagChange.<locals>.login  r   r6   c                 >   < SP                   P                  S 4       R # r/   )r~  ro  )r  rE   s   r3   r  9UnsolicitedResponseTests.testFlagChange.<locals>.loggedIn  s    KK$$U+r6   )	r  r   r7   r  r  r   r  r"   _cbTestFlagChange)rE   r  r  r  r   r  s   f    @r3   testFlagChange'UnsolicitedResponseTests.testFlagChange  s    \;/BZLI	D	, ^^''e5
uX'224??C" 56}}T33U;;r6   c                	   V P                   P                  pVP                  4        Uu. uF  pR V^ ,          V^,          /.NK  	  ppVP                  R R7       VP                  R R7       V P	                  W54       R# u upi )ro  c                    V ^ ,          # r  r0   rt   s   &r3   r4   <UnsolicitedResponseTests._cbTestFlagChange.<locals>.<lambda>  s    QqTr6   )keyc                    V ^ ,          # r  r0   r  s   &r3   r4   r    s    !A$r6   N)r  r^  itemsr  rB   )rE   r  r  r  r  expects   &&&   r3   r  *UnsolicitedResponseTests._cbTestFlagChange  sl    KK:?++-H-Q>AaD!A$<0-H	>"'# Is   Bc                	L  a  V 3R  lpV 3R lpS P                   P                  \        V4      4      pVP                  \        V4      4      P                  S P                  4       \
        P                  ! S P                  4       V.4      pVP                  S P                  4      # )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  7UnsolicitedResponseTests.testNewMessages.<locals>.login  r   r6   c                 @   < S P                   P                  ^
R4       R# )r  Nr~  rt  rU   s   r3   r  :UnsolicitedResponseTests.testNewMessages.<locals>.loggedIn  s    KK##B-r6   )	r  r   r7   r  r  r   r  r"   _cbTestNewMessagesr  s   f    r3   testNewMessages(UnsolicitedResponseTests.testNewMessages  sw    	D	. ^^''e5
uX'224??C" 56}}T4455r6   c                	\    V P                   P                  pV P                  V. RO.4       R# )rt  N)rt  r  Nr  r  s   && r3   r  +UnsolicitedResponseTests._cbTestNewMessages  %    KK678r6   c                	L  a  V 3R  lpV 3R lpS P                   P                  \        V4      4      pVP                  \        V4      4      P                  S P                  4       \
        P                  ! S P                  4       V.4      pVP                  S P                  4      # )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  =UnsolicitedResponseTests.testNewRecentMessages.<locals>.login  r   r6   c                 @   < S P                   P                  R ^
4       R # r/   r   rU   s   r3   r  @UnsolicitedResponseTests.testNewRecentMessages.<locals>.loggedIn  s    KK##D"-r6   )	r  r   r7   r  r  r   r  r"   _cbTestNewRecentMessagesr  s   f    r3   testNewRecentMessages.UnsolicitedResponseTests.testNewRecentMessages  sw    	D	. ^^''e5
uX'224??C" 56}}T::;;r6   c                	\    V P                   P                  pV P                  V. RO.4       R# )rt  Nrt  Nr  r  r  s   && r3   r  1UnsolicitedResponseTests._cbTestNewRecentMessages  r  r6   c                	L  a  V 3R  lpV 3R lpS P                   P                  \        V4      4      pVP                  \        V4      4      P                  S P                  4       \
        P                  ! S P                  4       V.4      pVP                  S P                  4      # )c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  @UnsolicitedResponseTests.testNewMessagesAndRecent.<locals>.login  r   r6   c                 @   < S P                   P                  ^^
4       R# )   Nr   rU   s   r3   r  CUnsolicitedResponseTests.testNewMessagesAndRecent.<locals>.loggedIn  s    KK##B+r6   )	r  r   r7   r  r  r   r  r"   _cbTestNewMessagesAndRecentr  s   f    r3   testNewMessagesAndRecent1UnsolicitedResponseTests.testNewMessagesAndRecent  sw    	D	, ^^''e5
uX'224??C" 56}}T==>>r6   c                	b    V P                   P                  pV P                  V. RO. RO.4       R# )rt  N)rt  r  Nr  r  r  s   && r3   r  4UnsolicitedResponseTests._cbTestNewMessagesAndRecent  s(    KK68QRSr6   r0   N)rx   ry   rz   r{   r  r  r  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r    s?    
42
32<$
69
<9
?Tr6   r  c                  2    ] tR tRtRtR tR tR tR tRt	R# )	ClientCapabilityTestsi  zL
Tests for issuance of the CAPABILITY command and handling of its response.
c                    \        4       V n        \        P                  ! 4       V n        V P                  P                  V P                  4       V P                  P                  R4       R# )zC
Create an L{imap4.IMAP4Client} connected to a L{StringTransport}.
s   * OK [IMAP4rev1]
N)r   rj  r   r\  protocolr  r  rU   s   &r3   r  ClientCapabilityTests.setUp  sG     )*))+$$T^^4""#:;r6   c                   a  S P                   P                  RR7      pS P                   P                  R4       S P                   P                  R4       V 3R lpVP                  V4       V# )z
A capability response consisting only of atoms without C{'='} in them
should result in a dict mapping those atoms to L{None}.
FuseCaches&   * CAPABILITY IMAP4rev1 LOGINDISABLED
   0001 OK Capability completed.
c                4   < SP                  V R RRR/4       R# )r  Ns   LOGINDISABLEDr  capabilitiesrE   s   &r3   gotCapabilities?ClientCapabilityTests.test_simpleAtoms.<locals>.gotCapabilities  s    \L$@PRV+WXr6   r!  r  r  r   rE   capabilitiesResultr*  s   f  r3   test_simpleAtoms&ClientCapabilityTests.test_simpleAtoms  s_    
 "]]::E:J""#NO""#GH	Y 	&&7!!r6   c                   a  S P                   P                  RR7      pS P                   P                  R4       S P                   P                  R4       V 3R lpVP                  V4       V# )a  
A capability response consisting of atoms including C{'='} should have
those atoms split on that byte and have capabilities in the same
category aggregated into lists in the resulting dictionary.

(n.b. - I made up the word "category atom"; the protocol has no notion
of structure here, but rather allows each capability to define the
semantics of its entry in the capability response in a freeform manner.
If I had realized this earlier, the API for capabilities would look
different.  As it is, we can hope that no one defines any crazy
semantics which are incompatible with this API, or try to figure out a
better API when someone does. -exarkun)
Fr$  s.   * CAPABILITY IMAP4rev1 AUTH=LOGIN AUTH=PLAIN
r&  c                8   < SP                  V R RRRR./4       R# )r  Nr  r-  r  r  r(  s   &r3   r*  AClientCapabilityTests.test_categoryAtoms.<locals>.gotCapabilities  s$    |T7Xx<PQr6   r,  r-  s   f  r3   test_categoryAtoms(ClientCapabilityTests.test_categoryAtoms  s^     "]]::E:J""#VW""#GH	
 	&&7!!r6   c                   a  S P                   P                  RR7      pS P                   P                  R4       S P                   P                  R4       V 3R lpVP                  V4       V# )z
A capability response consisting of both simple and category atoms of
the same type should result in a list containing L{None} as well as the
values for the category.
Fr$  s0   * CAPABILITY IMAP4rev1 FOO FOO=BAR BAR=FOO BAR
r&  c           
     @   < SP                  V R RRRR.RRR./4       R# )r  N   FOOs   BARr  r(  s   &r3   r*  >ClientCapabilityTests.test_mixedAtoms.<locals>.gotCapabilities0  s,    tVdF^Vfd^Tr6   r,  r-  s   f  r3   test_mixedAtoms%ClientCapabilityTests.test_mixedAtoms"  sd     "]]::E:J 	""A	
 	""#GH	 	&&7!!r6   )r!  rj  N)
rx   ry   rz   r{   rZ  r  r/  r4  r:  r|   r0   r6   r3   r  r    s    <""4"r6   r  c                  &    ] tR tRtRtR tR tRtR# )StillSimplerClienti:  z@
An IMAP4 client which keeps track of unsolicited flag changes.
c                	R    \         P                  P                  V 4       / V n        R # r/   )r   r\  r   r  rU   s   &r3   r   StillSimplerClient.__init__?  s    ""4(
r6   c                	<    V P                   P                  V4       R # r/   )r  r  rp  s   &&r3   ro  StillSimplerClient.flagsChangedC  s    

(#r6   r  N)rx   ry   rz   r{   rZ  r   ro  r|   r0   r6   r3   r=  r=  :  s    $r6   r=  c                  L    ] 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# )HandCraftedTestsiG  c                	$  a aaaa \        4       o\        P                  ! 4       oSP                  S4       SP	                  R 4       V V3R loVV3R loVV3R lpSP                  RR4      pSP                  R4       VP                  V4       V# )   * OK [IMAP4rev1]c                r   < SP                  SP                  4       P                  4       R,          R4       R# )r   s   0003 FETCH 1 (RFC822)Nr  rB   r  r  )r  rE   rj  s   &r3   cbCheckTransport>HandCraftedTests.testTrailingLiteral.<locals>.cbCheckTransportN  s,    !,,.r2(r6   c                   < SP                  R 4      pSP                  R4       SP                  R4       VP                  S4       V# )r	  s6   * 1 FETCH (RFC822 {10}
0123456789
 RFC822.SIZE 10)
s   0003 OK FETCH
)fetchMessager  r   )r  r   r   rH  s   & r3   cbSelect6HandCraftedTests.testTrailingLiteral.<locals>.cbSelectT  sA    s#ANNO NN/0MM*+Hr6   c                n   < SP                  R 4      pSP                  R4       VP                  S4       V# r     0002 OK SELECT)r<  rT  r   )r  r   r   rL  s   & r3   cbLogin5HandCraftedTests.testTrailingLiteral.<locals>.cbLogin]  s/    !ANN,-MM(#Hr6      blah   0001 OK LOGIN
)r   r   r\  r  rT  r  r  r   )rE   rQ  r   r   rH  rL  rj  s   f  @@@@r3   testTrailingLiteral$HandCraftedTests.testTrailingLiteralH  ss    #%		#	*+			 GGGW%	+,	gr6   c                |   V P                   P                  P                  RR4       \        4       pV P                   P	                  V4       VP                  4        V P                   P                  R4       V P                  VP                  4       R4       VP                  4        V P                   P                  R4       V P                  VP                  4       R4       VP                  4        V P                   P                  R4       V P                  VP                  4       4       V P                   P                  R4       V P                  VP                  4       R	4       V P                  V P                   P                  R
4       V P                   P                  \        P                  ! R4      4       R# )zE
String literals whose data is not immediately available are
parsed.
rC  rG  s   01 LOGIN {8}
s   + Ready for 8 octets of text
s   testuser {13}
s   + Ready for 13 octets of text
s   passwords   -test
   01 OK LOGIN succeeded
r  r  N)r~  rK  rJ  r   r  r  r  rB   r  	assertNotr  r  r   r  rE   rj  s   & r3   test_fragmentedStringLiterals.HandCraftedTests.test_fragmentedStringLiteralsh  s4   
 	##K1AB#%	""9-  !45*,OP  !56*,PQ  -y()  .*,HI**F3""5#7#78J#KLr6   c                `   RR/V P                   P                  n        \        4       pV P                   P	                  V4       VP                  4        V P                   P                  R4       V P                  VP                  4       R4       VP                  4        V P                   P                  R4       V P                  VP                  4       R4       V P                  V P                   P                  R4       V P                   P                  \        P                  ! R4      4       R# )	z#
Empty string literals are parsed.
r6   s   01 LOGIN {0}
s   + Ready for 0 octets of text
s   {0}
rX  r  r  N)r~  rK  r.  r   r  r  r  rB   r  r  r  r   r  rZ  s   & r3   test_emptyStringLiteral(HandCraftedTests.test_emptyStringLiteral  s     &)#J!#%	""9-  !45*,OP  ,*,HI**F3""5#7#78J#KLr6   c                4  a aa \        4       o\        4       oSP                  S4       SP                  R4       V3R lpV3R lpV3R lpVV V3R lpV! 4       P	                  \        V4      4      P	                  \        V4      4      P	                  V4      # )a.  
If unsolicited data is received along with solicited data in the
response to a I{FETCH} command issued by L{IMAP4Client.fetchSpecific},
the unsolicited data is passed to the appropriate callback and not
included in the result with which the L{Deferred} returned by
L{IMAP4Client.fetchSpecific} fires.
rE  c                 N   < SP                  R R 4      p SP                  R4       V # rS  rT  r  r  r   r   s    r3   r  RHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.login  %    )ANN/0Hr6   c                 L   < SP                  R 4      p SP                  R4       V # rO  r<  rT  rd  s    r3   r<  SHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.select  #    !ANN,-Hr6   c                   < SP                  R RR.R7      p SP                  R4       SP                  R4       SP                  R4       SP                  R4       SP                  R4       SP                  R	4       SP                  R
4       SP                  R4       SP                  R4       SP                  R4       V # )r   HEADER.FIELDSSUBJECT
headerType
headerArgss1   * 1 FETCH (BODY[HEADER.FIELDS ("SUBJECT")] {38}
s$   Subject: Suprise for your woman...
r     )
s   * 1 FETCH (FLAGS (\Seen))
s1   * 2 FETCH (BODY[HEADER.FIELDS ("SUBJECT")] {75}
sI   Subject: What you been doing. Order your meds here . ,. handcuff madsen
   0003 OK FETCH completed
fetchSpecificr  rd  s    r3   r  RHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.fetch  s    /yk   A NNQRNNDENN7#NN8$NN<=NNQRNN^ NN7#NN8$NN9:Hr6   c           	        < SP                  SP                  4       P                  4       R	,          R4       SP                  V ^RRR..R..^RRR..R../4       SP                  SP                  ^R./4       R# )
r   ,   0003 FETCH 1:* BODY[HEADER.FIELDS (SUBJECT)]r  rl  rm  z&Subject: Suprise for your woman...

zKSubject: What you been doing. Order your meds here . ,. handcuff madsen

\SeenNr  rB   r  r  r  resr   rE   rj  s   &r3   r  QHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.test  s    !,,.r2?
 ",yk:H ",yk:m( QWWq8*o6r6   r   r=  r  rT  r   r7   rE   r  r<  r  r  r   rj  s   f    @@r3   2test_unsolicitedResponseMixedWithSolicitedResponseCHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse  sv     $%	 	#	*+	
	
	$	7: G[v'[u&[		
r6   c                X  a aa \        4       o\        P                  ! 4       oSP                  S4       SP	                  R4       V3R lpV3R lpV3R lpV V3R lpV! 4       pVP                  \        V4      4       VP                  \        V4      4       VP                  V4       V# )zN
Literals should be recognized even when they are not preceded by
whitespace.
rE  c                 N   < SP                  R R 4      p SP                  R4       V # rb  rc  r   r!  s    r3   r  FHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.login  '    w0A!!"67Hr6   c                 L   < SP                  R 4      p SP                  R4       V # )   inboxrP  rh  r  s    r3   r<  GHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.select  s%    )A!!"34Hr6   c                 v   < SP                  R RR.R7      p SP                  R4       SP                  R4       V # )r   rl  rm  rn  s8   * 1 FETCH (BODY[HEADER.FIELDS ({7}
SUBJECT)] "Hello")
rr  rs  r  s    r3   r  FHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.fetch  sJ    &&/yk ' A !!O !!"@AHr6   c                   < SP                  SP                  4       P                  4       R,          R4       SP                  V ^RRR..R../4       R# )r   rw  r  rl  rm  HelloNr  rG  )r1   rE   rj  s   &r3   r  EHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.test   sW    !,,.r2? f&DgNOPr6   r   r   r\  r  rT  r   r7   )rE   r  r<  r  r  r   r!  rj  s   f     @@r3   &test_literalWithoutPrecedingWhitespace7HandCraftedTests.test_literalWithoutPrecedingWhitespace  s    
 $%	$$&	*12	
	
		 G	eFm$	eEl#	dr6   c                ,  a aa \        4       o\        P                  ! 4       oSP                  S4       SP	                  R4       V3R lpV3R lpVV V3R lpV! 4       pVP                  \        V4      4       VP                  \        V4      4       V# )z
If the server sends a literal length which cannot be parsed as an
integer, L{IMAP4Client.lineReceived} should cause the protocol to be
disconnected by raising L{imap4.IllegalServerResponse}.
rE  c                 N   < SP                  R R 4      p SP                  R4       V # rb  rc  r  s    r3   r  <HandCraftedTests.test_nonIntegerLiteralLength.<locals>.login  r  r6   c                 L   < SP                  R 4      p SP                  R4       V # rO  rh  r  s    r3   r<  =HandCraftedTests.test_nonIntegerLiteralLength.<locals>.select   s%    (A!!"34Hr6   c                    < S P                  R RR.R7       SP                  SP                  4       P                  4       R,          R4       SP	                  \
        P                  S P                  R4       R# )r   rl  rm  rn  rw  s   * 1 FETCH {xyz}
...Nr  )rt  rB   r  r  r   r   IllegalServerResponser  )r!  rE   rj  s   r3   r  <HandCraftedTests.test_nonIntegerLiteralLength.<locals>.fetch%  so    ""/yk #  !,,.r2?
 ++%%)r6   r  )rE   r  r<  r  r   r!  rj  s   f    @@r3   test_nonIntegerLiteralLength-HandCraftedTests.test_nonIntegerLiteralLength  su     $%	$$&	*12	
	
	  G	eFm$	eEl#r6   c                0  a a \        4       p\        4       oSP                  V4       SP                  R4       V3R lpV3R lpV3R lpVV 3R lpV! 4       P	                  \        V4      4      P	                  \        V4      4      P	                  V4      # )z
Any unrequested flag information received along with other requested
information in an untagged I{FETCH} received in response to a request
issued with L{IMAP4Client.fetchSpecific} is passed to the
C{flagsChanged} callback.
rE  c                 N   < SP                  R R 4      p SP                  R4       V # rb  rc  rd  s    r3   r  LHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.loginF  rf  r6   c                 L   < SP                  R 4      p SP                  R4       V # rO  rh  rd  s    r3   r<  MHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.selectK  rj  r6   c                    < SP                  R RR.R7      p SP                  R4       SP                  R4       SP                  R4       SP                  R4       SP                  R4       SP                  R	4       SP                  R
4       V # )r   rl  rm  rn  s1   * 1 FETCH (BODY[HEADER.FIELDS ("SUBJECT")] {22}
s   Subject: subject one
s    FLAGS (\Recent))
s?   * 2 FETCH (FLAGS (\Seen) BODY[HEADER.FIELDS ("SUBJECT")] {22}
s   Subject: subject two
rq  rr  rs  rd  s    r3   r  LHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.fetchP  s    ?	{   A NNQRNN67NN45NNU NN67NN8$NN9:Hr6   c           	        < SP                  V ^RRR..R..^RRR..R../4       SP                  SP                  ^R.^R./4       R# )	r   r  rl  rm  zSubject: subject one
zSubject: subject two
r  rx  N)rB   r  )r{  r   rE   s   &r3   r  KHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.testa  sx    ",yk:6 ",yk:6( QWWq:,H:&FGr6   r}  )rE   rj  r  r<  r  r  r   s   f     @r3   ,test_flagsChangedInsideFetchSpecificResponse=HandCraftedTests.test_flagsChangedInsideFetchSpecificResponse:  sw     $%	 	#	*+	
	
	"	H0 G[v'[u&[		
r6   c                4  a aa \        4       o\        4       oSP                  S4       SP                  R4       V3R lpV3R lpV3R lpVV V3R lpV! 4       P	                  \        V4      4      P	                  \        V4      4      P	                  V4      # )z
Any unrequested flag information received along with other requested
information in an untagged I{FETCH} received in response to a request
issued with L{IMAP4Client.fetchMessage} is passed to the
C{flagsChanged} callback.
rE  c                 N   < SP                  R R 4      p SP                  R4       V # rb  rc  rd  s    r3   r  KHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.login  rf  r6   c                 L   < SP                  R 4      p SP                  R4       V # rO  rh  rd  s    r3   r<  LHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.select  rj  r6   c                   < SP                  R 4      p SP                  R4       SP                  R4       SP                  R4       SP                  R4       SP                  R4       SP                  R4       SP                  R4       V # )r   s   * 1 FETCH (RFC822 {24}
s   Subject: first subject
s    FLAGS (\Seen))
s.   * 2 FETCH (FLAGS (\Recent \Seen) RFC822 {25}
s   Subject: second subject
rq  rr  )rK  r  rd  s    r3   r  KHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.fetch  sp    u%ANN89NN89NN23NNPQNN9:NN8$NN9:Hr6   c                   < SP                  SP                  4       P                  4       R,          R4       SP                  V ^RR/^RR//4       SP                  SP                  ^R.^RR./4       R# )	r   s   0003 FETCH 1:* (RFC822)r  zSubject: first subject
zSubject: second subject
rx  r  Nr  ry  rz  s   &r3   r  JHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.test  s    !,,.r2*
 ">?"?@ QWWq8*a*h9O&PQr6   r}  r~  s   f    @@r3   +test_flagsChangedInsideFetchMessageResponse<HandCraftedTests.test_flagsChangedInsideFetchMessageResponse  sw     $%	 	#	*+	
	
			R" G[v'[u&[		
r6   c                B   \        4       p\        P                  ! 4       pW!n        VP	                  V4       VP                  R4       \        P                  ! R4      pVP                  V4       VP                  R4      pV P                  V\        P                  4       VP                  R4       V P                  \        P                  4      pV P                  \!        V4      ^4       V P                  V^ ,          P"                  P$                  ^ ,          R4       V# )z
When decoding a base64 encoded authentication message from the server,
decoding errors are logged and then the client closes the connection.
sP   * OK [CAPABILITY IMAP4rev1 IDLE NAMESPACE AUTH=CRAM-MD5] Twisted IMAP4rev1 ReadyrC  r<  s   + Something bad! and bad
s   Something bad! and bad)r   r   r\  r!  r  rT  rp  r#  r  assertFailurer   r  r  r#  r  rB   r   r  rO  )rE   rj  r!  r$  r   loggeds   &     r3   -test_authenticationChallengeDecodingException>HandCraftedTests.test_authenticationChallengeDecodingException  s    
 56	$$&%	*'	
 00=&&u-!!(+ 	1e223=> ''(C(CDVa(--a02KLr6   r0   N)rx   ry   rz   r{   rU  r[  r^  r  r  r  r  r  r  r|   r0   r6   r3   rC  rC  G  s9    @M4M&J
X,\)VC
J6
pr6   rC  c                  D    ] tR tRt$ Rt]P                  tR]R&   R t	Rt
R# )PreauthIMAP4ClientMixini  aR  
Mixin for L{SynchronousTestCase} subclasses which
provides a C{setUp} method which creates an L{IMAP4Client}
connected to a L{StringTransport} and puts it into the
I{authenticated} state.

@ivar transport: A L{StringTransport} to which C{client} is
    connected.

@ivar client: An L{IMAP4Client} which is connected to
    C{transport}.
zType[imap4.IMAP4Client]clientProtocolc                    \        4       V n        V P                  4       V n        V P                  P	                  V P                  4       V P                  P                  R4       R# )zU
Create an IMAP4Client connected to a fake transport and in the
authenticated state.
s   * PREAUTH Hello unittest
N)r   rj  r  r  r  r  rU   s   &r3   r  PreauthIMAP4ClientMixin.setUp  sG    
 )*))+""4>>2  !@Ar6   )r  rj  N)rx   ry   rz   r{   rZ  r   r\  r  r  r  r|   r0   r6   r3   r  r    s      /4.?.?N+?Br6   r  c                  z    ] 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R tR tR tR tRtR# )SelectionTestsMixini  z`
Mixin for test cases which defines tests which apply to both I{EXAMINE} and
I{SELECT} support.
c                    \        V P                  V P                  4      ! R4      pV P                  V P                  P                  4       RV P                  ,           R,           4       V# )z
Issue either an I{EXAMINE} or I{SELECT} command (depending on
C{self.method}), assert that the correct bytes are written to the
transport, and return the L{Deferred} returned by whichever method was
called.
fooboxs   0001 s	    foobox
)r  r  methodrB   rj  r  r  rE   r   s   & r3   _examineOrSelect$SelectionTestsMixin._examineOrSelect  sR     DKK-h7NN  "Ht||$;n$L	
 r6   c                    V F%  pV P                   P                  VR,           4       K'  	  V P                   P                  RV P                  ,           R,           4       R# )z
Deliver the given (unterminated) response lines to C{self.client} and
then deliver a tagged SELECT or EXAMINE completion line to finish the
SELECT or EXAMINE response.
r  s   0001 OK [READ-ONLY] s    completed
N)r  r  r  )rE   linesrV  s   &* r3   	_responseSelectionTestsMixin._response  sH     DKK$$TG^4   #dll25FF	
r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RRR^/4       R# )z
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{EXISTS} response, the L{Deferred} return by L{IMAP4Client.select} or
L{IMAP4Client.examine} fires with a C{dict} including the value
associated with the C{'EXISTS'} key.
s
   * 3 EXISTSrw  Frv  Nr  r  rB   successResultOfr  s   & r3   test_existsSelectionTestsMixin.test_exists  C     !!#}%--a0<RS2TUr6   c                    V P                  4       pV P                  R4       V P                  V\        P                  4       R# )z
If the server returns a non-integer EXISTS value in its response to a
I{SELECT} or I{EXAMINE} command, the L{Deferred} returned by
L{IMAP4Client.select} or L{IMAP4Client.examine} fails with
L{IllegalServerResponse}.
s   * foo EXISTSNr  r  failureResultOfr   r  r  s   & r3   test_nonIntegerExists)SelectionTestsMixin.test_nonIntegerExists  4     !!#'Q ; ;<r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RRR^/4       R# )z
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{RECENT} response, the L{Deferred} return by L{IMAP4Client.select} or
L{IMAP4Client.examine} fires with a C{dict} including the value
associated with the C{'RECENT'} key.
s
   * 5 RECENTrw  Fr  Nr  r  s   & r3   test_recentSelectionTestsMixin.test_recent&  r  r6   c                    V P                  4       pV P                  R4       V P                  V\        P                  4       R# )z
If the server returns a non-integer RECENT value in its response to a
I{SELECT} or I{EXAMINE} command, the L{Deferred} returned by
L{IMAP4Client.select} or L{IMAP4Client.examine} fails with
L{IllegalServerResponse}.
s   * foo RECENTNr  r  s   & r3   test_nonIntegerRecent)SelectionTestsMixin.test_nonIntegerRecent1  r  r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RRR^/4       R# )z
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{UNSEEN} response, the L{Deferred} returned by L{IMAP4Client.select} or
L{IMAP4Client.examine} fires with a C{dict} including the value
associated with the C{'UNSEEN'} key.
s)   * OK [UNSEEN 8] Message 8 is first unseenrw  Fr  Nr  r  s   & r3   test_unseenSelectionTestsMixin.test_unseen<  sD     !!#CD--a0<RS2TUr6   c                    V P                  4       pV P                  R4       V P                  V\        P                  4       R# )z
If the server returns a non-integer UNSEEN value in its response to a
I{SELECT} or I{EXAMINE} command, the L{Deferred} returned by
L{IMAP4Client.select} or L{IMAP4Client.examine} fails with
L{IllegalServerResponse}.
s-   * OK [UNSEEN foo] Message foo is first unseenNr  r  s   & r3   test_nonIntegerUnseen)SelectionTestsMixin.test_nonIntegerUnseenG  s5     !!#GHQ ; ;<r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RRRR/4       R# )a  
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{UIDVALIDITY} response, the L{Deferred} returned by
L{IMAP4Client.select} or L{IMAP4Client.examine} fires with a C{dict}
including the value associated with the C{'UIDVALIDITY'} key.
s#   * OK [UIDVALIDITY 12345] UIDs validrw  Fr  r  Nr  r  s   & r3   test_uidvalidity$SelectionTestsMixin.test_uidvalidityR  sF     !!#=>  #lE=%%P	
r6   c                    V P                  4       pV P                  R4       V P                  V\        P                  4       R# )z
If the server returns a non-integer UIDVALIDITY value in its response to
a I{SELECT} or I{EXAMINE} command, the L{Deferred} returned by
L{IMAP4Client.select} or L{IMAP4Client.examine} fails with
L{IllegalServerResponse}.
s!   * OK [UIDVALIDITY foo] UIDs validNr  r  s   & r3   test_nonIntegerUIDVALIDITY.SelectionTestsMixin.test_nonIntegerUIDVALIDITY_  s5     !!#;<Q ; ;<r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RRRR/4       R# )z
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{UIDNEXT} response, the L{Deferred} returned by L{IMAP4Client.select}
or L{IMAP4Client.examine} fires with a C{dict} including the value
associated with the C{'UIDNEXT'} key.
s&   * OK [UIDNEXT 4392] Predicted next UIDrw  Fr  i(  Nr  r  s   & r3   test_uidnext SelectionTestsMixin.test_uidnextj  sF     !!#@A  #lE9d%K	
r6   c                    V P                  4       pV P                  R4       V P                  V\        P                  4       R# )z
If the server returns a non-integer UIDNEXT value in its response to a
I{SELECT} or I{EXAMINE} command, the L{Deferred} returned by
L{IMAP4Client.select} or L{IMAP4Client.examine} fails with
L{IllegalServerResponse}.
s%   * OK [UIDNEXT foo] Predicted next UIDNr  r  s   & r3   test_nonIntegerUIDNEXT*SelectionTestsMixin.test_nonIntegerUIDNEXTw  s5     !!#?@Q ; ;<r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RRRR/4       R# )
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{FLAGS} response, the L{Deferred} returned by L{IMAP4Client.select} or
L{IMAP4Client.examine} fires with a C{dict} including the value
associated with the C{'FLAGS'} key.
s2   * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)rw  Fr  N)r  z\Flaggedr  rx  z\Draftr  r  s   & r3   
test_flagsSelectionTestsMixin.test_flags  sK     !!#QR  #eV	
r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RRRR/4       R# )r  sN   * OK [PERMANENTFLAGS (\Starred)] Just one permanent flag in that list up thererw  FPERMANENTFLAGSN)z\Starredr  r  s   & r3   test_permanentflags'SelectionTestsMixin.test_permanentflags  sN     !!#"	
 	  #5"2NC	
r6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RR/4       R# )z
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{OK} with unrecognized response code text, parsing does not fail.
s3   * OK [X-MADE-UP] I just made this response text up.rw  FNr  r  s   & r3   test_unrecognizedOk'SelectionTestsMixin.test_unrecognizedOk  sA    
 !!#MN 	--a0<2GHr6   c                    V P                  4       pV P                  R4       V P                  V P                  V4      RR/4       R# )z
If the server response to a I{SELECT} or I{EXAMINE} command includes an
I{OK} with no response code text, parsing does not fail.
s   * OKrw  FNr  r  s   & r3   test_bareOkSelectionTestsMixin.test_bareOk  s>    
 !!#w--a0<2GHr6   r0   N)rx   ry   rz   r{   rZ  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r  r    s\    


	V	=	V	=	V	=
	=
	=
"
"	IIr6   r  c                  "    ] tR tRtRtRtRtRtR# )IMAP4ClientExamineTestsi  a  
Tests for the L{IMAP4Client.examine} method.

An example of usage of the EXAMINE command from RFC 3501, section 6.3.2::

    S: * 17 EXISTS
    S: * 2 RECENT
    S: * OK [UNSEEN 8] Message 8 is first unseen
    S: * OK [UIDVALIDITY 3857529045] UIDs valid
    S: * OK [UIDNEXT 4392] Predicted next UID
    S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
    S: * OK [PERMANENTFLAGS ()] No permanent flags permitted
    S: A932 OK [READ-ONLY] EXAMINE completed
r  s   EXAMINEr0   Nrx   ry   rz   r{   rZ  r  r  r|   r0   r6   r3   r  r    s     FGr6   r  c                  "    ] tR tRtRtRtRtRtR# )IMAP4ClientSelectTestsi  a  
Tests for the L{IMAP4Client.select} method.

An example of usage of the SELECT command from RFC 3501, section 6.3.1::

    C: A142 SELECT INBOX
    S: * 172 EXISTS
    S: * 1 RECENT
    S: * OK [UNSEEN 12] Message 12 is first unseen
    S: * OK [UIDVALIDITY 3857529045] UIDs valid
    S: * OK [UIDNEXT 4392] Predicted next UID
    S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
    S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited
    S: A142 OK [READ-WRITE] SELECT completed
r<  s   SELECTr0   Nr  r0   r6   r3   r  r    s      FGr6   r  c                  2    ] tR tRtRtR tR tR tR tRt	R# )	IMAP4ClientExpungeTestsi  z
Tests for the L{IMAP4Client.expunge} method.

An example of usage of the EXPUNGE command from RFC 3501, section 6.4.3::

    C: A202 EXPUNGE
    S: * 3 EXPUNGE
    S: * 3 EXPUNGE
    S: * 5 EXPUNGE
    S: * 8 EXPUNGE
    S: A202 OK EXPUNGE completed
c                	    V P                   P                  4       pV P                  V P                  P	                  4       R 4       V P                  P                  4        V# )s   0001 EXPUNGE
)r  r  rB   rj  r  r  r  s   & r3   _expunge IMAP4ClientExpungeTests._expunge  sG    KK!--/1DEr6   c                	    V F+  pV P                   P                  \        R V R24      4       K-  	  V P                   P                  R4       R# )z* z EXPUNGEs   0001 OK EXPUNGE COMPLETEDN)r  rT  r(   )rE   sequenceNumbersnumbers   && r3   r  !IMAP4ClientExpungeTests._response  s?    %FKK$$]Rxx3H%IJ &  !=>r6   c                    V P                  4       pV P                  . RO4       V P                  V P                  V4      . RO4       R# )z
L{IMAP4Client.expunge} sends the I{EXPUNGE} command and returns a
L{Deferred} which fires with a C{list} of message sequence numbers
given by the server's response.
N)r   r   r   r   )r	  r  rB   r  r  s   & r3   test_expunge$IMAP4ClientExpungeTests.test_expunge  s6     MMO|$--a0,?r6   c                    V P                  4       pV P                  . RO4       V P                  V\        P                  4       R# )z
If the server responds with a non-integer where a message sequence
number is expected, the L{Deferred} returned by L{IMAP4Client.expunge}
fails with L{IllegalServerResponse}.
N)r   r   rv  r   )r	  r  r  r   r  r  s   & r3   test_nonIntegerExpunged/IMAP4ClientExpungeTests.test_nonIntegerExpunged  s2     MMO'(Q ; ;<r6   r0   N)
rx   ry   rz   r{   rZ  r	  r  r	  r	  r|   r0   r6   r3   r  r    s    ?
@=r6   r  c                  2    ] tR tRtRtR tR tR tR tRt	R# )	IMAP4ClientSearchTestsi  a  
Tests for the L{IMAP4Client.search} method.

An example of usage of the SEARCH command from RFC 3501, section 6.4.4::

    C: A282 SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM "Smith"
    S: * SEARCH 2 84 882
    S: A282 OK SEARCH completed
    C: A283 SEARCH TEXT "string not in mailbox"
    S: * SEARCH
    S: A283 OK SEARCH completed
    C: A284 SEARCH CHARSET UTF-8 TEXT {6}
    C: XXXXXX
    S: * SEARCH 43
    S: A284 OK SEARCH completed
c                	    V P                   P                  \        P                  ! R R7      4      pV P	                  V P
                  P                  4       R4       V# )ABCDEF)rF   s   0001 SEARCH (TEXT "ABCDEF")
)r  searchr   rW  rB   rj  r  r  s   & r3   _searchIMAP4ClientSearchTests._search"  sB    KKu{{9:--/1STr6   c                	    V P                   P                  R \        RP                  \	        \
        V4      4      4      ,           4       V P                   P                  R4       R# )s	   * SEARCH  s   0001 OK SEARCH completedN)r  rT  r(   r   mapr   )rE   messageNumberss   &&r3   r   IMAP4ClientSearchTests._response'  sF      =#c>2J)KLL	
 	  !<=r6   c                    V P                  4       pV P                  . RO4       V P                  V P                  V4      . RO4       R# )z
L{IMAP4Client.search} sends the I{SEARCH} command and returns a
L{Deferred} which fires with a C{list} of message sequence numbers
given by the server's response.
N)r   r   r  )r	  r  rB   r  r  s   & r3   test_search"IMAP4ClientSearchTests.test_search-  s6     LLNz"--a0*=r6   c                    V P                  4       pV P                  . RO4       V P                  V\        P                  4       R# )z
If the server responds with a non-integer where a message sequence
number is expected, the L{Deferred} returned by L{IMAP4Client.search}
fails with L{IllegalServerResponse}.
N)r   rv  r  )r	  r  r  r   r  r  s   & r3   test_nonIntegerFound+IMAP4ClientSearchTests.test_nonIntegerFound7  s1     LLN~&Q ; ;<r6   r0   N)
rx   ry   rz   r{   rZ  r	  r  r	  r	  r|   r0   r6   r3   r	  r	    s    "
>>=r6   r	  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R tR tR tR tR tR tR tR tRtR# )IMAP4ClientFetchTestsiB  zJ
Tests for the L{IMAP4Client.fetch} method.

See RFC 3501, section 6.4.5.
c                    V P                   P                  R4      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                   P                  R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^RR	/^RR
/^RR/^RR//4       R# )z
L{IMAP4Client.fetchUID} sends the I{FETCH UID} command and returns a
L{Deferred} which fires with a C{dict} mapping message sequence numbers
to C{dict}s mapping C{'UID'} to that message's I{UID} in the server's
response.
1:7   0001 FETCH 1:7 (UID)
   * 2 FETCH (UID 22)s   * 3 FETCH (UID 23)   * 4 FETCH (UID 24)s   * 5 FETCH (UID 25)   0001 OK FETCH completedr  22232425N)r  fetchUIDrB   rj  r  rT  r  r  s   & r3   test_fetchUID#IMAP4ClientFetchTests.test_fetchUIDI  s     KK  '--/1LM  !67  !67  !67  !67  !;<  #q5$-UDM1udmT	
r6   c                <   V P                   P                  R4      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V\        P                  4       R# )z
If the server responds with a non-integer where a message sequence
number is expected, the L{Deferred} returned by L{IMAP4Client.fetchUID}
fails with L{IllegalServerResponse}.
r	  s   0001 FETCH 1 (UID)
s   * foo FETCH (UID 22)r&	  N	r  r+	  rB   rj  r  rT  r  r   r  r  s   & r3   test_fetchUIDNonIntegerFound2IMAP4ClientFetchTests.test_fetchUIDNonIntegerFound\  sr     KK  %--/1JK  !89  !;<Q ; ;<r6   c                   V P                   P                  R4      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                   P                  R4       V P                   P                  R4       V P                  V\        P                  4       R# )z
If the server responds with an incomplete I{FETCH} response line, the
L{Deferred} returned by L{IMAP4Client.fetchUID} fails with
L{IllegalServerResponse}.
r"	  r#	  r$	  s   * 3 FETCH (UID)r%	  r&	  Nr/	  r  s   & r3   test_incompleteFetchUIDResponse5IMAP4ClientFetchTests.test_incompleteFetchUIDResponseh  s     KK  '--/1LM  !67  !34  !67  !;<Q ; ;<r6   c                F   V P                   P                  R4      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^RR//4       R# )z
L{IMAP4Client.fetchBody} sends the I{FETCH BODY} command and returns a
L{Deferred} which fires with a C{dict} mapping message sequence numbers
to C{dict}s mapping C{'RFC822.TEXT'} to that message's body as given in
the server's response.
3s   0001 FETCH 3 (RFC822.TEXT)
s&   * 3 FETCH (RFC822.TEXT "Message text")r&	  r  zMessage textN)r  	fetchBodyrB   rj  r  rT  r  r  s   & r3   test_fetchBody$IMAP4ClientFetchTests.test_fetchBodyv  s     KK!!#&--/1RS  !JK  !;<--a01}n6U2VWr6   c                J   V P                   P                  R4      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^R. R../4       R# )a  
L{IMAP4Client.fetchSpecific} sends the I{BODY[]} command if no
parameters beyond the message set to retrieve are given.  It returns a
L{Deferred} which fires with a C{dict} mapping message sequence numbers
to C{list}s of corresponding message data given by the server's
response.
7   0001 FETCH 7 BODY[]
s   * 7 FETCH (BODY[] "Some body")r&	  r  	Some bodyNr  rt  rB   rj  r  rT  r  r  s   & r3   test_fetchSpecific(IMAP4ClientFetchTests.test_fetchSpecific  s     KK%%c*--/1KL  !BC  !;<--a01K7P6Q2RSr6   c                N   V P                   P                  RRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^R. R../4       R	# )
zk
L{IMAP4Client.fetchSpecific} issues a I{BODY.PEEK[]} command if passed
C{True} for the C{peek} parameter.
6T)r  s   0001 FETCH 6 BODY.PEEK[]
s   * 6 FETCH (BODY[] "Some body")r&	  r  r=	  Nr>	  r  s   & r3   test_fetchSpecificPeek,IMAP4ClientFetchTests.test_fetchSpecificPeek  s    
 KK%%c%5--/1PQ  !BC  !;<--a01K7P6Q2RSr6   c                P   V P                   P                  RR
R7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^RR.R../4       R	# )a  
L{IMAP4Client.fetchSpecific}, when passed a sequence for
C{headerNumber}, sends the I{BODY[N.M]} command.  It returns a
L{Deferred} which fires with a C{dict} mapping message sequence numbers
to C{list}s of corresponding message data given by the server's
response.
r;	  headerNumbers   0001 FETCH 7 BODY[1.2.3]
s#   * 7 FETCH (BODY[1.2.3] "Some body")r&	  r  z1.2.3r=	  Nr   r>	  r  s   & r3   test_fetchSpecificNumbered0IMAP4ClientFetchTests.test_fetchSpecificNumbered  s     KK%%c	%B--/1PQ  !GH  !;<  #a6G9k*J)K%L	
r6   c                P   V P                   P                  RRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^RR.R../4       R	# )
a	  
L{IMAP4Client.fetchSpecific}, when passed C{'TEXT'} for C{headerType},
sends the I{BODY[TEXT]} command.  It returns a L{Deferred} which fires
with a C{dict} mapping message sequence numbers to C{list}s of
corresponding message data given by the server's response.
8TEXTro     0001 FETCH 8 BODY[TEXT]
s"   * 8 FETCH (BODY[TEXT] "Some body")r&	  r  r=	  Nr>	  r  s   & r3   test_fetchSpecificText,IMAP4ClientFetchTests.test_fetchSpecificText       KK%%cf%=--/1OP  !FG  !;<  #a6F8[*I)J%K	
r6   c                R   V P                   P                  RR^R7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^RR.R	../4       R
# )a8  
If passed a value for the C{headerNumber} parameter and C{'TEXT'} for
the C{headerType} parameter, L{IMAP4Client.fetchSpecific} sends a
I{BODY[number.TEXT]} request and returns a L{Deferred} which fires with
a C{dict} mapping message sequence numbers to C{list}s of message data
given by the server's response.
4rL	  )ro  rG	  s   0001 FETCH 4 BODY[7.TEXT]
s$   * 4 FETCH (BODY[7.TEXT] "Some body")r&	  r  z7.TEXTr=	  Nr>	  r  s   & r3   test_fetchSpecificNumberedText4IMAP4ClientFetchTests.test_fetchSpecificNumberedText  s     KK%%cf1%M--/1QR  !HI  !;<  #a6H:{*K)L%M	
r6   c                @   V P                   P                  RRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V\        P                  4       R# )z
If the server responds to a I{BODY[TEXT]} request with a I{FETCH} line
which is truncated after the I{BODY[TEXT]} tokens, the L{Deferred}
returned by L{IMAP4Client.fetchUID} fails with
L{IllegalServerResponse}.
rK	  rL	  rM	  rN	  s   * 8 FETCH (BODY[TEXT])r&	  N	r  rt  rB   rj  r  rT  r  r   r  r  s   & r3   (test_incompleteFetchSpecificTextResponse>IMAP4ClientFetchTests.test_incompleteFetchSpecificTextResponse  sw     KK%%cf%=--/1OP  !:;  !;<Q ; ;<r6   c                P   V P                   P                  RRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^RR.R../4       R	# )
a	  
L{IMAP4Client.fetchSpecific}, when passed C{'MIME'} for C{headerType},
sends the I{BODY[MIME]} command.  It returns a L{Deferred} which fires
with a C{dict} mapping message sequence numbers to C{list}s of
corresponding message data given by the server's response.
rK	  r  rM	  s   0001 FETCH 8 BODY[MIME]
s"   * 8 FETCH (BODY[MIME] "Some body")r&	  r  r=	  Nr>	  r  s   & r3   test_fetchSpecificMIME,IMAP4ClientFetchTests.test_fetchSpecificMIME  rQ	  r6   c                V   V P                   P                  RR^^R7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^	RR.RR	../4       R
# )a(  
L{IMAP4Client.fetchSpecific}, when passed C{offset} and C{length},
sends a partial content request (like I{BODY[TEXT]<offset.length>}).
It returns a L{Deferred} which fires with a C{dict} mapping message
sequence numbers to C{list}s of corresponding message data given by the
server's response.
9rL	  )ro  offsetr  s   0001 FETCH 9 BODY[TEXT]<17.3>
s    * 9 FETCH (BODY[TEXT]<17> "foo")r&	  r  z<17>rv  Nr>	  r  s   & r3   test_fetchSpecificPartial/IMAP4ClientFetchTests.test_fetchSpecificPartial  s     KK%%cfRPQ%R--/1UV  !DE  !;<  #a6F8VU*K)L%M	
r6   c                @   V P                   P                  RRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V\        P                  4       R# )z
If the server responds to a I{BODY[TEXT]} request with a I{FETCH} line
which is truncated after the I{BODY[TEXT]<offset>} tokens, the
L{Deferred} returned by L{IMAP4Client.fetchUID} fails with
L{IllegalServerResponse}.
rK	  rL	  rM	  rN	  s   * 8 FETCH (BODY[TEXT]<17>)r&	  NrW	  r  s   & r3   +test_incompleteFetchSpecificPartialResponseAIMAP4ClientFetchTests.test_incompleteFetchSpecificPartialResponse  sw     KK%%cf%=--/1OP  !>?  !;<Q ; ;<r6   c                J   V P                   P                  R4      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^R. R../4       R# )a  
If the body of a message begins with I{<} and ends with I{>} (as,
for example, HTML bodies typically will), this is still interpreted
as the body by L{IMAP4Client.fetchSpecific} (and particularly, not
as a length indicator for a response to a request for a partial
body).
r;	  r<	  s&   * 7 FETCH (BODY[] "<html>test</html>")r&	  r  z<html>test</html>Nr>	  r  s   & r3   test_fetchSpecificHTML,IMAP4ClientFetchTests.test_fetchSpecificHTML  s     KK%%c*--/1KL  !JK  !;<  #a627J*K)L%M	
r6   c                   V P                   P                  RVR7      pV P                  V P                  P	                  4       RVP                  R4      ,           R,           4       V P                   P                  RVP                  R4      ,           R,           4       V P                   P                  R4       V P                  V P                  V4      ^
R	V. .R
../4       R# )a  
Assert that the provided C{BODY} section, when invoked with no
arguments, produces an empty list, and that it returns a
L{Deferred} which fires with a C{dict} mapping message
sequence numbers to C{list}s of corresponding message data
given by the server's response.

@param section: The C{BODY} section to test: either
    C{'HEADER.FIELDS'} or C{'HEADER.FIELDS.NOT'}
@type section: L{str}
10rM	  s   0001 FETCH 10 BODY[r  s    ()]
s   * 10 FETCH (BODY[s    ()] "")r&	  r  rv  N)r  rt  rB   rj  r  rC   rT  r  )rE   sectionr   s   && r3   &assertFetchSpecificFieldsWithEmptyList<IMAP4ClientFetchTests.assertFetchSpecificFieldsWithEmptyList  s     KK%%dw%?NN  ""W^^G%<<{J	
 	   7>>'#::[H	
 	  !;<--a02'2PR8S7T2UVr6   c                (    V P                  R4       R# )aB  
L{IMAP4Client.fetchSpecific}, when passed C{'HEADER.FIELDS'}
for C{headerType} but no C{headerArgs}, sends the
I{BODY[HEADER.FIELDS]} command with no arguments.  It returns
a L{Deferred} which fires with a C{dict} mapping message
sequence numbers to C{list}s of corresponding message data
given by the server's response.
rl  Nrk	  rU   s   &r3   ,test_fetchSpecificHeaderFieldsWithoutHeadersBIMAP4ClientFetchTests.test_fetchSpecificHeaderFieldsWithoutHeaders.  s     	33ODr6   c                (    V P                  R4       R# )aJ  
L{IMAP4Client.fetchSpecific}, when passed
C{'HEADER.FIELDS.NOT'} for C{headerType} but no C{headerArgs},
sends the I{BODY[HEADER.FIELDS.NOT]} command with no
arguments.  It returns a L{Deferred} which fires with a
C{dict} mapping message sequence numbers to C{list}s of
corresponding message data given by the server's response.
zHEADER.FIELDS.NOTNrn	  rU   s   &r3   /test_fetchSpecificHeaderFieldsNotWithoutHeadersEIMAP4ClientFetchTests.test_fetchSpecificHeaderFieldsNotWithoutHeaders9  s     	334GHr6   c                P   V P                   P                  RRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V P                  V4      ^RR.R../4       R	# )
a  
L{IMAP4Client.fetchSpecific}, when passed C{'HEADER'} for
C{headerType}, sends the I{BODY[HEADER]} command.  It returns
a L{Deferred} which fires with a C{dict} mapping message
sequence numbers to C{list}s of corresponding message data
given by the server's response.
11HEADERrM	  s   0001 FETCH 11 BODY[HEADER]
sJ   * 11 FETCH (BODY[HEADER] "From: someone@localhost
Subject: Some subject")r&	  r  z.From: someone@localhost
Subject: Some subjectNr>	  r  s   & r3   test_fetchSpecificHeader.IMAP4ClientFetchTests.test_fetchSpecificHeaderD  s     KK%%dx%@--/1RS  D	
 	  !;<  #!
J	
r6   r0   N)rx   ry   rz   r{   rZ  r,	  r0	  r3	  r8	  r?	  rC	  rH	  rO	  rT	  rX	  r[	  r`	  rc	  rf	  rk	  ro	  rr	  rw	  r|   r0   r6   r3   r 	  r 	  B  sg    
&
==XT
T
 

 =

 =
 W2	E	I
r6   r 	  c                  f    ] tR tRtRt]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# )IMAP4ClientStoreTestsia  a  
Tests for the L{IMAP4Client.setFlags}, L{IMAP4Client.addFlags}, and
L{IMAP4Client.removeFlags} methods.

An example of usage of the STORE command, in terms of which these three
methods are implemented, from RFC 3501, section 6.4.6::

    C: A003 STORE 2:4 +FLAGS (\Deleted)
    S: * 2 FETCH (FLAGS (\Deleted \Seen))
    S: * 3 FETCH (FLAGS (\Deleted))
    S: * 4 FETCH (FLAGS (\Deleted \Flagged \Seen))
    S: A003 OK STORE completed
c                l   \        V P                  V4      ! RRR4      pV P                  V P                  P	                  4       RV,           R,           4       V P                  P                  R4       V P                  P                  R4       V P                  V P                  V4      ^R	RR.//4       R
# )a=  
Test a non-silent flag modifying method.  Call the method, assert that
the correct bytes are sent, deliver a I{FETCH} response, and assert
that the result of the Deferred returned by the method is correct.

@param method: The name of the method to test.
@param item: The data item which is expected to be specified.
r6	  \Readrx  F   0001 STORE 3     (\Read \Seen)
s   * 3 FETCH (FLAGS (\Read \Seen))   0001 OK STORE completedr  Nr|	  rx  r  r  rB   rj  r  rT  r  rE   r  itemr   s   &&& r3   
_flagsTest IMAP4ClientStoreTests._flagsTestr  s     DKK(.BEJNN  "$4t$;>U$U	
 	  !EF  !;<--a01w8@T6U2VWr6   c                *   \        V P                  V4      ! RRR4      pV P                  V P                  P	                  4       RV,           R,           4       V P                  P                  R4       V P                  V P                  V4      / 4       R# )a7  
Test a silent flag modifying method.  Call the method, assert that the
correct bytes are sent, deliver an I{OK} response, and assert that the
result of the Deferred returned by the method is correct.

@param method: The name of the method to test.
@param item: The data item which is expected to be specified.
r6	  Tr}	  r~	  r	  Nr	  r	  r	  s   &&& r3   _flagsSilentlyTest(IMAP4ClientStoreTests._flagsSilentlyTest  sz     DKK(.BDINN  "$4t$;>U$U	
 	  !;<--a0"5r6   c                   \        V P                  V4      ! RR
R4      pV P                  V P                  P	                  4       RV,           R,           4       V P                  P                  R4       V P                  P                  R4       V P                  V P                  V4      / 4       V P                  V P                  P                  ^RR./4       R	# )ap  
Test unsolicited data received in response to a silent flag modifying
method.  Call the method, assert that the correct bytes are sent,
deliver the unsolicited I{FETCH} response, and assert that the result
of the Deferred returned by the method is correct.

@param method: The name of the method to test.
@param item: The data item which is expected to be specified.
r6	  r|	  rx  Tr}	  r~	  s   * 2 FETCH (FLAGS (\Read \Seen))r	  Nr	  )r  r  rB   rj  r  rT  r  r  r	  s   &&& r3   %_flagsSilentlyWithUnsolicitedDataTest;IMAP4ClientStoreTests._flagsSilentlyWithUnsolicitedDataTest  s     DKK(.BDINN  "$4t$;>U$U	
 	  !EF  !;<--a0"5**Q80D,EFr6   c                *    V P                  RR4       R# )a!  
When passed a C{False} value for the C{silent} parameter,
L{IMAP4Client.setFlags} sends the I{STORE} command with a I{FLAGS} data
item and returns a L{Deferred} which fires with a C{dict} mapping
message sequence numbers to C{dict}s mapping C{'FLAGS'} to the new
flags of those messages.
setFlagsr  Nr	  rU   s   &r3   test_setFlags#IMAP4ClientStoreTests.test_setFlags  s     	
H-r6   c                *    V P                  RR4       R# )z
When passed a C{True} value for the C{silent} parameter,
L{IMAP4Client.setFlags} sends the I{STORE} command with a
I{FLAGS.SILENT} data item and returns a L{Deferred} which fires with an
empty dictionary.
r	     FLAGS.SILENTNr	  rU   s   &r3   test_setFlagsSilently+IMAP4ClientStoreTests.test_setFlagsSilently  s     	
O<r6   c                *    V P                  RR4       R# )z
If unsolicited flag data is received in response to a I{STORE}
I{FLAGS.SILENT} request, that data is passed to the C{flagsChanged}
callback.
r	  r	  Nr	  rU   s   &r3   (test_setFlagsSilentlyWithUnsolicitedData>IMAP4ClientStoreTests.test_setFlagsSilentlyWithUnsolicitedData  s     	22:Or6   c                *    V P                  RR4       R# )zc
L{IMAP4Client.addFlags} is like L{IMAP4Client.setFlags}, but sends
I{+FLAGS} instead of I{FLAGS}.
addFlagss   +FLAGSNr	  rU   s   &r3   test_addFlags#IMAP4ClientStoreTests.test_addFlags  s    
 	
I.r6   c                *    V P                  RR4       R# )z
L{IMAP4Client.addFlags} with a C{True} value for C{silent} behaves like
L{IMAP4Client.setFlags} with a C{True} value for C{silent}, but it
sends I{+FLAGS.SILENT} instead of I{FLAGS.SILENT}.
r	     +FLAGS.SILENTNr	  rU   s   &r3   test_addFlagsSilently+IMAP4ClientStoreTests.test_addFlagsSilently  s     	
,<=r6   c                *    V P                  RR4       R# )zy
L{IMAP4Client.addFlags} behaves like L{IMAP4Client.setFlags} when used
in silent mode and unsolicited data is received.
r	  r	  Nr	  rU   s   &r3   (test_addFlagsSilentlyWithUnsolicitedData>IMAP4ClientStoreTests.test_addFlagsSilentlyWithUnsolicitedData  s    
 	22:?OPr6   c                *    V P                  RR4       R# )zf
L{IMAP4Client.removeFlags} is like L{IMAP4Client.setFlags}, but sends
I{-FLAGS} instead of I{FLAGS}.
removeFlagss   -FLAGSNr	  rU   s   &r3   test_removeFlags&IMAP4ClientStoreTests.test_removeFlags  s    
 	y1r6   c                *    V P                  RR4       R# )z
L{IMAP4Client.removeFlags} with a C{True} value for C{silent} behaves
like L{IMAP4Client.setFlags} with a C{True} value for C{silent}, but it
sends I{-FLAGS.SILENT} instead of I{FLAGS.SILENT}.
r	     -FLAGS.SILENTNr	  rU   s   &r3   test_removeFlagsSilently.IMAP4ClientStoreTests.test_removeFlagsSilently  s     	/?@r6   c                *    V P                  RR4       R# )z|
L{IMAP4Client.removeFlags} behaves like L{IMAP4Client.setFlags} when
used in silent mode and unsolicited data is received.
r	  r	  Nr	  rU   s   &r3   +test_removeFlagsSilentlyWithUnsolicitedDataAIMAP4ClientStoreTests.test_removeFlagsSilentlyWithUnsolicitedData  s    
 	22=BRSr6   r0   N)rx   ry   rz   r{   rZ  r=  r  r	  r	  r	  r	  r	  r	  r	  r	  r	  r	  r	  r	  r|   r0   r6   r3   rz	  rz	  a  sP     (NX"6 G&.=P/>Q2ATr6   rz	  c                  &    ] tR tRtRtR tR tRtR# )IMAP4ClientStatusTestsi  a?  
Tests for the L{IMAP4Client.status} method.

An example of usage of the STATUS command from RFC 3501, section
5.1.2::

    C: A042 STATUS blurdybloop (UIDNEXT MESSAGES)
    S: * STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292)
    S: A042 OK STATUS completed

@see: U{https://tools.ietf.org/html/rfc3501#section-5.1.2}
c                    V P                  \        V P                  P                  RR4      pV P	                  \        V4      R\        R04      ,           4       R# )zy
Only allow sending the C{STATUS} names defined in RFC 3501.

@see: U{https://tools.ietf.org/html/rfc3501#section-5.1.2}
r  zIMPOSSIBLE?!zUnknown names: N)r   r#  r  rb  rB   r   r   )rE   excs   & r3   testUnknownName&IMAP4ClientStatusTests.testUnknownName  sN     KK	
 	S#4t^<L7M#MNr6   c                >   V P                   P                  RR4      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                   P                  R4       V P                  V\        P                  4       R# )zq
C{STATUS} names that cannot be decoded as ASCII cause the
status Deferred to fail with L{IllegalServerResponse}
blurdybloopr  s$   0001 STATUS blurdybloop (MESSAGES)
s?   * STATUS blurdybloop (MESSAGES 1 ASCIINAME "OK" NOTASCII "NO")s   0001 OK STATUS completedN)	r  rb  rB   rj  r  rT  r  r   r  r  s   & r3   testUndecodableName*IMAP4ClientStatusTests.testUndecodableName
  s}     KK}j9NN  "5	

 	  U	
 	  !<=Q ; ;<r6   r0   N)rx   ry   rz   r{   rZ  r	  r	  r|   r0   r6   r3   r	  r	    s    O=r6   r	  c                  6    ] tR tRtRt]tR tR tR t	R t
RtR# )	IMAP4ClientCopyTestsi  z
Tests for the L{IMAP4Client.copy} method.

An example of the C{COPY} command, which this method implements,
from RFC 3501, section 6.4.7::

    C: A003 COPY 2:4 MEETING
    S: A003 OK COPY completed
c                   V P                   P                  RRRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                  V P                  V4      . R34       R# )	z
L{IMAP4Client.copy} copies the messages identified by their
sequence numbers to the mailbox, returning a L{Deferred} that
succeeds with a true value.
r  MEETINGFrU     0001 COPY 2:3 MEETING
   0001 OK COPY completed   OK COPY completedNr  copyrB   rj  r  rT  r  r  s   & r3   test_copySequenceNumbers-IMAP4ClientCopyTests.test_copySequenceNumbers*  sv     KKUI59NN  "(	

 	  !:;--a027K2LMr6   c                >   V P                   P                  RRRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                  V P                  V4      P                  \        P                  4       R# )z
L{IMAP4Client.copy} returns a L{Deferred} that fails with an
L{IMAP4Exception} when the messages specified by the given
sequence numbers could not be copied to the mailbox.
r  r	  FrU  r	     0001 BAD COPY failedN
r  r	  rB   rj  r  rT  r  r  r   r  r  s   & r3   test_copySequenceNumbersFails2IMAP4ClientCopyTests.test_copySequenceNumbersFails:  s|     KKUI59NN  "(	

 	  !89d2215;;U=Q=QRr6   c                   V P                   P                  RRRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                  V P                  V4      . R34       R# )	z
L{IMAP4Client.copy} copies the messages identified by their
UIDs to the mailbox, returning a L{Deferred} that succeeds
with a true value.
r  r	  TrU     0001 UID COPY 2:3 MEETING
r	  r	  Nr	  r  s   & r3   test_copyUIDs"IMAP4ClientCopyTests.test_copyUIDsJ  sv     KKUI48NN  ",	

 	  !:;--a027K2LMr6   c                >   V P                   P                  RRRR7      pV P                  V P                  P	                  4       R4       V P                   P                  R4       V P                  V P                  V4      P                  \        P                  4       R# )z
L{IMAP4Client.copy} returns a L{Deferred} that fails with an
L{IMAP4Exception} when the messages specified by the given
UIDs could not be copied to the mailbox.
r  r	  TrU  r	  r	  Nr	  r  s   & r3   test_copyUIDsFails'IMAP4ClientCopyTests.test_copyUIDsFailsZ  s|     KKUI48NN  ",	

 	  !89d2215;;U=Q=QRr6   r0   N)rx   ry   rz   r{   rZ  r=  r  r	  r	  r	  r	  r|   r0   r6   r3   r	  r	    s&     (NN S N Sr6   r	  c                  $    ] tR tRtRtRtR tRtR# )FakeyServerik  r<  Nc                	    R # r/   r0   rU   s   &r3   sendServerGreetingFakeyServer.sendServerGreetingo  r  r6   r0   )rx   ry   rz   r{   r  timeoutr	  r|   r0   r6   r3   r	  r	  k  s    EGr6   r	  c                  P    ] 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# )r   is  c                	n    Wn         W n        W@n        \        V4      V n        W0n        WPn        W`n        R # r/   )r   r  _bodyr   sizer  r  subpart)rE   r   r  r  r   r  r	  s   &&&&&&&r3   r   FakeyMessage.__init__w  s+    

I		r6   c                	*    W3V n         V P                  # r/   )got_headersr   )rE   r  r  s   &&*r3   
getHeadersFakeyMessage.getHeaders  s    !=||r6   c                	    V P                   # r/   r  rU   s   &r3   r  FakeyMessage.getFlags  r  r6   c                	    V P                   # r/   )r  rU   s   &r3   getInternalDateFakeyMessage.getInternalDate      yyr6   c                	,    \        V P                  4      # r/   )r   r	  rU   s   &r3   getBodyFileFakeyMessage.getBodyFile  s    tzz""r6   c                	    V P                   # r/   )r	  rU   s   &r3   getSizeFakeyMessage.getSize  r	  r6   c                	    V P                   # r/   rU  rU   s   &r3   r  FakeyMessage.getUID  s    xxr6   c                	    V P                   R J# r/   )r	  rU   s   &r3   isMultipartFakeyMessage.isMultipart  s    ||4''r6   c                	4    Wn         V P                  V,          # r/   )got_subpartr	  )rE   r  s   &&r3   
getSubPartFakeyMessage.getSubPart  s    ||D!!r6   )	r	  r  r  r	  r	  r   r	  r	  r  N)r   r  r  r	  r  )rx   ry   rz   r{   showAttributesr   r	  r  r	  r	  r	  r  r	  r	  r|   r0   r6   r3   r   r   s  s4    AN#("r6   r   c                  F    ] tR tRtRtRtR tR tR tR t	R t
R
R ltR	tR# )NewStoreTestsi  Nc                	    R ;V n         V n        \        P                  ! 4       V n        RV P                  n        W P                  n        \        P                  ! 4       V n	        \        V P                  4      V n        R # Nr<  )received_messagesreceived_uidr   rH  r~  r  r  r   r   r  rZ  r  rU   s   &r3   r  NewStoreTests.setUp  sV    599!2'')$)"4>>2r6   c                	    R # r/   r0   rE   r  s   &&r3   r  NewStoreTests.addListener  r  r6   c                	    R # r/   r0   r	  s   &&r3   r  NewStoreTests.removeListener  r  r6   c                	*    W3V n         V P                  # r/   )	storeArgsr  )rE   rO  rP  s   &*,r3   r  NewStoreTests.store  s    }}r6   c                	r  a  V 3R  lpV 3R lpS P                   P                  \        V4      4      P                  V4      P                  S P                  4      P	                  S P
                  4       V 3R lp\        P                  ! S P                  S P                  RR7      pVP                  V4       V# )c                 |   < S P                  S P                  S P                  S P                  S P                  4      # r/   )functionrj  r  silentr  rU   s   r3   r  +NewStoreTests._storeWork.<locals>.connected  s(    ==

DKKRRr6   c                   < V Sn         R # r/   r1   RrE   s   &r3   r1   (NewStoreTests._storeWork.<locals>.result  
    DKr6   c                   < SP                  SP                  SP                  4       SP                  SP                  SP                  4       R # r/   )rB   r1   r  r
  expectedArgsr  rE   s   &r3   r  'NewStoreTests._storeWork.<locals>.check  s5    T[[$--8T^^T->->?r6   Fnoisy
r  r   r7   r  r  r  r"   loopbackTCPr~  r  )rE   r  r1   r  r   s   f    r3   
_storeWorkNewStoreTests._storeWork  s    	S	 	""5#34@@HTT	

*T__
%	@   dkkG	er6   c                	   V P                   P                  V n        R V n        . ROV n        RV n        Wn        ^. RO^. RO^	. RO/V n        ^R. RO/^R. RO/^	R. RO//V n        \        P                  ! 4       pVP                  ^4       VP                  ^4       VP                  ^	4       V. RO^ 3R^ /3V n        V P                  4       # )z1,5,9Fr  r  )z\Az\BC)r  r	  r
  rj  r  r	
  r  r  r  r   r   r   r
  r
  )rE   r  r   s   && r3   testSetFlagsNewStoreTests.testSetFlags  s    ,,(
"""
 ,-,-,-

  


!#6:UAJG  r6   )r  r  r  r
  r  r
  rj  r	  r	  r  r1   r~  r	
  r
  r  r  )rx   ry   rz   r{   r1   r
  r  r  r  r  r
  r
  r|   r0   r6   r3   r	  r	    s/    FI3&! !r6   r	  c                  P    ] 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# )GetBodyStructureTestsi  z
Tests for L{imap4.getBodyStructure}, a helper for constructing a list which
directly corresponds to the wire information needed for a I{BODY} or
I{BODYSTRUCTURE} response.
c                   RpRpRpRpRpRpRp\        RVR	,           V,           R
,           V,           R,           RVRVRV/RRV^{R4      p\        P                  ! V4      p	V P                  VVRVRR.VVV\	        V4      .V	4       R# )z
L{imap4.getBodyStructure} accepts a L{IMessagePart} provider and returns
a list giving the basic fields for the I{BODY} response for that
message.
   hello, worldimagejpegus-asciisome kind of idgreat justicemaximumr   rs  
; charset=; x=y
content-idcontent-descriptioncontent-transfer-encodingr6   Ncharsetr  yr0   r   r   getBodyStructurerB   r   
rE   r   majorminorr.
  r  descriptionr  r   	structures
   &         r3   test_singlePart%GetBodyStructureTests.test_singlePart  s     &
%e 3l BW Lw Vj%{+X	 
 **3/	GS#.D	 	
r6   c                   \        / RRR^{R4      p\        P                  ! V4      pVR,          w  r4V P                  RV4       V P                  RV4       \        RR/RRR^{R4      p\        P                  ! V4      pVR,          w  rxV P                  RV4       V P                  RV4       \        RR/RRR^{R4      p	\        P                  ! V	4      p
V
R,          w  rV P                  RV4       V P                  RV4       R# )z
L{imap4.getBodyStructure} returns L{None} for the major and
minor MIME types of a L{IMessagePart} provider whose headers
lack a C{Content-Type}, or have an empty value for it.
r6   NNr   Nr   rv  
r0   )r   r   r1
  assertIs)rE   missingmissingContentTypeStructuremissingMajormissingMinorr  emptyContentTypeStructure
emptyMajor
emptyMinornewlinenewlineContentTypeStructurenewlineMajornewlineMinors   &            r3   test_emptyContentType+GetBodyStructureTests.test_emptyContentType  s     r2sCd;&+&<&<W&E#%@%D"dL)dL)nb12sCdK$)$:$:5$A!!:2!>
dJ'dJ'5r3S$O&+&<&<W&E#%@%D"dL)dL)r6   c                    \        RR/RRR^{R4      p\        P                  ! V4      pVR,          w  r4V P                  VR4       V P	                  VR4       R# )z
L{imap4.getBodyStructure} returns only a non-L{None} major
MIME type for a L{IMessagePart} provider whose headers only
have a main a C{Content-Type}.
r   mainr6   Nr:
  r0   )r   r   r1
  rB   r<
  )rE   rK
  mainStructure	mainMajor	mainMinors   &    r3   test_onlyMajorContentType/GetBodyStructureTests.test_onlyMajorContentType$  sX     ^V4b#sCN..t4,R0	F+i&r6   c                8   RpRpRpRpRpRpRpRp\        R	VR
,           V,           R,           V,           R,           RVRVRVRVRRRRRR/RRV^{R4      p	\        P                  ! V	RR7      p
V P                  VVRVRR.VVV\	        V4      VR. R O.RR.V
4       R# )!z
L{imap4.getBodyStructure} returns a list giving the basic and extended
fields for a I{BODYSTRUCTURE} response if passed C{True} for the
C{extended} parameter.
r"
  r#
  r$
  r%
  r&
  r'
  r(
  abcdefabcdefr   rs  r)
  r*
  r+
  r,
  r-
  content-md5content-dispositionzattachment; name=foo; size=barcontent-languagefrcontent-locationFrancerv  NTextendedr.
  r  r/
  
attachmentr0   )r6  rv  r	  rw  r0
  )rE   r   r3
  r4
  r.
  r  r5
  r  md5r   r6
  s   &          r3   test_singlePartExtended-GetBodyStructureTests.test_singlePartExtended0  s     &
%e 3l BW Lw Vj%{+Xs%'G"D"H	 
" **3>	GS#.D	=> 	
r6   c                    RpRpRp\        RVR,           V,           /R
RV^{R4      p\        P                  ! VRR	7      pV P                  WRRRR\	        V4      RRRR.V4       R# )z
For fields with no information contained in the message headers,
L{imap4.getBodyStructure} fills in L{None} values in its result.
r#
  r$
  r"
  r   rs  r6   NTrY
  r0   r0
  )rE   r3
  r4
  r   r   r6
  s   &     r3   test_singlePartWithMissing0GetBodyStructureTests.test_singlePartWithMissinga  sz    
 US[5012sD#t
 **3>	4tT3t9dD$PTU	
r6   c                @   RpRpRpRpRpRpRp\        RVR	,           V,           R
,           V,           R,           RVRVRV/RRV^{R4      p\        P                  ! V4      p	V P                  VVRVRR.VVV\	        V4      \	        VP                  4       4      .V	4       R# )zz
For a I{text/*} message, the number of lines in the message body are
included after the common single-part basic fields.
"   hello, world
how are you?
goodbye
rF   r$
  r%
  r&
  r'
  r(
  r   rs  r)
  r*
  r+
  r,
  r-
  r6   Nr.
  r  r/
  r0   )r   r   r1
  rB   r   r  r2
  s
   &         r3   test_textPart#GetBodyStructureTests.test_textPartr  s    
 8&
%e 3l BW Lw Vj%{+X	 
 **3/	GS#.D	DOO%&	 	
r6   c                z   RpRpRpRpRpRpRp\        RVR	,           V,           R
,           V,           R,           RRRRRVRVRV/RRV^{R4      p\        RR/RRR^{V.4      p	\        P                  ! V	4      p
V P                  RRRRRR^ \        P                  ! V4      \        P                  ! V4      ^.
V
4       R# )zs
For a I{message/rfc822} message, the common basic fields are followed
by information about the contained message.
rc
  rF   r$
  r%
  r&
  r'
  r(
  r   rs  r)
  r*
  r   zAlice <alice@example.com>r   zBob <bob@example.com>r+
  r,
  r-
  rv  Nmessage/rfc822r6   r  r  r0   )r   r   r1
  rB   getEnvelope)rE   r   r3
  r4
  r.
  r  r5
  r  r   	containerr6
  s   &          r3   test_rfc822Message(GetBodyStructureTests.test_rfc822Message  s   
 8&
%e 3l BW Lw V3-j%{+X 
  ! 0 E	
	 **95	!!#&&&s+ 	
r6   c           
     "   \        RRRRRRRR/RR	R
^{R4      p\        RR/RR	RRR4      p\        RR/RR	R	RW.4      pV P                  \        P                  ! V4      \        P                  ! V4      R.\        P                  ! V4      4       R# )z
For a I{multipart/*} message, L{imap4.getBodyStructure} returns a list
containing the body structure information for each part of the message
followed by an element giving the MIME subtype of the message.
r   zimage/jpeg; x=yr+
  r&
  r,
  r'
  r-
  r(
  r6      hello worldNztext/plain; charset=us-ascii
   some stuffA  zmultipart/related+  relatedr0   r   rB   r   r1
  rE   
oneSubPartanotherSubPartri
  s   &   r3   test_multiPart$GetBodyStructureTests.test_multiPart  s     " 1/%+Y	 

 & > 	
 ! 3 (	
	 	&&z2&&~6
 ""9-	
r6   c           
     N   \        RRRRRRRR/R R	R
^{R4      p\        RR/R R	RRR4      p\        RRRRRRRR/R R	R	RW.4      pV P                  \        P                  ! VRR7      \        P                  ! VRR7      RRR.RRR..RR.\        P                  ! VRR7      4       R# )!a  
When passed a I{multipart/*} message and C{True} for the C{extended}
argument, L{imap4.getBodyStructure} includes extended structure
information from the parts of the multipart message and extended
structure information about the multipart message itself.
s   content-types   image/jpeg; x=ys
   content-ids   some kind of ids   content-descriptions   great justices   content-transfer-encodings   maximumr6   rm
  Ns   text/plain; charset=us-asciirn
  ro
  r   zmultipart/related; foo=barrU
  esrW
  SpainrT
  zattachment; name=monkeysrp
  TrY
  rq
  rv  rw  r[
  r6  monkeysr0   rr
  rs
  s   &   r3   test_multiPartExtended,GetBodyStructureTests.test_multiPartExtended  s    "!31&(8,j	 

 &!@ 	
 ! <"D"G%'A	 (
	 	&&zDA&&~E	23 ""9t<	
r6   r0   N)rx   ry   rz   r{   rZ  r7
  rH
  rO
  r]
  r`
  rd
  rj
  rv
  r|
  r|   r0   r6   r3   r 
  r 
    s9    &
P*0
'/
b
"&
P6
p1
f9
r6   r 
  c                  :   ] tR tRtR tR tR tR tR tR t	R/R lt
R	 tR/R
 ltR t]P                  ! ]P                   R4      t ]P                  ! ]P                   R4       ]P                  ! ]P                   ]4       Rt]! ]R4      R 4       tR/R ltR tR/R ltR tR/R ltR/R ltR tR/R ltR tR/R ltR t R t!R/R lt"R t#R/R  lt$R! t%R/R" lt&R# t'R$ t(R% t)R/R& lt*R' t+R/R( lt,R) t-R/R* lt.R+ t/R/R, lt0R- t1R.t2R#   ]P&                   d    Rt Li ; i)0NewFetchTestsiA  c                	   R ;V n         V n        R V n        \        P                  ! 4       V n        RV P
                  n        W P
                  n        \        P                  ! 4       V n
        \        V P                  4      V n        R # r	  )r	  r	  r1   r   rH  r~  r  r  r   r   r  rZ  r  rU   s   &r3   r  NewFetchTests.setUpB  s]    599!2'')$)"4>>2r6   c                	    R # r/   r0   r	  s   &&r3   r  NewFetchTests.addListenerL  r  r6   c                	    R # r/   r0   r	  s   &&r3   r  NewFetchTests.removeListenerO  r  r6   c           	     	    Wn         W n        \        \        \	        \        V P                  4      4      V P                  4      4      # r/   )r	  r	  iterr   rr   r   msgObjsr  s   &&&r3   r  NewFetchTests.fetchR  s2    !)Cc$,,/0$,,?@@r6   c                	<  a a S'       di   \        \        \        S P                  4      4      S P                  4       F2  w  r#\	        VP                  4       4      S P                  V,          R &   K4  	  V 3R lpS P                  P                  V V3R l4      P                  V4      P                  S P                  4      P                  S P                  4       \        P                  ! S P                  S P                  RR7      pVP                  V 3R l4       V# )r  c                   < V Sn         R # r/   r
  r
  s   &r3   r1   (NewFetchTests._fetchWork.<locals>.result\  r
  r6   c                <   < SP                  SP                  S4      # r/   r
  rj  )r  rE   r  s   &r3   r4   *NewFetchTests._fetchWork.<locals>.<lambda>`  s    dmmDMM37r6   Fr
  c                P   < SP                  SP                  SP                  4      # r/   rB   r1   r  )r  rE   s   &r3   r4   r
  f  s     0 0dmm Lr6   )r   rr   r   r
  r   r  r  r  r   r  r  r  r"   r
  r~  r  )rE   r  r   r   r1   r   s   ff    r3   
_fetchWorkNewFetchTests._fetchWorkW  s    eC$56E*-cjjl*;a ' F	 	""7	

+f
kk$*<*<=jjOO?
   dkkG	LMr6   c           
     	   a  V 3R  lS n         RS n        \        / RRRRR4      \        / RRRRR4      \        / RRRRR4      .S n        ^ RR/^RR	/^RR
//S n        S P                  ^ 4      # )c                :   < SP                   P                  V 4      # r/   r  r+	  )r  urE   s   &&r3   r4   ,NewFetchTests.testFetchUID.<locals>.<lambda>j  s    T[[%9%9!%<r6   r;	  r6   r  N  u'  r  1234599910101r0   )r
  rj  r   r
  r  r
  rU   s   fr3   testFetchUIDNewFetchTests.testFetchUIDi  s    <Rc5$7Rc35Rc5$7
 wu~w

 q!!r6   c           	     	    V P                   P                  V n        R V n        \	        / . RORRRR4      \	        / . RORRRR4      .V n        ^ R. RO/^R. RO//V n        V P                  V4      # )r^	  r6   1  Nr  r  )FlagAFlagB\FlagC)r
  r
  r
  )r  
fetchFlagsr
  rj  r   r
  r  r
  rE   r  s   &&r3   testFetchFlagsNewFetchTests.testFetchFlagsy  s{    ..:CeTR:CeTR

 6767
 s##r6   c                	$    V P                  ^4      # r  )r
  rU   s   &r3   testFetchFlagsUIDNewFetchTests.testFetchFlagsUID  s    ""1%%r6   c                	   V P                   P                  V n        R V n        \	        / RRRRR4      \	        / RRR^eR4      \	        / RRR^R4      \	        / RRRRR4      .V n        ^ R	R
/^R	R/^R	R/^R	R//V n        V P                  V4      # )13s   Fri, 02 Nov 2003 21:25:10 GMTr6   iZ  Ns   Thu, 29 Dec 2013 11:31:52 ESTs   Mon, 10 Mar 1992 02:44:30 CSTs   Sat, 11 Jan 2000 14:40:24 PSTi/  r  z02-Nov-2003 21:25:10 +0000z29-Dec-2013 11:31:52 -0500z10-Mar-1992 02:44:30 -0600z11-Jan-2000 14:40:24 -0800r0   )r  fetchInternalDater
  rj  r   r
  r  r
  r
  s   &&r3   testFetchInternalDate#NewFetchTests.testFetchInternalDate  s    55R!A3tTR!A3TRR!A3TRR!A3TR	
  <= <= <= <=	
 s##r6   c                	$    V P                  ^4      # r  )r
  rU   s   &r3   testFetchInternalDateUID&NewFetchTests.testFetchInternalDateUID  s    ))!,,r6   N
es_AR.UTF8FTz'The es_AR.UTF8 locale is not installed.c                   \         P                  ! \         P                  R4      p\         P                  ! \         P                  R4       V P                  \         P                  \         P                  V4       V P	                  ^4      # )z3
The month name in the date is locale independent.
Nr
  )locale	setlocaleLC_ALLr  r
  )rE   currentLocales   & r3   'test_fetchInternalDateLocaleIndependent5NewFetchTests.test_fetchInternalDateLocaleIndependent  sY     ((=5((&--G))!,,r6   c                	    V P                   P                  V n        R V n        \	        RRRRRRRRR	R
/RRRRR4      .V n        ^ RRR. RO.. RO.. RO.. RO.RRRR
.
//V n        V P                  V4      # )15r   zuser@domainr   zresu@domainr  thursdayr   zit is a messagez
message-idzid-id-id-yayayar6   ix  Nr  r0   )NNr  domain)NNresur
  )r  fetchEnveloper
  rj  r   r
  r  r
  r
  s   &&r3   testFetchEnvelopeNewFetchTests.testFetchEnvelope  s    11M-J0 "3 
" %34343434%
  s##r6   c                	$    V P                  ^4      # r  )r
  rU   s   &r3   testFetchEnvelopeUID"NewFetchTests.testFetchEnvelopeUID  s    %%a((r6   c                    V P                   P                  V n        RV n        \	        RRRRRRRR	R
RRRRRRR/RRRRR4      .V n        ^ RRR. RORRR	RRRRRR..RR.//V n        V P                  V4      # ) a+  
L{IMAP4Client.fetchBodyStructure} issues a I{FETCH BODYSTRUCTURE}
command and returns a Deferred which fires with a structure giving the
result of parsing the server's response.  The structure is a list
reflecting the parenthesized data sent by the server, as described by
RFC 3501, section 7.4.2.
3:9,10:*r   #text/plain; name=thing; key="value"r+
  this-is-the-content-idr,
  !describing-the-content-goes-here!r-
  8BITrS
  abcdef123456rT
  zattachment; filename=monkeysrU
  ry
  rW
  zhttp://example.com/monkeysrv     Body
Text
Goes
Here
 Nr  rF   plain20rS	  r[
  filenamer{
  r0   r  r  r6  thingr  fetchBodyStructurer
  rj  r   r
  r  r
  r
  s   &&r3   test_fetchBodyStructure%NewFetchTests.test_fetchBodyStructure  s     66""$I ":)+N/!>)+I&&(D	 +
( 5,7"!J	#:;0"
$ s##r6   c                $    V P                  ^4      # )zw
If passed C{True} for the C{uid} argument, C{fetchBodyStructure} can
also issue a I{UID FETCH BODYSTRUCTURE} command.
)r
  rU   s   &r3   testFetchBodyStructureUID'NewFetchTests.testFetchBodyStructureUID  s    
 ++A..r6   c                (   V P                   P                  V n        RV n        \	        RRRRRRRR	R
RRRRRRR/R!RRRR4      p\	        RRR
RRR/R!RRRV.4      .V n        ^ RRR. R"ORRR	RRRRR.RR.RRR .RRR.//V n        V P                  V4      # )#z|
L{IMAP4Client.fetchBodyStructure} can also parse the response to a
I{FETCH BODYSTRUCTURE} command for a multipart message.
r
  r   r
  r+
  r
  r,
  r
  r-
  r
  rU
  rV
  rS
  123456abcdefrT
  inlinerW
  zouter spacer6   r
  r
  Nzmultipart/mixed; boundary="xyz"ennearbyr  rF   r
  r
  rS	  mixedboundaryxyzr0   r
  r
  )rE   r  innerMessages   && r3    test_fetchBodyStructureMultipart.NewFetchTests.test_fetchBodyStructureMultipart  s   
 66"# E6%'J+V"D~%x"M	 '
$ "$E&&
 
 90;&!4(% ''"
2 s##r6   c                	    V P                   P                  V n        R V n        \	        / R	RRR\	        RR/R	RRRR4      .4      .V n        ^ R. R
O//V n        V P                  V4      # )21r6      Yea whateverf r   	image/jpg   Body Body BodyNr  r0   NNNNNN12r  fetchSimplifiedBodyr
  rj  r   r
  r  r
  r
  s   &&r3   testFetchSimplifiedBody%NewFetchTests.testFetchSimplifiedBodyW  s    77 '5)	
& V%OPQs##r6   c                	$    V P                  ^4      # r  )r
  rU   s   &r3   testFetchSimplifiedBodyUID(NewFetchTests.testFetchSimplifiedBodyUIDq  s    ++A..r6   c                	    V P                   P                  V n        R V n        \	        RR/RRRRR4      .V n        ^ R. R	O//V n        V P                  V4      # )
r
  r   r   r6   r
  r
  Nr  r0   )rF   r
  NNNNr
  r	  r
  r
  s   &&r3   testFetchSimplifiedBodyText)NewFetchTests.testFetchSimplifiedBodyTextt  se    77.C%QU
 LM
 s##r6   c                	$    V P                  ^4      # r  )r
  rU   s   &r3   testFetchSimplifiedBodyTextUID,NewFetchTests.testFetchSimplifiedBodyTextUID  s    //22r6   c                	   V P                   P                  V n        R V n        \	        RR/RRRR\	        RR/RRRR	R	4      .4      .V n        ^ R
RRR	R	R	R	RR	R	. RO.. RO.R	R	R	R	R	R	.
. ROR.
//V n        V P                  V4      # )r
  r   rg
  r6   r
  r
  r
  rv  r
  Nr  r  r  r
  r	  r0   NNN)r#
  jpgNNNN14r
  r
  s   &&r3   testFetchSimplifiedBodyRFC822+NewFetchTests.testFetchSimplifiedBodyRFC822  s    77!12 '5)	
( +,+, C+
8 s##r6   c                	$    V P                  ^4      # r  )r   rU   s   &r3    testFetchSimplifiedBodyRFC822UID.NewFetchTests.testFetchSimplifiedBodyRFC822UID  s    11!44r6   c           	     2   V P                   P                  V n        RV n        \	        RR/RRRRR4      \	        RR/RRR	R
R4      .p\	        RR/RRRRV4      p\	        RR/RRRRV.4      pV.V n        ^ R. RO. ROR.R.//V n        V P                  R4      # )a   
L{IMAP4Client.fetchSimplifiedBody} returns a dictionary mapping message
sequence numbers to fetch responses for the corresponding messages.  In
particular, for a multipart message, the value in the dictionary maps
the string C{"BODY"} to a list giving the body structure information for
that message, in the form of a list of subpart body structure
information followed by the subtype of the message (eg C{"alternative"}
for a I{multipart/alternative} message).  This structure is self-similar
in the case where a subpart is itself multipart.
r
  r   r   s   dates   Stuffr
  Nr   s   Thingsi~  r   r6   s
   Irrelevantr  zmultipart/mixeds   RootOfí r  alternativer
  Fr0   )rF   r
  NNNN5r	  )rF   htmlNNNNrB	  r	  r
  )rE   singlesr  r
  s   &   r3   !test_fetchSimplifiedBodyMultipart/NewFetchTests.test_fetchSimplifiedBodyMultipart  s     77 .GXud -r7Iud	
 #45
 ./M
 w KJ%
 	
 u%%r6   c                	    V P                   P                  V n        R V n        \	        RR/RRR^[R4      .V n        ^ RR//V n        V P                  V4      # )	z1,3,7,10101r   Valuer6   s   BODY TEXT
Nr  zHeader: Value

BODY TEXT
r0   )r  rK  r
  rj  r   r
  r  r
  r
  s   &&r3   testFetchMessageNewFetchTests.testFetchMessage  s^    00%(G,b#7GTR
 X'KLMs##r6   c                	$    V P                  ^4      # r  )r  rU   s   &r3   testFetchMessageUID!NewFetchTests.testFetchMessageUID      $$Q''r6   c                	    V P                   P                  V n        R V n        \	        RRRR/RRR^cR4      .V n        \        \        P                  ! RRRR/4      4      p^ RV//V n	        V P                  V4      # )	z9,6,2H1V1H2V2r6   Nr  r0   )r  fetchHeadersr
  rj  r   r
  r'   r   r  r  r
  )rE   r  r   s   && r3   testFetchHeadersNewFetchTests.testFetchHeaders  s    00$dD12sCTJ
 u33T4t4LMN )
 s##r6   c                	$    V P                  ^4      # r  )r  rU   s   &r3   testFetchHeadersUID!NewFetchTests.testFetchHeadersUID  r  r6   c                	    V P                   P                  V n        R V n        \	        RR/RRR^R4      .V n        ^ RR//V n        V P                  V4      # )	z1,2,3,4,5,6,7r   r  rv  s   Body goes here
Nr  zBody goes here
r0   )r  r7	  r
  rj  r   r
  r  r
  r
  s   &&r3   testFetchBodyNewFetchTests.testFetchBody  sc    --'(G,b"6KSRVW
 34
 s##r6   c                	$    V P                  ^4      # r  )r   rU   s   &r3   testFetchBodyUIDNewFetchTests.testFetchBodyUID$      !!!$$r6   c                   a  S P                   P                  S n        RS n        RpRpRp\	        4       pRVR&   RVR&   R	VR
&   RVR&   \	        4       pRVR
&   RVR&   \	        4       pRVR
&   RVR&   \        VRRV^{\        VRRVRR4      \        VRRVRR4      .4      .S n        ^ RR.R../S n        V 3R lpS P                  P                  V 3R l4       S P                  P                  V4       S P                  P                  S P                  4       S P                  P                  S P                  4       \        P                  ! S P                  S P                   RR7      pVP                  V 3R l4       V# )zD
Test the server's handling of requests for specific body sections.
r	  rv  r   r   r   r   r   r   r   r   r   r   r   r   r   r   Nr  z&Contained body message text.  Squarge.c                   < V Sn         R # r/   r
  r
  s   &r3   r1   0NewFetchTests.testFetchBodyParts.<locals>.resultJ  r
  r6   c                >   < SP                  SP                  ^R7      # )r   rF	  r
  r  s   &r3   r4   2NewFetchTests.testFetchBodyParts.<locals>.<lambda>N  s    dmmDMMmBr6   Fr
  c                P   < SP                  SP                  SP                  4      # r/   r
  ignrE   s   &r3   r4   r*  U      $"2"24;;"Nr6   r0   r  rt  r
  rj  r   r   r
  r  r  r   r  r  r  r"   r
  r~  )	rE   r   r   r   r   r   r   r1   r   s	   f        r3   testFetchBodyParts NewFetchTests.testFetchBodyParts'  s    11	>
F
-'*.	"I"}"8Y'3^$##;i (3n% r4T4P D*dDQ

 fse-UVWX	 	""B	
 	""6*""4#5#56!!$//2  dkkG	NOr6   c                v  a a S P                   P                  S n        RS n        ^.oRp\	        4       pRVR&   RVR&   RVR&   R	VR
&   \        VRRV^{R4      .S n        ^ RR.R../S n        V 3R lpS P                  P                  VV 3R l4       S P                  P                  V4       S P                  P                  S P                  4       S P                  P                  S P                  4       \        P                  ! S P                  S P                   RR7      pVP                  V 3R l4       V# )z
Single-part messages have an implicit first part which clients
should be able to retrieve explicitly.  Test that a client
requesting part 1 of a text/plain message receives the body of the
text/plain part.
r	  s   DA bodyr   r   r   r   r   r   r   r   Nr  zDA bodyc                   < V Sn         R # r/   r
  r
  s   &r3   r1   >NewFetchTests.test_fetchBodyPartOfNonMultipart.<locals>.resultl  r
  r6   c                >   < SP                  SP                  SR 7      # )rF	  r
  )r  partsrE   s   &r3   r4   @NewFetchTests.test_fetchBodyPartOfNonMultipart.<locals>.<lambda>p  s    dmmDMMmFr6   Fr
  c                P   < SP                  SP                  SP                  4      # r/   r
  r,  s   &r3   r4   r7  w  r.  r6   r0   r/  )rE   r   r   r1   r   r6  s   f    @r3    test_fetchBodyPartOfNonMultipart.NewFetchTests.test_fetchBodyPartOfNonMultipartX  s    11	-'*.	".$Wb$	3MNfseY789	 	""F	
 	""6*""4#5#56!!$//2  dkkG	NOr6   c                	    V P                   P                  V n        R V n        \	        / RRR^{R4      .V n        ^ RR//V n        V P                  V4      # )z	1:100,2:*r6   Nr  r
  r0   s   xxxxxxxxxxxxxxxxxxxx)r  	fetchSizer
  rj  r   r
  r  r
  r
  s   &&r3   testFetchSizeNewFetchTests.testFetchSizez  s[    --#Rid;
 t$
 s##r6   c                	$    V P                  ^4      # r  )r=  rU   s   &r3   testFetchSizeUIDNewFetchTests.testFetchSizeUID  r%  r6   c                	@   V P                   P                  V n        R V n        \	        / RRRRR4      \	        / RRRRR4      .V n        ^ R. RORRR	R
RRR. RO.. RO.RRRRRR.
R. RO/^R. RORRR	RRRR. RO.. RO.RRRRRR.
R. RO//V n        V P                  V4      # )z1,3s%   Sun, 25 Jul 2010 06:20:30 -0400 (EDT)i  Ns   Mon, 14 Apr 2003 19:43:44 -0400rp
  r  r  z25-Jul-2010 06:20:30 -0400r  rB	  r  r  z14-Apr-2003 19:43:44 -0400r
  )z\XYZz\YZXAbcs   xyzxyz)z\Onez\TwoThrees   abcabcabcabcr
  )NNNNNNrB	  r
  )r  	fetchFullr
  rj  r   r
  r  r
  r
  s   &&r3   testFetchFullNewFetchTests.testFetchFull  s   --)8 +2
& 2 <s'('( A!$ 4 <t'('( B!'%
L s##r6   c                	$    V P                  ^4      # r  )rF  rU   s   &r3   testFetchFullUIDNewFetchTests.testFetchFullUID  r%  r6   c                	(   V P                   P                  V n        R V n        \	        / RRRRR4      \	        / RRRRR4      .V n        ^ RRR. RO.. RO.RRRRRR.
R	R
RRR. /^RRR. RO.. RO.RRRRRR.
R	R
RRR. //V n        V P                  V4      # )z1,2:3s   Mon, 14 Apr 2003 19:43:44 +0400s   Lalalar
  Ns   Tue, 15 Apr 2003 19:43:44 +0200s   AlalaliN  r  r  rB	  r  z14-Apr-2003 19:43:44 +0400r  z15-Apr-2003 19:43:44 +0200r0   r
  )r  fetchAllr
  rj  r   r
  r  r
  r
  s   &&r3   testFetchAllNewFetchTests.testFetchAll  s    ,,B:Iud B:Iud	
 '('( s <" '('( s <%#
H s##r6   c                	$    V P                  ^4      # r  )rM  rU   s   &r3   testFetchAllUIDNewFetchTests.testFetchAllUID  s      ##r6   c                	    V P                   P                  V n        R V n        \	        / R
RR^	R4      .V n        ^ RR.RRRR	//V n        V P                  V4      # )r	  \Xs   19 Mar 2003 19:22:21 -0500r6   Nr  r  z19-Mar-2003 19:22:21 -0500r  0)rS  )r  	fetchFastr
  rj  r   r
  r  r
  r
  s   &&r3   testFetchFastNewFetchTests.testFetchFast  sl    --X'Dc1dS
 % <s
 s##r6   c                	$    V P                  ^4      # r  )rV  rU   s   &r3   testFetchFastUIDNewFetchTests.testFetchFastUID  r%  r6   )
r  r  r  r
  rj  r
  r	  r	  r1   r~  r  )3rx   ry   rz   r{   r  r  r  r  r
  r
  r
  r
  r
  r
  r
  r
  r
  r
  noEsARLocaleErrorr	   r
  r
  r
  r
  r
  r
  r
  r
  r
  r
  r   r  r
  r  r  r  r  r   r#  r0  r9  r=  r@  rF  rI  rM  rP  rV  rY  r|   r0   r6   r3   r
  r
  A  sL   3A
$" $&$"- $$V]]D9M5 	6LCD- E-#$J)/$b/?$B$4/$32$h5>&@$($(	$%/b D	$%;$z%/$b$$%M << s   D DDr
  c                  z    ] 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R tR tR tR tRtR# )DefaultSearchTestsi  zn
Test the behavior of the server's SEARCH implementation, particularly in
the face of unhandled search terms.
c                	   \         P                  ! 4       V n        R V P                  n        W P                  n        \
        P                  ! 4       V n        \        V P                  4      V n	        \        / RRRRR4      \        / RRRRR4      \        / RRRRR4      \        / RRRRR4      \        / RRRRR4      .V n        R# )	r<  r6   r
  Nr
  r  i!N  i"N  r0   )r   rH  r~  r  r  r   r   r  rZ  r  r   r
  rU   s   &r3   r  DefaultSearchTests.setUp  s    '')$)"4>>2Rc35Rc5$7Rc5$7Rc5$7Rc5$7
r6   c           
         \        \        \        ^\        V P                  4      ^,           4      V P                  4      4      # )zG
Pretend to be a mailbox and let C{self.server} lookup messages on me.
)r   r   rr   r   r
  r  s   &&&r3   r  DefaultSearchTests.fetch#  s/     CaT\\!2Q!67FGGr6   c                  a aa VV 3R lpS P                   P                  \        V4      4      pVV 3R lpVP                  V4       VP                  S P                  4       VP	                  S P
                  4       S P                  4        V# )aH  
Issue a search with given query and verify that the returned messages
match the given expected messages.

@param queryTerms: A string giving the search query.
@param expectedMessages: A list of the message sequence numbers
    expected as the result of the search.
@return: A L{Deferred} which fires when the test is complete.
c                 :   < SP                   P                  S 4      # r/   r  r	  
queryTermsrE   s   r3   r	  8DefaultSearchTests._messageSetSearchTest.<locals>.search4  r  r6   c                ,   < SP                  V S4       R # r/   r  )rB  expectedMessagesrE   s   &r3   searched:DefaultSearchTests._messageSetSearchTest.<locals>.searched9  s    W&67r6   )r  r   r7   r  r  r  r"   )rE   rg  rj  r	  r   rk  s   fff   r3   _messageSetSearchTest(DefaultSearchTests._messageSetSearchTest)  se    	2 NN&&uV}5	8 	
h	d(()	T__%r6   c                (    V P                  R^.4      # )zp
Test that a search which starts with a message set properly limits
the search results to messages in that set.
r	  rm  rU   s   &r3   test_searchMessageSet(DefaultSearchTests.test_searchMessageSetB  s    
 ))#s33r6   c                *    V P                  R. RO4      # )z^
If the search filter ends with a star, all the message from the
starting point are returned.
z2:*r   r   r  r   rp  rU   s   &r3   test_searchMessageSetWithStar0DefaultSearchTests.test_searchMessageSetWithStarI      
 ))%>>r6   c                *    V P                  R. RO4      # )zs
If the search filter starts with a star, the result should be identical
with if the filter would end with a star.
z*:2rt  rp  rU   s   &r3   "test_searchMessageSetWithStarFirst5DefaultSearchTests.test_searchMessageSetWithStarFirstP  rw  r6   c                *    V P                  R. RO4      # )z}
If the search filter ends with a star, all the message from the
starting point are returned (also for the SEARCH UID case).
zUID 10000:*rt  rp  rU   s   &r3    test_searchMessageSetUIDWithStar3DefaultSearchTests.test_searchMessageSetUIDWithStarW      
 ))-FFr6   c                *    V P                  R. RO4      # )z
If the search filter starts with a star, the result should be identical
with if the filter would end with a star (also for the SEARCH UID case).
zUID *:10000rt  rp  rU   s   &r3   %test_searchMessageSetUIDWithStarFirst8DefaultSearchTests.test_searchMessageSetUIDWithStarFirst^  r~  r6   c                (    V P                  R^.4      # )zy
A search filter of 1234:* should include the UID of the last message in
the mailbox, even if its UID is less than 1234.
zUID 30000:*rp  rU   s   &r3   ,test_searchMessageSetUIDWithStarAndHighStart?DefaultSearchTests.test_searchMessageSetUIDWithStarAndHighStarte  s     ))-!==r6   c                (    V P                  R^.4      # )z
If the search filter contains nesting terms, one of which includes a
message sequence set with a wildcard, IT ALL WORKS GOOD.
z(6:*)rp  rU   s   &r3   test_searchMessageSetWithList0DefaultSearchTests.test_searchMessageSetWithListm  s     ))'A377r6   c                *    V P                  R^^.4      # )zj
If the search filter contains an I{OR} term, all messages
which match either subexpression are returned.
zOR 1 2rp  rU   s   &r3   r   DefaultSearchTests.test_searchOrw  s    
 ))(QF;;r6   c                *    V P                  R. RO4      # )z
If the search filter contains an I{OR} term with a
subexpression which includes a message sequence set wildcard,
all messages in that set are considered for inclusion in the
results.
z
OR 2:* 2:*rt  rp  rU   s   &r3   test_searchOrMessageSet*DefaultSearchTests.test_searchOrMessageSet~  s     )),EEr6   c                *    V P                  R. RO4      # )zn
If the search filter contains a I{NOT} term, all messages
which do not match the subexpression are returned.
zNOT 3)r   r   r  r   rp  rU   s   &r3   r  !DefaultSearchTests.test_searchNot  s    
 ))'<@@r6   c                (    V P                  R^.4      # )z
If the search filter contains a I{NOT} term with a
subexpression which includes a message sequence set wildcard,
no messages in that set are considered for inclusion in the
result.
zNOT 2:*rp  rU   s   &r3   test_searchNotMessageSet+DefaultSearchTests.test_searchNotMessageSet  s     )))aS99r6   c                (    V P                  R^.4      # )z
If the search filter contains multiple terms implicitly
conjoined with a message sequence set wildcard, only the
intersection of the results of each term are returned.
z2:* 3rp  rU   s   &r3   test_searchAndMessageSet+DefaultSearchTests.test_searchAndMessageSet  s     ))'A377r6   c                (  a a RoVV 3R lpS P                   P                  \        V4      4      pS P                  V\        P
                  4      pV 3R lpVP                  V4       VP                  S P                  4       S P                  4        V# )z
If the search criteria is not a valid key, a NO result is returned to
the client (resulting in an error callback), and an IllegalQueryError is
logged on the server side.
FOOc                 :   < SP                   P                  S 4      # r/   re  rf  s   r3   r	  =DefaultSearchTests.test_searchInvalidCriteria.<locals>.search  r  r6   c                T  < SP                   P                  P                  4        SP                  P                  P                  4        SP	                  \
        P                  4      pSP                  \        V4      ^4       SP                  \        R4      \        V 4      4       R# )s
Verify that the server logs an IllegalQueryError and the
client raises an IMAP4Exception with 'Search failed:...'
s)   SEARCH failed: Invalid search command FOON
r  rj  rk  r~  r#  r   rq  rB   r   r   rB  r  rE   s   & r3   errorReceivedDDefaultSearchTests.test_searchInvalidCriteria.<locals>.errorReceived  s}    
 KK!!002KK!!002 ++E,C,CDFS[!, @AGr6   	r  r   r7   r  r   r  r  r  r"   )rE   r	  r   r  rg  s   f   @r3   test_searchInvalidCriteria-DefaultSearchTests.test_searchInvalidCriteria  sr     
	2 NN&&uV}5q%"6"67	$ 	
m$	T__%r6   )r  r  r
  r~  N)rx   ry   rz   r{   rZ  r  r  rm  rq  ru  ry  r|  r  r  r  r  r  r  r  r  r  r|   r0   r6   r3   r^  r^    s\    

H24??GG>8<FA:8#r6   r^  c                  V    ] tR tRtR tR tR t]tR tR t	R t
R tR	 tR
 tR tRtR# )FetchSearchStoreTestsi  c                	8   R ;V n         V n        R V n        R V n        R V n        R V n        \        P                  ! 4       V n        RV P                  n	        W P                  n
        \        P                  ! 4       V n        \        V P                  4      V n        R # r	  )r  r1   server_received_queryserver_received_uidserver_received_partsserver_received_messagesr   rH  r~  r  r  r   r   r  rZ  r  rU   s   &r3   r  FetchSearchStoreTests.setUp  st    &**%)"#' %)"(,%'')$)"4>>2r6   c                	n    VR .8X  d   \         P                  ! R4      hWn        W n        V P                  # )r8  z"FOO is not a valid search criteria)r   rq  r  r  r  )rE   rZ  r  s   &&&r3   r	  FetchSearchStoreTests.search  s4    VH))*NOO%*"#& }}r6   c                	    R # r/   r0   )rE   r  rP  s   &*,r3   r  !FetchSearchStoreTests.addListener  r  r6   c                	v  a a V V3R  lpV 3R lpS P                   P                  \        V4      4      P                  V4      P                  S P                  4      P	                  S P
                  4       V 3R lp\        P                  ! S P                  S P                  RR7      pVP                  V4       V# )c                 R   < S P                   P                  S P                  SR 7      # )rU  )r  r	  rZ  r
  s   r3   r	  1FetchSearchStoreTests._searchWork.<locals>.search  s!    ;;%%djjc%::r6   c                   < V Sn         R # r/   r
  r
  s   &r3   r1   1FetchSearchStoreTests._searchWork.<locals>.result  r
  r6   c                  < SP                  SP                  SP                  J 4       SP                  SP                  SP                  4       SP                  SP                  SP
                  4       SP                  \        P                  ! SP                  P                  R 4      4      SP                  4       R# )charmapN)r  r1   r  rB   r  r  r   r  rZ  rC   r  r
  s   &r3   r  0FetchSearchStoreTests._searchWork.<locals>.check  s    T[[DMM9:T[[$--8TXXt'?'?@ ''

(9(9)(DE**	r6   Fr
  r
  )rE   r  r	  r1   r  r   s   ff    r3   _searchWork!FetchSearchStoreTests._searchWork  s    	;	 	""5=1==fEQQ	

*T__
%	   dkkG	er6   c                	    \         P                  ! \         P                  ! RR7      \         P                  ! RRR7      4      V n        . ROV n        ^ V n        V P                  ^ 4      # )r   r        rS  rQ  r   	substring)r   r  r   r   )r   rX  rW  rZ  r  r  r  rU   s   &r3   
testSearch FetchSearchStoreTests.testSearch  sN    XXKK78KKtT2

 %""r6   c                	    \         P                  ! \         P                  ! RR7      \         P                  ! RRR7      4      V n        ^V n        . ROV n        V P                  ^4      # )r   r  r  r  r  r  r   )r   rX  rW  rZ  r  r  r  rU   s   &r3   testUIDSearch#FetchSearchStoreTests.testUIDSearch  sN    XXKK78KKtT2

 !""r6   c                	     V P                   V,          R ,          #   \        \        3 d    T P                   T^,
          ,          u # \         d     ^*# i ; i)r  )r  r   
IndexErrorKeyErrorrE   r   s   &&r3   r  FetchSearchStoreTests.getUID  sM    	==%e,,:& 	*==q)) 		s    +A	AAAc                	F    W n         \        V4      V n        V P                  # r/   )r  r   r  r  r  s   &&&r3   r  FetchSearchStoreTests.fetch  s    #& (+H%}}r6   c                	f  a  V 3R  lpS P                   P                  \        V4      4      P                  V4      P                  S P                  4      P	                  S P
                  4       V 3R lp\        P                  ! S P                  S P                  RR7      pVP                  V4       V# )c                   < V Sn         R # r/   r
  r
  s   &r3   r1   0FetchSearchStoreTests._fetchWork.<locals>.result  r
  r6   c                  < SP                  SP                  SP                  J 4       SP                  ;'       d    SP                  P	                  4        SP
                  ;'       d    SP
                  P	                  4        SP                  '       d2   SP                  P                  4        F  w  r\        V4      VR &   K  	  SP                  SP                  SP                  4       SP                  SP                  SP                  4       SP                  SP                  SP
                  4       SP                  \        P                  ! SP                  4      \        P                  ! SP                  4      4       R# )r  N)r  r1   r  r6  r  r  r  r  r   rB   r  r   r   rj  r  )r  kvrE   s   &  r3   r  /FetchSearchStoreTests._fetchWork.<locals>.check%  s   T[[DMM9:JJ,,4::??,&&LL4+E+E+J+J+Lxxx MM//1DA"1vAeH 2 T[[$--8TXXt'?'?@TZZ)C)CD!!$--0!!$"?"?@r6   Fr
  r
  )rE   r  r1   r  r   s   f&   r3   r
   FetchSearchStoreTests._fetchWork  s    	 	""5<0<<VDPP	

*T__
%	&   dkkG	er6   c                (  a a RoVV 3R lpS P                   P                  \        V4      4      pS P                  V\        P
                  4      pV 3R lpVP                  V4       VP                  S P                  4       S P                  4        V# )z
If, as part of a search, an ISearchableMailbox raises an
IllegalQueryError (e.g. due to invalid search criteria), client sees a
failure response, and an IllegalQueryError is logged on the server.
r  c                 :   < SP                   P                  S 4      # r/   re  )rZ  rE   s   r3   r	  6FetchSearchStoreTests.test_invalidTerm.<locals>.searchD  s    ;;%%e,,r6   c                T  < SP                   P                  P                  4        SP                  P                  P                  4        SP	                  \
        P                  4      pSP                  \        V4      ^4       SP                  \        R4      \        V 4      4       R# )r  s1   SEARCH failed: FOO is not a valid search criteriaNr  r  s   & r3   r  =FetchSearchStoreTests.test_invalidTerm.<locals>.errorReceivedJ  s|    
 KK!!002KK!!002 ++E,C,CDFS[!, HI3w<r6   r  )rE   r	  r   r  rZ  s   f   @r3   test_invalidTerm&FetchSearchStoreTests.test_invalidTerm<  sr     	- NN&&uV}5q%"6"67	" 	
m$	T__%r6   )r  r  r  rZ  r1   r~  r  r  r  r  r  N)rx   ry   rz   r{   r  r	  r  r  r  r  r  r  r  r
  r  r|   r0   r6   r3   r  r    s;    3 !N8##
>"r6   r  c                  "    ] tR tRtR tR tRtR# )FakeMailboxia  c                	    . V n         R # r/   rO  rU   s   &r3   r   FakeMailbox.__init__b  	    	r6   c                	h    V P                   P                  WV34       \        P                  ! R 4      # r/   )rO  r   r   r  )rE   r   r  r  s   &&&&r3   r  FakeMailbox.addMessagee  s(    		$t,-}}T""r6   r  N)rx   ry   rz   r{   r   r  r|   r0   r6   r3   r  r  a  s    #r6   r  c                  (    ] tR tRtR tR tR tRtR# )FeaturefulMessageij  c                	    R # r  r0   rU   s   &r3   r  FeaturefulMessage.getFlagsl  s    r6   c                	    R # )r  r0   rU   s   &r3   r	  !FeaturefulMessage.getInternalDateo  s    r6   c                	    \        R 4      # )   openr   rU   s   &r3   r  FeaturefulMessage.openr  s    wr6   r0   N)rx   ry   rz   r{   r  r	  r  r|   r0   r6   r3   r  r  j  s     r6   r  c                  "    ] tR tRtR tR tRtR# )MessageCopierMailboxiv  c                	    . V n         R # r/   msgsrU   s   &r3   r   MessageCopierMailbox.__init__x  r  r6   c                	b    V P                   P                  V4       \        V P                   4      # r/   )r  r   r   r  s   &&r3   r	  MessageCopierMailbox.copy{  s"    		499~r6   r  N)rx   ry   rz   r{   r   r	  r|   r0   r6   r3   r  r  v  s    r6   r  c                  (    ] tR tRtR tR tR tRtR# )CopyWorkerTestsi  c                	   a a \         P                  ! 4       pVP                  p\        4       oT! \	        ^^4       Uu. uF  q3\        4       3NK  	  upRS4      pVV 3R lpVP                  V4      # u upi )r   r  c                <  < SP                    F\  pSP                  V^ ,          P                  4       R4       SP                  V^,          R4       SP                  V^,          R4       K^  	  V  F(  w  r#SP                  V4       SP                  VR4       K*  	  R# )r  r  r  r  N)rO  rB   r[   r  )rB  r  rb  r1   r  rE   s   &   r3   cbCopy5CopyWorkerTests.testFeaturefulMessage.<locals>.cbCopy  s}    VV  1g6  1w/  1~6 
 #*'  . #*r6   )r   rH  _IMAP4Server__cbCopyr  rr   r  r   )rE   r  r2   r   r   r  r  s   f     @r3   testFeaturefulMessage%CopyWorkerTests.testFeaturefulMessage  sj     ""Mq">A$&'>qI	/ }}V$$ ?s   A3c                	  a a \         P                  ! 4       pVP                  p\        4       o\	        ^^4       Uu. uF-  p\        R\        V4      /RRRV3,          V^
,           R4      NK/  	  ppT! \        \	        ^^4      V4       Uu. uF  qUNK  	  upRS4      pVV 3R lpVP                  V4      # u upi u upi )r   zHeader-Counter   Dates   Body %dNr  c                  < . pSP                    F[  pVP                  V^ ,          P                  4       4       SP                  V^,          R4       SP                  V^,          R4       K]  	  VP	                  4        \        R \        ^^4       4       4      pSP                  W4       V  F(  w  rESP                  V4       SP                  VR4       K*  	  R# )r  r  c              3  6   "   T F  pR W3,          x  K  	  R# 5i)s   Header-Counter: %d

Body %dNr0   rP  s   & r3   rR  JCopyWorkerTests.testUnfeaturefulMessage.<locals>.cbCopy.<locals>.<genexpr>  s      GS!4v==|s   Nr0   )rO  r   r[   rB   r  r  rr   r  )rB  seenr  exprb  r1   r  rE   s   &     r3   r  7CopyWorkerTests.testUnfeaturefulMessage.<locals>.cbCopy  s    DVVAaDIIK(  1r*  1w/ 
 IIK GLQPR| C T'")'  . #*r6   r0   )	r   rH  r  r  rr   r   r   r   r   )	rE   r  r2   r   r  imr   r  r  s	   f       @r3   testUnfeaturefulMessage'CopyWorkerTests.testUnfeaturefulMessage  s     ""M
 1b\	
 " !3q6*Bqd9JAPRFTX "	 	 
 Cad343br34eQ?	/" }}V$$3
 5s   3B6
B;c                	F  a aa \         P                  ! 4       pVP                  p\        4       o\	        ^^4       Uu. uF  p\        4       NK  	  upoT! \        \	        ^^4      S4       Uu. uF  qDNK  	  upRS4      pVVV 3R lpVP                  V4      # u upi u upi )r   s   tagc                   < SP                  V \        \        ^.^
,          \        ^^4      4      4      4       \        SSP                  4       F  w  rSP                  W4       K  	  R# r  )rB   r   r   rr   r  r   )rB  origrN  r  r  rE   s   &  r3   r  1CopyWorkerTests.testMessageCopier.<locals>.cbCopy  sP    Wd3sRxq"+F&GH qvv.	$$T/ /r6   )r   rH  r  r  rr   objectr   r   )	rE   r  r2   r   r  r   r  r  r  s	   f      @@r3   testMessageCopier!CopyWorkerTests.testMessageCopier  s     "" ""'2,/,Q,/Cad343br34fa@	0
 }}V$$ 04s   B-
Br0   N)rx   ry   rz   r{   r  r  r  r|   r0   r6   r3   r  r    s    %8 %D%r6   r  zOpenSSL not presentzReactor doesn't support SSLc                      ] tR tRtRtRt]'       d   ]! 4       t]'       d   ]! 4       tR tR t	R t
R tR tR R	 ltR
 tR tR tR tRtR# )TLSTestsi  Nc                	\    \         P                  ! V P                  V P                  R R7      # )Fr
  )r"   r
  r~  r  rU   s   &r3   r"   TLSTests.loopback  s    ##DKKEJJr6   c                	  a a	a
 \         P                  P                  R 4       . o	V	V 3R lpV	V 3R lpV	V 3R lpV	V 3R lpV	V 3R lpRS P                  n        WW4V.o
S
 F'  pS P
                  P                  \        V4      4       K)  	  S P
                  P                  S P                  S P                  4       V	V
V 3R lpS P                  4       pVP                  V4       V# )r  c                 ^   < S P                  R 4       SP                  P                  RR4      # )NrC  rG  )r   r  r  calledrE   s   r3   r  )TLSTests.testAPileOfThings.<locals>.login  s'    MM$;;$$[2BCCr6   c                 ^   < S P                  R 4       SP                  P                  RR4      # )Nr     %)r   r  r   r  s   r3   r   (TLSTests.testAPileOfThings.<locals>.list  s&    MM$;;##Hd33r6   c                 ^   < S P                  R 4       SP                  P                  RR4      # )Nr  r  )r   r  rb  r  s   r3   rb  *TLSTests.testAPileOfThings.<locals>.status  s&    MM$;;%%h	::r6   c                 \   < S P                  R 4       SP                  P                  R4      # )Nr  )r   r  r  r  s   r3   r  +TLSTests.testAPileOfThings.<locals>.examine  s$    MM$;;&&x00r6   c                 Z   < S P                  R 4       SP                  P                  4       # r/   )r   r  r  r  s   r3   r  *TLSTests.testAPileOfThings.<locals>.logout  s"    MM$;;%%''r6   Tc                   < SP                  SP                  P                  R 4       SP                  SP                  P                  R 4       SP                  \	        S4      \	        S4      4       R# r  )rB   r~  
startedTLSr  r   )r  r  methodsrE   s   &r3   r  )TLSTests.testAPileOfThings.<locals>.check  sO    T[[33T:T[[33T:S[#g,7r6   )rB  rX  ra  r  requireTransportSecurityr  r   r7   r  r  r  r"   )rE   r  r   rb  r  r  r  r  r   r  r"  s   f        @@r3   testAPileOfThingsTLSTests.testAPileOfThings  s    **84	D	4	;	1	( 04,8FNN&&uV}5  	##D$6$6H	8
 MMO	er6   c                	  a a S P                   P                  P                  R R4       . oS P                  P	                  \
        P                  ! R 4      4       S P                  P                  V 3R l4      P                  V 3R l4      P                  SP                  4      P                  S P                  4      P                  S P                  4       S P                  4       pVP                  V V3R l4       V# )rC  rG  c                :   < SP                   P                  R 4      # )rG  r  r  s   &r3   r4   )TLSTests.testLoginLogin.<locals>.<lambda>  s    dkk../?@r6   c                8   < SP                   P                  4       # r/   )r  r  r  s   &r3   r4   r)    s     2 2 4r6   c                :   < SP                  \        S4      ^4      # r  )rB   r   r  rE   successs   &r3   r4   r)    s     0 0Wq Ar6   )r~  rK  rJ  r  r#  r   r"  r  r   r   r  r  r  r"   )rE   r   r-  s   f @r3   testLoginLoginTLSTests.testLoginLogin  s    ##K1AB))%*B*B;*OP""@	

+4
5kkNN7

+

*OO
 MMO	ABr6   c                  a a . oS P                   P                  \        S P                  P                  4      4       V 3R lpS P                   P                  V4       S P                   P                  SP
                  4       S P                  4       pVP                  V V3R l4       \        P                  ! VS P                   .4      # )z
Begin a C{STARTTLS} sequence and assert that it results in a
TLS session.

@return: A L{Deferred} that fires when the underlying
    connection between the client and server has been terminated.
c                   < SP                  \        P                  P                  SP                  P
                  4      4       R # r/   )r  r   ISSLTransport
providedByr  rj  r
  s   &r3   checkSecure6TLSTests.startTLSAndAssertSession.<locals>.checkSecure$  s*    OOJ44??@U@UVWr6   c                &   < SP                  S4      # r/   )r  r,  s   &r3   r4   3TLSTests.startTLSAndAssertSession.<locals>.<lambda>+  s     8r6   )	r  r   r7   r  startTLSr   r"   r   r  )rE   r4  r   r-  s   f  @r3   startTLSAndAssertSession!TLSTests.startTLSAndAssertSession  s     ""5)=)=#>?	X 	"";/""7>>2MMO	89""At~~#677r6   c                    V P                  4       pV P                  P                  V P                  4       V P                  P	                  V P
                  4       V# )z
L{IMAP4Client.startTLS} triggers TLS negotiation and returns a
L{Deferred} which fires after the client's transport is using
encryption.
)r9  r  r   r  r  r  rE   disconnecteds   & r3   test_startTLSTLSTests.test_startTLS.  sF     446""4#5#56!!$//2r6   c                   V ^8  d   QhRR/# )r   returnzDeferred[object]r0   )formats   "r3   __annotate__TLSTests.__annotate__9  s     
 
&6 
r6   c                &   V P                  V P                  P                  4       RV P                  n        V P                  4       pV P                  P                  V P                  4       V P                  P                  V P                  4       V# )zL
L{IMAPClient.startTLS} supplies a default TLS context if none is
supplied.
N)	assertIsNotNoner  contextr9  r  r   r  r  r  r<  s   & r3   test_startTLSDefaultTLSTests.test_startTLSDefault9  sj    
 	T[[001")-)F)F)H""4#5#56!!$//2r6   c                    ! R R\         4      pV! V P                  V P                  R7      V n        V P	                  4       pV P                  P                  \        V P                  P                  4      4       V P                  P                  V P                  R4       V P                  P                  V P                  4       V P                  P                  V P                  4       V# )zE
A server that receives a second C{STARTTLS} sends a C{NO}
response.
c                      ] tR tRtR tRtR# ):TLSTests.test_doubleSTARTTLS.<locals>.DoubleSTARTTLSClientiK  c                	    V P                   '       g   \        P                  V 4      # V P                  \        P
                  ! R 4      4      # )s   STARTTLS)r!  rZ  r8  r  r   r_  rU   s   &r3   r8  CTLSTests.test_doubleSTARTTLS.<locals>.DoubleSTARTTLSClient.startTLSL  s6    '0066''k(BCCr6   r0   N)rx   ry   rz   r{   r8  r|   r0   r6   r3   DoubleSTARTTLSClientrL  K  s    Dr6   rO  r}  s   TLS already negotiated)rZ  r  r{  r  r9  r   r7   r8  r  r  r  r  )rE   rO  r=  s   &  r3   test_doubleSTARTTLSTLSTests.test_doubleSTARTTLSE  s    	D< 	D +NN4>>
 446""5)=)=#>?!!++-F	
 	""4#5#56!!$//2r6   c                  a  R\         P                  R\         P                  /S P                  n        \
        P                  V 3R l4       pS P                  P                  \        V4      4       S P                  4       pS P                  P                  \        V4      4       S P                  P                  S P                  4       S P                  P                  S P                  4       V# )z
Starting a TLS negotiation with an L{IMAP4Server} that already
has C{LOGIN} and C{PLAIN} L{IChallengeResponse} factories uses
those factories.
r-  r  c               3     <"   SP                   P                  4       x p SP                  R V 4       SP                  RV R ,          4       SP                  RV R ,          4       R# 5i)r  r-  r  N)r  r  r9  r(  s    r3   assertLOGINandPLAINJTLSTests.test_startTLSWithExistingChallengers.<locals>.assertLOGINandPLAINm  sO     !%!<!<!>>LMM'<0MM(L$9:MM(L$9:s   A#A&)r   r!  r  r~  r  r   r  r  r   r7   r9  r  r  r  )rE   rT  r=  s   f  r3   $test_startTLSWithExistingChallengers-TLSTests.test_startTLSWithExistingChallengersb  s     e,,e,,#

 
			; 
	; 	""5)<#=>446""5)<#=>""4#5#56!!$//2r6   c                  a  R S P                   n        S P                  P                  V 3R l4       S P                  P	                  S P
                  R4       S P                  P                  S P                  4       S P                  P	                  S P                  4       \        P                  ! S P                  4       S P                  .4      # )zd
A client that attempts to log in before issuing the
C{STARTTLS} command receives a C{NO} response.
c                 2    \         P                  ! . R 34      # )zOK Begin TLS negotiation now)r   r  r0   r6   r3   r4   3TLSTests.test_loginBeforeSTARTTLS.<locals>.<lambda>  s    u}}/0(
r6   c                <   < SP                   P                  R R4      # )s   wrongs   timer  r  s   &r3   r4   rZ    s    dkk''':r6   s!   LOGIN is disabled before STARTTLS)r  r8  r  r   r  r  r  r  r   r  r"   rU   s   fr3   test_loginBeforeSTARTTLS!TLSTests.test_loginBeforeSTARTTLS  s     
 	"":	
 	!!++0	

 	""4#5#56!!$//2""DMMOT^^#DEEr6   c                	  a a . oV 3R  lpS P                   P                  V4       S P                   P                  V 3R l4       S P                   P                  V3R l4       S P                   P                  S P                  4       S P                   P                  S P                  4       VV 3R lpS P                  4       P                  V4      # )c                *   < R SP                   n        R# )FN)r~  canStartTLSr,  s   &r3   breakServerTLS3TLSTests.testFailedStartTLS.<locals>.breakServerTLS  s    &+DKK#r6   c                8   < SP                   P                  4       # r/   )r  r8  r,  s   &r3   r4   -TLSTests.testFailedStartTLS.<locals>.<lambda>  s    t{{/C/C/Er6   c                `   < SP                  V P                  \        P                  4      4      # r/   )r   r  r   r  )r  r  s   &r3   r4   rd    s    1E1E(FGr6   c                x   < SP                  S4       SP                  S^ ,          \        P                  4       R# r  )r  r   r   r  )r  r  rE   s   &r3   r  *TLSTests.testFailedStartTLS.<locals>.check  s)    OOH%  !e.B.BCr6   )r  r   r  r  r  r"   )rE   ra  r  r  s   f  @r3   testFailedStartTLSTLSTests.testFailedStartTLS  s    	, 	"">2""#EF!!G	
 	""4#5#56!!$//2	D }}**511r6   )r  )rx   ry   rz   r{   rz  r{  r,   r+   r"   r%  r.  r9  r>  rH  rP  rV  r\  rh  r|   r0   r6   r3   r  r    sY     II$&	$&	K'R$8*	
::F.2r6   r  c                  (    ] tR tRt^tRtRtR tRtR# )SlowMailboxi  Nc                	    \         P                  ! 4       pV P                  V P                  VP                  R4       V P
                  P	                  R 4       V# )Nr0   )r   r   	callLaterhowSlowrb  fetchDeferred)rE   rj  r  r   s   &&& r3   r  SlowMailbox.fetch  s?    NNt||QZZ4##D)r6   r0   )	rx   ry   rz   r{   rn  rm  ro  r  r|   r0   r6   r3   rk  rk    s    GIMr6   rk  c                  :    ] tR tRtR tR tR tR tR tR t	Rt
R	# )
TimeoutTestsi  c                  a aa \        4       oRS P                  n        ^S P                  n        SP
                  S P                  n        RS n        VV V3R lpV 3R loS P                  P                  \        V4      4      pVP                  S P                  4       \        P                  ! VS P                  4       .4      # )zc
The *client* has a timeout mechanism which will close connections that
are inactive for a period.
TNc                    < SP                   P                  R R4      p SP                  ^4       V P                  S4       V # r  )r  r  advancer  )r   r   rE   timedOuts    r3   r  .TimeoutTests.test_serverTimeout.<locals>.login  s6    !!+/?@AIIaLLL"Hr6   c                j   < SP                  R 4       V P                  ! \        P                  4       R # r/   )r  r  r   TimeoutErrorr  s   &r3   rv  1TimeoutTests.test_serverTimeout.<locals>.timedOut  s#    t$LL++,r6   )r   r~  rN  r  r	  rm  r\  r  r   r7   r  r  r   r  r"   )rE   r  r   r   rv  s   f  @@r3   test_serverTimeoutTimeoutTests.test_serverTimeout  s    
 G"& ! 		- NN&&uU|4	T__%""At}}#788r6   c                2  a a \        4       oSP                  S P                  n        V 3R lpVV 3R lpS P                  P	                  \        V4      4      pVP	                  \        V4      4       \        P                  ! VS P                  4       .4      # )z$
The server times out a connection.
c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  /TimeoutTests.test_serverTimesOut.<locals>.login  r   r6   c                 `   < S P                  SP                  P                  ^,          4       R# r   Nru  r~  POSTAUTH_TIMEOUTr   rE   s   r3   
expireTime4TimeoutTests.test_serverTimesOut.<locals>.expireTime      IIdkk22Q67r6   )	r   rm  r~  r  r   r7   r   r  r"   )rE   r  r  r   r   s   f   @r3   test_serverTimesOut TimeoutTests.test_serverTimesOut  sp     G !	D	8 NN&&uU|4	eJ'(
 ""At}}#788r6   c                
  a aa S P                  \        P                  R\        4       \        P                  P	                  R4       \        P                  P
                  R,          oS P                  \        P                  ! S4      4       \        4       oSP                  S P                  n
        V 3R lpV 3R lpVV 3R lpVV 3R lpV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      4       VP                  \        V4      4       VP                  \        V4      4       VP                  \        V4      4       \        P                   ! VS P#                  4       .4      # )	zF
The server unsets the selected mailbox when timing out a
connection.
r5  mailbox-testMAILBOX-TESTc                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  7TimeoutTests.test_serverUnselectsMailbox.<locals>.login  r   r6   c                 :   < S P                   P                  R 4      # r  ri  rU   s   r3   r<  8TimeoutTests.test_serverUnselectsMailbox.<locals>.select  rk  r6   c                 T   < SP                  S SP                  P                  4       R # r/   )r<
  r~  r  r  rE   s   r3   	assertSet;TimeoutTests.test_serverUnselectsMailbox.<locals>.assertSet  s    MM$ 0 01r6   c                 `   < S P                  SP                  P                  ^,          4       R# r  r  r  s   r3   r  <TimeoutTests.test_serverUnselectsMailbox.<locals>.expireTime  r  r6   c                 R   < S P                  S P                  P                  4       R # r/   )r  r~  r  rU   s   r3   assertUnset=TimeoutTests.test_serverUnselectsMailbox.<locals>.assertUnset  s    T[[--.r6   )r  rB  rX  r  ra  rx  r  r!   r3  r   rm  r~  r  r   r7   r   r  r"   )	rE   r  r<  r  r  r  r   r   r  s	   f      @@r3   test_serverUnselectsMailbox(TimeoutTests.test_serverUnselectsMailbox  s   
 	

<**,<>PQ**>:&&00@.99$?@G !	D	6	2	8	/ NN&&uU|4	eFm$	eI&'	eJ'(	eK()
 ""At}}#788r6   c                  a aa \         P                  P                  R4       \         P                  P                  R,          o\	        \
        S4       \        4       oSP                  S P                  n        V 3R lpV 3R lpVV 3R lpVV 3R lpVV 3R lpS P                  P                  \        V4      4      pVP                  \        V4      4       VP                  \        V4      4       VP                  \        V4      4       VP                  \        V4      4       \        P                  ! VS P                  4       .4      # )zQ
The server closes the selected, closeable mailbox when timing
out a connection.
r  r  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  ?TimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.login  r   r6   c                 :   < S P                   P                  R 4      # r  ri  rU   s   r3   r<  @TimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.select  rk  r6   c                 >   < SP                  S P                  4       R # r/   )r  r  r  s   r3   assertMailboxOpenKTimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.assertMailboxOpen!  s    T[[)r6   c                 `   < S P                  SP                  P                  ^,          4       R# r  r  r  s   r3   r  DTimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.expireTime$  r  r6   c                 >   < SP                  S P                  4       R # r/   )r  r  r  s   r3   assertMailboxClosedMTimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.assertMailboxClosed'  s    OODKK(r6   )rB  rX  ra  rx  r   r!   r   rm  r~  r  r   r7   r   r  r"   )	rE   r  r<  r  r  r  r   r   r  s	   f      @@r3   #test_serverTimesOutAndClosesMailbox0TimeoutTests.test_serverTimesOutAndClosesMailbox  s    
 	**>:&&00@*D1G !	D	6	*	8	) NN&&uU|4	eFm$	e-./	eJ'(	e/01
 ""At}}#788r6   c                v  a a \        4       oSP                  \        n        \        P                  ! 4       \        n        SP                  S P                  n        \        \        P                  n	        \        P                  P                  R4       S P                  P                  ^4       V 3R lpV 3R lpV 3R lpV 3R lpV3R lp\        P
                  P                  V4       S P                  P                  \        V4      4      pVP                  \        V4      4       VP                  \        V4      4       VP                  \        V4      4       VP                  S P                  4       VP!                  S P"                  4       \        P$                  ! VS P'                  4       .4      pV# )z=
The connection timeout does not take effect during fetches.
r  c                 <   < S P                   P                  R R4      # r  r  rU   s   r3   r  7TimeoutTests.test_longFetchDoesntTimeout.<locals>.loginB  r   r6   c                 p   < S P                   P                  ^4       S P                  P                  R4      # )r   r  )r~  
setTimeoutr  r<  rU   s   r3   r<  8TimeoutTests.test_longFetchDoesntTimeout.<locals>.selectE  s*    KK""1%;;%%n55r6   c                 :   < S P                   P                  R 4      # )r   r
  rU   s   r3   r  7TimeoutTests.test_longFetchDoesntTimeout.<locals>.fetchI  s    ;;''..r6   c                 T   < S P                  S P                  P                  R 4       R# )r	  N)r   r~  r  rU   s   r3   stillConnected@TimeoutTests.test_longFetchDoesntTimeout.<locals>.stillConnectedL  s     1 19=r6   c                N   < \        ^4       F  pSP                  R4       K  	  R# )r  g      ?N)rr   ru  )r  r   r   s   & r3   	cbAdvance;TimeoutTests.test_longFetchDoesntTimeout.<locals>.cbAdvanceO  s    1X		# r6   )r   rm  rk  r   r   ro  r~  rB  rX  r5  ra  r  r   r  r7   r  r  r  r  r"   )	rE   r  r<  r  r  r  r  r   r   s	   f       @r3   test_longFetchDoesntTimeout(TimeoutTests.test_longFetchDoesntTimeout5  s&    G !$)NN$4! !1<.**>:q!	D	6	/	>	 	!!--i8^^''e5
uV}%
uU|$
u^,-
t))*
doo&T]]_ 56r6   c                6  aa \        4       p\        4       pV P                  Vn        VP                  V P                  n        V P                  P                  V4       . oV P                  P                  oVV3R lV P                  n        VP                  R.V P                  P                  R,          .^,          ,           4       V P                  SS4       VP                  RV P                  P                  R,          .4       V P                  S4       R# )zc
The *server* has a timeout mechanism which will close connections that
are inactive for a period.
c                D   < SP                  R 4      S! V 4      3^,          # r/   )r   )reasonconnLostlosts   &r3   r4   <TimeoutTests.test_idleClientDoesDisconnect.<locals>.<lambda>m  s&    KKV5
 5r6   g        g      @g       @N)r   r   r~  r!  rm  r  r  pumptimeOutr  r  )rE   r   rj  r  r  s   &  @@r3   test_idleClientDoesDisconnect*TimeoutTests.test_idleClientDoesDisconnect^  s    
 G46	![[	 !""9- ;;--&" 	
u++c12Q667t$ 	
T[[((3./0r6   )r\  N)rx   ry   rz   r{   r{  r  r  r  r  r  r|   r0   r6   r3   rr  rr    s#    929*%9N$9L'Rr6   rr  c                      ] tR tRtR tRtR# )DisconnectionTestsi{  c                	   \         P                  ! 4       p\        4       pVP                  V4       V P	                  VP                  R R4      \        P                  4      pVP                  \        P                  ! R4      4       V# )rC  zexample.comConnection closed)	r   r\  r   r  r  r  r   r  r  )rE   r   tr   s   &   r3   "testClientDisconnectFailsDeferreds5DisconnectionTests.testClientDisconnectFailsDeferreds|  sm    ,.	GGK/1E1E
 	
--.ABCr6   r0   N)rx   ry   rz   r{   r  r|   r0   r6   r3   r  r  {  s    r6   r  c                  &    ] tR tRtRtR tR tRtR# )SynchronousMailboxi  zV
Trivial, in-memory mailbox implementation which can produce a message
synchronously.
c                	    Wn         R # r/   ri  )rE   rj  s   &&r3   r   SynchronousMailbox.__init__  s     r6   c              #  	x   "   V'       d   Q R 4       hV F   pW0P                   V^,
          ,          3x  K"  	  R# 5i)zCannot handle uid requests.Nri  )rE   r  r  r   s   &&& r3   r  SynchronousMailbox.fetch  s3     555wC}}S1W--- s   8:ri  N)rx   ry   rz   r{   rZ  r   r  r|   r0   r6   r3   r  r    s    
!.r6   r  c            
          ] tR tRtRt]! / . RRRR4      ]! / . RRRR4      ]! / . RRRR4      .tR tR	 tR
 3R lt	R t
R tR tRtR# )PipeliningTestsi  zE
Tests for various aspects of the IMAP4 server's pipelining support.
r6   r  Nr     2c                	j   . V n         \        4       V n        \        P                  ! R R V P
                  4      V n        V P                  P                  V P                  4       \        V P                  4      pRV P                  n
        WP                  n        V P                  P                  4        R # r	  )	iteratorsr   rj  r   rH  iterateInReactorr~  r  r  rj  r  r  r  )rE   rR  s   & r3   r  PipeliningTests.setUp  s}    (*''dD4I4IJ""4>>2$T]]3 %" 	r6   c                h    \         P                  ! 4       pV P                  P                  W34       V# )z
A fake L{imap4.iterateInReactor} that records the iterators it
receives.

@param iterator: An iterator.

@return: A L{Deferred} associated with this iterator.
)r   r   r  r   )rE   iteratorr   s   && r3   r   PipeliningTests.iterateInReactor  s)     NNxm,r6   c                 	    R # )Tr0   r0   r6   r3   r4   PipeliningTests.<lambda>  s    Dr6   c                t   V P                   '       d   V! 4       '       d   V P                   ^ ,          ^ ,           FE  pV P                  P                  '       g   K!  V P                  P                  P                  4        KD  	  V P                   P	                  ^ 4      ^,          P                  R4       K  R# R# )aN  
Advance pending iterators enqueued with L{iterateInReactor} in
a round-robin fashion, resuming the transport's producer until
it has completed.  This ensures bodies are flushed.

@param asLongAs: (optional) An optional predicate function.
    Flushing iterators continues as long as there are
    iterators and this returns L{True}.
N)r  rj  producerr   rO  rb  )rE   asLongAses   && r3   flushPendingPipeliningTests.flushPending  s     nnn^^A&q))nn---NN++;;= * ""1%a(11$7 ",nr6   c                	    V P                   P                  \        P                  ! \        P
                  ! 4       4      4       R # r/   r  rU   s   &r3   r  PipeliningTests.tearDown  r  r6   c                l   V P                   P                  R4       V P                  4        V P                  V P                  P                  4       RP                  R\        R\        V P                  ^ ,          P                  4       P                  4       4      : 24      R\        R\        V P                  ^,          P                  4       P                  4       4      : 24      R\        R\        V P                  ^,          P                  4       P                  4       4      : 24      .4      4       R	# )
zh
Test that pipelined FETCH commands which can be responded to
synchronously are responded to correctly.
s9   01 FETCH 1 BODY[]
02 FETCH 2 BODY[]
03 FETCH 3 BODY[]
r6      * 1 FETCH (BODY[] )
 01 OK FETCH completed
{5}


   * 2 FETCH (BODY[] )
z 02 OK FETCH completed
{5}


s   * 3 FETCH (BODY[] )
z 03 OK FETCH completed
{5}


N)r~  r  r  rB   rj  r  r   r(   r'   rj  r	  r[   rU   s   &r3   test_synchronousFetch%PipeliningTests.test_synchronousFetch  s     	  V	
 	NN  "HH.!'a(8(D(D(F(K(K(MNQ /!'a(8(D(D(F(K(K(MNQ /!'a(8(D(D(F(K(K(MNQ	
r6   c                   V P                   P                  R4       \        P                  ! \        \        . RO4      4      pV P                  VR7       V P                  V P                  P                  4       RP                  R\        R\        V P                  ^ ,          P                  4       P                  4       4      : 24      .4      4       V P                  P!                  4        V P                   P#                  RR7       V P%                  V P                  P                  4       4       V P                  4        V P                  V P                  P                  4       RP                  RR	\        R
\        V P                  ^,          P                  4       P                  4       4      : 24      .4      4       R# )z~
When a server status change occurs during an ongoing FETCH
command, the server status is buffered until the FETCH
completes.
s   01 FETCH 1,2 BODY[]
T)r  r6   r  z	{5}


)rl  r  s   * [READ-WRITE]
r  N)TTF)r~  r  	functoolspartialnextr
  r  rB   rj  r  r   r(   r'   rj  r	  r[   r  rh  r  )rE   twices   & r3   test_bufferedServerStatus)PipeliningTests.test_bufferedServerStatus  sa    	  !;< !!$-@(AB5)NN  "HH /!'a(8(D(D(F(K(K(MNQ	
	
 	 	$/ 	--/0NN  "HH /)!'a(8(D(D(F(K(K(MNQ
	
r6   )r  r~  rj  )rx   ry   rz   r{   rZ  r   rj  r  r  r  r  r  r  r|   r0   r6   r3   r  r    sk    
 	RS$d3RS$d3RS$d3H  %1 8"L!
F5
r6   r  c                  &    ] tR tRtRtR tR tRtR# )IMAP4ServerFetchTestsi-  zJ
This test case is for the FETCH tests that require
a C{StringTransport}.
c                	    \        4       V n        \        P                  ! 4       V n        R V P                  n        V P                  P                  V P                  4       R# )r<  N)r   rj  r   rH  r~  r  r  rU   s   &r3   r  IMAP4ServerFetchTests.setUp3  s>    (*'')$""4>>2r6   c                Z   V P                   P                  4        V P                  P                  R4       RpV P	                  V P                   P                  4       V4       V P                   P                  4        V P                  P                  \        P                  ! R4      4       R# )z
If by any chance, extra bytes got appended at the end of a valid
FETCH arguments, the client should get a BAD - arguments invalid
response.

See U{RFC 3501<http://tools.ietf.org/html/rfc3501#section-6.4.5>},
section 6.4.5,
s   0001 FETCH 1 FULLL
s+   0001 BAD Illegal syntax: Invalid Argument
r  N)	rj  r  r~  r  rB   r  r  r   r  )rE   r  s   & r3   "test_fetchWithPartialValidArgument8IMAP4ServerFetchTests.test_fetchWithPartialValidArgument9  sw     	  !:;C--/:""5#7#78K#LMr6   r  N)rx   ry   rz   r{   rZ  r  r  r|   r0   r6   r3   r  r  -  s    
3Nr6   r  c                  8    ] tR tRtRtR tR tR tR tR t	Rt
R	# )
LiteralTestsMixiniL  z{
Shared tests for literal classes.

@ivar literalFactory: A callable that returns instances of the
    literal under test.
c                :    \         P                  ! 4       V n        R# )z
Shared setup.
N)r   r   r]  rU   s   &r3   r  LiteralTestsMixin.setUpT  s     (r6   c                    V P                  RV P                  4      pV P                  RVP                  R4      4       V P	                  V P                  4       R# )zM
The literal returns L{None} when given less data than the
literal requires.
r  Ns
   incomplete)literalFactoryr]  r<
  ra   assertNoResult)rE   literals   & r3   test_partialWrite#LiteralTestsMixin.test_partialWriteZ  sC    
 %%dDMM:dGMM-89DMM*r6   c                    RpV P                  \        V4      V P                  4      pVP                  V4      pV P	                  V\
        4       V P                  V4       V P                  V P                  4       R# )zb
The literal returns an empty L{bytes} instance when given
exactly the data the literal requires.
   completeN)r   r   r]  ra   r  rM   r  r  rE   datar  leftovers   &   r3   test_exactWrite!LiteralTestsMixin.test_exactWritec  sa    
 %%c$i?==&h."DMM*r6   c                    RpV P                  \        R4      V P                  4      pVP                  V4      pV P	                  VR4       R# )z\
The literal returns any left over L{bytes} when given more
data than the literal requires.
s   completeleftoverr     leftoverN)r   r   r]  ra   rB   r  s   &   r3   test_overlongWrite$LiteralTestsMixin.test_overlongWritep  sB    
 #%%c+&6F==&;/r6   c                    V P                  ^ V P                  4      pRpVP                  V4      pV P                  W24       R# )zW
The literal returns an empty L{bytes} instance
when given an empty L{bytes} instance.
r  N)r   r]  ra   rB   )rE   r  r  r	  s   &   r3   test_emptyLiteral#LiteralTestsMixin.test_emptyLiteral|  s;    
 %%a7==&(r6   )r]  N)rx   ry   rz   r{   rZ  r  r  r
  r  r  r|   r0   r6   r3   r  r  L  s     )++
0
)r6   r  c                  8    ] tR tRtRt]P                  tR tRt	R# )LiteralStringTestsi  z#
Tests for L{self.literalFactory}.
c                &   RpRp\         P                  ! \        V4      V P                  4      p\	        V4       F  pVP                  V4       K  	  VP                  R4       V P                  V P                  4      pV P                  WQV34       R# )z
Calling L{imap4.LiteralString.callback} with a line fires the
instance's L{Deferred} with a 2-L{tuple} whose first element
is the collected data and whose second is the provided line.
   datar^  N)	r   LiteralStringr   r]  r&   ra   rb  r  rB   )rE   r  extrar  r   r1   s   &     r3   test_callback LiteralStringTests.test_callback  sx     %%c$i?4AMM! ! 	"%%dmm4/r6   r0   N)
rx   ry   rz   r{   rZ  r   r  r   r  r|   r0   r6   r3   r  r    s     ((N0r6   r  c                  >    ] tR tRtRt]P                  tR tR t	Rt
R# )LiteralFileTestsi  z!
Tests for L{imap4.LiteralFile}.
c                ~   RpRp\         P                  ! \        V4      V P                  4      p\	        V4       F  pVP                  V4       K  	  VP                  R4       V P                  V P                  4      pV P                  \        V4      ^4       Vw  rbV P                  VP                  4       R4       R# )z
Calling L{imap4.LiteralFile.callback} with a line fires the
instance's L{Deferred} with a 2-L{tuple} whose first element
is the file and whose second is the provided line.
r  r^  N)
r   LiteralFiler   r]  r&   ra   rb  r  rB   r[   rE   r  r  r  r   r1   dataFiles   &      r3   r  LiteralFileTests.test_callback  s     ##CIt}}=4AMM! ! 	"%%dmm4Va( '2r6   c                   RpRpV P                  \        P                  R^4       \        P                  ! \        V4      V P                  4      p\        V4       F  pVP                  V4       K  	  VP                  R4       V P                  V P                  4      pV P                  \        V4      ^4       Vw  rbV P                  VP                  4       R4       R# )a  
A L{imap4.LiteralFile} whose size exceeds the maximum
in-memory size spools its content to disk, and invoking its
L{callback} with a line fires the instance's L{Deferred} with
a 2-L{tuple} whose first element is the spooled file and whose second
is the provided line.
r  r^  _memoryFileLimitN)r  r   r  r   r]  r&   ra   rb  r  rB   r[   r  s   &      r3   test_callbackSpooledToDisk+LiteralFileTests.test_callbackSpooledToDisk  s     

5$$&8!<##CIt}}=4AMM! ! 	"%%dmm4Va( '2r6   r0   N)rx   ry   rz   r{   rZ  r   r  r   r  r$  r|   r0   r6   r3   r  r    s     &&N3,3r6   r  c                  >    ] tR tRtRtR tR tR tR tR t	R t
R	tR
# )WriteBufferTestsi  z!
Tests for L{imap4.WriteBuffer}.
c                	$    \        4       V n        R # r/   )r   rj  rU   s   &r3   r  WriteBufferTests.setUp  s    (*r6   c                    \         P                  ! V P                  4      pRVP                  ,          pVP	                  V4       V P                  V P                  P                  4       4       R# )zL
L{imap4.WriteBuffer} buffers writes that are smaller than its
buffer size.
rc  N)r   WriteBufferrj  
bufferSizera   r  r  rE   bufr  s   &  r3   r  "WriteBufferTests.test_partialWrite  sL    
 /cnn$		$--/0r6   c                    \         P                  ! V P                  4      pRVP                  ^,           ,          pVP	                  V4       V P                  V P                  P                  4       V4       R# )zq
L{imap4.WriteBuffer} writes data without buffering it when
the size of the data exceeds the size of its buffer.
rc  N)r   r+  rj  r,  ra   rB   r  r-  s   &  r3   r  #WriteBufferTests.test_overlongWrite  sS    
 /s~~)*		$--/6r6   c                f   \         P                  ! V P                  4      pRVP                  ,          pRpVP	                  V4       V P                  V P                  P                  4       4       VP	                  V4       V P                  V P                  P                  4       W#,           4       R# )zX
L{imap4.WriteBuffer} buffers writes until its buffer's size
exceeds its maximum value.
rc     yN)r   r+  rj  r,  ra   r  r  rB   )rE   r.  	firstData
secondDatas   &   r3   test_writesImplyFlush&WriteBufferTests.test_writesImplyFlush  s~    
 /3>>)	
		)--/0		*--/1GHr6   c                T   \         P                  ! V P                  4      pRVP                  ,          pVP	                  V4       V P                  V P                  P                  4       4       VP                  4        V P                  V P                  P                  4       V4       R# )zc
L{imap4.WriteBuffer.flush} flushes the buffer even when its
size is smaller than the buffer size.
rc  N)	r   r+  rj  r,  ra   r  r  flushrB   r-  s   &  r3   test_explicitFlush#WriteBufferTests.test_explicitFlush  sr    
 /s~~&		$--/0		--/6r6   c                    \         P                  ! V P                  4      pVP                  4        V P	                  V P                  P                  4       4       R# )zG
L{imap4.WriteBuffer.flush} has no effect if when the buffer is
empty.
N)r   r+  rj  r9  r  r  )rE   r.  s   & r3   test_explicitFlushEmptyBuffer.WriteBufferTests.test_explicitFlushEmptyBuffer  s<    
 /		--/0r6   )rj  N)rx   ry   rz   r{   rZ  r  r  r  r6  r:  r=  r|   r0   r6   r3   r'  r'    s&    +
1
7I"7 	1r6   r'  )rZ  
__future__r   r  rY   r  r
  r  r   collectionsr   ior   	itertoolsr   typingr   r   unittestr	   zope.interfacer
   zope.interface.verifyr   r   twisted.cred.checkersr   twisted.cred.credentialsr   r   r   twisted.cred.errorr   twisted.cred.portalr   r   twisted.internetr   r   r   r   twisted.internet.deferr   twisted.internet.taskr   twisted.internet.testingr   r   twisted.mailr   twisted.mail.imap4r   twisted.mail.interfacesr   r    r!   twisted.protocolsr"   twisted.pythonr#   r$   r%   twisted.python.compatr&   r'   r(   twisted.trial.unittestr)   r*   twisted.test.ssl_helpersr+   r,   ImportErrorr7   r9   r~   r   r   r\  IMailboxInfoIMailboxICloseableMailboxr  r  MemoryAccountWithoutNamespacesr3  r;  r?  rH  rB  r\  rZ  ry  r  r  r  rI  r  r  r  r  r  r=  rC  r  r  r  r  r  r	  r 	  rz	  r	  r	  r	  IMessageFancyStrMixinr   r	  r 
  r
  r^  ISearchableMailboxr  r  IMessageFiler  IMessageCopierr  r  IReactorSSLr  rk  rr  r  r  r  r  r  r  r  r'  r0   r6   r3   <module>rb     s   #     	  #   !  & ; I 
 1 . > > + ' V  ) 
 ' - - H H @K#b;X b;J "d). d)NHV) HVV
C+x C+L U1H1HIP P JPf U0T T 1TnuCC "&(;(; 35$$ 3,(5$$ (,., .,b_/' _/Da21 a2HdX-x dXN V@ @ @:" ""h4)8 h4V/
X /
ddT/ dTNL"H L"^
$** 
$L' L^B B6EI1 EIP13F (02E *+=57J +=\/=46I /=d\
35H \
~JT3X JTZ,=46I ,=^KS24G KS\%##  U^^$"4%% $" $"N?!H. ?!Da
H a
HK%H. K%\s)8 sl U%%&XH&6 X 'Xv# # U     !  U!!"  #N%h N%b 34J""7D113PQU2 U2 R 5U2p- #X D	 	. .T
h T
nNH N>:) :)z0*,? 0653(( 53pJ1* J1Qu  s   Q Q-,Q-