%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/mail/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/mail/test/__pycache__/test_imap.cpython-312.pyc

�

Ϫ�f�!����dZddlmZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZddl
mZddlmZmZddlmZdd	lmZdd
lmZmZddlmZddlmZmZmZdd
lm Z ddl!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;m<Z<m=Z=ddl>m?Z?m@Z@mAZAddlBmCZCmDZD	ddlEmFZFmGZGd�ZIGd�deD�ZJGd�d�ZKGd �d!eC�ZLGd"�d#eC�ZMGd$�d%eD�ZNee1j�e1j�e1j��Gd&�d'��ZRee1j�e1j��Gd(�d)��ZSGd*�d+e1j��ZUGd,�d-eUe1j��ZWGd.�d/e1j��ZYGd0�d1e1j��Z[Gd2�d3�Z\Gd4�d5e\eD�Z]Gd6�d7eC�Z^Gd8�d9e\eD�Z_ee"�Gd:�d;��Z`Gd<�d=�ZaGd>�d?e\eD�ZbGd@�dAeD�ZcGdB�dCe\eD�ZdGdD�dEeD�ZeGdF�dGe1j��ZfGdH�dIe\eD�ZgGdJ�dK�ZhGdL�dMeh�ZiGdN�dOeieC�ZjGdP�dQeieC�ZkGdR�dSeheC�ZlGdT�dUeheC�ZmGdV�dWeheC�ZnGdX�dYeheD�ZoGdZ�d[eheC�ZpGd\�d]eheC�ZqGd^�d_e1j��Zree1j��Gd`�dae=j���ZuGdb�dceDe\�ZvGdd�deeD�ZwGdf�dgeDe\�ZxGdh�die\eD�Zyee1j��Gdj�dkeDe\��Z{Gdl�dm�Z|ee1j��Gdn�do��Z~ee1j��Gdp�dq��Z�Gdr�dseD�Z�eeFdt�ee'�je(d�du�Gdv�dwe\eD���Z�Gdx�dyeR�Z�Gdz�d{e\eD�Z�Gd|�d}eD�Z�Gd~�d�Z�Gd��d�eD�Z�Gd��d�eD�Z�Gd��d��Z�Gd��d�e�eC�Z�Gd��d�e�eD�Z�Gd��d�eC�Z�y#eH$rdZFdZGY���wxYw)�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��|fd�S)Nc��|�S�N�)�result�fs  �=/usr/lib/python3/dist-packages/twisted/mail/test/test_imap.py�<lambda>zstrip.<locals>.<lambda>:s��q�s��r1)r3s r4�stripr79s���"�"r6c�d�eZdZddgddgddgddgd	d
ggZd�Zd�Zd
�Zd�Zd�Zd�Z	d�Z
d�Zd�Zy)�IMAP4UTF7Tests�Hello world�Hello worldz
Hello & worldsHello &- world�Helloÿworld�Hello&AP8-worlduÿþýüs
&AP8A,gD9APw-u~peter/mail/日本語/台北s~peter/mail/&ZeVnLIqe-/&U,BTFw-c�j�d}|j|jdd�|jd��y)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  r4�test_encodeWithErrorsz$IMAP4UTF7Tests.test_encodeWithErrorsIs0��������K�K�
�x�0�$�+�+�m�2L�	
r6c�j�d}|j|jdd�|jd��y)zO
        Similar to L{test_encodeWithErrors}, but for C{bytes.decode}.
        r;r?r@N�rB�decode�rE�bytess  r4�test_decodeWithErrorsz$IMAP4UTF7Tests.test_decodeWithErrorsTs0��������L�L���1�5�<�<�
�3N�	
r6c�J�d}|j|jd�d�y)z�
        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-&-NrArDs  r4�test_encodeAmpersandz#IMAP4UTF7Tests.test_encodeAmpersand]s&��
6������K�K�
�&��	
r6c�F�|jdjd�d�y)z�
        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?�½NrI�rEs r4�!test_decodeWithoutFinalASCIIShiftz0IMAP4UTF7Tests.test_decodeWithoutFinalASCIIShifths!��
	
����N�N�=�)�*�	
r6c��tjd�td��}|j|j	�d�y)zl
        C{codecs.getreader('imap4-utf-7')} returns the I{imap4-utf-7} stream
        reader class.
        r?r=r<N)�codecs�	getreaderrrB�read)rE�readers  r4�test_getreaderzIMAP4UTF7Tests.test_getreaderrs8��
1��!�!�-�0��9K�1L�M���������(8�9r6c��t�}tjd�|�}|jd�|j	|j�d�y)zl
        C{codecs.getwriter('imap4-utf-7')} returns the I{imap4-utf-7} stream
        writer class.
        r?r<r=N)rrU�	getwriter�writerB�getvalue)rE�output�writers   r4�test_getwriterzIMAP4UTF7Tests.test_getwriterzsG��
���0��!�!�-�0��8�����%�&�������*�,>�?r6c�n�|jD]&\}}|j|jd�|��(y)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)�testsrBrC�rE�inputr^s   r4�test_encodezIMAP4UTF7Tests.test_encode�s6��
"�Z�Z�	B�M�E�6����U�\�\�-�8�&�A�	Br6c�n�|jD]&\}}|j||jd���(y)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)rbrBrJrcs   r4�test_decodezIMAP4UTF7Tests.test_decode�s6��
"�Z�Z�	B�M�E�6����U�F�M�M�-�$@�A�	Br6c��ttdd�tdd��D]o}t|�j�}|j	|t|�jd��|j	t|�|jd���q|j	djd�d�|j	djd�d�y)	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�chrrCrBrJ)rE�o�charbytes   r4�test_printableSingletonsz'IMAP4UTF7Tests.test_printableSingletons�s����u�T�4�(�%��d�*;�<�	E�A��1�v�}�}��H����X�s�1�v�}�}�]�'C�D����S��V�X�_�_�]�%C�D�	E�	
������M�2�E�:�������m�4�c�:r6N)
�__name__�
__module__�__qualname__rbrGrMrOrSrYr`rergrrr1r6r4r9r9=sg��	��'�	�+�,�	�-�.�	�-�.�9�.�	
�	
�E�	
�
�	
�
�:�@�B�B�;r6r9c�$�eZdZd�Zd�Zd�Zd�Zy)�BufferingConsumerc��g|_yr0)�bufferrRs r4�__init__zBufferingConsumer.__init__�s	����r6c��|jj|�|jr|jj�yyr0)ry�append�consumer�resumeProducingrKs  r4r\zBufferingConsumer.write�s0�������5�!��=�=��M�M�)�)�+�r6c�F�||_|jj�yr0)r}r~)rEr}�	streamings   r4�registerProducerz"BufferingConsumer.registerProducer�s�� ��
��
�
�%�%�'r6c��d|_yr0)r}rRs r4�unregisterProducerz$BufferingConsumer.unregisterProducer�s	����
r6N)rsrtrurzr\r�r�r1r6r4rwrw�s���,�
(�r6rwc�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�MessageProducerTestsc������d�t�}d|d<d|d<d|d<d|d	<t|d
d�dd�}t��tj|���j��}����fd�}|j
|�S)
NsThis is body text.  Rar.�sender@host�from�recipient@domain�to�booga booga boo�subject�
text/plain�content-typer1�{c����j|���jdj�j�d�z�y)Nr6sf{119}
From: sender@host
To: recipient@domain
Subject: booga booga boo
Content-Type: text/plain

)�assertIdenticalrB�joinry)r2�body�c�prEs ����r4�
cbProducedz7MessageProducerTests.testSinglePart.<locals>.cbProduced�s@���� � ���+����������"��
��
r6�r�FakeyMessagerwr�MessageProducer�beginProducing�addCallback)rE�headers�msg�dr�r�r�r�s`    @@@r4�testSinglePartz#MessageProducerTests.testSinglePart�s����*���-��'����*���
�.��	��".�����7�B��d�C��>������!�!�#�&��
���Q���
	��}�}�Z�(�(r6c�F����	�d}d�t�}d|d<d|d<d|d<d	|d
<t�}d|d<d|d
<t|d
d|dt|d
d�dd�g�}t��tj|��	�	j��}���	�fd�}|j
|�S)Nr6�&Contained body message text.  Squarge.r�r�r�r�r�r��%multipart/alternative; boundary="xyz"r��this is subject textr�r1r�c����j|���jdj�j�d�zdz�y)Nr6s�{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--
��failUnlessIdenticalrBr�ry�r2r��	innerBodyr�rEs ����r4r�z<MessageProducerTests.testSingleMultiPart.<locals>.cbProduced�sJ����$�$�V�Q�/����������"�
�$�
$�'9�
9�

r6r��
rE�	outerBodyr��innerHeadersr�r�r�r�r�r�s
`      @@@r4�testSingleMultiPartz(MessageProducerTests.testSingleMultiPart�s�����	�=�	��-��'����*���
�.��	��"I����"�}��"8��Y��'3��^�$�������
�,��D�)�T�4�
H�I�

��
����!�!�#�&��
���Q���	�$�}�}�Z�(�(r6c����	�
��d}d�	d�
t�}d|d<d|d<d|d	<d
|d<t�}d|d	<d
|d<t�}d|d	<d|d<t|dd|dt|dd�	dd�t|dd�
dd�g�}t��tj|���j��}��	�
��fd�}|j
|�S)Nr6r��.Secondary <i>message</i> text of squarge body.r�r�r�r�r�r�r�r�r�r��<b>this is subject</b>�	text/htmlr1r�c����j|���jdj�j�d�zdz�zdz�y)Nr6s�{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�r�)r2r��
innerBody1�
innerBody2r�rEs �����r4r�z>MessageProducerTests.testMultipleMultiPart.<locals>.cbProduceds^����$�$�V�Q�/����������"�
�%�
%�(�
�%�
%�(:�
:�
r6r�)rEr�r�r��
innerHeaders2r�r�r�r�r�r�r�s`       @@@@r4�testMultipleMultiPartz*MessageProducerTests.testMultipleMultiPart�s�����	�>�
�F�
��-��'����*���
�.��	��"I����"�}��"8��Y��'3��^�$�#�
�
�#;�
�i� �(3�
�n�%��������\�2�t�Z��t�L��]�B��j�$��M�
�

��
����!�!�#�&��
���Q���	�	�*�}�}�Z�(�(r6c�V����	�d}d�t�}d|d<d|d<d|d<d	|d
<t�}d|d<d|d
<t|d
d|dt|d
d�dd�g�}t��tj|��	d��	_�	j
��}���	�fd�}|j|�S)z>
        A boundary is generated if none is provided.
        r6r�r�r�r�r�r�r��multipart/alternativer�r�r�r1Nr�c�,�tjd�S)Nz$aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)�uuid�UUIDr1r6r4r5z?MessageProducerTests.test_multiPartNoBoundary.<locals>.<lambda>Ms��4�9�9�%K�L�r6c����j|���jdj�j�d�zdz�y)Nr6s	{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--
r�r�s ����r4r�zAMessageProducerTests.test_multiPartNoBoundary.<locals>.cbProducedQsL����$�$�V�Q�/����������"���
�G�G�
r6)rr�rwrr��_uuid4r�r�r�s
`      @@@r4�test_multiPartNoBoundaryz-MessageProducerTests.test_multiPartNoBoundary3s�����	�=�	��-��'����*���
�.��	��"9����"�}��"8��Y��'3��^�$�������
�,��D�)�T�4�
H�I�

��
����!�!�#�&��L���
���Q���	�*�}�}�Z�(�(r6c�F����	�d}d�t�}d|d<d|d<d|d<d	|d
<t�}d|d<d|d
<t|d
d|dt|d
d�dd�g�}t��tj|��	�	j��}���	�fd�}|j
|�S)z>
        A boundary without does not have them added.
        r6r�r�r�r�r�r�r�z#multipart/alternative; boundary=xyzr�r�r�r1Nr�c����j|���jdj�j�d�zdz�y)Nr6s�{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�r�r�s ����r4r�z?MessageProducerTests.test_multiPartNoQuotes.<locals>.cbProduced�sJ����$�$�V�Q�/����������"��$�$�'9�9�
r6r�r�s
`      @@@r4�test_multiPartNoQuotesz+MessageProducerTests.test_multiPartNoQuoteshs�����	�=�	��-��'����*���
�.��	��"G����"�}��"8��Y��'3��^�$�������
�,��D�)�T�4�
H�I�

��
����!�!�#�&��
���Q���	�&�}�}�Z�(�(r6N)rsrtrur�r�r�r�r�r1r6r4r�r��s��)�8+)�Z4)�l3)�j/)r6r�c�|�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�MessageSetTestsz"
    Tests for L{MessageSet}.
    c��t�}t�}|j||�|j|d�|dz}|jt|�d�|jt	|�dg�|dz}|jt|�d�|jt	|�gd��|dz}|j||�|jt	||z�gd��|jd�|jt|�d�|jt	|�gd��|j||�|jd	d
�|jt|�d�|jt	|�gd��y
)a4
        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.
        r1��r��r��r��r���)r�r�r�r����)r�r�r�r�r�r�r�N)rrB�assertNotEqual�len�list�add)rE�m1�m2s   r4�!test_equalityIterationAndAdditionz1MessageSetTests.test_equalityIterationAndAddition�s@��.�\��
�\������R� ����B��#�
�!�V������R��!�$�����b��A�3�'�
�&�[������R��!�$�����b��9�-�
�&�[������R� �����b�2�g��	�2�
���q�	�����R��!�$�����b��<�0����B��#�
���q�!������R��!�$�����b��#8�9r6c�N�|jtttdd��y)z�
        A L{MessageSet} that has a range that ends with L{None} raises
        a L{TypeError} when its length is requested.
        r�N)�assertRaises�	TypeErrorr�rrRs r4�test_lengthWithWildcardRangez,MessageSetTests.test_lengthWithWildcardRange�s��
	
���)�S�*�Q��*=�>r6c�.�ttdd��y)zD
        L{MessageSet.__repr__} does not raise an exception
        r�r�N)�reprrrRs r4�test_reprSanityzMessageSetTests.test_reprSanity�s��	
�Z��1�
�r6c��tjd�tjd�tjdd�tjdd�g}gd�}t||�D] \}}|jt	|�|��"y)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:*s3:*r�s*:2)�*�1:*z3:6z2:6N�r�parseIdList�ziprB�str�rE�inputs�outputs�irps     r4�&test_stringRepresentationWithWildcardsz6MessageSetTests.test_stringRepresentationWithWildcards�s~��
���d�#����f�%����f�a�(����f�a�(�	
��
�����(�	(�D�A�q����S��V�Q�'�	(r6c��tjd�tjd�g}ddg}t||�D] \}}|jt	|�|��"y)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:3s3:2�2:3Nr�r�s     r4�&test_stringRepresentationWithInversionz6MessageSetTests.test_stringRepresentationWithInversion�sf��
���f�%����f�%�
��
��
��
���(�	(�D�A�q����S��V�Q�'�	(r6c��td�}|jt|�d�|jt|�d�|jt	|�dg�y)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.
        r��1N�rrBr�r�r��rE�ms  r4�"test_createWithSingleMessageNumberz2MessageSetTests.test_createWithSingleMessageNumber
sK��
�q�M������Q���%�����Q���#�����a��1�#�&r6c���tdd�}|jt|�d�|jt|�d�|jt	|�gd��y)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.
        r��
z1:10)
r�r�r�r�r�r�r�r��	r�Nr�r�s  r4�test_createWithSequencez'MessageSetTests.test_createWithSequencesM��
�q�"�������Q���(�����Q���$�����a��"A�Br6c��td�}|jt|�d�|jt|�d�|j	t
t|�y)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�)rrBr�r�r�r�r�r�s  r4�test_createWithSingleWildcardz-MessageSetTests.test_createWithSingleWildcard#sH��
�t�������Q���%�����Q���#����)�T�1�-r6c��td�}d|_|jt|�dg�tdd�}d|_|jt|�gd��y)z�
        Setting L{MessageSet.last} replaces L{None}, representing
        C{*}, with that number, making that L{MessageSet} iterable.
        Nr�r�r�r�)r�lastrBr�)rE�singleMessageReplaced�
rangeReplaceds   r4�test_setLastSingleWildcardz*MessageSetTests.test_setLastSingleWildcard/sY��
!+�4� 0��%'��"�����3�4�r�d�;�"�1�d�+�
��
������m�,�i�8r6c��tdd�}|jdd�d|_|jt	|�gd��y)zL
        Setting L{MessageSet.last} replaces L{None} in all ranges.
        r�Nr�r��r�r�r�r�r�)rr�r�rBr�r�s  r4�test_setLastWithWildcardRangez-MessageSetTests.test_setLastWithWildcardRange<s8��
�q�$���	���a����������a��/�2r6c��tdd�}d|_|jt�5d|_ddd�y#1swYyxYw)z9
        L{MessageSet.last} cannot be set twice.
        r�Nr�r�)rr�r��
ValueErrorr�s  r4�test_setLastTwiceFailsz&MessageSetTests.test_setLastTwiceFailsEsA��
�q�$������
�
�
�z�
*�	��A�F�	�	�	�s	�:�Ac�"�td�}d|_|jd�|jt	|�ddg�|jt	|dz�gd��|jdd�|jt	|�gd��y)a
        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>}.
        r�r�N)Nr�)r�r�r�r�)r�r�r�)rr�r�rBr�)rE�hasLasts  r4�test_lastOverridesNoneInAddz+MessageSetTests.test_lastOverridesNoneInAddNst���Q�-��������D������g���A��/�����g�	�1�2�I�>����A�t������g��	�2r6c�b�tdd�}d|_|j|jd�y)zF
        Accessing L{MessageSet.last} returns the last value.
        r�Nr�)rr�rBr�s  r4�test_getLastzMessageSetTests.test_getLastas+��
�q�$�������������#r6c�>�t�}|jd�|jt|�dg�t�}|jd�|jt	|�d�t�}|jd�|jt|�gd��t�}|jd�|jt	|�d�t�}|jtdd��|jt|�gd��y)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.
        r�Nr�r�r��NNr�)r�extendrBr�r�)rE�
extendWithInt�extendWithNone�extendWithSequenceOfInts�extendWithSequenceOfNones�extendWithMessageSets      r4�test_extendzMessageSetTests.test_extendis���#��
����Q������m�,�q�c�2�#������d�#�����^�,�c�2�#-�<� � �'�'��/�����6�7��C�$.�L�!�!�(�(��6�����6�7��=�)�|���#�#�J�q�!�$4�5�����2�3�Y�?r6c��tdd�}tdd�tdd�z}|jd|�|jd|�|dz}|jt�5d|vddd�|dz}|jdd�|jt�5d|vddd�y#1swY�CxYw#1swYyxYw)	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}.
        r�r�r�r�r�N)r��r�)r�assertIn�assertNotInr�r�r�)rE�hasFive�doesNotHaveFive�hasFiveButHasNone�hasFiveButHasNoneInSequences     r4�
test_containszMessageSetTests.test_contains�s����Q��"��$�Q��*�Z��1�-=�=���
�
�a��!�����O�,�#�d�N��
�
�
�y�
)�	#�
�"�"�	#�'.��&8�#�#�'�'��4�0�
�
�
�y�
)�	-�
�,�,�	-�	-�	#�	#��
	-�	-�s�$B+�B7�+B4�7Cc���tdd�}tdd�}||z}|tdd�z}|jt|dz�gd��|jt|d	z�gd
��|jt|dz�gd��|jt|d
z�gd��|jt|d	z�gd��|jt|td�z�gd��y)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.
        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�r�r�r�r�r�r�N)rrBr�)rE�
mergeAfter�mergeBefore�mergeBetweenSequence�mergeBetweenNumbers     r4�test_rangesMergedz!MessageSetTests.test_rangesMerged�s��� ��1�%�
� ��A�&��)�K�7��'�*�Q��*:�:������j�6�1�2�L�A�����j�6�1�2�O�D�����k�F�2�3�\�B�����k�F�2�3�_�E�����2�V�;�<�>V�W�����#�j��m�3�4�6K�	
r6c��|jtdd�tdd��|jttdd��gd��tdd�}d|_|jt|�ddg�y)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}
        r�r��r�r�r�i�Ni�)rBrr�r�r�s  r4�test_seq_rangeExamplesz&MessageSetTests.test_seq_rangeExamples�si��	
����A�q�)�:�a��+;�<�����j��A�.�/��;��t�T�"���������a��4��,�/r6c�T�td�tdd�ztd�ztdd�z}d|_|jdjd	�|D��d
�tdd�tdd�z}d|_|jdjd
�|D��d�y)a�
        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}
        r�r�r�r�rN��,c3�2K�|]}t|����y�wr0�r���.0r�s  r4�	<genexpr>z<MessageSetTests.test_sequence_setExamples.<locals>.<genexpr>�s����9��S��V�9���z2,4,5,6,7,9,12,13,14,15r�r�c3�2K�|]}t|����y�wr0r*r+s  r4r-z<MessageSetTests.test_sequence_setExamples.<locals>.<genexpr>�s����!B�Q�#�a�&�!B�r.z4,5,6,7,8,9,10)rr�rBr�)rE�fromFifteenMessages�fromTenMessagess   r4�test_sequence_setExamplesz)MessageSetTests.test_sequence_setExamples�s���$
�q�M�J�q�!�,�,�z�!�}�<�z�"�d�?S�S�	�$&�� �����H�H�9�%8�9�9�;T�	
�%�T�1�-�
�1�a�0@�@��!���������!B�/�!B�B�DT�Ur6N)rsrtru�__doc__r�r�r�r�r�r�r�r�r�rrrr
rrr"r%r2r1r6r4r�r��se���1:�f?��(�.(�(
'�C�
.�9�3��3�&$�@�6-�*
�00�,Vr6r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+y*)+�IMAP4HelperTestszA
    Tests for various helper utilities in the IMAP4 module.
    c�F�ttjddgd��y)zI
        L{imap4.Command}'s C{repr} does not raise an exception.
        sCOMMANDsarg�extraN)r�r�CommandrRs r4�test_commandReprz!IMAP4HelperTests.test_commandRepr�s��	
�U�]�]�:��x�(�
<�=r6c������d�t��t��}tj|���j	��}����fd�}�fd�}|j|�|j|�|j|�S)Nsxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzc����j|���jdt���fzdj�j��|S)Ns{%d}
%br6)r�rBr�r�ry)r2�br�r�rEs ����r4r�z6IMAP4HelperTests.test_fileProducer.<locals>.cbProduced�sB����$�$�V�Q�/����]�c�!�f�a�[�8�#�(�(�1�8�8�:L�M��Mr6c�(���j�|Sr0)r~)r2r�s �r4�cbResumez4IMAP4HelperTests.test_fileProducer.<locals>.cbResume�s���
�����Mr6)rwrr�FileProducerr�r�)rEr3r�r�r>r<r�r�s`    @@@r4�test_fileProducerz"IMAP4HelperTests.test_fileProducer�sn���7������A�J�����q�!��
���Q���	�
	�	
�
�
�j�!�	�
�
�h���}�}�Z�(�(r6c��dgd�ddggdgd�gd�gdgd	�gd
�gg}|D]j\}}}tj|d�}|D]"}|j|j|���$|D]"}|j	|j|���$�ly)N�foo/%gum/bar�zfoo/barzoo/lalagum/barzfoo/gumx/barzfoo/gum/baz�foo/xgum/bar�foo/gum/bar�foo/x%x/bar��foo�barzfuz fuz fuzz	foo/*/bar�foo/xyz/barz
foo/xx/baz)�foo/xyx/bar�
foo/xx/bar�foo/xxxxxxxxxxxxxx/bar�foo/xyz*abc/bar�rJzfoo/abc/barzfoo/xyzab/cbarzfoo/xyza/bcbar�zfoo/xyzabc/barzfoo/xyz/abc/barzfoo/xyz/123/abc/bar�/�r�wildcardToRegexp�assertFalse�match�
assertTrue�rE�cases�wildcard�fail�succeed�xs      r4�
test_wildcardzIMAP4HelperTests.test_wildcards����L���/�
��W�G�
�"�R�L�
�
��$(-�	3�#�H�d�G��-�-�h��<�H��
4��� � �����!2�3�
4��
3��������q� 1�2�
3�		3r6c��dgd�gd�gdgd�gd�gdgd�gd	�gg}|D]l\}}}tj|d�}|D]#}|j|j|�|��%|D]#}|j	|j|�|��%�ny)
NrBrC)rDrEz
foo/x/gum/barrFrG)rKrLrMzfoo/x/x/barrNrOrPrRrWs      r4�test_wildcardNoDelimz%IMAP4HelperTests.test_wildcardNoDelim"s����L�@�
��W�V�
�"�R�L�
�
��$(-�	6�#�H�d�G��-�-�h��=�H��
7��� � �����!2�A�6�
7��
6��������q� 1�1�5�
6�		6r6c	���ddd�dfg}|D]\\}}tj|�}|jt|j	d��t|j	d����^y)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.
        �Value1�Value2)�Header1�Header2s"Header2: Value2
Header1: Value1
TN)r�_formatHeadersrB�sorted�
splitlines)rErXrd�expectedr^s     r4�test_headerFormatterz%IMAP4HelperTests.test_headerFormatter<ss��%��:�9�
�
�� %�	�O�E�8��)�)�%�0�F�����v�(�(��.�/���8K�8K�D�8Q�1R�
�	r6c�^�gd�}ddgddggd�gd�gd�gd�gd	�gd
�gd�gd�d
gddgdggd�dggd�dggd�dgg}gd�}|D]1}|jtjtj|��3t	||�D]*\}}|jtj|�|��,y)N)sHello WorldsHello "World!"sWorld "Hello" "How are you?"s"Hello world" How "are you?"sfoo bar "baz buz" NILsfoo bar "baz buz" "NIL"sfoo NIL "baz buz" barsfoo "NIL" "baz buz" bars"NIL" bar "baz buz" foosoo \"oo\" oos"oo \"oo\" oo"�oo 	 oos	"oo 	 oo"�oo \t oos
"oo \t oo"�oo \o oo�
"oo \o oo"rmrn�Hello�WorldsWorld!)rprosHow are you?)r;sHowsare you?)�foo�bar�baz buzN)rqrrrs�NIL)rqNrsrr)rqrtrsrr)rtrrrsrq)�oos"oo"ru�
oo "oo" oorurk)rus\trurl)ru�\orurm)s"mismatched quotesmismatched quote"smismatched"quotes"oops here is" another")r�r�MismatchedQuoting�splitQuotedr�rB)rErX�answers�errors�s�caserhs       r4�test_quotedSplitterz$IMAP4HelperTests.test_quotedSplitterOs���
��.�x� �
�y�!�1�1�.�0�.�0�0�#�
�O�
�E�N�
�M�"�
�N�"�
�N�"�
�N�'
��,
���	M�A����e�5�5�u�7H�7H�!�L�	M�"�%��1�	@�N�D�(����U�.�.�t�4�h�?�	@r6c��gd�gd�gd�ddgdgd�dgddgd	�gd
ddd
gd�d
ddd
g	dgd�ddgg}d
ggd�dgdgddgdgddggddgdgddgdgg}t||�D]*\}}|jtj|�|��,y)N)�a�b�c�d�e)
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�sabcde)r�sbc �desabcr�sbcdsabscdesa s es bc  )r�rBr�collapseStrings)rErXrzr}rhs     r4�test_stringCollapserz%IMAP4HelperTests.test_stringCollapser�s���*�H�
��t�,�
�%�t�,�
�4�+�,�
�4��t�%7��t�T�4�P�
�=�t�T�J�
���J�!��X�u��
�F�8�T�"�
�V�H��
�V�H�e�$�
�H�:�u�%�
��"�%��1�	D�N�D�(����U�2�2�4�8�(�C�	Dr6c�z��djdgdz�}�fd�}|dt|�|fzddgd�g|g�|d	d
dgdd
dddddgd�ggd�ggd�ggd�ggd�gd�gdddg
dddddgdddddgg
�|d d!g�|d"d#g�|d$d%g�|d&d'g�|d&d'g�|d(d)d*g�|d(d)d*g�y)+N�
sxxr�c�V��tj|�}�j||g�yr0)r�parseNestedParensrB)r}rh�parsedrEs   �r4�checkz0IMAP4HelperTests.test_parenParser.<locals>.check�s%����,�,�T�2�F����V�h�Z�0r6s8(BODY.PEEK[HEADER.FIELDS.NOT (subject bcc cc)] {%d}
%b)�	BODY.PEEKsHEADER.FIELDS.NOT)ssubjectsbccsccs(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INTERNALDATEs17-Jul-1996 02:44:25 -0700sRFC822.SIZEs4286sENVELOPEs%Wed, 17 Jul 1996 02:23:25 -0700 (PDT)s$IMAP4rev1 WG mtg summary and minutes)s
Terry GrayNsgray�cac.washington.edu)NNsimapr�)NNsminutessCNRI.Reston.VA.US)sJohn KlensinNsKLENSINsINFOODS.MIT.EDUs#<B27397-0100000@cac.washington.edu>�BODYsTEXT�PLAIN�CHARSETsUS-ASCIIs7BITs3028s92s("oo \"oo\" oo")rvs("oo \\ oo")soo \\ oos("oo \ oo")soo \ oos	("oo \o")soo \os(oo \o)rurw)r�r�)rEr|r�s`  r4�test_parenParserz!IMAP4HelperTests.test_parenParser�s5����L�L�%��1��%��	1�	�I�S�QR�V�UV�K�W�
�0�2M�N�PQ�R�	
�	�
J�����-����<�;�J�K�J�K�J�K�A�B�F�O����:�������-������	�1"
�0	
�d	�#�m�_�5�
��-��1�
�o��}�-�
�m�i�[�)�
�m�i�[�)�
�k�E�6�?�+�
�k�E�6�?�+r6c
��gd�gd�gd�gd�gd�gd�gd�gd�gd	�g	}|D]�\}}}|jd
�}tj�}|j|�|j	t|j�d�|jt|jdt||���|j	t|jd�|���y)
N)�ENVELOPE�Envelope�envelope)�FLAGS�Flags�flags)�INTERNALDATE�InternalDate�internaldate)�
RFC822.HEADER�RFC822Headerz
rfc822.header)�RFC822.SIZE�
RFC822Sizezrfc822.size)�RFC822.TEXT�
RFC822Textzrfc822.text)�RFC822r��rfc822)�UIDr��uid)�
BODYSTRUCTURE�
BodyStructure�
bodystructure�asciir�r)rCr�_FetchParser�parseStringrBr�r2rV�
isinstance�getattrr�)rErX�inp�outp�asStringr�s      r4�test_fetchParserSimplez'IMAP4HelperTests.test_fetchParserSimple�s���0�'�<�>�8�8�*�!�?�

��$)�	9��C��x��*�*�W�%�C��"�"�$�A�
�M�M�#�����S����]�A�.��O�O�J�q�x�x��{�G�A�t�4D�E�F����S����!��-�x�8�
	9r6c���ddgd�fgddgd�fgddgd	�fgg}|D]�\}}tj�}|j|�|jt	|j
�|d
�|j
D�cgc]*}t
|�j�jd���,}}|j�|dj�|j||d���ycc}w)
NsALLr�)�flags�internaldate�rfc822.size�envelopesFULLr�)r�r�r�r�sbodysFASTr�)r�r�r�rr�r�)
rr�r�rBr�r2r��lowerrC�sort)rErXr�r�r��token�expectedResults       r4�test_fetchParserMacrosz'IMAP4HelperTests.test_fetchParserMacross���
�a�Q�R�S���U�V�
��q�E�F�G�

���	6�I�C���"�"�$�A�
�M�M�#�����S����]�D��G�4�NO�h�h�W�U�c�%�j�.�.�0�7�7��@�W�N�W����!���G�L�L�N����^�T�!�W�5�	6��Xs�;/C'c�Z�tj}|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j|j
djd�|jt|j
d�d�|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|jt|j
d�d�|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|jt|j
d�d	�|�}|jd
�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j
t|j
dj|j��|j|j
djjd�|j|j
djjd�|j|j
djd�|jt|j
d�d�|�}|jd
�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j
t|j
dj|j��|j|j
djjd�|j|j
djjd�|j|j
djd�|jt|j
d�d�|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j
t|j
dj|j��|j|j
djjd�|j|j
djjgd��|j|j
djd�|jt!|j
d�d�|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j
t|j
dj|j��|j|j
djjd�|j|j
djjgd��|j|j
djd�|jt!|j
d�d�|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j
t|j
dj|j��|j|j
djjd�|j|j
djjgd��|j|j
djd�|jt!|j
d�d�|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j
t|j
dj"|j$��|j|j
dj&d�|j|j
dj(d�|j|j
dj*d�|j|j
djd�|jt!|j
d�d�|�}|jd�|jt	|j
�d�|j
t|j
d|j��|j|j
djd�|j
t|j
dj|j��|j|j
dj&d�|j|j
djjddg�|j|j
dj(d�|j|j
dj*d�|j|j
djd�|jt!|j
d�d�y)Nr�r�rF�BODYr�TsBODY[]zBODY[]sBODY[HEADER]r1zBODY[HEADER]sBODY.PEEK[HEADER]s+BODY[HEADER.FIELDS (Subject Cc Message-Id)])sSUBJECTsCC�
MESSAGE-IDs0BODY.PEEK[HEADER.FIELDS (Subject Cc Message-Id)]s4BODY.PEEK[HEADER.FIELDS.NOT (Subject Cc Message-Id)]s/BODY[HEADER.FIELDS.NOT (Subject Cc Message-Id)]sBODY[1.MIME]<10.50>�rr��2s?BODY.PEEK[1.3.9.11.HEADER.FIELDS.NOT (Message-Id Date)]<103.69>)rr�r�r�r�sDATE�g�Es:BODY[1.3.9.11.HEADER.FIELDS.NOT (Message-Id Date)]<103.69>)rr�r�rBr�r2rVr��Body�peek�headerr��empty�Header�negate�fieldsrL�mime�MIME�part�partialBegin�
partialLength)rE�Pr�s   r4�test_fetchParserBodyz%IMAP4HelperTests.test_fetchParserBodys�	������
�C��	�
�
�g������Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�5�1�������!��+�+�T�2�����Q�X�X�a�[�)�6�2�
�C��	�
�
�l�#�����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�4�0�����Q�X�X�a�[�)�6�2�
�C��	�
�
�i� �����Q�X�X���*����
�1�8�8�A�;����7�8�������!��*�*�D�1�����Q�X�X�a�[�)�8�4�
�C��	�
�
�o�&�����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�5�1����
�1�8�8�A�;�#5�#5�q�x�x�@�A�������!��+�+�2�2�D�9�������!��+�+�2�2�B�7�������!��*�*�E�2�����Q�X�X�a�[�)�>�:�
�C��	�
�
�*�+�����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�4�0����
�1�8�8�A�;�#5�#5�q�x�x�@�A�������!��+�+�2�2�D�9�������!��+�+�2�2�B�7�������!��*�*�E�2�����Q�X�X�a�[�)�>�:�
�C��	�
�
�D�E�����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�5�1����
�1�8�8�A�;�#5�#5�q�x�x�@�A�������!��+�+�2�2�E�:�������!��+�+�2�2�4V�W�������!��*�*�E�2�����!�(�(�1�+�� N�	
�
�C��	�
�
�I�J�����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�4�0����
�1�8�8�A�;�#5�#5�q�x�x�@�A�������!��+�+�2�2�E�:�������!��+�+�2�2�4V�W�������!��*�*�E�2�����!�(�(�1�+�� N�	
�
�C��	�
�
�M�N�����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�4�0����
�1�8�8�A�;�#5�#5�q�x�x�@�A�������!��+�+�2�2�D�9�������!��+�+�2�2�4V�W�������!��*�*�E�2�����!�(�(�1�+�� R�	
�
�C��	�
�
�,�-�����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�5�1����
�1�8�8�A�;�#3�#3�Q�V�V�<�=�������!��)�)�4�0�������!��1�1�2�6�������!��2�2�B�7�������!��*�*�E�2�����q�x�x��{�+�-C�D�
�C��	�
�
�N�	
�	
����Q�X�X���*����
�1�8�8�A�;����7�8�������!��)�)�4�0����
�1�8�8�A�;�#5�#5�q�x�x�@�A�������!��)�)�=�9�������!��+�+�2�2�]�G�4L�M�������!��1�1�3�7�������!��2�2�B�7�������!��*�*�E�2�����!�(�(�1�+��I�	
r6c���tj�}|jd�|jt	|j
�d�|j|j
djd�|j|j
d|j�|j|j
dj|j�|jt|j
d�d�y)z�
        Parsing a C{BODY} whose C{HEADER} values require quoting
        results in a object that perserves that quoting when
        serialized.
        sBODY[HEADER.FIELDS ((Quoted)]r�rFsBODY[HEADER.FIELDS ("(Quoted")]N)rr�r�rBr�r2r��assertIsInstancer�r�r�rL�rEr�s  r4�test_fetchParserQuotedHeaderz-IMAP4HelperTests.test_fetchParserQuotedHeader�s���
��� ��	�
�
�6�7�����Q�X�X���*�������!��)�)�5�1����a�h�h�q�k�1�6�6�2����a�h�h�q�k�0�0�!�(�(�;�����q�x�x��{�+�-O�Pr6c��tj�}|jd�|jt	|j
��y)z=
        Parsing an empty string results in no data.
        r6N)rr�r�rTr�r2r�s  r4�test_fetchParserEmptyStringz,IMAP4HelperTests.test_fetchParserEmptyString�s4��
��� ��	�
�
�c������Q�X�X��'r6c�n�tj�}|jt|jd�y)z\
        Parsing a string with an unknown attribute raises an
        L{Exception}.
        sUNKNOWNN�rr�r��	Exceptionr�r�s  r4� test_fetchParserUnknownAttributez1IMAP4HelperTests.test_fetchParserUnknownAttribute�s(��

��� �����)�Q�]�]�J�?r6c�n�tj�}|jt|jd�y)zf
        Parsing a string that prematurely ends in whitespace raises an
        L{Exception}.
        sBODY[HEADER.FIELDS  Nr�r�s  r4�0test_fetchParserIncompleteStringEndsInWhitespacezAIMAP4HelperTests.test_fetchParserIncompleteStringEndsInWhitespace��)��

��� �����)�Q�]�]�4K�Lr6c�n�tj�}|jt|jd�y)z
        Parsing a string that contains an unexpected character rather
        than whitespace raises an L{Exception}.
        sBODY[HEADER.FIELDS!]Nr�r�s  r4�"test_fetchParserExpectedWhitespacez3IMAP4HelperTests.test_fetchParserExpectedWhitespace�r�r6c���tj�}|jd�|jt	|j
�d�|j
|j
d|j�|j|j
djd�|j
|j
dj|j�|jt|j
d�d�y)z:
        A C{BODY} can contain a C{TEXT} section.
        s
BODY[TEXT]r�rFN)rr�r�rBr�r2r�r�r�rF�TextrLr�s  r4�test_fetchParserTextSectionz,IMAP4HelperTests.test_fetchParserTextSection�s���
��� ��	�
�
�m�$�����Q�X�X���*����a�h�h�q�k�1�6�6�2�������!��)�)�5�1����a�h�h�q�k�.�.����7�����q�x�x��{�+�]�;r6c�n�tj�}|jt|jd�y)z[
        Parsing a C{BODY} with an unknown section raises an
        L{Exception}.
        s
BODY[UNKNOWN]Nr�r�s  r4�test_fetchParserUnknownSectionz/IMAP4HelperTests.test_fetchParserUnknownSection�s)��

��� �����)�Q�]�]�4D�Er6c���tj�}|jt|jd�tj�}|jt|jd�y)ze
        Parsing a C{BODY} with an unterminated section list raises an
        L{Exception}.
        sBODY[HEADERsBODY[HEADER.FIELDS (SUBJECT)Nr�r�s  r4�#test_fetchParserMissingSectionClosez4IMAP4HelperTests.test_fetchParserMissingSectionClose�sM��

��� �����)�Q�]�]�N�C���� �����)�Q�]�]�4S�Tr6c���tj�}|jt|jd�tj�}|jt|jd�y)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}.
        sBODY[HEADER.FIELDS Missing)]sBODY[HEADER.FIELDS (Missing]Nr�r�s  r4�(test_fetchParserHeaderMissingParenthesesz9IMAP4HelperTests.test_fetchParserHeaderMissingParentheses�sN��
��� �����)�Q�]�]�4S�T���� �����)�Q�]�]�4S�Tr6c�n�tj�}|jt|jd�y)zk
        Parsing a C{BODY} with a range that lacks a period (C{.})
        raises an L{Exception}.
        sBODY<01>Nr�r�s  r4�test_fetchParserDotlessPartialz/IMAP4HelperTests.test_fetchParserDotlessPartial�s(��

��� �����)�Q�]�]�K�@r6c�n�tj�}|jt|jd�y)z�
        Parsing a C{BODY} with a partial range that's missing its
        closing greater than sign (C{>}) raises an L{EXCEPTION}.
        sBODY<0Nr�r�s  r4�test_fetchParserUnclosedPartialz0IMAP4HelperTests.test_fetchParserUnclosedPartial�s(��

��� �����)�Q�]�]�I�>r6c�t�dddtd�ddg}d}|jtj|�|�y)NrHrI�baz�this is a file
�buz�bizs4"foo" "bar" "baz" {16}
this is a file
 "buz" "biz")rrBr�collapseNestedLists)rE�inputStructurer^s   r4�
test_fileszIMAP4HelperTests.test_files�sD������)�*���

��M������2�2�>�B�F�Kr6c���dtjd�dtd�dtjd�dg}d}|jtj|�|�y)	Nrqrrsbazr�sthis is
quotedsbuzr6sC"foo" bar "baz" {16}
this is a file
 {15}
this is
quoted buz "")r�DontQuoteMerrBr�rcs   r4�test_quoteAvoiderz"IMAP4HelperTests.test_quoteAvoidersa������f�%���)�*� ����f�%��
��
�	�	
����2�2�5�9�6�Br6c�p�ddggfg}|D]*\}}|jtj|�|��,y)Ns({10}
0123456789)s
0123456789)rBrr�)rErXr}rhs    r4�
test_literalszIMAP4HelperTests.test_literalssH��
$�
��&7�8�
��$�	F�N�D�(����U�4�4�T�:�H�E�	Fr6c��tjd��tjddd��tjtjd��tjd���tjd��tjtjd��tjd��tjd���tjtjtjtjdd	d
��tjddd
��tjdddd��tjtjd�����tjtjd����g}gd�}t	||�D]\}}|j||��y)Nr�)�flagged)rf�	unflagged�deleted)r�today)�before)�unseen)�new�	yesterdayi�)rf�since�smaller�tuesdayi')rfr�larger)rfrrr�spam)r�z1:5�r�)�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)rEr�r��queryrhs     r4�test_queryBuilderz"IMAP4HelperTests.test_queryBuilders2���K�K��"��K�K�q�A�q�9��H�H�U�[�[��+�U�[�[��-C�D��K�K�w�'��H�H�U�[�[��+�U�[�[��-B�E�K�K�TU�DV�W��H�H��	�	��H�H����1�K��N����1�Y�u�M����1�Q��'�R��	�	�%�+�+�f�"=�>�	���	�	�%�+�+�%�0�1�

�

��&

�� #�6�7�3�	.�O�E�8����U�H�-�	.r6c�T�tjd��}|jd|�y)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�rrrB�rErs  r4�test_queryKeywordFlagWithQuotesz0IMAP4HelperTests.test_queryKeywordFlagWithQuotes@s#�����I�.�����,�e�4r6c�T�tjd��}|jd|�y)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)Nrrs  r4�!test_queryUnkeywordFlagWithQuotesz2IMAP4HelperTests.test_queryUnkeywordFlagWithQuotesKs#�����i�0�����.��6r6c�|�tjtjdd���}|j|d�y)z�
        When passed a L{MessageSet}, L{imap4.Query} returns a query
        containing a quoted string representing the ID sequence.
        r�N��messagesz(MESSAGES "1:*"))rrrrBrs  r4�test_queryWithMesssageSetz*IMAP4HelperTests.test_queryWithMesssageSetVs0��
���U�%5�%5�a��%>�?������ 2�3r6c�T�tjd��}|j|d�y)zl
        When passed an L{int}, L{imap4.Query} returns a query
        containing a quoted integer.
        r�rz(MESSAGES "1")Nrrs  r4�test_queryWithIntegerz&IMAP4HelperTests.test_queryWithInteger^s#��
���Q�'������ 0�1r6c��|jtjtjtjd���y)zq
        An L{imap4.Or} query with less than two arguments raises an
        L{imap4.IllegalQueryError}.
        r�rN)r�r�IllegalQueryErrorrrrRs r4�test_queryOrIllegalQueryz)IMAP4HelperTests.test_queryOrIllegalQueryfs*��
	
���%�1�1�5�8�8�U�[�[�RS�=T�Ur6c�.�|jd|j��d�tjd
i|di���|jd|j��d�tjd
i|ddj	d�td�D���d�i���y	)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)ztwisted (){%*"\] rocksztwisted �c3�2K�|]}t|����y�wr0)ro)r,�chs  r4r-z9IMAP4HelperTests._keywordFilteringTest.<locals>.<genexpr>�s����;�2�s�2�w�;�r.�!z rocksNr1)rB�upperrrr�rn)rErs  r4�_keywordFilteringTestz&IMAP4HelperTests._keywordFilteringTestms���	
�����
�
�� ��/��K�K�?�7�$=�>�?�	
�	
�����
�
�� ��/��K�K�
���w�w�;��r��;�;�>��
�	
r6c�&�|jd�y)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>}
        rN�r-rRs r4�test_queryKeywordFlagz&IMAP4HelperTests.test_queryKeywordFlag�s��	
�"�"�9�-r6c�&�|jd�y)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>}
        rNr/rRs r4�test_queryUnkeywordFlagz(IMAP4HelperTests.test_queryUnkeywordFlag�s��	
�"�"�;�/r6c�z�gd�}|D]2}|jtjtj|d��4y)z|
        Trying to parse an invalid representation of a sequence range raises an
        L{IllegalIdentifierError}.
        )s*:*rqs4:sbar:5�90N�r�r�IllegalIdentifierErrorr��rEr�rds   r4�test_invalidIdListParserz)IMAP4HelperTests.test_invalidIdListParser�s;��
3���	�E�����,�,�e�.?�.?���
�	r6c�z�gd�}|D]2}|jtjtj|d��4y)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).
        )s0:5s0:0s*:0�0s-3:5s1:-2s-1r4Nr5r7s   r4�#test_invalidIdListParserNonPositivez4IMAP4HelperTests.test_invalidIdListParserNonPositive�s<��I���	�E�����,�,�e�.?�.?���
�	r6c��gd�}tdd�tdd�tdd�tdd�ztdd�td�tdd�td�td�ztd�ztdd�tdd�tdd�tdd	�ztd�tdd�ztd�tdd�ztd
d	�ztdd�td
�ztd	d�ztdd�g}gd
�}t||�D]*\}}|jtj|�|��,t||�D]p\}}|�/|jtttj|���7ttj|��}|j||d|�d|�d|����ry)zi
        The function to parse sequence ranges yields appropriate L{MessageSet}
        objects.
        )r�s5:*s1:2,5:*r��1s1,2s1,3,5s1:10s1:10,11s	1:5,10:20s1,5:10s1,5:10,15:20s
1:10,15,20:25�4:2r�Nr�r�r�r���r'�r�)NNNr�r�r�r�r�r?�r��
�r�zlen(z) = z != )rr�rBrr�r�r�r�)rEr�r��lengthsrdrh�Ls       r4�test_parseIdListz!IMAP4HelperTests.test_parseIdList�s���

��$
�q�$���q�$���q�$��*�Q��"2�2��t�T�"��q�M��q�!���q�M�J�q�M�)�J�q�M�9��q�"���q�"���q�!��z�"�b�1�1��q�M�J�q�"�-�-��q�M�J�q�"�-�-�
�2�r�0B�B��q�"��
�2��.��B��1C�C��q�!��
��"K��"�6�7�3�	A�O�E�8����U�.�.�u�5�x�@�	A� #�6�7�3�	Y�O�E�8����!�!�)�S�%�2C�2C�E�2J�K���)�)�%�0�1��� � ��H��U�I�T�!��d�8�,�.W�X�	Yr6c�N�|jttjd�y)zu
        L{imap4.parseTime} raises L{ValueError} when given a a time
        string whose format is invalid.
        �invalidN�r�rr�	parseTimerRs r4�test_parseTimeInvalidFormatz,IMAP4HelperTests.test_parseTimeInvalidFormat�s��
	
���*�e�o�o�y�Ar6c�d�gd�}|D]'}|jttj|��)y)zv
        L{imap4.parseTime} raises L{ValueError} when given a time
        string composed of invalid values.
        )zinvalid-July-2017z2-invalid-2017z2-July-invalidNrJ)rE�invalidStringsrIs   r4�test_parseTimeInvalidValuesz,IMAP4HelperTests.test_parseTimeInvalidValues�s2��

��
&�	D�G����j�%�/�/�7�C�	Dr6c� �t�}|j�|j�|j�|j	�|j�d�}t
j||j��}|j||�y)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�mboxrhr2s    r4�test_statusRequestHelperz)IMAP4HelperTests.test_statusRequestHelpersx������,�,�.��)�)�+����(��.�.�0��)�)�+�
���*�*�4�����A������6�*r6N),rsrtrur3r9r@r]r_rir~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr r"r%r-r0r2r8r;rGrLrOr_r1r6r4r5r5�s����>�)�03�46�4�&8@�tD�0M,�^9�*6�&r
�hQ�(�@�M�M�
<�F�U�	U�A�?�L�C�(F�!.�F	5�	7�4�2�V�
�2
.�
0�
��1Y�fB�D�+r6r5c��eZdZUdZgZded<dZdZdZd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zy)rV�z\Flag1�Flag2z\AnotherSysFlag�LastFlag�+list[tuple[bytes, list[bytes], bytes, int]]rrr�Fc�~�g|_|jj|_|jj|_yr0��	listenersr|�addListener�remove�removeListenerrRs r4rzzSimpleMailbox.__init__!�-������>�>�0�0���"�n�n�3�3��r6c��|jSr0�r�rRs r4�getFlagszSimpleMailbox.getFlags&����z�z�r6c��y)N�*r1rRs r4rZzSimpleMailbox.getUIDValidity)s��r6c�2�t|j�dzS�Nr��r�rrRs r4rYzSimpleMailbox.getUIDNext,s���4�=�=�!�A�%�%r6c��y)Nr�r1rRs r4rWzSimpleMailbox.getMessageCount/���r6c��y)Nr�r1rRs r4rXzSimpleMailbox.getRecentCount2rvr6c��y)Nr�r1rRs r4r[zSimpleMailbox.getUnseenCount5rvr6c��|jSr0��rwrRs r4�isWriteablezSimpleMailbox.isWriteable8s���w�w�r6c��yr0r1rRs r4�destroyzSimpleMailbox.destroy;���r6c��y)NrQr1rRs r4�getHierarchicalDelimiterz&SimpleMailbox.getHierarchicalDelimiter>s��r6c��i}d|vr|j�|d<d|vr|j�|d<d|vr|j�dz|d<d|vr|j�|d<d|vr|j�|d<t	j
|�S)NrQrRrSr�rTrU�rWrX�getUIDr[rr[�rE�names�rs   r4�
requestStatuszSimpleMailbox.requestStatusAs�������� �0�0�2�A�j�M��u���-�-�/�A�h�K�����/�/�1�A�5�A�i�L��E�!�#�{�{�}�A�m���u���-�-�/�A�h�K��}�}�Q��r6Nc��|jj||||jf�|xjdz
c_tjd�Srs�rr|�mUIDrr[�rE�messager��dates    r4�
addMessagezSimpleMailbox.addMessageOs=���
�
���g�u�d�D�I�I�>�?��	�	�Q��	��}�}�T�"�"r6c���g}|jD]}d|dvs�|j|��|D]}|jj|��|D�cgc]}|d��	c}Scc}w)N�\Deletedr�r��rr|ri�rE�deleter�s   r4�expungezSimpleMailbox.expungeTsm�������	!�A��a��d�"��
�
�a� �	!��	$�A��M�M� � ��#�	$�$�%���!��%�%��%��A"c��d|_y�NT)�closedrRs r4�closezSimpleMailbox.close]s	����r6c��yr0r1�rErr�s   r4�fetchzSimpleMailbox.fetch`���r6c��yr0r1�rEr�s  r4r�zSimpleMailbox.getUIDdr�r6c��yr0r1�rErr��moder�s     r4�storezSimpleMailbox.storehr�r6r0)rsrtrur�r�__annotations__r�r{r�rzrnrZrYrWrXr[r|r~r�r�r�r�r�r�r�r�r1r6r4rVrVsv��@�E�<>�H�9�>��D�	
�B�
�F�4�
��&�����
�� �#�
&��
�
�
r6rVc��eZdZUdZdZgZded<dZdZdZ	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zy)�UncloseableMailboxz*
    A mailbox that cannot be closed.
    rardrrr�Fc�~�g|_|jj|_|jj|_yr0rfrRs r4rzzUncloseableMailbox.__init__yrkr6c��|jS)zB
        The flags

        @return: A sequence of flags.
        rmrRs r4rnzUncloseableMailbox.getFlags~s���z�z�r6c��y)zF
        The UID validity value.

        @return: The value.
        rqr1rRs r4rZz!UncloseableMailbox.getUIDValidity�s��r6c�2�t|j�dzS)z:
        The next UID.

        @return: The UID.
        r�rtrRs r4rYzUncloseableMailbox.getUIDNext�s���4�=�=�!�A�%�%r6c��y)zG
        The number of messages.

        @return: The number.
        r�r1rRs r4rWz"UncloseableMailbox.getMessageCount����r6c��y)�D
        The recent messages.

        @return: The number.
        r�r1rRs r4rXz!UncloseableMailbox.getRecentCount�r�r6c��y)r�r�r1rRs r4r[z!UncloseableMailbox.getUnseenCount�r�r6c��|jS)z`
        The recent messages.

        @return: Whether or not the mailbox is writable.
        rzrRs r4r|zUncloseableMailbox.isWriteable�s
���w�w�r6c��y)z'
        Destroy this mailbox.
        Nr1rRs r4r~zUncloseableMailbox.destroy�s��	
r6c��y)zU
        Return the hierarchical delimiter.

        @return: The delimiter.
        rQr1rRs r4r�z+UncloseableMailbox.getHierarchicalDelimiter�s��r6c��i}d|vr|j�|d<d|vr|j�|d<d|vr|j�dz|d<d|vr|j�|d<d|vr|j�|d<t	j
|�S)z�
        Return the mailbox's status.

        @param names: The status items to include.

        @return: A L{dict} of status data.
        rQrRrSr�rTrUr�r�s   r4r�z UncloseableMailbox.requestStatus�s���
����� �0�0�2�A�j�M��u���-�-�/�A�h�K�����/�/�1�A�5�A�i�L��E�!�#�{�{�}�A�m���u���-�-�/�A�h�K��}�}�Q��r6Nc��|jj||||jf�|xjdz
c_tjd�S)a
        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.
        r�Nr�r�s    r4r�zUncloseableMailbox.addMessage�s?��	
�
�
���g�u�d�D�I�I�>�?��	�	�Q��	��}�}�T�"�"r6c���g}|jD]}d|dvs�|j|��|D]}|jj|��|D�cgc]}|d��	c}Scc}w)zj
        Delete messages marked for deletion.

        @return: A L{list} of deleted message IDs.
        r�r�r�r�r�s   r4r�zUncloseableMailbox.expunge�so�������	!�A��a��d�"��
�
�a� �	!��	$�A��M�M� � ��#�	$�$�%���!��%�%��%r�c��yr0r1r�s   r4r�zUncloseableMailbox.fetch�r�r6c��yr0r1r�s  r4r�zUncloseableMailbox.getUID�r�r6c��yr0r1r�s     r4r�zUncloseableMailbox.storer�r6r0)rsrtrur3r�rr�r�r{r�rzrnrZrYrWrXr[r|r~r�r�r�r�r�r�r�r1r6r4r�r�msy���
A�E�<>�H�9�>��D�	
�B�
�F�4�
��&�����
�� �*#�"&�
�
�
r6r�c�"�eZdZdZeZd�Zdd�Zy)�AccountWithoutNamespaceszL
    An in-memory account that does not provide L{INamespacePresenter}.
    c�"�|j�Sr0)�mailboxFactory)rE�name�ids   r4�
_emptyMailboxz&AccountWithoutNamespaces._emptyMailboxs���"�"�$�$r6c�X�tjj||�}|�||_|Sr0)r�
MemoryAccount�selectr{)rEr�r{r^s    r4r�zAccountWithoutNamespaces.selects,���"�"�)�)�$��5�����D�G��r6N�r�)rsrtrur3rVr�r�r�r1r6r4r�r�s���#�N�%�r6r�c��eZdZdZy)�AccountzD
    An in-memory account that provides L{INamespacePresenter}.
    N�rsrtrur3r1r6r4r�r�s��r6r�c�(�eZdZed�Zd�Zd�Zy)�SimpleServer�testuserc��tjj|g|��i|��t|��}t	|�}t�}|j
dd�||_||_|j|�d|_
y)N��
accountHolderr��
password-testF)r�IMAP4Serverrz�	TestRealmrr�addUser�checker�portal�registerChecker�timeoutTest)rE�args�kw�realmr�r�s      r4rzzSimpleServer.__init__sn��
���"�"�4�5�$�5�"�5���-������3�5��	�	�	�+�/�0����������q�!� ��r6c�^�|jrytjj||�yr0)r�rr��lineReceived�rE�lines  r4r�zSimpleServer.lineReceived*s$������
���&�&�t�T�2r6N)rsrtrur��
theAccountrzr�r1r6r4r�r�s����%�J�	!�3r6r�c�,�eZdZdd�Zd�Zd�Zd�Zd�Zy)�SimpleClientNc�`�tjj||�||_g|_yr0)r�IMAP4Clientrz�deferred�events)rEr��contextFactorys   r4rzzSimpleClient.__init__3s&��
���"�"�4��8� ��
���r6c�:�|jjd�yr0)r��callback)rE�capss  r4�serverGreetingzSimpleClient.serverGreeting8s���
�
���t�$r6c�r�|jjd|g�|jj�y)N�modeChanged�r�r|�	transport�loseConnection)rE�	writeables  r4r�zSimpleClient.modeChanged;s)�������M�9�5�6����%�%�'r6c�r�|jjd|g�|jj�y)N�flagsChangedr��rE�newFlagss  r4r�zSimpleClient.flagsChanged?s)�������N�H�5�6����%�%�'r6c�t�|jjd||g�|jj�y)N�newMessagesr�)rE�exists�recents   r4r�zSimpleClient.newMessagesCs+�������M�6�6�:�;����%�%�'r6r0)rsrtrurzr�r�r�r�r1r6r4r�r�2s���
%�(�(�(r6r�c�N�eZdZUdZded<dZded<d�Zd�Zd�Zd	�Z	d
�Z
d�Zy)�IMAP4HelperMixinNzOptional[ServerTLSContext]�	serverCTXzOptional[ClientTLSContext]�	clientCTXc��tj�}t|j��|_t||j��|_||_gt_
td�}t|_|t_
y)N�r�r�)rrr�r��serverr�r��client�	connectedrVrr��mboxTyper�)rEr�r�s   r4�setUpzIMAP4HelperMixin.setUpLsY���N�N���"�$�.�.�A���"�1�T�^�^�D������!#�
���[�)�
�+�
��",��r6c��|`|`|`yr0)r�r�r�rRs r4�tearDownzIMAP4HelperMixin.tearDownWs���K��K��Nr6c�L�|jjj�yr0)r�r�r�)rE�ignores  r4�
_cbStopClientzIMAP4HelperMixin._cbStopClient\s�������,�,�.r6c���|jjj�|jjj�t	j
|dt
|�z�y)N�
Problem with )r�r�r�r�r%�errr�)rEr$s  r4�
_ebGeneralzIMAP4HelperMixin._ebGeneral_sE�������,�,�.������,�,�.������3�t�9�4�5r6c�V�tj|j|j�Sr0)r#�
loopbackAsyncr�r�rRs r4r#zIMAP4HelperMixin.loopbackds���%�%�d�k�k�4�;�;�?�?r6c��|jtj�t|j�}t|�}|j
||�y)a.
        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)rEr$rhr�s    r4�assertClientFailureMessagez+IMAP4HelperMixin.assertClientFailureMessagegs?��	����U�)�)�*��g�m�m�$����>������(�+r6)rsrtrur�r�r�rrrr
r#rr1r6r4r�r�Hs7��,0�I�)�0�,0�I�)�0�	-��
/�6�
@�,r6r�c�>�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-d,�Z.d-�Z/d.�Z0d/�Z1d0�Z2d1�Z3d2�Z4d3�Z5y4)5�IMAP4ServerTestsc�����i���fd�}�jjt|��j�j�}tj�j�|g�}dddd��|j���fd��S)Nc�b����fd�}�jj�j|�S)Nc�p���j|��jjj�yr0��updater�r�r��r�r�rEs ��r4�gotCapszAIMAP4ServerTests.testCapability.<locals>.getCaps.<locals>.gotCaps~�$������A�����%�%�4�4�6r6�r��getCapabilitiesr��rr�rEs ��r4�getCapsz0IMAP4ServerTests.testCapability.<locals>.getCaps}�(���
7��;�;�.�.�0�<�<�W�E�Er6)�	IMAP4rev1�	NAMESPACE�IDLEc�(���j���Sr0�rB)�_r�rhrEs ���r4r5z1IMAP4ServerTests.testCapability.<locals>.<lambda>�s���t�'7�'7��$�'G�r6)r�r�r7�
addErrbackr
r�
gatherResultsr#)rEr�d1r�r�rhs`   @@r4�testCapabilityzIMAP4ServerTests.testCapabilityzsn�����	F��^�^�
'�
'��g��
7�
B�
B�4�?�?�
S���������"� 5�6��"&�d�T�J���}�}�G�H�Hr6c�R����i�t�jjd<��fd�}�jj	t|��j
�j�}tj�j�|g�}ddddgd��|j	���fd��S)N�CRAM-MD5c�b����fd�}�jj�j|�S)Nc�p���j|��jjj�yr0rrs ��r4rzIIMAP4ServerTests.testCapabilityWithAuth.<locals>.getCaps.<locals>.gotCaps�rr6rrs ��r4rz8IMAP4ServerTests.testCapabilityWithAuth.<locals>.getCaps�r r6)r!r"r#�AUTHc�(���j���Sr0r%)r&r��expCaprEs ���r4r5z9IMAP4ServerTests.testCapabilityWithAuth.<locals>.<lambda>�s���t�'7�'7���'E�r6)rr��challengersr�r�r7r'r
rr(r#)rErr)r�r�r1s`   @@r4�testCapabilityWithAuthz'IMAP4ServerTests.testCapabilityWithAuth�s������/A�������,�	F��^�^�
'�
'��g��
7�
B�
B�4�?�?�
S���������"� 5�6�����!�]�	
���}�}�E�F�Fr6c����d�_�fd�}�jjt|��j	�j
��j
�}|j�fd��S)Nrc�t���fd�}�jj�jt|��y)Nc���d�_yrs)�	loggedOutrRs�r4�setLoggedOutzAIMAP4ServerTests.testLogout.<locals>.logout.<locals>.setLoggedOut�s
���!"��r6)r��logoutr�r7)r8rEs �r4r9z+IMAP4ServerTests.testLogout.<locals>.logout�s*���
#�
�K�K��� �,�,�U�<�-@�Ar6c�<���j�jd�Srs)rBr7�r&rEs �r4r5z-IMAP4ServerTests.testLogout.<locals>.<lambda>�s���t�'7�'7�����'J�r6)r7r�r�r7r'r
r#)rEr9r�s`  r4�
testLogoutzIMAP4ServerTests.testLogout�sR������	B�	
���"�"�5��=�1�<�<�T�_�_�M��M�M�O���}�}�J�K�Kr6c����d�_�fd�}�jjt|��j	�j
��j
�}|j�fd��S)Nc�b���fd�}�jj�j|�y)Nc�\��|�_�jjj�yr0)�	responsesr�r�r�)r@rEs �r4�setResponsesz=IMAP4ServerTests.testNoop.<locals>.noop.<locals>.setResponses�s ���!*������%�%�4�4�6r6)r��noopr�)rArEs �r4rBz'IMAP4ServerTests.testNoop.<locals>.noop�s%���
7�
�K�K����*�*�<�8r6c�<���j�jg�Sr0)rBr@r;s �r4r5z+IMAP4ServerTests.testNoop.<locals>.<lambda>�s���t�'7�'7�����'K�r6)r@r�r�r7r'r
r#)rErBr�s`  r4�testNoopzIMAP4ServerTests.testNoop�sQ������	9�	
���"�"�5��;�/�:�:�4�?�?�K��M�M�O���}�}�K�L�Lr6c����fd�}�jjt|��j�j�}tj|�j�g�}|j�j�S)Nc�t���jjdd�}|j�j�y�Nr�r�)r��loginr�r�r�rEs �r4rHz)IMAP4ServerTests.testLogin.<locals>.login�s,������!�!�+�/?�@�A�
�M�M�$�,�,�-r6)	r�r�r7r'r
rr(r#�_cbTestLogin�rErHr)r�s`   r4�	testLoginzIMAP4ServerTests.testLogin�sa���	.��^�^�
'�
'��e��
5�
@�
@����
Q������T�]�]�_� 5�6���}�}�T�.�.�/�/r6c��|j|jjtj�|j|jj
d�y�N�auth�rBr��accountr�r��state�rE�ignoreds  r4rJzIMAP4ServerTests._cbTestLogin��<��������,�,�l�.E�.E�F�������*�*�F�3r6c����fd�}�jjt|��j�j�}�j�}t
j||g�}|j�j�S)Nc�t���jjdd�}|j�j�y�Nr�swrong-password�r�rH�addBothrrIs �r4rHz/IMAP4ServerTests.testFailedLogin.<locals>.login��,������!�!�+�/@�A�A�
�I�I�d�(�(�)r6)	r�r�r7r'r
r#rr(�_cbTestFailedLogin�rErHr)�d2r�s`    r4�testFailedLoginz IMAP4ServerTests.testFailedLogin�se���	*��^�^�
'�
'��e��
5�
@�
@����
Q��
�]�]�_������R��)���}�}�T�4�4�5�5r6c��|j|jjd�|j|jjd�y)N�unauth)rBr�rQrRrSs  r4r\z#IMAP4ServerTests._cbTestFailedLogin�s6��������,�,�d�3�������*�*�H�5r6c�.��d�j_�fd�}�jjt	|��j�j�}�j�}tj||g�}|j�j�S)zj
        Attempting to log into a server that has no L{Portal} results
        in a failed login.
        Nc�t���jjdd�}|j�j�yrXrYrIs �r4rHz7IMAP4ServerTests.test_loginWithoutPortal.<locals>.login�r[r6)r�r�r�r�r7r'r
r#rr(r\r]s`    r4�test_loginWithoutPortalz(IMAP4ServerTests.test_loginWithoutPortal�ss���
"�����	*��^�^�
'�
'��e��
5�
@�
@����
Q��
�]�]�_������R��)���}�}�T�4�4�5�5r6c�\��d�}|�jjj_�fd�}�jjt
|��j�j�}�j�}tj||g�}|j�j�S)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��ddd�fS)NzNot IAccountzNot an accountc��yr0r1r1r6r4r5zVIMAP4ServerTests.test_nonIAccountAvatar.<locals>.brokenRequestAvatar.<locals>.<lambda>���r6r1)r&�__s  r4�brokenRequestAvatarzDIMAP4ServerTests.test_nonIAccountAvatar.<locals>.brokenRequestAvatar�s��"�$4�l�C�Cr6c�t���jjdd�}|j�j�yrGrYrIs �r4rHz6IMAP4ServerTests.test_nonIAccountAvatar.<locals>.login�s,������!�!�+�/?�@�A�
�I�I�d�(�(�)r6)
r�r�r��
requestAvatarr�r�r7r'r
r#rr(r\)rErjrHr)r^r�s`     r4�test_nonIAccountAvatarz'IMAP4ServerTests.test_nonIAccountAvatar�s����	D�2E������ � �.�	*��^�^�
'�
'��e��
5�
@�
@����
Q��
�]�]�_������R��)���}�}�T�4�4�5�5r6c�����Gd�dt���fd�}|�j_�fd�}�jj	t|��}|j
�jd�|j��fd��}|j
�j�|j�j��j�}tj||g�}|j	�j�S)z�
        Any exception raised by L{IMAP4Server.authenticateLogin} that
        is not L{UnauthorizedLogin} is logged results in a C{BAD}
        response.
        c��eZdZdZy)�AIMAP4ServerTests.test_loginException.<locals>.UnexpectedException�2
            An unexpected exception.
            Nr�r1r6r4�UnexpectedExceptionrp���
r6rrc����d��)N�Whoopsr1)�user�passwdrrs  �r4�raisesUnexpectedExceptionzGIMAP4ServerTests.test_loginException.<locals>.raisesUnexpectedExceptions���%�h�/�/r6c�<���jjdd�SrG�r�rHrRs�r4rHz3IMAP4ServerTests.test_loginException.<locals>.login
�����;�;�$�$�[�2B�C�Cr6sServer error: Whoopsc�F���j�j���yr0�rV�flushLoggedErrors)r&rrrEs ��r4�assertErrorLoggedz?IMAP4ServerTests.test_loginException.<locals>.assertErrorLoggeds����O�O�D�2�2�3F�G�Hr6)r�r��authenticateLoginr�r�r7r'rr
rZrr#rr(r\)rErxrHr)rr^r�rrs`      @r4�test_loginExceptionz$IMAP4ServerTests.test_loginException�s����	�)�	�
	0�)B����%�	D��^�^�
'�
'��e��
5��
�
�
�d�5�5�7N�O�	���	I�
�	I�	�
�
�d�o�o�&�
�
�
�4�%�%�&�
�]�]�_������R��)���}�}�T�4�4�5�5r6c�B��ddi�jj_�fd�}�jj	t|��j
�j�}tj�j�|g�}|j	�j�S)N�
{test}user�{test}passwordc�����jjdd�}|jtjdt��z�|j
�j�y)Nr�r�r)r�rHr'r%r	r�r�rrIs �r4rHz9IMAP4ServerTests.testLoginRequiringQuoting.<locals>.login"sG������!�!�-�1B�C�A�
�L�L����/�C��I�"=�>�
�M�M�$�,�,�-r6)r�r��usersr�r�r7r'r
rr(r#�_cbTestLoginRequiringQuotingrKs`   r4�testLoginRequiringQuotingz*IMAP4ServerTests.testLoginRequiringQuotingsy���%2�4E�$F������!�	.�
�^�^�
'�
'��e��
5�
@�
@����
Q���������"� 5�6���}�}�T�>�>�?�?r6c��|j|jjtj�|j|jj
d�yrNrPrSs  r4r�z-IMAP4ServerTests._cbTestLoginRequiringQuoting+rUr6c���d�_�fd�}�fd�}�jjt|��}|jt|��|j	�j
��j
�}tj||g�}|j�fd��}|j�jddggggg�|S)Nc�<���jjdd�SrGrzrRs�r4rHz-IMAP4ServerTests.testNamespace.<locals>.login2r{r6c�`���fd�}�jj�j|�S)Nc�6��|�_�jd�yr0��
namespaceArgsr�r�rEs �r4�gotNamespacezGIMAP4ServerTests.testNamespace.<locals>.namespace.<locals>.gotNamespace6����%)��"��"�"�4�(r6�r��	namespacer��r�rEs �r4r�z1IMAP4ServerTests.testNamespace.<locals>.namespace5�(���
)��;�;�(�(�*�6�6�|�D�Dr6c����jD]&}|D]}|D]}�j|t���!�(�jSr0)r�r�r�)rT�
namespaces�pairrrEs    �r4�assertAllPairsNativeStringszCIMAP4ServerTests.testNamespace.<locals>.assertAllPairsNativeStringsBsT���"�0�0�
:�
�&�:�D�!%�:���-�-�e�S�9�:�:�
:��%�%�%r6r(rQ)
r�r�r�r7r'r
r#rr(rB)rErHr�r)r^r�r�s`      r4�
testNamespacezIMAP4ServerTests.testNamespace/s����!���	D�	E��^�^�
'�
'��e��
5��
���u�Y�'�(�
�
�
�d�o�o�&�
�]�]�_������R��)��	
���	&�
�	&�	
�
�
�d�&�&�2�s�)��b�"�(=�>��r6c����td��j_d�_�fd�}�fd�}�jjt
|��}|jt
|��|j�j��j�}tj||g�}|j�fd��|j�jgggg�|S)z�
        A mailbox that does not provide L{INamespacePresenter} returns
        empty L{list}s for its personal, shared, and user namespaces.
        r�Nc�<���jjdd�SrGrzrRs�r4rHz<IMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.loginUr{r6c�`���fd�}�jj�j|�S)Nc�6��|�_�jd�yr0r�r�s �r4r�zVIMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.namespace.<locals>.gotNamespaceYr�r6r�r�s �r4r�z@IMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.namespaceXr�r6c����jSr0)r�r;s �r4r5z?IMAP4ServerTests.test_mailboxWithoutNamespace.<locals>.<lambda>ds
���� 2� 2�r6)
r�r�r�r�r�r�r7r'r
r#rr(rB)rErHr�r)r^r�s`     r4�test_mailboxWithoutNamespacez-IMAP4ServerTests.test_mailboxWithoutNamespaceMs����
":�+�!F�����!���	D�	E��^�^�
'�
'��e��
5��
���u�Y�'�(�
�
�
�d�o�o�&�
�]�]�_������R��)��	�
�
�2�3�	�
�
�d�&�&��R���5��r6c���tjjd�d�_�fd�}�fd�}�jjt
|��}|jt
|��|j�j��j�}tj||g�j�j�S)N�test-mailboxc�<���jjdd�SrGrzrRs�r4rHz*IMAP4ServerTests.testSelect.<locals>.loginlr{r6c�j���fd�}�jjd�}|j|�|S)Nc�6��|�_�jd�yr0)�selectedArgsrr�s �r4�selectedz=IMAP4ServerTests.testSelect.<locals>.select.<locals>.selectedp����$(��!��"�"�4�(r6r�)r�r�r�)r�r�rEs  �r4r�z+IMAP4ServerTests.testSelect.<locals>.selectos/���
)����"�"�>�2�A�
�M�M�(�#��Hr6)
r�r��
addMailboxr�r�r�r7r'r
r#rr(�
_cbTestSelect)rErHr�r)r^s`    r4�
testSelectzIMAP4ServerTests.testSelecths�������*�*�>�:� ���	D�	��^�^�
'�
'��e��
5��
���u�V�}�%�
�
�
�d�o�o�&�
�]�]�_���"�"�B��8�,�8�8��9K�9K�L�Lr6c����fd�}�fd�}�jjt|���jjt|���jj�jd��jj�j
��jj�j�tj�j�j�g�}|j�fd��}|S)zh
        A client that selects a mailbox that does not exist receives a
        C{NO} response.
        c�<���jjdd�SrGrzrRs�r4rHz9IMAP4ServerTests.test_selectWithoutMailbox.<locals>.login�r{r6c�:���jjd�S)Nr��r�r�rRs�r4r�z:IMAP4ServerTests.test_selectWithoutMailbox.<locals>.select������;�;�%�%�n�5�5r6�No such mailboxc�P���j�jj�yr0)�assertIsNoner�r^r;s �r4�assertNoMailboxSelectedzKIMAP4ServerTests.test_selectWithoutMailbox.<locals>.assertNoMailboxSelected�s������d�k�k�.�.�/r6)
r�r�r7r'rrr
rr(r#)rErHr��connectionCompleter�s`    r4�test_selectWithoutMailboxz*IMAP4ServerTests.test_selectWithoutMailbox~s����	D�	6�	
���"�"�5��<�0����"�"�5��=�1����!�!�$�"A�"A�CU�V����"�"�4�#5�#5�6����!�!�$�/�/�2�"�0�0�$�.�.�$�-�-�/�1R�S��	�	'�	'�	0�
(�	0�"�!r6c	���tjjd}|j|jj
|�|j|jdddddd��y)N�TEST-MAILBOXr�r�rqraT��EXISTSrRrTr��
READ-WRITE)r�r��	mailboxesrBr�r^r��rErTr^s   r4r�zIMAP4ServerTests._cbTestSelect�s]���&�&�0�0��@��������)�)�4�0���������!�M�"�
�		
r6c���tjjd�d�_�fd�}�fd�}�jjt
|��}|jt
|��|j�j��j�}tj||g�}|j�j�S)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.
        r�Nc�<���jjdd�SrGrzrRs�r4rHz,IMAP4ServerTests.test_examine.<locals>.login�r{r6c�j���fd�}�jjd�}|j|�|S)Nc�6��|�_�jd�yr0)�examinedArgsrr�s �r4�examinedz@IMAP4ServerTests.test_examine.<locals>.examine.<locals>.examined�r�r6r�)r��examiner�)r�r�rEs  �r4r�z.IMAP4ServerTests.test_examine.<locals>.examine�s/���
)����#�#�N�3�A�
�M�M�(�#��Hr6)
r�r�r�r�r�r�r7r'r
r#rr(�_cbTestExamine)rErHr�r)r^r�s`     r4�test_examinezIMAP4ServerTests.test_examine�s����	���*�*�>�:� ���	D�	��^�^�
'�
'��e��
5��
���u�W�~�&�
�
�
�d�o�o�&�
�]�]�_������R��)���}�}�T�0�0�1�1r6c	���tjjd}|j|jj
|�|j|jdddddd��y)Nr�r�r�rqraFr�)r�r�r�rBr�r^r�r�s   r4r�zIMAP4ServerTests._cbTestExamine�s]���&�&�0�0��@��������)�)�4�0���������!�M�#�
�		
r6c�R�����	�d�	d��fd���fd���fd�}�����	fd�}g�_�jjt|��jt|��}�j	�}tj||g�}|j�j�	��S)N)�testbox�test/boxztest/�test/box/box�INBOX)r�r�c�<���jjd�yrs�r2r|rRs�r4�cbz'IMAP4ServerTests.testCreate.<locals>.cb������K�K���q�!r6c�<���jjd�y�Nrr��r$rEs �r4�ebz'IMAP4ServerTests.testCreate.<locals>.eb�r�r6c�<���jjdd�SrGrzrRs�r4rHz*IMAP4ServerTests.testCreate.<locals>.login�r{r6c������zD]F}�jj|�}|jt���j	���Hj�j�j�yr0)r��creater�r7r'�addCallbacksrr
)r�r�r�r�rZrEr[s  �����r4r�z+IMAP4ServerTests.testCreate.<locals>.create�s_����$��
8���K�K�&�&�t�,���
�
�e�B�i�(�3�3�B�7�
8�
�N�N�4�-�-�t���?r6)r2r�r�r7r#rr(�
_cbTestCreate)
rErHr�r)r^r�r�r�rZr[s
`     @@@@r4�
testCreatezIMAP4ServerTests.testCreate�s����K��&��	"�	"�	D�	@�	@����
�^�^�
'�
'��e��
5�
A�
A�%��-�
P��
�]�]�_������R��)���}�}�T�/�/��$�?�?r6c�<�|j|jdgt|�zdgt|�zz�ttj
j�}tgd��}|j||D�cgc]}|j���c}�ycc}w)Nr�r)�inboxr�r��testr�)rBr2r�rfr�r�r�r,)rErTr[rZr^rz�as       r4r�zIMAP4ServerTests._cbTestCreate�su��������q�c�C��L�&8�A�3��T��?�&J�K��l�-�-�7�7�8���Q�R������7�;�a����	�;�<��;s�:B
c���tjjd��fd�}�fd�}�jj	t|��}|j
t|��j�|j
�j�j��j�}tj||g�}|j	�fd��|S)N�	delete/mec�<���jjdd�SrGrzrRs�r4rHz*IMAP4ServerTests.testDelete.<locals>.login�r{r6c�:���jjd�S�Nr��r�r�rRs�r4r�z+IMAP4ServerTests.testDelete.<locals>.delete������;�;�%�%�k�2�2r6c�j���jttjj�g�Sr0)rBr�r�r�r�r;s �r4r5z-IMAP4ServerTests.testDelete.<locals>.<lambda>	s&���d�&�&�t�L�,C�,C�,M�,M�'N�PR�S�r6�r�r�r�r�r�r7r�r
rr#rr()rErHr�r)r^r�s`     r4�
testDeletezIMAP4ServerTests.testDelete�s�������*�*�;�7�	D�	3��^�^�
'�
'��e��
5��
����f�
�t���7�
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�S�	
��r6c���tjjd�tjjd��fd�}�fd�}�fd�}�jj	t|��}|j
t|��j�|j|�|j
�j��j�}tj||g�}|j	�fd��|S)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�<���jjdd�SrGrzrRs�r4rHzGIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.login	r{r6c�:���jjd�S�Nr�r�rRs�r4r�zHIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.delete	�����;�;�%�%�h�/�/r6c���|jtj��jt	|j
�t	d��y)Ns-Name "DELETE" has inferior hierarchical names)rrrrBr�rr�s �r4�assertIMAPExceptionzUIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.assertIMAPException	s:����G�L�L��-�-�.�����G�M�M�"��D�E�
r6c�n���jttjj�ddg�S)N�DELETEz	DELETE/ME)rBrfr�r�r�r;s �r4r5zJIMAP4ServerTests.testDeleteWithInferiorHierarchicalNames.<locals>.<lambda>,	s-���d�&�&��|�.�.�8�8�9�H�k�;R��r6)
r�r�r�r�r�r7r�r
r'rr#rr()rErHr�r��loggedIn�
loopedBackr�s`      r4�'testDeleteWithInferiorHierarchicalNamesz8IMAP4ServerTests.testDeleteWithInferiorHierarchicalNames	s����	���*�*�8�4����*�*�;�7�	D�	0�	��>�>�-�-�e�E�l�;�����e�F�m�T�_�_�=����/�0����d�0�0�1��]�]�_�
�����:� 6�7��	�
�
�
�	
�
�r6c���d�_�fd�}�fd�}�fd�}�jjt|��}|j	t|��j
�|j
|�|j	�j�j
��j�}tj||g�}|j�fd��|S)Nc�<���jjdd�SrGrzrRs�r4rHz6IMAP4ServerTests.testIllegalInboxDelete.<locals>.login5	r{r6c�:���jjd�S)Nr�r�rRs�r4r�z7IMAP4ServerTests.testIllegalInboxDelete.<locals>.delete8	s����;�;�%�%�g�.�.r6c���|�_yr0��stashed�r2rEs �r4�stashz6IMAP4ServerTests.testIllegalInboxDelete.<locals>.stash;	s
���!�D�Lr6c�j���jt�jtj��Sr0�rVr�r�r$�Failurer;s �r4r5z9IMAP4ServerTests.testIllegalInboxDelete.<locals>.<lambda>E	����d�o�o�j����w���&O�P�r6�r�r�r�r7r�r
rZrr#rr()rErHr�r�r)r^r�s`      r4�testIllegalInboxDeletez'IMAP4ServerTests.testIllegalInboxDelete2	s�������	D�	/�	"��^�^�
'�
'��e��
5��
����f�
�t���7�
�
�
�5��
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�P�	
��r6c����fd�}�fd�}�fd�}d�_�jjt|��}|jt|��j	|�|j�j�j��j�}tj||g�}|j�fd��|S)Nc�<���jjdd�SrGrzrRs�r4rHz5IMAP4ServerTests.testNonExistentDelete.<locals>.loginJ	r{r6c�:���jjd�Sr�r�rRs�r4r�z6IMAP4ServerTests.testNonExistentDelete.<locals>.deleteM	r�r6c���|�_yr0�r$r�s �r4�deleteFailedz<IMAP4ServerTests.testNonExistentDelete.<locals>.deleteFailedP	�
���"�D�Lr6c�t���jt�jj�td��S)Nr��rBr�r$rr;s �r4r5z8IMAP4ServerTests.testNonExistentDelete.<locals>.<lambda>Z	s)���d�&�&�s�4�<�<�+=�+=�'>��DV�@W�X�r6)r$r�r�r7r'r�rr
r#rr()rErHr�r	r)r^r�s`      r4�testNonExistentDeletez&IMAP4ServerTests.testNonExistentDeleteI	s����	D�	3�	#����
�^�^�
'�
'��e��
5��
���u�V�}�%�0�0��>�
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�X�	
��r6c�J���t�}d|_tjj	d|�tjj	d��fd�}�fd�}�fd�}d�_�jjt|��}|jt|��j|�|j�j�j��j�}tj||g�}t!d��|j��fd��|S)	N)z	\Noselectr�r�c�<���jjdd�SrGrzrRs�r4rHz1IMAP4ServerTests.testIllegalDelete.<locals>.logind	r{r6c�:���jjd�Sr�r�rRs�r4r�z2IMAP4ServerTests.testIllegalDelete.<locals>.deleteg	r�r6c���|�_yr0rr�s �r4r	z8IMAP4ServerTests.testIllegalDelete.<locals>.deleteFailedj	r
r6s<Hierarchically inferior mailboxes exist and \Noselect is setc�b���jt�jj���Sr0r)r&rhrEs ��r4r5z4IMAP4ServerTests.testIllegalDelete.<locals>.<lambda>v	s#���� 0� 0��T�\�\�5G�5G�1H�(� S�r6)rVr�r�r�r�r$r�r�r7r'r�rr
r#rr(r�)	rEr�rHr�r	r)r^r�rhs	`       @r4�testIllegalDeletez"IMAP4ServerTests.testIllegalDelete^	s�����O��!������*�*�8�Q�7����*�*�;�7�	D�	0�	#����
�^�^�
'�
'��e��
5��
���u�V�}�%�0�0��>�
����*�*�D�O�O�<�
�]�]�_������R��)���P�
��	
�
�
�S�T��r6c���tjjd��fd�}�fd�}�jj	t|��}|j
t|��j�|j
�j�j��j�}tj||g�}|j	�fd��|S)N�oldmboxc�<���jjdd�SrGrzrRs�r4rHz*IMAP4ServerTests.testRename.<locals>.login|	r{r6c�<���jjdd�S)Nsoldmboxsnewname�r��renamerRs�r4rz+IMAP4ServerTests.testRename.<locals>.rename	s����;�;�%�%�j�*�=�=r6c����jttjjj��dg�S)N�NEWNAME)rBr�r�r�r�r]r;s �r4r5z-IMAP4ServerTests.testRename.<locals>.<lambda>�	s3���d�&�&��\�,�,�6�6�;�;�=�>����r6r��rErHrr)r^r�s`     r4�
testRenamezIMAP4ServerTests.testRenamey	s�������*�*�9�5�	D�	>��^�^�
'�
'��e��
5��
����f�
�t���7�
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�
�	
�
�r6c���d�_�fd�}�fd�}�fd�}�jjt|��}|j	t|��j
�|j
|�|j	�j�j
��j�}tj||g�}|j�fd��|S)Nc�<���jjdd�SrGrzrRs�r4rHz6IMAP4ServerTests.testIllegalInboxRename.<locals>.login�	r{r6c�<���jjdd�S)Nr��frotzrrRs�r4rz7IMAP4ServerTests.testIllegalInboxRename.<locals>.rename�	s����;�;�%�%�g�w�7�7r6c���|�_yr0r�)�stuffrEs �r4r�z6IMAP4ServerTests.testIllegalInboxRename.<locals>.stash�	s
��� �D�Lr6c�j���jt�jtj��Sr0r�r;s �r4r5z9IMAP4ServerTests.testIllegalInboxRename.<locals>.<lambda>�	rr6r)rErHrr�r)r^r�s`      r4�testIllegalInboxRenamez'IMAP4ServerTests.testIllegalInboxRename�	s�������	D�	8�	!��^�^�
'�
'��e��
5��
����f�
�t���7�
�
�
�5��
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�P�	
��r6c���tjjd�tjjd��fd�}�fd�}�jj	t|��}|j
t|��j�|j
�j�j��j�}tj||g�}|j	�j�S)Nz
oldmbox/m1z
oldmbox/m2c�<���jjdd�SrGrzrRs�r4rHz6IMAP4ServerTests.testHierarchicalRename.<locals>.login�	r{r6c�<���jjdd�S)Nr�newnamerrRs�r4rz7IMAP4ServerTests.testHierarchicalRename.<locals>.rename�	s����;�;�%�%�i��;�;r6)
r�r�r�r�r�r7r�r
rr#rr(�_cbTestHierarchicalRenamers`     r4�testHierarchicalRenamez'IMAP4ServerTests.testHierarchicalRename�	s�������&�&�|�4����&�&�|�4�	D�	<��^�^�
'�
'��e��
5��
����f�
�t���7�
����*�*�D�O�O�<�
�]�]�_������R��)���}�}�T�;�;�<�<r6c���tjjj�}gd�}t	t|��}|j
||D�cgc]}|j���c}�ycc}w)N)r)z
newname/m1z
newname/m2)r�r�r�r]r�rfrBr,)rErT�mboxesrhr|s     r4r*z*IMAP4ServerTests._cbTestHierarchicalRename�	sS���(�(�2�2�7�7�9��:���f�V�n�%������X�!>��!�'�'�)�!>�?��!>s�A0
c�p���fd�}�fd�}�jjt|��}|jt|��j�|j�j
�j��j
�}tj||g�}|j�fd��|S)Nc�<���jjdd�SrGrzrRs�r4rHz-IMAP4ServerTests.testSubscribe.<locals>.login�	r{r6c�:���jjd�S�Nz	this/mbox)r��	subscriberRs�r4r2z1IMAP4ServerTests.testSubscribe.<locals>.subscribe�	s����;�;�(�(��5�5r6c�Z���jtjjdg�S)N�	THIS/MBOX�rBr�r��
subscriptionsr;s �r4r5z0IMAP4ServerTests.testSubscribe.<locals>.<lambda>�	�%���d�&�&��'�'�5�5��}��r6)	r�r�r7r�r
rr#rr()rErHr2r)r^r�s`     r4�
testSubscribezIMAP4ServerTests.testSubscribe�	s����	D�	6��^�^�
'�
'��e��
5��
����i�(�$�/�/�:�
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�
�	
�
�r6c���ddgtj_�fd�}�fd�}�jj	t|��}|j
t|��j�|j
�j�j��j�}tj||g�}|j	�fd��|S)Nr4�	THAT/MBOXc�<���jjdd�SrGrzrRs�r4rHz/IMAP4ServerTests.testUnsubscribe.<locals>.login�	r{r6c�:���jjd�Sr1)r��unsubscriberRs�r4r=z5IMAP4ServerTests.testUnsubscribe.<locals>.unsubscribe�	s����;�;�*�*�;�7�7r6c�Z���jtjjdg�S)Nr:r5r;s �r4r5z2IMAP4ServerTests.testUnsubscribe.<locals>.<lambda>�	r7r6)r�r�r6r�r�r7r�r
rr#rr()rErHr=r)r^r�s`     r4�testUnsubscribez IMAP4ServerTests.testUnsubscribe�	s����1<�k�0J����-�	D�	8��^�^�
'�
'��e��
5��
����k�*�D�O�O�<�
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�
�	
�
�r6c�h��tjjd�tjjd�tjjd��fd�}�fd�}d�_�jjt
|��}|jt
|��j�|j|�j�|j�j�j��j�}tj||g�j�fd��S)N�
root/subthingzroot/another-thingznon-root/subthingc�<���jjdd�SrGrzrRs�r4rHz*IMAP4ServerTests._listSetup.<locals>.login�	r{r6c���|�_yr0��listed)rzrEs �r4rEz+IMAP4ServerTests._listSetup.<locals>.listed�	s
���!�D�Kr6c����jSr0rDr;s �r4r5z-IMAP4ServerTests._listSetup.<locals>.<lambda>�	s���4�;�;�r6)
r�r�r�rEr�r�r7r�r
rr#rr()rEr3rHrEr)r^s`     r4�
_listSetupzIMAP4ServerTests._listSetup�	s�������*�*�?�;����*�*�+?�@����*�*�+>�?�	D�	"����
�^�^�
'�
'��e��
5��
����a��$�/�/�2�
�������0�
����*�*�D�O�O�<�
�]�]�_���"�"�B��8�,�8�8�9N�O�Or6c�|�|D]6}|j|dtd�|j|dtd��8|S)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}.
        r�zdelimiter %r is not a strr�zmailbox %r is not a str)r�r�)rE�resultsr2s   r4�'assertListDelimiterAndMailboxAreStringsz8IMAP4ServerTests.assertListDelimiterAndMailboxAreStrings�	sJ���	M�F��!�!�&��)�S�2M�N��!�!�&��)�S�2K�L�	M��r6c�\���fd�}�j|�}|j�fd��}|S)Nc�<���jjdd�S�N�root�%)r�r�rRs�r4�mailboxListz.IMAP4ServerTests.testList.<locals>.mailboxList
�����;�;�#�#�F�C�0�0r6c�&��ttj�ddfttj�ddfg}td�D]5}|j	d�\}}}�jt|�||f|��7�j
|d|���y)NrQ�
ROOT/SUBTHINGzROOT/ANOTHER-THINGr�rzMore results than expected: )rfrVr�rn�poprrT)rE�expectedContentsr&r��	delimiter�mailboxrEs      �r4�assertListContentsz5IMAP4ServerTests.testList.<locals>.assertListContents

s�����
�+�+�,�c�?�C��
�+�+�,�c�3G�H� ��
�1�X�
��,2�J�J�q�M�)��y�'��
�
��E�]�I�w�7�$��
�
���V�'C�F�:�%N�Or6)rGr�)rErPr�rXs`   r4�testListzIMAP4ServerTests.testList
s7���	1�
�O�O�K�(��	
���
	P�
�
	P��r6c���tjjd��fd�}�j|�}|j	�j
�|j	�jtjddfg�|S)NrSc�<���jjdd�SrM)r��lsubrRs�r4r\z'IMAP4ServerTests.testLSub.<locals>.lsub
rQr6rQ)	r�r�r2rGr�rJrBrVr�)rEr\r�s`  r4�testLSubzIMAP4ServerTests.testLSub
sg������)�)�/�:�	1�
�O�O�D�!��	�
�
�d�B�B�C�	�
�
�d�&�&�-�*=�*=�s�O�)T�(U�V��r6c���tjjd��fd�}�fd�}�fd�}d�_�jjt
|��}|jt
|��j�|j|�j�|j�j�j��j�}tj||g�}|j�fd��|S)NrAc�<���jjdd�SrGrzrRs�r4rHz*IMAP4ServerTests.testStatus.<locals>.login*
r{r6c�@���jjdddd�S)NrArQrSrU�r��statusrRs�r4rbz+IMAP4ServerTests.testStatus.<locals>.status-
s����;�;�%�%�o�z�9�h�W�Wr6c���|�_yr0��statusedr�s �r4rez-IMAP4ServerTests.testStatus.<locals>.statused0
�
���"�D�Mr6c�D���j�jdddd��S)Nr�s10r�)rQrSrU)rBrer;s �r4r5z-IMAP4ServerTests.testStatus.<locals>.<lambda>;
s"���d�&�&��
�
�A�%�1�M��r6)
r�r�r�rer�r�r7r�r
rr#rr()rErHrbrer)r^r�s`      r4�
testStatuszIMAP4ServerTests.testStatus'
s�������*�*�?�;�	D�	X�	#���
�
�^�^�
'�
'��e��
5��
����f�
�t���7�
����$�/�/�2�
����*�*�D�O�O�<�
�]�]�_������R��)��	�
�
�
�	
�
�r6c�����fd�}�fd�}�fd�}�fd�}dx�_�_�jjt	|��}|jt	|��j�|j||�|j�j�j��j�}tj||g�j�j�S)Nc�<���jjdd�SrGrzrRs�r4rHz0IMAP4ServerTests.testFailedStatus.<locals>.loginB
r{r6c�@���jjdddd�S)Nzroot/nonexistentrQrSrUrarRs�r4rbz1IMAP4ServerTests.testFailedStatus.<locals>.statusE
s#����;�;�%�%�"�J�	�8��
r6c���|�_yr0rdr�s �r4rez3IMAP4ServerTests.testFailedStatus.<locals>.statusedJ
rfr6c���|�_yr0rr�s �r4�failedz1IMAP4ServerTests.testFailedStatus.<locals>.failedM
r
r6)rer$r�r�r7r�r
rr#rr(�_cbTestFailedStatus)rErHrbrernr)r^s`      r4�testFailedStatusz!IMAP4ServerTests.testFailedStatusA
s����	D�	�
	#�	#�(,�+��
���
�^�^�
'�
'��e��
5��
����f�
�t���7�
����&�)�
����*�*�D�O�O�<�
�]�]�_���"�"�B��8�,�8�8��9Q�9Q�R�Rr6c��|j|jd�|j|jjjd�y)N)sCould not open mailbox)rBrer$rr�rSs  r4roz$IMAP4ServerTests._cbTestFailedStatusX
s7���������-�������+�+�0�0�2N�Or6c����tjtd��tjjd��fd�}tj��fd��}�jjt|��}|jt|��j�|j�j�j��j�}t
j||g�}|j�j ��S)N�rfc822.messagerAc�<���jjdd�SrGrzrRs�r4rHz.IMAP4ServerTests.testFullAppend.<locals>.login`
r{r6c3��K�t�d�5}�jjd|dd���}tj|�ddd�y#1swYyxYw�w)N�rbrA)�\SEEN�\DELETEDz%Tue, 17 Jun 2003 11:22:16 -0600 (MDT))�openr�r|r�returnValue�r�r2�infilerEs  ��r4r|z/IMAP4ServerTests.testFullAppend.<locals>.appendc
s\������f�d�#�
*�w�#�{�{�1�1�#��+�;�	 ����!�!�&�)�
*�
*�
*�s�
A�6A�	A�A�A)r&�sibpath�__file__r�r�r�r�inlineCallbacksr�r�r7r�r
rr#r(�_cbTestFullAppend�rErHr|r)r^r�r|s`     @r4�testFullAppendzIMAP4ServerTests.testFullAppend\
s�������h�(8�9�����*�*�?�;�	D�
�	�	�	*�
�	*��^�^�
'�
'��e��
5��
����f�
�t���7�
����*�*�D�O�O�<�
�]�]�_������R��)���}�}�T�3�3�V�<�<r6c��tjjd}|jdt	|j
��|jddgddf|j
ddd�t
|d�5}|j|j�|j
ddj��ddd�y#1swYyxYw)NrSr�rwrxs%Tue, 17 Jun 2003 11:22:16 -0600 (MDT)rrv�	r�r�r�rBr�rryrWr]�rErTr|�mbr3s     r4r�z"IMAP4ServerTests._cbTestFullAppendw
s���
�
$�
$�
.�
.��
?������C����,�-������
$�&N�PQ�R��K�K��N�1�2��	
��&�$�
�	E�1����Q�V�V�X�r�{�{�1�~�a�'8�'A�'A�'C�D�	E�	E�	E�s�6?B>�>Cc����tjtd��tjjd��fd�}tj��fd��}�jjt|��}|jt|��j�|j�j�j��j�}t
j||g�}|j�j ��S)Nrs�PARTIAL/SUBTHINGc�<���jjdd�SrGrzrRs�r4rHz1IMAP4ServerTests.testPartialAppend.<locals>.login�
r{r6c3�^�K�t�d�5}�jjtjdtdtjj��fz�d�jj|����}tj|�ddd�y#1swYyxYw�w)NrvsAPPENDz)PARTIAL/SUBTHING (\SEEN) "Right now" {%d}r1)ryr��sendCommandrr8r)�os�path�getsize�_IMAP4Client__cbContinueAppendrrzr{s  ��r4r|z2IMAP4ServerTests.testPartialAppend.<locals>.append�
s�������f�d�#�
*�w�#�{�{�6�6��M�M�!�
&�#�&(�g�g�o�o�f�&=�%?�@��
����B�B��� ���"�!�!�&�)�%
*�
*�
*�s�
B-�BB!�	B-�!B*�&B-)r&r}r~r�r�r�rrr�r�r7r�r
rr#r(�_cbTestPartialAppendr�s`     @r4�testPartialAppendz"IMAP4ServerTests.testPartialAppend�
s�������h�(8�9�����*�*�+=�>�	D�
�	�	�	*�
�	*�*�^�^�
'�
'��e��
5��
����f�
�t���7�
����*�*�D�O�O�<�
�]�]�_������R��)���}�}�T�6�6��?�?r6c��tjjd}|jdt	|j
��|jdgddf|j
ddd�t
|d�5}|j|j�|j
ddj��ddd�y#1swYyxYw)Nr�r�rws	Right nowrrvr�r�s     r4r�z%IMAP4ServerTests._cbTestPartialAppend�
s���
�
$�
$�
.�
.�/A�
B������C����,�-����8�*�l�A�6����A��q�r�8J�K�
�&�$�
�	E�1����Q�V�V�X�r�{�{�1�~�a�'8�'A�'A�'C�D�	E�	E�	E�s�5?B=�=Cc���tjjd��fd�}�fd�}�fd�}�jj	t|��}|j
t|��j�|j
t|��j�|j
�j�j��j�S)N�
root/subthingc�<���jjdd�SrGrzrRs�r4rHz*IMAP4ServerTests._testCheck.<locals>.login�
r{r6c�:���jjd�S)Nr�r�rRs�r4r�z+IMAP4ServerTests._testCheck.<locals>.select�
s����;�;�%�%�&6�7�7r6c�8���jj�Sr0)r�r�rRs�r4r�z*IMAP4ServerTests._testCheck.<locals>.check�
�����;�;�$�$�&�&r6)
r�r�r�r�r�r7r�r
rr#)rErHr�r�r�s`    r4�
_testCheckzIMAP4ServerTests._testCheck�
s�������*�*�+;�<�	D�	8�	'�
�N�N�&�&�u�U�|�4��	���u�V�}�d�o�o�6�	���u�U�|�T�_�_�5�	���t�)�)�4�?�?�;��}�}��r6c�"�|j�S)zf
        Trigger the L{imap.IMAP4Server._cbSelectWork} callback
        by selecting an mbox.
        )r�rRs r4�
test_checkzIMAP4ServerTests.test_check�
s��
��� � r6c���dd�}�fd�}�jtd|��j�}|j|�S)zr
        Trigger the L{imap.IMAP4Server._ebSelectWork} errback
        by failing when we select an mbox.
        c�,�tjd��)N�encoding)r�IllegalMailboxEncoding)rEr�r{s   r4�
failSelectz3IMAP4ServerTests.test_checkFail.<locals>.failSelect�
s���.�.�z�:�:r6c�~���j�}�j|djjdd�y)Nr�rsSELECT failed: Server error)r~rBrr�)r�failuresrEs  �r4�
checkResponsez6IMAP4ServerTests.test_checkFail.<locals>.checkResponse�
s7����-�-�/�H����X�a�[�.�.�3�3�A�6�8V�Wr6r�r�)�patchr�r�r�)rEr�r�r�s`   r4�test_checkFailzIMAP4ServerTests.test_checkFail�
s;���	;�	X�	
�
�
�7�H�j�1��O�O����}�}�]�+�+r6c�2��t�}gd�|_tjj	d|��fd�}�fd�}�fd�}�j
j
t|��}|jt|��j�|jt|��j�|j�j�j��j�}tj||g�j
�j|�S)N�)s	Message 1)r��AnotherFlagNr�s	Message 2)r�Nr�)s	Message 3)r�Nr�rWc�<���jjdd�SrGrzrRs�r4rHz)IMAP4ServerTests.testClose.<locals>.login�
r{r6c�:���jjd�S)Nsmailboxr�rRs�r4r�z*IMAP4ServerTests.testClose.<locals>.select�
�����;�;�%�%�j�1�1r6c�8���jj�Sr0)r�r�rRs�r4r�z)IMAP4ServerTests.testClose.<locals>.close�
r�r6)rVrr�r�r�r�r�r7r�r
rr#rr(�_cbTestClose)rEr�rHr�r�r�r^s`      r4�	testClosezIMAP4ServerTests.testClose�
s�����O��
��
�
	���*�*�9�a�8�	D�	2�	'�
�N�N�&�&�u�U�|�4��	���u�V�}�d�o�o�6�	���u�U�|�T�_�_�5�	���t�)�)�4�?�?�;�
�]�]�_���"�"�A�r�7�+�7�7��8I�8I�1�M�Mr6c���|jt|j�d�|j|jdd�|j|j�y)Nr�rr�)rBr�rrVr��rErTr�s   r4r�zIMAP4ServerTests._cbTestClose�
sC������Q�Z�Z��!�,�������A��(Q�R�������!r6c���t�}gd�|_tjj	d|��fd�}�fd�}�fd�}�fd�}d�_�jjt|��}|jt|��j�|jt|��j�|j|�j�|j�j�j��j�}tj||g�}|j�j|�S)Nr�rWc�<���jjdd�SrGrzrRs�r4rHz+IMAP4ServerTests.testExpunge.<locals>.login�
r{r6c�:���jjd�S)NrWr�rRs�r4r�z,IMAP4ServerTests.testExpunge.<locals>.selects����;�;�%�%�i�0�0r6c�8���jj�Sr0)r�r�rRs�r4r�z-IMAP4ServerTests.testExpunge.<locals>.expunges����;�;�&�&�(�(r6c�b���j�jjdu�|�_yr0)rTr�r^rI)rIrEs �r4�expungedz.IMAP4ServerTests.testExpunge.<locals>.expungeds'������T�[�[�-�-��5�6�"�D�Lr6)rVrr�r�r�rIr�r�r7r�r
rr#rr(�_cbTestExpunge)	rEr�rHr�r�r�r)r^r�s	`        r4�testExpungezIMAP4ServerTests.testExpunge�
s�����O��
��
�
	���*�*�9�a�8�	D�	1�	)�	#����
�^�^�
'�
'��e��
5��
����f�
�t���7�
����g�����8�
����$�/�/�2�
����*�*�D�O�O�<�
�]�]�_������R��)���}�}�T�0�0�!�4�4r6c���|jt|j�d�|j|jdd�|j|jddg�y)Nr�rr�r�)rBr�rrIr�s   r4r�zIMAP4ServerTests._cbTestExpungesK������Q�Z�Z��!�,�������A��(Q�R��������1�v�.r6N)6rsrtrur*r3r<rDrLrJr_r\rdrmr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrr%r+r*r8r?rGrJrYr]rhrpror�r�r�r�r�r�r�r�r�r�r�r1r6r4rrys��
I�G�.L�M�0�4�6�6�6� 6�,!6�F
@�4��<�6M�,"�4
�#2�J
�@�2=��&%�N�.�*�6�*�.=�"@��&�*P�&��0	��4S�.P�=�6E�"@�HE��$!�,�"N�2"�
5�@/r6rc��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*y))*�IMAP4ServerParsingTestsz6
    Test L{imap4.IMAP4Server}'s command parsing.
    c���t�|_tj�|_|jj|j�|jj
�yr0)rr�rr�r��makeConnection�clearrRs r4rzIMAP4ServerParsingTests.setUp sB��(�*����'�'�)������"�"�4�>�>�2������r6c��|jjtjt	j
���yr0�r��connectionLostr$rr�ConnectionDonerRs r4rz IMAP4ServerParsingTests.tearDown&�&�����"�"�7�?�?�5�3G�3G�3I�#J�Kr6c����Gd�dt���fd�}d|j_||j_|jj	d�|j|j
���y)zO
        L{imap4.IMAP4Server} logs exceptions raised by parse methods.
        c��eZdZdZy)�SIMAP4ServerParsingTests.test_parseMethodExceptionLogged.<locals>.UnhandledException�1
            An unhandled exception.
            Nr�r1r6r4�UnhandledExceptionr�.rsr6r�c�����r0r1)r�r�s �r4�raisesValueErrorzQIMAP4ServerParsingTests.test_parseMethodExceptionLogged.<locals>.raisesValueError3s	���$�$r6�command�invalidN)r�r��
parseState�
parse_commandr�rVr~)rEr�r�s  @r4�test_parseMethodExceptionLoggedz7IMAP4ServerParsingTests.test_parseMethodExceptionLogged)sX���
	��	�
	%�"+�����$4����!���� � ��,�����.�.�/A�B�Cr6c��|jjd�|j|jj	�d�|jjt
jtjd���y)z�
        L{imap4.IMAP4Server.parse_command} sends a C{BAD} response to
        a line that includes a tag but no command.
        �001s001 BAD Missing command
�DoneN)
r�r�rBr�rr�r$rrr�rRs r4�test_missingCommandz+IMAP4ServerParsingTests.test_missingCommand=s]��
	
���!�!�&�)�������-�-�/�1O�P����"�"��O�O�E�0�0��8�9�	
r6c��|jjd�|j|jj	�d�y)zf
        L{imap4.IMAP4Server.parse_command} sends a C{BAD} response to
        an empty line.
        r6s* BAD Null command
N)r�r�rBr�rrRs r4�test_emptyLinez&IMAP4ServerParsingTests.test_emptyLineJs4��
	
���!�!�#�&�������-�-�/�1J�Kr6c����fd�}||j_|jjdj|dg��|j	|j
j
�dj||g��y)aV
        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�����r0r1)�tag�cmd�rest�	exceptions   �r4�raiseszDIMAP4ServerParsingTests.assertParseExceptionResponse.<locals>.raisesc�����Or6r�r�N)r��dispatchCommandr�r�rBr�r�rEr�r��expectedResponser�s `   r4�assertParseExceptionResponsez4IMAP4ServerParsingTests.assertParseExceptionResponseSsb��� 	�'-����#����!�!�$�)�)�S�*�,=�">�?�������-�-�/����C�AQ�;R�1S�Tr6c�P�|jtjd�dd�y)zt
        When a parsing method raises L{IllegalClientResponse}, the
        server sends a C{BAD} response.
        �client responser��%BAD Illegal syntax: client response
N)r�r�IllegalClientResponserRs r4�'test_parsingRaisesIllegalClientResponsez?IMAP4ServerParsingTests.test_parsingRaisesIllegalClientResponsels'��
	
�)�)��'�'�(9�:��6�	
r6c�P�|jtjd�dd�y)zn
        When a parsing method raises L{IllegalOperation}, the server
        sends a C{NO} response.
        �	operationr��!NO Illegal operation: operation
N)r�r�IllegalOperationrRs r4�*test_parsingRaisesIllegalOperationResponsezBIMAP4ServerParsingTests.test_parsingRaisesIllegalOperationResponsews&��
	
�)�)��"�"�;�/��2�	
r6c�P�|jtjd�dd�y)zt
        When a parsing method raises L{IllegalMailboxEncoding}, the
        server sends a C{NO} response.
        r�r��#NO Illegal mailbox name: encoding
N)r�rr�rRs r4�(test_parsingRaisesIllegalMailboxEncodingz@IMAP4ServerParsingTests.test_parsingRaisesIllegalMailboxEncoding�s&��
	
�)�)��(�(��4��4�	
r6c��|jjd�|j|jj	�d�y)zi
        L{imap4.IMAP4Server} responds to an unsupported command with a
        C{BAD} response.
        s001 HULLABALOOs001 BAD Unsupported command
N)r�r�rBr�rrRs r4�test_unsupportedCommandz/IMAP4ServerParsingTests.test_unsupportedCommand�s5��
	
��� � �!2�3�������-�-�/�1S�Tr6c���|jjd�|j|jj	�dtd�j
d�zdz�y)z~
        L{imap4.IMAP4Server} responds with a C{BAD} response to a
        command with more arguments than expected.
        s001 LOGIN A B Cs8001 BAD Illegal syntax: Too many arguments for command: �Czutf-8r�N)r�r�rBr�rr�rCrRs r4�test_tooManyArgumentsForCommandz7IMAP4ServerParsingTests.test_tooManyArgumentsForCommand�s[��
	
��� � �!3�4�����N�N� � �"�7��t�*�#�#�G�,�-���	
r6c�d���fd�}|j|jjd�|f|jjddz|j_|jj	|dd�|j|j
j
�dj||g��y)aR
        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�����r0r1)�serverInstancer�rvrwr�s    �r4r�zFIMAP4ServerParsingTests.assertCommandExceptionResponse.<locals>.raises�r�r6rar�N�LOGINsuser passwdr�)rBr�rR�unauth_LOGINr�r�rr�r�s `   r4�assertCommandExceptionResponsez6IMAP4ServerParsingTests.assertCommandExceptionResponse�s���� 	�	
������*�*�H�5�$*�9�t�{�{�/G�/G���/K�#K���� ����#�#�C��>�B�������-�-�/����C�AQ�;R�1S�Tr6c�P�|jtjd�dd�y)zm
        When a command raises L{IllegalClientResponse}, the
        server sends a C{BAD} response.
        r�r�r�N)r�rr�rRs r4�'test_commandRaisesIllegalClientResponsez?IMAP4ServerParsingTests.test_commandRaisesIllegalClientResponse�s'��
	
�+�+��'�'�(9�:��6�	
r6c�P�|jtjd�dd�y)zg
        When a command raises L{IllegalOperation}, the server sends a
        C{NO} response.
        r�r�r�N)r�rr�rRs r4�*test_commandRaisesIllegalOperationResponsezBIMAP4ServerParsingTests.test_commandRaisesIllegalOperationResponse�s&��
	
�+�+��"�"�;�/��2�	
r6c�P�|jtjd�dd�y)zm
        When a command raises L{IllegalMailboxEncoding}, the server
        sends a C{NO} response.
        r�r�r�N)r�rr�rRs r4�(test_commandRaisesIllegalMailboxEncodingz@IMAP4ServerParsingTests.test_commandRaisesIllegalMailboxEncoding�s&��
	
�+�+��(�(��4��4�	
r6c��Gd�dt�}|j|d�dd�|j|j|��y)z�
        Wehn a command raises an unhandled exception, the server sends
        a C{BAD} response and logs the exception.
        c��eZdZdZy)�XIMAP4ServerParsingTests.test_commandRaisesUnhandledException.<locals>.UnhandledExceptionr�Nr�r1r6r4r�r�rsr6r��	unhandledr�sBAD Server error: unhandled
N)r�r�rVr~)rEr�s  r4�$test_commandRaisesUnhandledExceptionz<IMAP4ServerParsingTests.test_commandRaisesUnhandledException�sF��	��	�
	
�+�+��{�+��.�	
�	
����.�.�/A�B�Cr6c��d|j_|jjd�|j|jj�d�y)zx
        A string literal whose length exceeds the maximum allowed
        length results in a C{BAD} response.
        r�s001 LOGIN {5}
sE001 BAD Illegal syntax: Literal too long! I accept at most 4 octets
N)r��_literalStringLimitr�rBr�rrRs r4�test_stringLiteralTooLongz1IMAP4ServerParsingTests.test_stringLiteralTooLong�sF��
+,����'���� � �!5�6�����N�N� � �"�
.�	
r6c�|�dD]7}|jtj|jj|��9y)zQ
        An empty string argument raises L{imap4.IllegalClientResponse}.
        )r6r�r�N�r�rr�r��arg_astring)rEr�s  r4�test_arg_astringEmptyLinez1IMAP4ServerParsingTests.test_arg_astringEmptyLines8��*�	�E�����+�+�T�[�[�-D�-D�e�
�	r6c�n�|jtj|jjd�y)zh
        An unmatched quote in a string argument raises
        L{imap4.IllegalClientResponse}.
        s"openNr
rRs r4�test_arg_astringUnmatchedQuotesz7IMAP4ServerParsingTests.test_arg_astringUnmatchedQuotess)��
	
����'�'����)@�)@�(�	
r6c�n�|jtj|jjd�y)zn
        An unmatched brace in a string literal's size raises
        L{imap4.IllegalClientResponse}.
        s{0Nr
rRs r4�&test_arg_astringUnmatchedLiteralBracesz>IMAP4ServerParsingTests.test_arg_astringUnmatchedLiteralBracess'��
	
���%�5�5�t�{�{�7N�7N�PU�Vr6c�n�|jtj|jjd�y)zc
        A non-integral string literal size raises
        L{imap4.IllegalClientResponse}.
        �{[object Object]}Nr
rRs r4�"test_arg_astringInvalidLiteralSizez:IMAP4ServerParsingTests.test_arg_astringInvalidLiteralSize�*��
	
����'�'����)@�)@�BV�	
r6c�n�|jtj|jjd�y)z@
        An empty atom raises L{IllegalClientResponse}.
        r6N�r�rr�r��arg_atomrRs r4�test_arg_atomEmptyLinez.IMAP4ServerParsingTests.test_arg_atomEmptyLine$s&��	
���%�5�5�t�{�{�7K�7K�S�Qr6c�n�|jtj|jjd�y)zC
        A malformed atom raises L{IllegalClientResponse}.
        s
 not an atom NrrRs r4�test_arg_atomMalformedAtomz2IMAP4ServerParsingTests.test_arg_atomMalformedAtom*s*��	
����'�'����)=�)=�?O�	
r6c�n�|jtj|jjd�y)zN
        An empty parenthesized list raises L{IllegalClientResponse}.
        r6N�r�rr�r��	arg_plistrRs r4�test_arg_plistEmptyLinez/IMAP4ServerParsingTests.test_arg_plistEmptyLine2s&��	
���%�5�5�t�{�{�7L�7L�c�Rr6c���|jtj|jjd�|jtj|jjd�y)ze
        A parenthesized with unmatched parentheses raises
        L{IllegalClientResponse}.
        s(foosfoo)NrrRs r4�"test_arg_plistUnmatchedParenthesesz:IMAP4ServerParsingTests.test_arg_plistUnmatchedParentheses8sH��
	
���%�5�5�t�{�{�7L�7L�g�V����%�5�5�t�{�{�7L�7L�g�Vr6c�n�|jtj|jjd�y)zH
        An empty file literal raises L{IllegalClientResponse}.
        r6N�r�rr�r��arg_literalrRs r4�test_arg_literalEmptyLinez1IMAP4ServerParsingTests.test_arg_literalEmptyLine@s'��	
���%�5�5�t�{�{�7N�7N�PS�Tr6c���|jtj|jjd�|jtj|jjd�y)zZ
        A literal with unmatched braces raises
        L{IllegalClientResponse}.
        s{10s10}Nr"rRs r4�test_arg_literalUnmatchedBracesz7IMAP4ServerParsingTests.test_arg_literalUnmatchedBracesFsJ��
	
���%�5�5�t�{�{�7N�7N�PV�W����%�5�5�t�{�{�7N�7N�PV�Wr6c�n�|jtj|jjd�y)z\
        A non-integral literal size raises
        L{imap4.IllegalClientResponse}.
        rNr"rRs r4�"test_arg_literalInvalidLiteralSizez:IMAP4ServerParsingTests.test_arg_literalInvalidLiteralSizeNrr6c�h�d}|jj|�\}}|j|d�y)zH
        A sequence set returns the unparsed portion of a line.
        s1:* blah blah blahsblah blah blahN)r��
arg_seqsetrB)rE�sequencer&r�s    r4�test_arg_seqsetReturnsRestz2IMAP4ServerParsingTests.test_arg_seqsetReturnsRestWs2��)���+�+�(�(��2���4�����0�1r6c�n�|jtj|jjd�y)zL
        An invalid sequence raises L{imap4.IllegalClientResponse}.
        sx:yN)r�rr�r�r*rRs r4�test_arg_seqsetInvalidSequencez6IMAP4ServerParsingTests.test_arg_seqsetInvalidSequence_s&��	
���%�5�5�t�{�{�7M�7M�v�Vr6c��d}|jj|�\}}|j||g�|j|�y)zJ
        A single flag that is not contained in a list is parsed.
        sflagN)r��arg_flaglistrBrT)rE�flagr�r�s    r4�test_arg_flaglistOneFlagz0IMAP4ServerParsingTests.test_arg_flaglistOneFlagesA�����{�{�/�/��5��������$��(�����r6c�n�|jtj|jjd�y)zk
        A list of flags with unmatched parentheses raises
        L{imap4.IllegalClientResponse}.
        s(invalidN�r�rr�r�r0rRs r4�&test_arg_flaglistMismatchedParentehsesz>IMAP4ServerParsingTests.test_arg_flaglistMismatchedParentehsesns+��
	
����'�'��K�K�$�$��	
r6c���|jtj|jjd�|jtj|jjd�y)zo
        A list of flags that contains a malformed flag raises
        L{imap4.IllegalClientResponse}.
        s	(first )s(first second)Nr4rRs r4�test_arg_flaglistMalformedFlagz6IMAP4ServerParsingTests.test_arg_flaglistMalformedFlagysQ��
	
����'�'����)A�)A�?�	
�	
����'�'����)A�)A�CX�	
r6c��d}|jj|�\}}|j|�|j||�y)z�
        A line that does not begin with an open parenthesis (C{(}) is
        parsed as L{None}, and the remainder is the whole line.
        snot (N)r��	opt_plistr�rB)rEr��plist�	remainders    r4�$test_opt_plistMissingOpenParenthesisz<IMAP4ServerParsingTests.test_opt_plistMissingOpenParenthesis�s@��
���;�;�0�0��6���y����%� �����D�)r6c��d}|jj|�\}}|j|�|j||�y)z�
        A line that does not begin with a double quote (C{"}) is
        parsed as L{None}, and the remainder is the whole line.
        snot "N)r��opt_datetimer�rB)rEr��dtr;s    r4�!test_opt_datetimeMissingOpenQuotez9IMAP4ServerParsingTests.test_opt_datetimeMissingOpenQuote�s?��
�����0�0��6�
��I����"������D�)r6c�r�d}|jtj|jj|�y)zx
        A line that does not have a closing double quote (C{"}) raises
        L{imap4.IllegalClientResponse}.
        s"21-Jul-2017 19:37:07 -0700N)r�rr�r�r>r�s  r4�"test_opt_datetimeMissingCloseQuotez:IMAP4ServerParsingTests.test_opt_datetimeMissingCloseQuote�s,��
.�����%�5�5�t�{�{�7O�7O�QU�Vr6c�r�d}|jtj|jj|�y)z�
        A line that contains C{CHARSET} but no character set
        identifier raises L{imap4.IllegalClientResponse}.
        r�N)r�rr�r��opt_charsetr�s  r4�!test_opt_charsetMissingIdentifierz9IMAP4ServerParsingTests.test_opt_charsetMissingIdentifier�s,��
�����%�5�5�t�{�{�7N�7N�PT�Ur6c��d}|jj|�\}}|j|d�|j|d�y)z�
        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-8r6N�r�rDrB�rEr��
identifierr;s    r4�test_opt_charsetEndOfLinez1IMAP4ServerParsingTests.test_opt_charsetEndOfLine�sB��
 �� $��� 7� 7�� =��
�I�����X�.�����C�(r6c��d}|jj|�\}}|j|d�|j|d�y)z�
        A line that has additional data after a C{CHARSET} identifier
        is parsed as that identifier, and the remainder is that
        additional data.
        sCHARSET UTF-8 remainderrGs	remainderNrHrIs    r4�test_opt_charsetWithRemainderz5IMAP4ServerParsingTests.test_opt_charsetWithRemainder�sB��*�� $��� 7� 7�� =��
�I�����X�.�����L�1r6N)+rsrtrur3rrr�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrrr r$r&r(r,r.r2r5r7r<r@rBrErKrMr1r6r4r�r�s�����L�D�(
�L�U�2	
�	
�	
�U�
� U�6	
�	
�	
�D�&
��
�W�
�R�
�S�W�U�X�
�2�W��	
�

�*�*�W�V�)�	2r6r�c�X�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zy)�IMAP4ServerSearchTestszS
    Tests for the behavior of the search_* functions in L{imap4.IMAP4Server}.
    c��tj|�dg|_dg|_dg|_d|_t
ddigddd	d�|_y)
Nz10-Dec-2009z13-Dec-2009z16-Dec-2009rr�zMon, 13 Dec 2009 21:25:10 GMTz13 Dec 2009 00:00:00 GMTr(��)r�r�earlierQuery�
sameDateQuery�
laterQuery�seqr�r�rRs r4rzIMAP4ServerSearchTests.setUp�sX�����t�$�*�O���+�_���(�/�������
�4�5��&����

��r6c�,�|j|jj|j|j|j
��|j
|jj|j|j|j
��y)z�
        L{imap4.IMAP4Server.search_SENTBEFORE} returns True if the message date
        is earlier than the query date.
        N)rTr��search_SENTBEFORErRrUr�rVrTrRs r4�test_searchSentBeforez,IMAP4ServerSearchTests.test_searchSentBefore�sf��
	
����K�K�)�)�$�*;�*;�T�X�X�t�x�x�P�	
�	
����K�K�)�)�$�/�/�4�8�8�T�X�X�N�	
r6c��|j|jjdg|j|jd��|j|jjdg|j|jd��|j|jjdg|j|jd��y)zq
        L{imap4.IMAP4Server.search_UID} returns True if the message UID is in
        the search range.
        r�)r�rQs2:*r�N)rTr��
search_UIDrUr�rVrRs r4�test_searchWildcardz*IMAP4ServerSearchTests.test_searchWildcard�s���
	
����K�K�"�"�F�8�T�X�X�t�x�x��K�	
�	
������.�.��x����4�8�8�Y�W�X�������.�.��v�t�x�x����9�U�Vr6c��|j|jjdg|j|jd��y)z�
        L{imap4.IMAP4Server.search_UID} should return True if there is a
        wildcard, because a wildcard means "highest UID in the mailbox".
        s1235:*)rQr�N)rVr�rZrUr�rRs r4�test_searchWildcardHighz.IMAP4ServerSearchTests.test_searchWildcardHigh�s2��
	
����K�K�"�"�I�;����$�(�(�I�N�	
r6c�h�tjd�}|jt|�gd��y)�|
        L{imap4.IMAP4Server.search_SENTON} returns True if the message date is
        the same as the query date.
        r>r$N)rr�rBr�)rE�msgsets  r4�test_reversedSearchTermsz/IMAP4ServerSearchTests.test_reversedSearchTerms�s(��
�"�"�6�*������f��y�1r6c��|j|jj|j|j|j
��|j
|jj|j|j|j
��|j|jj|j|j|j
��y)r_N)	rTr��
search_SENTONrRrUr�rVrSrTrRs r4�test_searchSentOnz(IMAP4ServerSearchTests.test_searchSentOn�s���
	
����K�K�%�%�d�&7�&7����4�8�8�L�	
�	
����K�K�%�%�d�&8�&8�$�(�(�D�H�H�M�	
�	
������2�2�4�?�?�D�H�H�d�h�h�W�Xr6c�,�|j|jj|j|j|j
��|j
|jj|j|j|j
��y)z~
        L{imap4.IMAP4Server.search_SENTSINCE} returns True if the message date
        is later than the query date.
        N)rVr��search_SENTSINCErRrUr�rTrTrRs r4�test_searchSentSincez+IMAP4ServerSearchTests.test_searchSentSince	
sf��
	
����K�K�(�(��):�):�D�H�H�d�h�h�O�	
�	
����K�K�(�(����$�(�(�D�H�H�M�	
r6c�D�|j|jjdg|jzdgz|jz|j
|jd��|j|jjdg|jzdgz|jz|j
|jd��|j|jjdg|jzdgz|jz|j
|jd��y)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.
        �	SENTSINCEr�SENTONN)rVr��	search_ORrRrTrUr�rTrRs r4�
test_searchOrz$IMAP4ServerSearchTests.test_searchOr
s���	
����K�K�!�!��
�� 1� 1�1�[�M�A�D�O�O�S��������	
�	
�	
����K�K�!�!��
����/�;�-�?�$�BS�BS�S��������	
�	
�	
����K�K�!�!��
�T�_�_�,��}�<�t���N��������	
�	
r6c�@�|j|jjdg|jz|j|j
d��|j
|jjdg|jz|j|j
d��y)z~
        L{imap4.IMAP4Server.search_NOT} returns the negation of the result
        of the expression supplied to it.
        rirrjN)rTr��
search_NOTrRrUr�rVrTrRs r4�test_searchNotz%IMAP4ServerSearchTests.test_searchNot4
s~��
	
����K�K�"�"��
�� 1� 1�1�4�8�8�T�X�X�|�
�	
�
	
����K�K�"�"��
�T�_�_�,�d�h�h����,�
�	
r6c��|j|jj|j|j|j
��|j|jj|j|j|j
��|j|jj|j|j|j
��y)z�
        L{imap4.IMAP4Server.search_BEFORE} returns True if the
        internal message date is before the query date.
        N)	rTr��
search_BEFORErRrUr�rSrVrTrRs r4�test_searchBeforez(IMAP4ServerSearchTests.test_searchBeforeD
s���
	
����K�K�%�%�d�&7�&7����4�8�8�L�	
�	
����K�K�%�%�d�&8�&8�$�(�(�D�H�H�M�	
�	
������1�1�$�/�/�4�8�8�T�X�X�V�Wr6c��|j|jj|j|j|j
��|j|jj|j|j|j
��|j|jj|j|j|j
��y)z�
        L{imap4.IMAP4Server.search_ON} returns True if the
        internal message date is the same as the query date.
        N)rTr��	search_ONrRrUr�rSrTrRs r4�
test_searchOnz$IMAP4ServerSearchTests.test_searchOnQ
s���
	
������.�.�t�/@�/@�$�(�(�D�H�H�U�V�������.�.�t�/A�/A�4�8�8�T�X�X�V�W�������.�.�t������$�(�(�S�Tr6c��|j|jj|j|j|j
��|j|jj|j|j|j
��|j|jj|j|j|j
��y)z�
        L{imap4.IMAP4Server.search_SINCE} returns True if the
        internal message date is greater than the query date.
        N)	rVr��search_SINCErRrUr�rSrTrTrRs r4�test_searchSincez'IMAP4ServerSearchTests.test_searchSinceZ
s���
	
������0�0��1B�1B�D�H�H�d�h�h�W�X�����K�K�$�$�T�%7�%7����4�8�8�L�	
�	
������1�1�$�/�/�4�8�8�T�X�X�V�Wr6N)rsrtrur3rrXr[r]rardrgrlrorrrurxr1r6r4rOrO�sH���

�

�
W�
�2�Y�

�
�>
� X�U�	Xr6rOc�"�eZdZdZdZdd�Zd�Zy)r�z�
    A L{IRealm} for tests.

    @cvar theAccount: An C{Account} instance.  Tests can set this to
        ensure predictable account retrieval.
    Nc�6����r�fd��_y�fd��_y)ab
        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����jSr0�r�r�s�r4r5z$TestRealm.__init__.<locals>.<lambda>|
s
���}�'?�'?�r6c����jSr0r|rRs�r4r5z$TestRealm.__init__.<locals>.<lambda>~
s���t���r6N)�_getAccount)rEr�s``r4rzzTestRealm.__init__q
s����?�D��6�D�r6c�F�tj|j�d�fS)Nc��yr0r1r1r6r4r5z)TestRealm.requestAvatar.<locals>.<lambda>�
rhr6)r�IAccountr~)rE�avatarId�mindrs    r4rlzTestRealm.requestAvatar�
s���~�~�t�/�/�1�<�?�?r6r0)rsrtrur3r�rzrlr1r6r4r�r�f
s����J�
7�@r6r�c�(�eZdZeefZddiZd�Zd�Zy)�TestCheckerr��secretc���|j|jvr[tj|j|j|j�j|j|j�Syr0)�usernamer�r�
maybeDeferred�
checkPasswordr��_cbCheck)rE�credentialss  r4�requestAvatarIdzTestChecker.requestAvatarId�
s\�����4�:�:�-��&�&��)�)�4�:�:�k�6J�6J�+K���k�$�-�-��)=�)=�>�
?�.r6c��|r|St��r0r)rEr2r�s   r4r�zTestChecker._cbCheck�
s����O��!�!r6N)	rsrtrurr�credentialInterfacesr�r�r�r1r6r4r�r��
s"��3�5F�G��
�)�$�E�?�"r6r�c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�AuthenticatorTestsc�.�tj|�t�}td�|_t|�|_|jjt��|j|j_d|_
|j|_y)Nr�r)r�rr�r�r�rr�r�r�r��
authenticatedrQ)rEr�s  r4rzAuthenticatorTests.setUp�
sh�����t�$����"�;�/����U�m������#�#�K�M�2�!�[�[���������'�'��r6c�
�ttt�Gd�d��}|�}tt|�t	j
d|i�}|j|_t�}|j|�|j|jtjd��|jd|j��|j�|j!d�|jt#j$|j'��|j��|j�|j!t#j$d�dz�|j)|j�d	�y
)z�
        L{imap4.IMAP4Server} accepts a L{dict} mapping challenge type
        names to L{twisted.mail.interfaces.IChallengeResponse}
        providers.
        c�$�eZdZd�Zd�Zd�Zd�Zy)�>AuthenticatorTests.test_customChallengers.<locals>.SPECIALAuthc��y)N�SPECIALr1rRs r4�getChallengezKAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.getChallenge�
���!r6c�B�|jdd�\|_|_yrs)�splitr��password�rE�responses  r4�setResponsezJAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.setResponse�
s��/7�~�~�d�A�/F�,��
�t�}r6c��y�NFr1rRs r4�moreChallengeszMAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.moreChallenges�
s��r6c�&�|j|_yr0)r�)rEr�s  r4r�zLAuthenticatorTests.test_customChallengers.<locals>.SPECIALAuth.checkPassword�
s
�� $�
�
��
r6N)rsrtrur�r�r�r�r1r6r4�SPECIALAuthr��
s��
"�
G�
�
.r6r�r��Connection done.sAUTH=SPECIALs001 AUTHENTICATE SPECIAL
susername passwordr�s"001 OK Authentication successful
N)rr rr
rr�r�rr��
addCleanupr�rr�rrr��dataReceived�base64�	b64encoder�rB)rEr��specialr�r�s     r4�test_customChallengersz)AuthenticatorTests.test_customChallengers�
s&��
�'�):�	;�	.�	.�
<�	.��-���'��1��"�"�J��#<�=������
�#�%�	����i�(�����-�-�u�/C�/C�DV�/W�X��
�
�o�y���'8�9��������;�<��
�
�f�&�&�w�';�';�'=�>�	���@Q�R��������F�,�,�-A�B�W�L�M�������*�,S�Tr6c�d�tj�}|j|_t�}|j	|�|j|jtjd��|j�|jd�|j|j�d�y)z_
        An unsupported C{AUTHENTICATE} method results in a negative
        response.
        r�s001 AUTHENTICATE UNKNOWN
s(001 NO AUTHENTICATE method unsupported
N)
rr�r�rr�r�r�rr�r�r�rBr)rEr�r�s   r4�test_unsupportedMethodz)AuthenticatorTests.test_unsupportedMethod�
s���
�"�"�$������
�#�%�	����i�(�����-�-�u�/C�/C�DV�/W�X��������;�<�����O�O��L�	
r6c����tj�jjd<tjd�}�j
j
|�d�j_�fd�}�jjt|��}|j�jd�|j�j�j�t!j"|�j%�g�S)zv
        An L{imap4.IMAP4Server} that is missing a L{Portal} responds
        negatively to an authentication
        r�r�Nc�:���jjd�S�Nr��r��authenticaterRs�r4rOz3AuthenticatorTests.test_missingPortal.<locals>.auth�
�����;�;�+�+�I�6�6r6s Temporary authentication failure)r�LOGINCredentialsr�r2�LOGINAuthenticatorr��registerAuthenticatorr�r�r�r7r'rr�rr
rr(r#)rE�cAuthrOr�s`   r4�test_missingPortalz%AuthenticatorTests.test_missingPortal�
s����
-2�,B�,B�������)��(�(��5�����)�)�%�0�!�����	7�
�N�N�&�&�u�T�{�3��	����+�+�-P�	
�	
���t�)�)�4�?�?�;��"�"�A�t�}�}��#7�8�8r6c�~��tt�Gd�d��}tt�Gd�d��}|�}tt|�|�jj
d<�jj|���fd�}�jjt|��}|j�jdt|j�zjd��|j!�j"�j$�t'j(|�j+�g�S)	z�
        When a challenger's
        L{getChallenge<IChallengeResponse.getChallenge>} method raises
        any exception, a C{NO} response is sent.
        c�"�eZdZdZd�Zd�Zd�Zy)�RAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallengesA challenge failurec�,�t|j��r0)rr�rRs r4r�z_AuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallenge.getChallenges�� ����.�.r6c��y�zw
                Never called.

                @param response: See L{IChallengeResponse.setResponse}
                Nr1r�s  r4r�z^AuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallenge.setResponserhr6c��y�z/
                Never called.
                Nr1rRs r4r�zaAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthChallenge.moreChallengesrhr6N�rsrtrur�r�r�r�r1r6r4�ValueErrorAuthChallenger��
s��,�G�
/�
�
r6r�c��eZdZd�Zd�Zy)�RAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthenticatorc��y)N�ERRORr1rRs r4�getNamezZAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthenticator.getNames��r6c��y)NsIGNOREDr1)rE�secret�chals   r4�challengeResponsezdAuthenticatorTests.test_challengerRaisesException.<locals>.ValueErrorAuthenticator.challengeResponser�r6N)rsrtrur�r�r1r6r4�ValueErrorAuthenticatorr�s��
 �
"r6r�r�c�:���jjd�Sr�r�rRs�r4rOz?AuthenticatorTests.test_challengerRaisesException.<locals>.authr�r6zServer error: r�)rr r!r
r�r2r�r�r�r�r7r'rr�r�rCr�rr
rr(r#)rEr�r��badrOr�s`     r4�test_challengerRaisesExceptionz1AuthenticatorTests.test_challengerRaisesException�
s	���
�'�	(�	�	�
)�	�$
�*�	+�	"�	"�
,�	"�&�'���'��-�,C�������)����)�)�*A�*C�D�	7�
�N�N�&�&�u�T�{�3��	����+�+�
��$;�$C�$C� D�
D�L�L�W�U�	
�	
���t�)�)�4�?�?�;��"�"�A�t�}�}��#7�8�8r6c�$�tt�Gd�d��}|�}tt|�tj�}|j
|_||jd<t�}|j|�|j|jtjd��|jd|j��|j�|j!d�|jt#j$|j'��|j��|j�|j!d�|j)|j�dj+d	|j,d
g��y)z�
        A client that responds with a challenge that cannot be decoded
        as Base 64 receives an L{IllegalClientResponse}.
        c�"�eZdZdZd�Zd�Zd�Zy)�EAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallengesMalformed Response - not base64c��y)Ns
SomeChallenger1rRs r4r�zRAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallenge.getChallenge5s��'r6c��yr�r1r�s  r4r�zQAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallenge.setResponse8rhr6c��yr�r1rRs r4r�zTAuthenticatorTests.test_authNotBase64.<locals>.NotBase64AuthChallenge.moreChallenges?rhr6Nr�r1r6r4�NotBase64AuthChallenger�1s��8�G�
(�
�
r6r�s	NOTBASE64r�sAUTH=NOTBASE64s001 AUTHENTICATE NOTBASE64
s Not base64
r6s001 NO Authentication failed: r�N)rr r
rr�r�r2rr�r�r�rr�rrr�r�r�r�r�rBr�r�)rEr��	notBase64r�r�s     r4�test_authNotBase64z%AuthenticatorTests.test_authNotBase64+s8��
�'�	(�	�	�
)�	�$+�,�	��'��3��"�"�$������
�+A����<�(�#�%�	����i�(�����-�-�u�/C�/C�DV�/W�X��
�
�'����):�;��������=�>��
�
�f�&�&�y�'=�'=�'?�@�)�/�/�BS�T��������2�3�����O�O���H�H�7��9J�9J�G�T�U�	
r6c�F��t�}t|�}|�j_tj
x�jjd<}tt|�t	jd�}�jj|��fd�}�jjt|��}|j�j d�|j#�j$�j&�t)j*�j-�|g�}|S)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�r�c�:���jjd�Sr�r�rRs�r4rOz:AuthenticatorTests.test_unhandledCredentials.<locals>.authsr�r6s+Authentication failed: server misconfigured)r�rr�r�rr�r2rr r�r�r�r�r�r7r'rr�rr
rr(r#)rEr�r��	loginCredr�rOr)r�s`       r4�test_unhandledCredentialsz,AuthenticatorTests.test_unhandledCredentials^s�����������$�����8=�8N�8N�N�������)�I��&�	�2��(�(��5�����)�)�%�0�	7��^�^�
'�
'��d��
4��
�
�
��+�+�:�	
�	����*�*�D�O�O�<��������"� 5�6���r6c����
�Gd�dt��
G�
fd�d�}t�}t|�}|j|��|�j_tjx�jjd<}tt|�t
jd�}�jj|��fd�}�
�fd�}�jjt!|��}|j#�j$d	�|jt!|��|j'�j(�j*�t-j.�j1�|g�}	|	S)
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��eZdZdZy)�KAuthenticatorTests.test_unexpectedLoginFailure.<locals>.UnexpectedExceptionrqNr�r1r6r4rrr��rsr6rrc�$��eZdZdZeefZ�fd�Zy)�FAuthenticatorTests.test_unexpectedLoginFailure.<locals>.FailingCheckerzz
            A credentials checker whose L{requestAvatarId} method
            raises L{UnexpectedException}.
            c����d��)NzUnexpected error.r1)rEr�rrs  �r4r�zVAuthenticatorTests.test_unexpectedLoginFailure.<locals>.FailingChecker.requestAvatarId�s���)�*=�>�>r6N)rsrtrur3rrr�r�)rrs�r4�FailingCheckerr��s���
�
%<�=N�#O� �
?r6r�r�r�c�:���jjd�Sr�r�rRs�r4rOz<AuthenticatorTests.test_unexpectedLoginFailure.<locals>.auth�r�r6c�F���j�j���yr0r})rrrEs��r4�assertUnexpectedExceptionLoggedzWAuthenticatorTests.test_unexpectedLoginFailure.<locals>.assertUnexpectedExceptionLogged�s����O�O�D�2�2�3F�G�Hr6s'Server error: login failed unexpectedly)r�r�rr�r�r�rr�r2rr r�r�r�r�r�r7r'rr�rr
rr(r#)rEr�r�r�r�r�rOr�r)r�rrs`         @r4�test_unexpectedLoginFailurez.AuthenticatorTests.test_unexpectedLoginFailures���	�)�	�
		?�		?�����������~�/�0�#�����8=�8N�8N�N�������)�I��&�	�2��(�(��5�����)�)�%�0�	7�	I��^�^�
'�
'��d��
4��
�
�
��+�+�-W�	
�	���u�<�=�>�
����*�*�D�O�O�<��������"� 5�6���r6c���t�jjd<tjd�}�j
j
|��fd�}�fd�}�jjt|��}|jt|��j�|j�j�j��j�}tj||g�}|j�j �S)Nr,r�c�:���jjd�Sr�r�rRs�r4rOz,AuthenticatorTests.testCramMD5.<locals>.auth�r�r6c���d�_yrs�r�rRs�r4�authedz.AuthenticatorTests.testCramMD5.<locals>.authed�����!"�D�r6)rr�r2r�CramMD5ClientAuthenticatorr�r�r�r�r7r�r
rr#rr(�_cbTestCramMD5)rEr�rOr�r)r^r�s`      r4�testCramMD5zAuthenticatorTests.testCramMD5�s����/A�������,��0�0��=�����)�)�%�0�	7�	#��^�^�
'�
'��d��
4��
����f�
�t���7�
����*�*�D�O�O�<�
�]�]�_������R��)���}�}�T�0�0�1�1r6c��|j|jd�|j|jj|j�yrs�rBr�r�rQrSs  r4r�z!AuthenticatorTests._cbTestCramMD5��6������+�+�Q�/�������,�,�d�l�l�;r6c���t�jjd<tjd�}�j
j
|��fd�}�fd�}�fd�}�jjt|��}|jt|�t|��|j�j�j�tj�j�|g�}|j�j �S)Nr,r�c�:���jjd�S�Nsnot the secretr�rRs�r4�misauthz5AuthenticatorTests.testFailedCramMD5.<locals>.misauth������;�;�+�+�,=�>�>r6c���d�_yrsr�rRs�r4r�z4AuthenticatorTests.testFailedCramMD5.<locals>.authed�r�r6c���d�_y�N���r�rRs�r4�	misauthedz7AuthenticatorTests.testFailedCramMD5.<locals>.misauthed�����!#�D�r6)rr�r2rr�r�r�r�r�r7r�rr
rr(r#�_cbTestFailedCramMD5�rEr�r�r�r�r)r�s`      r4�testFailedCramMD5z$AuthenticatorTests.testFailedCramMD5�s����/A�������,��0�0��=�����)�)�%�0�	?�	#�	$��^�^�
'�
'��g��
7��
����f�
�u�Y�'7�8�
����*�*�D�O�O�<��������"� 5�6���}�}�T�6�6�7�7r6c��|j|jd�|j|jjd�yr�r�rSs  r4rz'AuthenticatorTests._cbTestFailedCramMD5��2������+�+�R�0�������,�,�d�3r6c�H��tjx�jjd<}t	t
|�tjd�}�jj|��fd�}�fd�}�jjt|��}|jt|��j�|j�j�j�tj �j#�|g�}|j�j$�S)Nr�r�c�:���jjd�Sr�r�rRs�r4rOz*AuthenticatorTests.testLOGIN.<locals>.auth�r�r6c���d�_yrsr�rRs�r4r�z,AuthenticatorTests.testLOGIN.<locals>.authed�r�r6)rr�r�r2rr r�r�r�r�r�r7r�r
rrr(r#�_cbTestLOGIN)rEr�r�rOr�r)r�s`      r4�	testLOGINzAuthenticatorTests.testLOGIN������8=�8N�8N�N�������)�I��&�	�2��(�(��5�����)�)�%�0�	7�	#��^�^�
'�
'��d��
4��
����f�
�t���7�
����*�*�D�O�O�<��������"� 5�6���}�}�T�.�.�/�/r6c��|j|jd�|j|jj|j�yrsr�rSs  r4rzAuthenticatorTests._cbTestLOGIN�r�r6c�,��tj�jjd<tjd�}�j
j
|��fd�}�fd�}�fd�}�jjt|��}|jt|�t|��|j�j�j�tj�j�|g�}|j�j �S)Nr�r�c�:���jjd�Sr�r�rRs�r4r�z3AuthenticatorTests.testFailedLOGIN.<locals>.misauth�r�r6c���d�_yrsr�rRs�r4r�z2AuthenticatorTests.testFailedLOGIN.<locals>.authed�r�r6c���d�_yr�r�rRs�r4r�z5AuthenticatorTests.testFailedLOGIN.<locals>.misauthedr�r6)rr�r�r2r�r�r�r�r�r7r�rr
rr(r#�_cbTestFailedLOGINrs`      r4�testFailedLOGINz"AuthenticatorTests.testFailedLOGIN������,1�,B�,B�������)��(�(��5�����)�)�%�0�	?�	#�	$��^�^�
'�
'��g��
7��
����f�
�u�Y�'7�8�
����*�*�D�O�O�<��������"� 5�6���}�}�T�4�4�5�5r6c��|j|jd�|j|jjd�yr�r�rSs  r4rz%AuthenticatorTests._cbTestFailedLOGINrr6c�H��tjx�jjd<}t	t
|�tjd�}�jj|��fd�}�fd�}�jjt|��}|jt|��j�|j�j�j�tj �j#�|g�}|j�j$�S)Nr�r�c�:���jjd�Sr�r�rRs�r4rOz*AuthenticatorTests.testPLAIN.<locals>.authr�r6c���d�_yrsr�rRs�r4r�z,AuthenticatorTests.testPLAIN.<locals>.authedr�r6)r�PLAINCredentialsr�r2rr �PLAINAuthenticatorr�r�r�r�r7r�r
rrr(r#�_cbTestPLAIN)rE�	plainCredr�rOr�r)r�s`      r4�	testPLAINzAuthenticatorTests.testPLAINr
r6c��|j|jd�|j|jj|j�yrsr�rSs  r4rzAuthenticatorTests._cbTestPLAIN#r�r6c�,��tj�jjd<tjd�}�j
j
|��fd�}�fd�}�fd�}�jjt|��}|jt|�t|��|j�j�j�tj�j�|g�}|j�j �S)Nr�r�c�:���jjd�Sr�r�rRs�r4r�z3AuthenticatorTests.testFailedPLAIN.<locals>.misauth,r�r6c���d�_yrsr�rRs�r4r�z2AuthenticatorTests.testFailedPLAIN.<locals>.authed/r�r6c���d�_yr�r�rRs�r4r�z5AuthenticatorTests.testFailedPLAIN.<locals>.misauthed2r�r6)rrr�r2rr�r�r�r�r7r�rr
rr(r#�_cbTestFailedPLAINrs`      r4�testFailedPLAINz"AuthenticatorTests.testFailedPLAIN'rr6c��|j|jd�|j|jjd�yr�r�rSs  r4r!z%AuthenticatorTests._cbTestFailedPLAIN;rr6N)rsrtrurr�r�r�r�r�r�r�r�r�rrr	rrrrrr"r!r1r6r4r�r��
sl��
(�)U�V
�&9�.29�h1
�f�B0�d2�$<�8�(4�0�(<�6�(4�0�(<�6�(4r6r�c�"�eZdZdZd�Zd�Zd�Zy)�SASLPLAINTestsz�
    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��d}d}d}tj|�}|j||�}|j|d|zdz|z�y)z�
        L{PLAINAuthenticator.challengeResponse} returns challenge strings of
        the form::

            NUL<authn-id>NUL<secret>
        r�r�s	challenge�N)rrr�rB)rEr�r�r�r�r�s      r4�#test_authenticatorChallengeResponsez2SASLPLAINTests.test_authenticatorChallengeResponseIsT���������(�(��2���*�*�6�4�8������5�8�#3�e�#;�f�#D�Er6c��tj�}|jd�|j|jd�|j|j
d�y)z�
        L{PLAINCredentials.setResponse} parses challenge strings of the
        form::

            NUL<authn-id>NUL<secret>
        stestusersecretr�r�N)rrr�rBr�r��rE�creds  r4�test_credentialsSetResponsez*SASLPLAINTests.test_credentialsSetResponseWsI���%�%�'�����.�/��������4�������	�2r6c�.�tj�}|jtj|jd�|jtj|jd�|jtj|jd�y)z�
        L{PLAINCredentials.setResponse} raises L{imap4.IllegalClientResponse}
        when passed a string not of the expected form.
        shelloshelloworldshelloworldZoom!N)rrr�r�r�r*s  r4�test_credentialsInvalidResponsez.SASLPLAINTests.test_credentialsInvalidResponsecsu��
�%�%�'�����%�5�5�t�7G�7G��R�����'�'��)9�)9�?�	
�	
����'�'��)9�)9�;S�	
r6N)rsrtrur3r(r,r.r1r6r4r%r%@s���F�
3�
r6r%c�T�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�UnsolicitedResponseTestsc�F���fd�}�fd�}�jjt|��}|jt|��j�j�tj�j�|g�}|j�j�S)Nc�<���jjdd�SrGrzrRs�r4rHz5UnsolicitedResponseTests.testReadWrite.<locals>.logintr{r6c�<���jjd�yrs�r�r�rRs�r4r�z8UnsolicitedResponseTests.testReadWrite.<locals>.loggedInw�����K�K�#�#�A�&r6)	r�r�r7r'r
rr(r#�_cbTestReadWrite�rErHr�r)r�s`    r4�
testReadWritez&UnsolicitedResponseTests.testReadWritessw���	D�	'��^�^�
'�
'��e��
5��
���u�X��'�2�2�4�?�?�C��������"� 5�6���}�}�T�2�2�3�3r6c�Z�|jj}|j|ddgg�y)Nr�r��r�r�rB�rErT�Es   r4r6z)UnsolicitedResponseTests._cbTestReadWrite�)���K�K��������m�Q�/�0�1r6c�F���fd�}�fd�}�jjt|��}|jt|��j�j�tj�j�|g�}|j�j�S)Nc�<���jjdd�SrGrzrRs�r4rHz4UnsolicitedResponseTests.testReadOnly.<locals>.login�r{r6c�<���jjd�yr�r4rRs�r4r�z7UnsolicitedResponseTests.testReadOnly.<locals>.loggedIn�r5r6)	r�r�r7r'r
rr(r#�_cbTestReadOnlyr7s`    r4�testReadOnlyz%UnsolicitedResponseTests.testReadOnly�sw���	D�	'��^�^�
'�
'��e��
5��
���u�X��'�2�2�4�?�?�C��������"� 5�6���}�}�T�1�1�2�2r6c�Z�|jj}|j|ddgg�y)Nr�rr:r;s   r4rAz(UnsolicitedResponseTests._cbTestReadOnly�r=r6c�^���ddggdgd���fd�}��fd�}�jjt|��}|jt|��j�j�tj�j�|g�}|j�j��S)N�	\Answeredr��\Recent)r�r�r�c�<���jjdd�SrGrzrRs�r4rHz6UnsolicitedResponseTests.testFlagChange.<locals>.login�r{r6c�<���jj��yr0)r�r�)r�rEs��r4r�z9UnsolicitedResponseTests.testFlagChange.<locals>.loggedIn�s����K�K�$�$�U�+r6)	r�r�r7r'r
rr(r#�_cbTestFlagChange)rErHr�r)r�r�s`    @r4�testFlagChangez'UnsolicitedResponseTests.testFlagChange�s����!�;�/�B�Z�L�I��	D�	,��^�^�
'�
'��e��
5��
���u�X��'�2�2�4�?�?�C��������"� 5�6���}�}�T�3�3�U�;�;r6c��|jj}|j�D�cgc]}d|d|dig��}}|jd���|jd���|j	||�ycc}w)Nr�rr�c��|dSr�r1�rps r4r5z<UnsolicitedResponseTests._cbTestFlagChange.<locals>.<lambda>�s
��Q�q�T�r6)�keyc��|dSr�r1rMs r4r5z<UnsolicitedResponseTests._cbTestFlagChange.<locals>.<lambda>�s
��!�A�$�r6)r�r��itemsr�rB)rErTr�r<r\�expects      r4rIz*UnsolicitedResponseTests._cbTestFlagChange�sm���K�K����:?�+�+�-�H�Q�>�A�a�D�!�A�$�<�0�H��H�	���>��"������'�����F�#��Is�A7c�F���fd�}�fd�}�jjt|��}|jt|��j�j�tj�j�|g�}|j�j�S)Nc�<���jjdd�SrGrzrRs�r4rHz7UnsolicitedResponseTests.testNewMessages.<locals>.login�r{r6c�>���jjdd�y�Nr��r�r�rRs�r4r�z:UnsolicitedResponseTests.testNewMessages.<locals>.loggedIn�s����K�K�#�#�B��-r6)	r�r�r7r'r
rr(r#�_cbTestNewMessagesr7s`    r4�testNewMessagesz(UnsolicitedResponseTests.testNewMessages�sw���	D�	.��^�^�
'�
'��e��
5��
���u�X��'�2�2�4�?�?�C��������"� 5�6���}�}�T�4�4�5�5r6c�Z�|jj}|j|gd�g�y)N)r�r�Nr:r;s   r4rWz+UnsolicitedResponseTests._cbTestNewMessages��%���K�K��������6�7�8r6c�F���fd�}�fd�}�jjt|��}|jt|��j�j�tj�j�|g�}|j�j�S)Nc�<���jjdd�SrGrzrRs�r4rHz=UnsolicitedResponseTests.testNewRecentMessages.<locals>.login�r{r6c�>���jjdd�yrUrVrRs�r4r�z@UnsolicitedResponseTests.testNewRecentMessages.<locals>.loggedIn�s����K�K�#�#�D�"�-r6)	r�r�r7r'r
rr(r#�_cbTestNewRecentMessagesr7s`    r4�testNewRecentMessagesz.UnsolicitedResponseTests.testNewRecentMessages�sw���	D�	.��^�^�
'�
'��e��
5��
���u�X��'�2�2�4�?�?�C��������"� 5�6���}�}�T�:�:�;�;r6c�Z�|jj}|j|gd�g�y)N�r�Nr�r:r;s   r4r^z1UnsolicitedResponseTests._cbTestNewRecentMessages�rZr6c�F���fd�}�fd�}�jjt|��}|jt|��j�j�tj�j�|g�}|j�j�S)Nc�<���jjdd�SrGrzrRs�r4rHz@UnsolicitedResponseTests.testNewMessagesAndRecent.<locals>.login�r{r6c�>���jjdd�y)Nr@r�rVrRs�r4r�zCUnsolicitedResponseTests.testNewMessagesAndRecent.<locals>.loggedIn�s����K�K�#�#�B��+r6)	r�r�r7r'r
rr(r#�_cbTestNewMessagesAndRecentr7s`    r4�testNewMessagesAndRecentz1UnsolicitedResponseTests.testNewMessagesAndRecent�sw���	D�	,��^�^�
'�
'��e��
5��
���u�X��'�2�2�4�?�?�C��������"� 5�6���}�}�T�=�=�>�>r6c�`�|jj}|j|gd�gd�g�y)N)r�r@Nrar:r;s   r4rez4UnsolicitedResponseTests._cbTestNewMessagesAndRecent�s(���K�K��������6�8Q�R�Sr6N)rsrtrur8r6rBrArJrIrXrWr_r^rfrer1r6r4r0r0rs?��
4�2�
3�2�<�$�
6�9�
<�9�
?�Tr6r0c�(�eZdZdZd�Zd�Zd�Zd�Zy)�ClientCapabilityTestszT
    Tests for issuance of the CAPABILITY command and handling of its response.
    c���t�|_tj�|_|jj|j�|jj
d�y)zS
        Create an L{imap4.IMAP4Client} connected to a L{StringTransport}.
        s* OK [IMAP4rev1]
N)rr�rr��protocolr�r�rRs r4rzClientCapabilityTests.setUp�sG��)�*����)�)�+��
��
�
�$�$�T�^�^�4��
�
�"�"�#:�;r6c�����jjd��}�jjd��jjd��fd�}|j|�|S)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�0���j|ddd��y)N)r!s
LOGINDISABLEDr%��capabilitiesrEs �r4�gotCapabilitiesz?ClientCapabilityTests.test_simpleAtoms.<locals>.gotCapabilities�s������\�$�RV�+W�Xr6�rkrr�r��rE�capabilitiesResultrss`  r4�test_simpleAtomsz&ClientCapabilityTests.test_simpleAtoms�s_���
"�]�]�:�:�E�:�J���
�
�"�"�#N�O��
�
�"�"�#G�H�	Y�	�&�&��7�!�!r6c�����jjd��}�jjd��jjd��fd�}|j|�|S)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)
        Frms.* CAPABILITY IMAP4rev1 AUTH=LOGIN AUTH=PLAIN
roc�4���j|dddgd��y)Nr�r�)r!r/r%rqs �r4rszAClientCapabilityTests.test_categoryAtoms.<locals>.gotCapabilitiess �������T�X�x�<P�Q�
r6rtrus`  r4�test_categoryAtomsz(ClientCapabilityTests.test_categoryAtoms�s^���"�]�]�:�:�E�:�J���
�
�"�"�#V�W��
�
�"�"�#G�H�	�
	�&�&��7�!�!r6c�����jjd��}�jjd��jjd��fd�}|j|�|S)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.
        Frms0* CAPABILITY IMAP4rev1 FOO FOO=BAR BAR=FOO BAR
roc�:���j|dddgddgd��y)N�BAR�FOO)r!r~r}r%rqs �r4rsz>ClientCapabilityTests.test_mixedAtoms.<locals>.gotCapabilitiess&�������#�d�F�^�f�d�^�T�
r6rtrus`  r4�test_mixedAtomsz%ClientCapabilityTests.test_mixedAtomssd���"�]�]�:�:�E�:�J��	
�
�
�"�"�A�	
�	
�
�
�"�"�#G�H�	�	�&�&��7�!�!r6N)rsrtrur3rrwrzrr1r6r4riri�s���<�
"�"�4"r6ric��eZdZdZd�Zd�Zy)�StillSimplerClientzH
    An IMAP4 client which keeps track of unsolicited flag changes.
    c�P�tjj|�i|_yr0)rr�rzr�rRs r4rzzStillSimplerClient.__init__-s��
���"�"�4�(���
r6c�:�|jj|�yr0)r�rr�s  r4r�zStillSimplerClient.flagsChanged1s���
�
���(�#r6N)rsrtrur3rzr�r1r6r4r�r�(s����$r6r�c�B�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�HandCraftedTestsc�������t��tj���j���j	d���fd����fd����fd�}�jdd�}�j
d�|j|�|S)N�* OK [IMAP4rev1]c�h���j�j�j�dd�y)Nr�s0003 FETCH 1 (RFC822)�rBrrg)rTrEr�s ��r4�cbCheckTransportz>HandCraftedTests.testTrailingLiteral.<locals>.cbCheckTransport<s,���������!�,�,�.�r�2�(�
r6c����jd�}�jd��jd�|j��|S)Nr�s6* 1 FETCH (RFC822 {10}
0123456789
 RFC822.SIZE 10)
s0003 OK FETCH
)�fetchMessager�r�)rTr�r�r�s  ��r4�cbSelectz6HandCraftedTests.testTrailingLiteral.<locals>.cbSelectBsA������s�#�A�
�N�N�O�
�
�N�N�/�0�
�M�M�*�+��Hr6c�n���jd�}�jd�|j��|S�Nr��0002 OK SELECT)r�r�r�)rTr�r�r�s  ��r4�cbLoginz5HandCraftedTests.testTrailingLiteral.<locals>.cbLoginKs/�������!�A�
�N�N�,�-�
�M�M�(�#��Hr6�blah�0001 OK LOGIN
)rrr�r�r�rHr�r�)rEr�r�r�r�r�r�s`  @@@@r4�testTrailingLiteralz$HandCraftedTests.testTrailingLiteral6ss���#�%�	������	����#�	���*�+�	�	�	�
�G�G�G�W�%��	���+�,�	�
�
�g���r6c�x�|jjjdd�t�}|jj	|�|j�|jj
d�|j|j�d�|j�|jj
d�|j|j�d�|j�|jj
d�|j|j��|jj
d�|j|j�d	�|j|jjd
�|jjtjd��y)
z]
        String literals whose data is not immediately available are
        parsed.
        r�r�s01 LOGIN {8}
s+ Ready for 8 octets of text
stestuser {13}
s+ Ready for 13 octets of text
spasswords-test
�01 OK LOGIN succeeded
rOr�N)r�r�r�rr�r�r�rBr�	assertNotrRr�rr��rEr�s  r4�test_fragmentedStringLiteralsz.HandCraftedTests.test_fragmentedStringLiteralsVs4��
	
�����#�#�K�1A�B�#�%�	����"�"�9�-�������� � �!4�5�������*�,O�P�������� � �!5�6�������*�,P�Q�������� � ��-����y���(�)���� � ��.�������*�,H�I�������*�*�F�3����"�"�5�#7�#7�8J�#K�Lr6c�\�ddi|jj_t�}|jj	|�|j�|jj
d�|j|j�d�|j�|jj
d�|j|j�d�|j|jjd�|jjtjd��y)	z3
        Empty string literals are parsed.
        r6s01 LOGIN {0}
s+ Ready for 0 octets of text
s{0}
r�rOr�N)
r�r�r�rr�r�r�rBrrRr�rr�r�s  r4�test_emptyStringLiteralz(HandCraftedTests.test_emptyStringLiteralps���&)�#�J������!�#�%�	����"�"�9�-�������� � �!4�5�������*�,O�P�������� � ��,�������*�,H�I�������*�*�F�3����"�"�5�#7�#7�8J�#K�Lr6c�,����t��t���j���jd��fd�}�fd�}�fd�}���fd�}|�j	t|��j	t|��j	|�S)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.
        r�c�N���jdd�}�jd�|S�Nr�r��rHr��r�r�s �r4rHzRHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.login��%��������)�A�
�N�N�/�0��Hr6c�L���jd�}�jd�|Sr��r�r�r�s �r4r�zSHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.select��#�������!�A�
�N�N�,�-��Hr6c����jdddg��}�jd��jd��jd��jd��jd	��jd
��jd��jd��jd��jd�|S)
Nr��
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}
sISubject: What you been doing. Order your meds here . ,. handcuff madsen
�0003 OK FETCH completed
��
fetchSpecificr�r�s �r4r�zRHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.fetch�s��������/�y�k� ��A�
�N�N�Q�R�
�N�N�D�E�
�N�N�7�#�
�N�N�8�$�
�N�N�<�=�
�N�N�Q�R�
�N�N�^�
�
�N�N�7�#�
�N�N�8�$�
�N�N�9�:��Hr6c�����j�j�j�dd��j|dddggdggdddggdggd���j�jd	d
gi�y)Nr��,0003 FETCH 1:* BODY[HEADER.FIELDS (SUBJECT)]r�r�r�z&Subject: Suprise for your woman...

zKSubject: What you been doing. Order your meds here . ,. handcuff madsen

�r�r�r��\Seen�rBrrgr���resr�rEr�s ���r4r�zQHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse.<locals>.test�s����������!�,�,�.�r�2�?�
�

����#�,�y�k�:�H���#�,�y�k�:�m����
�(
���Q�W�W�q�8�*�o�6r6�rr�r�r�r�r7�rErHr�r�r�r�r�s`    @@r4�2test_unsolicitedResponseMixedWithSolicitedResponsezCHandCraftedTests.test_unsolicitedResponseMixedWithSolicitedResponse�sv���$�%�	�� ��	����#�	���*�+�	�
	�
	�$	7�:
�G�
�[��v��
'�
�[��u��
&�
�[��
�		
r6c�N����t��tj���j���j	d��fd�}�fd�}�fd�}��fd�}|�}|jt
|��|jt
|��|j|�|S)zf
        Literals should be recognized even when they are not preceded by
        whitespace.
        r�c�N���jdd�}�jd�|Sr�r��r�rks �r4rHzFHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.login��'������w��0�A��!�!�"6�7��Hr6c�L���jd�}�jd�|S)N�inboxr�r�r�s �r4r�zGHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.select�s%�������)�A��!�!�"3�4��Hr6c�v���jdddg��}�jd��jd�|S)Nr�r�r�r�s8* 1 FETCH (BODY[HEADER.FIELDS ({7}
SUBJECT)] "Hello")
r�r�r�s �r4r�zFHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.fetch�sJ����&�&��/�y�k�'��A�
�!�!�O�
�
�!�!�"@�A��Hr6c����j�j�j�dd��j|ddddggdggi�y)Nr�r�r�r�r�r��Hellor�)r2rEr�s ��r4r�zEHandCraftedTests.test_literalWithoutPrecedingWhitespace.<locals>.test�sW���������!�,�,�.�r�2�?�
�
�����f����&D�g�N�O�P�
r6�rrr�r�r�r�r7)rErHr�r�r�r�rkr�s`     @@r4�&test_literalWithoutPrecedingWhitespacez7HandCraftedTests.test_literalWithoutPrecedingWhitespace�s����
$�%�	��$�$�&�����	�*����1�2�	�
	�
	�	�
�G��	�
�
�e�F�m�$�	�
�
�e�E�l�#�	�
�
�d���r6c�$����t��tj���j���j	d��fd�}�fd�}���fd�}|�}|jt
|��|jt
|��|S)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}.
        r�c�N���jdd�}�jd�|Sr�r�r�s �r4rHz<HandCraftedTests.test_nonIntegerLiteralLength.<locals>.login	r�r6c�L���jd�}�jd�|Sr�r�r�s �r4r�z=HandCraftedTests.test_nonIntegerLiteralLength.<locals>.selects%�������(�A��!�!�"3�4��Hr6c�����jdddg���j�j�j�dd��j	t
j�jd�y)Nr�r�r�r�r�r�s* 1 FETCH {xyz}
...)r�rBrrgr�r�IllegalServerResponser�)rkrEr�s���r4r�z<HandCraftedTests.test_nonIntegerLiteralLength.<locals>.fetchso����"�"��/�y�k�
#�
�
������!�,�,�.�r�2�?�
�

����+�+��%�%�)�
r6r�)rErHr�r�r�rkr�s`    @@r4�test_nonIntegerLiteralLengthz-HandCraftedTests.test_nonIntegerLiteralLength�su���$�%�	��$�$�&�����	�*����1�2�	�
	�
	� 
�G��	�
�
�e�F�m�$�	�
�
�e�E�l�#��r6c�(���t�}t���j|��jd��fd�}�fd�}�fd�}��fd�}|�j	t|��j	t|��j	|�S)a
        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.
        r�c�N���jdd�}�jd�|Sr�r�r�s �r4rHzLHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.login4r�r6c�L���jd�}�jd�|Sr�r�r�s �r4r�zMHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.select9r�r6c� ���jdddg��}�jd��jd��jd��jd��jd	��jd
��jd�|S)Nr�r�r�r�s1* 1 FETCH (BODY[HEADER.FIELDS ("SUBJECT")] {22}
sSubject: subject one
s FLAGS (\Recent))
s?* 2 FETCH (FLAGS (\Seen) BODY[HEADER.FIELDS ("SUBJECT")] {22}
sSubject: subject two
r�r�r�r�s �r4r�zLHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.fetch>s��������?�	�{� ��A�
�N�N�Q�R�
�N�N�6�7�
�N�N�4�5�
�N�N�U�
�
�N�N�6�7�
�N�N�8�$�
�N�N�9�:��Hr6c����j|dddggdggdddggdggd���j�jdgdgd��y)	Nr�r�r�zSubject: subject one
zSubject: subject two
r�rFr�)rBr�)r�r�rEs ��r4r�zKHandCraftedTests.test_flagsChangedInsideFetchSpecificResponse.<locals>.testOsp�������#�,�y�k�:�6���#�,�y�k�:�6����
�(
���Q�W�W�:�,�H�:�&F�Gr6r�)rEr�rHr�r�r�r�s`     @r4�,test_flagsChangedInsideFetchSpecificResponsez=HandCraftedTests.test_flagsChangedInsideFetchSpecificResponse(sw���$�%�	�� ��	����#�	���*�+�	�
	�
	�"	H�0
�G�
�[��v��
'�
�[��u��
&�
�[��
�		
r6c�,����t��t���j���jd��fd�}�fd�}�fd�}���fd�}|�j	t|��j	t|��j	|�S)a
        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.
        r�c�N���jdd�}�jd�|Sr�r�r�s �r4rHzKHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.loginyr�r6c�L���jd�}�jd�|Sr�r�r�s �r4r�zLHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.select~r�r6c����jd�}�jd��jd��jd��jd��jd��jd��jd�|S)	Nr�s* 1 FETCH (RFC822 {24}
sSubject: first subject
s FLAGS (\Seen))
s.* 2 FETCH (FLAGS (\Recent \Seen) RFC822 {25}
sSubject: second subject
r�r�)r�r�r�s �r4r�zKHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.fetch�sp������u�%�A�
�N�N�8�9�
�N�N�8�9�
�N�N�2�3�
�N�N�P�Q�
�N�N�9�:�
�N�N�8�$�
�N�N�9�:��Hr6c�����j�j�j�dd��j|ddiddid���j�jdgddgd��y)	Nr�s0003 FETCH 1:* (RFC822)r�zSubject: first subject
zSubject: second subject
r�r�rFr�r�s ���r4r�zJHandCraftedTests.test_flagsChangedInsideFetchMessageResponse.<locals>.test�sx���������!�,�,�.�r�2�*�
�

���� �">�?� �"?�@��
�
���Q�W�W�8�*�*�h�9O�&P�Qr6r�r�s`    @@r4�+test_flagsChangedInsideFetchMessageResponsez<HandCraftedTests.test_flagsChangedInsideFetchMessageResponsemsw���$�%�	�� ��	����#�	���*�+�	�
	�
		�	R�"
�G�
�[��v��
'�
�[��u��
&�
�[��
�		
r6c�0�t�}tj�}||_|j	|�|jd�tjd�}|j|�|jd�}|j|tj�|jd�|jtj�}|jt!|�d�|j|dj"j$dd�|S)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 Readyr�r�s+ Something bad! and bad
r�rsSomething bad! and bad)rrr�rkr�r�r�r�r��
assertFailurerr�r�r~r�rBr�rr�)rEr�rkr�r��loggeds      r4�-test_authenticationChallengeDecodingExceptionz>HandCraftedTests.test_authenticationChallengeDecodingException�s���
5�6�	��$�$�&��%�	�����	�*����
'�	
��0�0��=���&�&�u�-��!�!�(�+��	
���1�e�2�2�3����=�>��'�'��(C�(C�D������V��a�(���������-�-�a�0�2K�L��r6N)rsrtrur�r�r�r�r�r�r�r�r�r1r6r4r�r�5s9���@M�4M�&J
�X,�\)�VC
�J6
�pr6r�c�:�eZdZUdZej
Zded<d�Zy)�PreauthIMAP4ClientMixinav
    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}.
    zType[imap4.IMAP4Client]�clientProtocolc���t�|_|j�|_|jj	|j�|jjd�y)zm
        Create an IMAP4Client connected to a fake transport and in the
        authenticated state.
        s* PREAUTH Hello unittest
N)rr�r�r�r�r�rRs r4rzPreauthIMAP4ClientMixin.setUp�sG��
)�*����)�)�+������"�"�4�>�>�2���� � �!@�Ar6N)	rsrtrur3rr�r�r�rr1r6r4r�r��s ���/4�.?�.?�N�+�?�Br6r�c�p�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zy)�SelectionTestsMixinzl
    Mixin for test cases which defines tests which apply to both I{EXAMINE} and
    I{SELECT} support.
    c���t|j|j�d�}|j|jj�d|jzdz�|S)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.
        �fooboxs0001 s	 foobox
)r�r��methodrBr�rr��rEr�s  r4�_examineOrSelectz$SelectionTestsMixin._examineOrSelect�sT��
.�G�D�K�K����-�h�7������N�N� � �"�H�t�|�|�$;�n�$L�	
��r6c��|D] }|jj|dz��"|jjd|jzdz�y)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�s0001 OK [READ-ONLY] s completed
N)r�r�r�)rE�linesr�s   r4�	_responsezSelectionTestsMixin._response�sM���	5�D��K�K�$�$�T�G�^�4�	5���� � �#�d�l�l�2�5F�F�	
r6c��|j�}|jd�|j|j|�ddd��y)a
        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 EXISTSFr�)r�r�N�r�r�rB�successResultOfr�s  r4�test_existszSelectionTestsMixin.test_exists��?��
�!�!�#�����}�%�����-�-�a�0��RS�2T�Ur6c��|j�}|jd�|j|tj�y)a
        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��failureResultOfrr�r�s  r4�test_nonIntegerExistsz)SelectionTestsMixin.test_nonIntegerExists	�4��
�!�!�#������'����Q�� ;� ;�<r6c��|j�}|jd�|j|j|�ddd��y)a
        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 RECENTFr�)r�rRNr�r�s  r4�test_recentzSelectionTestsMixin.test_recentr�r6c��|j�}|jd�|j|tj�y)a
        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  r4�test_nonIntegerRecentz)SelectionTestsMixin.test_nonIntegerRecentr�r6c��|j�}|jd�|j|j|�ddd��y)a
        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 unseenFr�)r�rUNr�r�s  r4�test_unseenzSelectionTestsMixin.test_unseen*s@��
�!�!�#�����C�D�����-�-�a�0��RS�2T�Ur6c��|j�}|jd�|j|tj�y)a
        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  r4�test_nonIntegerUnseenz)SelectionTestsMixin.test_nonIntegerUnseen5s5��
�!�!�#�����G�H����Q�� ;� ;�<r6c��|j�}|jd�|j|j|�ddd��y)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 validFr4)r�rTNr�r�s  r4�test_uidvalidityz$SelectionTestsMixin.test_uidvalidity@sB��
�!�!�#�����=�>����� � ��#�E�%�%P�	
r6c��|j�}|jd�|j|tj�y)a
        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  r4�test_nonIntegerUIDVALIDITYz.SelectionTestsMixin.test_nonIntegerUIDVALIDITYMs5��
�!�!�#�����;�<����Q�� ;� ;�<r6c��|j�}|jd�|j|j|�ddd��y)a!
        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 UIDFi()r�rSNr�r�s  r4�test_uidnextz SelectionTestsMixin.test_uidnextXsB��
�!�!�#�����@�A����� � ��#�E�d�%K�	
r6c��|j�}|jd�|j|tj�y)a
        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  r4�test_nonIntegerUIDNEXTz*SelectionTestsMixin.test_nonIntegerUIDNEXTes5��
�!�!�#�����?�@����Q�� ;� ;�<r6c��|j�}|jd�|j|j|�ddd��y)�
        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)F)rEz\Flaggedr�r�z\Draft)r�r�Nr�r�s  r4�
test_flagszSelectionTestsMixin.test_flagspsF��
�!�!�#�����Q�R����� � ��#�#�V�
�	
r6c��|j�}|jd�|j|j|�ddd��y)rsN* OK [PERMANENTFLAGS (\Starred)] Just one permanent flag in that list up thereF)z\Starred)r��PERMANENTFLAGSNr�r�s  r4�test_permanentflagsz'SelectionTestsMixin.test_permanentflags�sI��
�!�!�#�����
"�	
�	
���� � ��#� �N�C�	
r6c��|j�}|jd�|j|j|�ddi�y)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.r�FNr�r�s  r4�test_unrecognizedOkz'SelectionTestsMixin.test_unrecognizedOk�sA��

�!�!�#�����M�N�	
����-�-�a�0�<��2G�Hr6c��|j�}|jd�|j|j|�ddi�y)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* OKr�FNr�r�s  r4�test_bareOkzSelectionTestsMixin.test_bareOk�s>��

�!�!�#�����w������-�-�a�0�<��2G�Hr6N)rsrtrur3r�r�r�r�r�r�r�r�r�r�r�rrrr	rr1r6r4r�r��s\���
�

�	V�	=�	V�	=�	V�	=�
�	=�
�	=�
�"
�"	I�Ir6r�c��eZdZdZdZdZy)�IMAP4ClientExamineTestsa�
    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�sEXAMINEN�rsrtrur3r�r�r1r6r4r
r
�s��
��F��Gr6r
c��eZdZdZdZdZy)�IMAP4ClientSelectTestsa
    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�sSELECTNrr1r6r4rr�s��� �F��Gr6rc�(�eZdZdZd�Zd�Zd�Zd�Zy)�IMAP4ClientExpungeTestsa
    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���|jj�}|j|jj	�d�|jj�|S)Ns0001 EXPUNGE
)r�r�rBr�rr�r�s  r4�_expungez IMAP4ClientExpungeTests._expunge�sG���K�K���!��������-�-�/�1D�E��������r6c��|D]*}|jjtd|�d����,|jjd�y)Nz* z EXPUNGEs0001 OK EXPUNGE COMPLETED)r�r�r))rE�sequenceNumbers�numbers   r4r�z!IMAP4ClientExpungeTests._response�sF��%�	K�F��K�K�$�$�]�R��x�x�3H�%I�J�	K���� � �!=�>r6c��|j�}|jgd��|j|j|�gd��y)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.
        )r�r�r�r�N)rr�rBr�r�s  r4�test_expungez$IMAP4ClientExpungeTests.test_expunge�s6��
�M�M�O�����|�$�����-�-�a�0�,�?r6c��|j�}|jgd��|j|tj�y)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}.
        )r�r�rHr�N)rr�r�rr�r�s  r4�test_nonIntegerExpungedz/IMAP4ClientExpungeTests.test_nonIntegerExpunged�s2��
�M�M�O�����'�(����Q�� ;� ;�<r6N)rsrtrur3rr�rrr1r6r4rr�s����?�
@�=r6rc�(�eZdZdZd�Zd�Zd�Zd�Zy)�IMAP4ClientSearchTestsa�
    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��|jjtjd���}|j	|j
j
�d�|S)N�ABCDEF)rFs0001 SEARCH (TEXT "ABCDEF")
)r��searchrrrBr�rr�s  r4�_searchzIMAP4ClientSearchTests._searchsB���K�K���u�{�{��9�:��������-�-�/�1S�T��r6c���|jjdtdjt	t
|���z�|jjd�y)Ns	* SEARCH � s0001 OK SEARCH completed)r�r�r)r��mapr�)rE�messageNumberss  r4r�z IMAP4ClientSearchTests._responsesF����� � ��=����#�c�>�2J�)K�L�L�	
�	
��� � �!<�=r6c��|j�}|jgd��|j|j|�gd��y)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.
        )r�r�r�N)r!r�rBr�r�s  r4�test_searchz"IMAP4ClientSearchTests.test_searchs6��
�L�L�N�����z�"�����-�-�a�0�*�=r6c��|j�}|jgd��|j|tj�y)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}.
        )r�rHr�N)r!r�r�rr�r�s  r4�test_nonIntegerFoundz+IMAP4ClientSearchTests.test_nonIntegerFound%s1��
�L�L�N�����~�&����Q�� ;� ;�<r6N)rsrtrur3r!r�r'r)r1r6r4rr�s���"�
>�>�=r6rc�|�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�IMAP4ClientFetchTestszV
    Tests for the L{IMAP4Client.fetch} method.

    See RFC 3501, section 6.4.5.
    c��|jjd�}|j|jj	�d�|jjd�|jjd�|jjd�|jjd�|jjd�|j|j
|�dd	idd
iddiddid
��y)a
        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�25�r�r�r�r�N)r��fetchUIDrBr�rr�r�r�s  r4�
test_fetchUIDz#IMAP4ClientFetchTests.test_fetchUID7s���
�K�K� � ��'��������-�-�/�1L�M���� � �!6�7���� � �!6�7���� � �!6�7���� � �!6�7���� � �!;�<����� � ��#���
�5�$�-�U�D�M�u�d�m�T�	
r6c�:�|jjd�}|j|jj	�d�|jjd�|jjd�|j
|tj�y)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�s0001 FETCH 1 (UID)
s* foo FETCH (UID 22)r1N�	r�r7rBr�rr�r�rr�r�s  r4�test_fetchUIDNonIntegerFoundz2IMAP4ClientFetchTests.test_fetchUIDNonIntegerFoundJsr��
�K�K� � ��%��������-�-�/�1J�K���� � �!8�9���� � �!;�<����Q�� ;� ;�<r6c��|jjd�}|j|jj	�d�|jjd�|jjd�|jjd�|jjd�|j
|tj�y)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)r0r1Nr:r�s  r4�test_incompleteFetchUIDResponsez5IMAP4ClientFetchTests.test_incompleteFetchUIDResponseVs���
�K�K� � ��'��������-�-�/�1L�M���� � �!6�7���� � �!3�4���� � �!6�7���� � �!;�<����Q�� ;� ;�<r6c�D�|jjd�}|j|jj	�d�|jjd�|jjd�|j|j
|�dddii�y)	a
        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.
        �3s0001 FETCH 3 (RFC822.TEXT)
s&* 3 FETCH (RFC822.TEXT "Message text")r1r�r�zMessage textN)r��	fetchBodyrBr�rr�r�r�s  r4�test_fetchBodyz$IMAP4ClientFetchTests.test_fetchBodyds���
�K�K�!�!�#�&��������-�-�/�1R�S���� � �!J�K���� � �!;�<�����-�-�a�0�1�}�n�6U�2V�Wr6c�H�|jjd�}|j|jj	�d�|jjd�|jjd�|j|j
|�ddgdggi�y)	aI
        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")r1r�r��	Some bodyN�r�r�rBr�rr�r�r�s  r4�test_fetchSpecificz(IMAP4ClientFetchTests.test_fetchSpecificqs���
�K�K�%�%�c�*��������-�-�/�1K�L���� � �!B�C���� � �!;�<�����-�-�a�0�1���K�7P�6Q�2R�Sr6c�L�|jjdd��}|j|jj	�d�|jjd�|jjd�|j|j
|�ddgd	ggi�y
)z�
        L{IMAP4Client.fetchSpecific} issues a I{BODY.PEEK[]} command if passed
        C{True} for the C{peek} parameter.
        �6T)r�s0001 FETCH 6 BODY.PEEK[]
s* 6 FETCH (BODY[] "Some body")r1r�r�rENrFr�s  r4�test_fetchSpecificPeekz,IMAP4ClientFetchTests.test_fetchSpecificPeeks���

�K�K�%�%�c��%�5��������-�-�/�1P�Q���� � �!B�C���� � �!;�<�����-�-�a�0�1���K�7P�6Q�2R�Sr6c�N�|jjdd��}|j|jj	�d�|jjd�|jjd�|j|j
|�ddd	gd
ggi�y)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.
        rCr���headerNumbers0001 FETCH 7 BODY[1.2.3]
s#* 7 FETCH (BODY[1.2.3] "Some body")r1r�r�z1.2.3rENrFr�s  r4�test_fetchSpecificNumberedz0IMAP4ClientFetchTests.test_fetchSpecificNumbered�s���
�K�K�%�%�c�	�%�B��������-�-�/�1P�Q���� � �!G�H���� � �!;�<����� � ��#�a�6�G�9�k�*J�)K�%L�	
r6c�N�|jjdd��}|j|jj	�d�|jjd�|jjd�|j|j
|�dddgd	ggi�y
)a1
        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�r��0001 FETCH 8 BODY[TEXT]
s"* 8 FETCH (BODY[TEXT] "Some body")r1r�r�rENrFr�s  r4�test_fetchSpecificTextz,IMAP4ClientFetchTests.test_fetchSpecificText����
�K�K�%�%�c�f�%�=��������-�-�/�1O�P���� � �!F�G���� � �!;�<����� � ��#�a�6�F�8�[�*I�)J�%K�	
r6c�P�|jjddd��}|j|jj	�d�|jjd�|jjd�|j|j
|�dd	d
gdggi�y)
ah
        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.
        �4rQr�)r�rMs0001 FETCH 4 BODY[7.TEXT]
s$* 4 FETCH (BODY[7.TEXT] "Some body")r1r�r�z7.TEXTrENrFr�s  r4�test_fetchSpecificNumberedTextz4IMAP4ClientFetchTests.test_fetchSpecificNumberedText�s���
�K�K�%�%�c�f�1�%�M��������-�-�/�1Q�R���� � �!H�I���� � �!;�<����� � ��#�a�6�H�:�{�*K�)L�%M�	
r6c�>�|jjdd��}|j|jj	�d�|jjd�|jjd�|j
|tj�y)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}.
        rPrQrRrSs* 8 FETCH (BODY[TEXT])r1N�	r�r�rBr�rr�r�rr�r�s  r4�(test_incompleteFetchSpecificTextResponsez>IMAP4ClientFetchTests.test_incompleteFetchSpecificTextResponse�sw��
�K�K�%�%�c�f�%�=��������-�-�/�1O�P���� � �!:�;���� � �!;�<����Q�� ;� ;�<r6c�N�|jjdd��}|j|jj	�d�|jjd�|jjd�|j|j
|�dddgd	ggi�y
)a1
        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.
        rPr�rRs0001 FETCH 8 BODY[MIME]
s"* 8 FETCH (BODY[MIME] "Some body")r1r�r�rENrFr�s  r4�test_fetchSpecificMIMEz,IMAP4ClientFetchTests.test_fetchSpecificMIME�rUr6c�T�|jjdddd��}|j|jj	�d�|jjd�|jjd�|j|j
|�d	d
dgddggi�y
)aX
        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.
        �9rQrDr�)r��offset�lengths0001 FETCH 9 BODY[TEXT]<17.3>
s * 9 FETCH (BODY[TEXT]<17> "foo")r1r�r�z<17>rHNrFr�s  r4�test_fetchSpecificPartialz/IMAP4ClientFetchTests.test_fetchSpecificPartial�s���
�K�K�%�%�c�f�R�PQ�%�R��������-�-�/�1U�V���� � �!D�E���� � �!;�<����� � ��#�a�6�F�8�V�U�*K�)L�%M�	
r6c�>�|jjdd��}|j|jj	�d�|jjd�|jjd�|j
|tj�y)a
        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}.
        rPrQrRrSs* 8 FETCH (BODY[TEXT]<17>)r1NrZr�s  r4�+test_incompleteFetchSpecificPartialResponsezAIMAP4ClientFetchTests.test_incompleteFetchSpecificPartialResponse�sw��
�K�K�%�%�c�f�%�=��������-�-�/�1O�P���� � �!>�?���� � �!;�<����Q�� ;� ;�<r6c�H�|jjd�}|j|jj	�d�|jjd�|jjd�|j|j
|�ddgdggi�y)	aA
        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).
        rCrDs&* 7 FETCH (BODY[] "<html>test</html>")r1r�r�z<html>test</html>NrFr�s  r4�test_fetchSpecificHTMLz,IMAP4ClientFetchTests.test_fetchSpecificHTML�s���
�K�K�%�%�c�*��������-�-�/�1K�L���� � �!J�K���� � �!;�<����� � ��#�a�6�2�7J�*K�)L�%M�	
r6c��|jjd|��}|j|jj	�d|jd�zdz�|jj
d|jd�zdz�|jj
d�|j|j|�d	d
|ggdggi�y)
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}
        �10rRs0001 FETCH 10 BODY[r�s ()]
s* 10 FETCH (BODY[s ()] "")r1r�r�r(N)r�r�rBr�rrCr�r�)rE�sectionr�s   r4�&assertFetchSpecificFieldsWithEmptyListz<IMAP4ClientFetchTests.assertFetchSpecificFieldsWithEmptyLists���
�K�K�%�%�d�w�%�?������N�N� � �"�"�W�^�^�G�%<�<�{�J�	
�	
��� � � �7�>�>�'�#:�:�[�H�	
�	
��� � �!;�<�����-�-�a�0�2��'�2��PR�8S�7T�2U�Vr6c�&�|jd�y)az
        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.
        r�N�rjrRs r4�,test_fetchSpecificHeaderFieldsWithoutHeaderszBIMAP4ClientFetchTests.test_fetchSpecificHeaderFieldsWithoutHeaderss��	
�3�3�O�Dr6c�&�|jd�y)a�
        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.
        zHEADER.FIELDS.NOTNrlrRs r4�/test_fetchSpecificHeaderFieldsNotWithoutHeaderszEIMAP4ClientFetchTests.test_fetchSpecificHeaderFieldsNotWithoutHeaders's��	
�3�3�4G�Hr6c�N�|jjdd��}|j|jj	�d�|jjd�|jjd�|j|j
|�dddgd	ggi�y
)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�HEADERrRs0001 FETCH 11 BODY[HEADER]
sJ* 11 FETCH (BODY[HEADER] "From: someone@localhost
Subject: Some subject")r1r?r�z.From: someone@localhost
Subject: Some subjectNrFr�s  r4�test_fetchSpecificHeaderz.IMAP4ClientFetchTests.test_fetchSpecificHeader2s���
�K�K�%�%�d�x�%�@��������-�-�/�1R�S���� � �
D�	
�	
��� � �!;�<����� � ��#���!�
�J���
�	
r6N)rsrtrur3r8r;r=rArGrJrNrTrXr[r]rbrdrfrjrmrorsr1r6r4r+r+0sg���
�&
=�=�X�T�
T�
� 

�
� =�

�
� =�
� W�2	E�	I�
r6r+c�\�eZdZdZeZd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zy)�IMAP4ClientStoreTestsa�
    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�Z�t|j|�ddd�}|j|jj	�d|zdz�|jjd�|jjd�|j|j
|�dd	d
dgii�y)
am
        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.
        r?��\Readr�F�
0001 STORE 3 � (\Read \Seen)
s* 3 FETCH (FLAGS (\Read \Seen))�0001 OK STORE completedr�r�rxr�N�r�r�rBr�rr�r��rEr��itemr�s    r4�
_flagsTestz IMAP4ClientStoreTests._flagsTest`s���
)�G�D�K�K��(��.B�E�J������N�N� � �"�$4�t�$;�>U�$U�	
�	
��� � �!E�F���� � �!;�<�����-�-�a�0�1�w��8�@T�6U�2V�Wr6c��t|j|�ddd�}|j|jj	�d|zdz�|jjd�|j|j
|�i�y)ag
        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.
        r?rwTryrzr{Nr|r}s    r4�_flagsSilentlyTestz(IMAP4ClientStoreTests._flagsSilentlyTestqs|��
)�G�D�K�K��(��.B�D�I������N�N� � �"�$4�t�$;�>U�$U�	
�	
��� � �!;�<�����-�-�a�0�"�5r6c��t|j|�ddd�}|j|jj	�d|zdz�|jjd�|jjd�|j|j
|�i�|j|jjdd	d
gi�y)a�
        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.
        r?rwTryrzs* 2 FETCH (FLAGS (\Read \Seen))r{r�rxr�N)r�r�rBr�rr�r�r�r}s    r4�%_flagsSilentlyWithUnsolicitedDataTestz;IMAP4ClientStoreTests._flagsSilentlyWithUnsolicitedDataTest�s���
)�G�D�K�K��(��.B�D�I������N�N� � �"�$4�t�$;�>U�$U�	
�	
��� � �!E�F���� � �!;�<�����-�-�a�0�"�5�������*�*�Q��8�0D�,E�Fr6c�(�|jdd�y)aQ
        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�rrRs r4�
test_setFlagsz#IMAP4ClientStoreTests.test_setFlags�s��	
���
�H�-r6c�(�|jdd�y)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�rRs r4�test_setFlagsSilentlyz+IMAP4ClientStoreTests.test_setFlagsSilently�s��	
���
�O�<r6c�(�|jdd�y)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�rRs r4�(test_setFlagsSilentlyWithUnsolicitedDataz>IMAP4ClientStoreTests.test_setFlagsSilentlyWithUnsolicitedData�s��	
�2�2�:��Or6c�(�|jdd�y)z{
        L{IMAP4Client.addFlags} is like L{IMAP4Client.setFlags}, but sends
        I{+FLAGS} instead of I{FLAGS}.
        �addFlagss+FLAGSNr�rRs r4�
test_addFlagsz#IMAP4ClientStoreTests.test_addFlags�s��
	
���
�I�.r6c�(�|jdd�y)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�rRs r4�test_addFlagsSilentlyz+IMAP4ClientStoreTests.test_addFlagsSilently�s��	
���
�,<�=r6c�(�|jdd�y)z�
        L{IMAP4Client.addFlags} behaves like L{IMAP4Client.setFlags} when used
        in silent mode and unsolicited data is received.
        r�r�Nr�rRs r4�(test_addFlagsSilentlyWithUnsolicitedDataz>IMAP4ClientStoreTests.test_addFlagsSilentlyWithUnsolicitedData�s��
	
�2�2�:�?O�Pr6c�(�|jdd�y)z~
        L{IMAP4Client.removeFlags} is like L{IMAP4Client.setFlags}, but sends
        I{-FLAGS} instead of I{FLAGS}.
        �removeFlagss-FLAGSNr�rRs r4�test_removeFlagsz&IMAP4ClientStoreTests.test_removeFlags�s��
	
���
�y�1r6c�(�|jdd�y)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�rRs r4�test_removeFlagsSilentlyz.IMAP4ClientStoreTests.test_removeFlagsSilently�s��	
���
�/?�@r6c�(�|jdd�y)z�
        L{IMAP4Client.removeFlags} behaves like L{IMAP4Client.setFlags} when
        used in silent mode and unsolicited data is received.
        r�r�Nr�rRs r4�+test_removeFlagsSilentlyWithUnsolicitedDatazAIMAP4ClientStoreTests.test_removeFlagsSilentlyWithUnsolicitedData�s��
	
�2�2�=�BR�Sr6N)rsrtrur3r�r�rr�r�r�r�r�r�r�r�r�r�r�r1r6r4ruruOsP���(�N�X�"6� G�&.�=�P�/�>�Q�2�A�Tr6ruc��eZdZdZd�Zd�Zy)�IMAP4ClientStatusTestsa_
    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��|jt|jjdd�}|j	t|�dt
dh�z�y)z�
        Only allow sending the C{STATUS} names defined in RFC 3501.

        @see: U{https://tools.ietf.org/html/rfc3501#section-5.1.2}
        rTzIMPOSSIBLE?!zUnknown names: N)r�rr�rbrBr�r�)rE�excs  r4�testUnknownNamez&IMAP4ClientStatusTests.testUnknownName�sN�������K�K�����	
��	
����S��#4�t�^�<L�7M�#M�Nr6c�<�|jjdd�}|j|jj	�d�|jjd�|jjd�|j
|tj�y)z�
        C{STATUS} names that cannot be decoded as ASCII cause the
        status Deferred to fail with L{IllegalServerResponse}
        �blurdyblooprQs$0001 STATUS blurdybloop (MESSAGES)
s?* STATUS blurdybloop (MESSAGES 1 ASCIINAME "OK" NOT�ASCII "NO")s0001 OK STATUS completedN)	r�rbrBr�rr�r�rr�r�s  r4�testUndecodableNamez*IMAP4ClientStatusTests.testUndecodableName�s}��
�K�K���}�j�9������N�N� � �"�5�	
�
	
��� � �U�	
�	
��� � �!<�=����Q�� ;� ;�<r6N)rsrtrur3r�r�r1r6r4r�r��s���O�=r6r�c�,�eZdZdZeZd�Zd�Zd�Zd�Z	y)�IMAP4ClientCopyTestsz�
    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��|jjddd��}|j|jj	�d�|jjd�|j|j
|�gdf�y)	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��MEETINGFr
�0001 COPY 2:3 MEETING
�0001 OK COPY completed�OK COPY completedN�r��copyrBr�rr�r�r�s  r4�test_copySequenceNumbersz-IMAP4ClientCopyTests.test_copySequenceNumberssv��
�K�K���U�I�5��9������N�N� � �"�(�	
�
	
��� � �!:�;�����-�-�a�0�2�7K�2L�Mr6c�<�|jjddd��}|j|jj	�d�|jjd�|j
|j|�jtj�y)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�Fr
r��0001 BAD COPY failedN�
r�r�rBr�rr�r�r�rrr�s  r4�test_copySequenceNumbersFailsz2IMAP4ClientCopyTests.test_copySequenceNumbersFails(s|��
�K�K���U�I�5��9������N�N� � �"�(�	
�
	
��� � �!8�9����d�2�2�1�5�;�;�U�=Q�=Q�Rr6c��|jjddd��}|j|jj	�d�|jjd�|j|j
|�gdf�y)	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�Tr
�0001 UID COPY 2:3 MEETING
r�r�Nr�r�s  r4�
test_copyUIDsz"IMAP4ClientCopyTests.test_copyUIDs8sv��
�K�K���U�I�4��8������N�N� � �"�,�	
�
	
��� � �!:�;�����-�-�a�0�2�7K�2L�Mr6c�<�|jjddd��}|j|jj	�d�|jjd�|j
|j|�jtj�y)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�Tr
r�r�Nr�r�s  r4�test_copyUIDsFailsz'IMAP4ClientCopyTests.test_copyUIDsFailsHs|��
�K�K���U�I�4��8������N�N� � �"�,�	
�
	
��� � �!8�9����d�2�2�1�5�;�;�U�=Q�=Q�Rr6N)
rsrtrur3r�r�r�r�r�r�r1r6r4r�r�s&���(�N�N� S� N� Sr6r�c��eZdZdZdZd�Zy)�FakeyServerr�Nc��yr0r1rRs r4�sendServerGreetingzFakeyServer.sendServerGreeting]rr6)rsrtrurR�timeoutr�r1r6r4r�r�Ys���E��G�
r6r�c�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)r�)r�r�r��_bodyr�c�x�||_||_||_t|�|_||_||_||_yr0)r�r�r�r��sizer�r��subpart)rEr�r�r�r�r�r�s       r4rzzFakeyMessage.__init__es7�������
���
���I��	���	������r6c�,�||f|_|jSr0)�got_headersr�)rEr�r�s   r4�
getHeaderszFakeyMessage.getHeadersns��!�5�=����|�|�r6c��|jSr0rmrRs r4rnzFakeyMessage.getFlagsrror6c��|jSr0)r�rRs r4�getInternalDatezFakeyMessage.getInternalDateu����y�y�r6c�,�t|j�Sr0)rr�rRs r4�getBodyFilezFakeyMessage.getBodyFilexs���t�z�z�"�"r6c��|jSr0)r�rRs r4�getSizezFakeyMessage.getSize{r�r6c��|jSr0r
rRs r4r�zFakeyMessage.getUID~s���x�x�r6c��|jduSr0)r�rRs r4�isMultipartzFakeyMessage.isMultipart�s���|�|�4�'�'r6c�.�||_|j|Sr0)�got_subpartr�)rEr�s  r4�
getSubPartzFakeyMessage.getSubPart�s������|�|�D�!�!r6N)
rsrtru�showAttributesrzr�rnr�r�r�r�r�r�r1r6r4r�r�as4��A�N�����#���(�"r6r�c�:�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	dd�Z
y)	�
NewStoreTestsNc��dx|_|_tj�|_d|j_||j_tj�|_	t|j�|_y�Nr�)�received_messages�received_uidrr�r�rRr^rrr�r�r�rRs r4rzNewStoreTests.setUp�sX��59�9����!2��'�'�)���$�������������)���"�4�>�>�2��r6c��yr0r1�rEr\s  r4rhzNewStoreTests.addListener�rr6c��yr0r1r�s  r4rjzNewStoreTests.removeListener�rr6c�,�||f|_|jSr0)�	storeArgsr�)rEr�r�s   r4r�zNewStoreTests.store�s���r�����}�}�r6c�j���fd�}�fd�}�jjt|��j|�j�j�j	�j
��fd�}t
j�j�jd��}|j|�|S)Nc�|���j�j�j�j�j�Sr0)�functionrr��silentr�rRs�r4r�z+NewStoreTests._storeWork.<locals>.connected�s(����=�=�����
�
�D�K�K����R�Rr6c���|�_yr0�r2��RrEs �r4r2z(NewStoreTests._storeWork.<locals>.result��
����D�Kr6c����j�j�j��j�j�j�yr0)rBr2rhr��expectedArgs�rTrEs �r4r�z'NewStoreTests._storeWork.<locals>.check�s5������T�[�[�$�-�-�8����T�^�^�T�->�->�?r6F��noisy�
r�r�r7rr'r
r#�loopbackTCPr�r�)rEr�r2r�r�s`    r4�
_storeWorkzNewStoreTests._storeWork�s����	S�	�	
���"�"�5��#3�4�@�@��H�T�T����	
�
�*�T�_�_�
%�	@�
� � ����d�k�k��G��	�
�
�e���r6c��|jj|_d|_gd�|_d|_||_gd�gd�gd�d�|_dgd�idgd�idgd�id�|_tj�}|jd�|jd�|jd�|gd�d	fd
d	if|_|j�S)Nz1,5,9)z\Az\B�CF)r�r�r�r�r�r�r�rr�)r�r�r�rr�r�r�r�rhrrr�r�r�)rEr�r�s   r4�testSetFlagszNewStoreTests.testSetFlags�s������,�,��
���
�(��
�������"�"�"�
��
��,�-��,�-��,�-�
��
�
��� ������
�����
�����
�!�#6��:�U�A�J�G������ � r6r�)rsrtrur2r�rrhrjr�r�r�r1r6r4r�r��s*��
�F��I�3�
�
���&!r6r�c�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�GetBodyStructureTestsz�
    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���d}d}d}d}d}d}d}t|dz|zd	z|zd
z|||d�dd
|dd�}tj|�}	|j||d|ddg|||t	|�g|	�y)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�maximumrQ�
; charset=�; x=y�r��
content-id�content-description�content-transfer-encodingr1r6r�N�charsetr\�y�r�r�getBodyStructurerBr��
rEr��major�minorrrJ�descriptionr�r��	structures
          r4�test_singlePartz%GetBodyStructureTests.test_singlePart�s�����������&�
�%����� %���e� 3�l� B�W� L�w� V�(�'2�-5�	
�
�����
���*�*�3�/�	�������G�S�#�.�����D�	�
�
�	
r6c���tiddddd�}tj|�}|dd\}}|jd|�|jd|�tddiddddd�}tj|�}|dd\}}|jd|�|jd|�tddiddddd�}	tj|	�}
|
dd\}}|jd|�|jd|�y)	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.
        r1r6r�Nr�r�r(�
)r�rr�assertIs)
rE�missing�missingContentTypeStructure�missingMajor�missingMinorr��emptyContentTypeStructure�
emptyMajor�
emptyMinor�newline�newlineContentTypeStructure�newlineMajor�newlineMinors
             r4�test_emptyContentTypez+GetBodyStructureTests.test_emptyContentType�s���r�2�s�C��d�;��&+�&<�&<�W�&E�#�%@��!�%D�"��l��
�
�d�L�)��
�
�d�L�)��n�b�1�2�s�C��d�K��$)�$:�$:�5�$A�!�!:�2�A�!>��
�J��
�
�d�J�'��
�
�d�J�'����5�r�3��S�$�O��&+�&<�&<�W�&E�#�%@��!�%D�"��l��
�
�d�L�)��
�
�d�L�)r6c��tddiddddd�}tj|�}|dd\}}|j|d�|j	|d�y)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��mainr1r6r�Nr�)r�rrrBr)rEr�
mainStructure�	mainMajor�	mainMinors     r4�test_onlyMajorContentTypez/GetBodyStructureTests.test_onlyMajorContentTypes\���^�V�4�b�#�s�C��N���.�.�t�4�
�,�R�a�0��	�9�����F�+��
�
�i��&r6c
��d}d}d}d}d}d}d}d}t|d	z|zd
z|zdz||||dd
dd�dd|dd�}	tj|	d��}
|j||d|ddg|||t	|�|dgd�gd
dg|
�y)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��abcdefabcdefrQr�rzattachment; name=foo; size=bar�fr�France�r�rrr�content-md5�content-disposition�content-language�content-locationr1r(r�NT��extendedrr\r�
attachment)r�rHr�rIr)rEr�r
rrrJrr��md5r�r
s           r4�test_singlePartExtendedz-GetBodyStructureTests.test_singlePartExtendeds�����������&�
�%������� %���e� 3�l� B�W� L�w� V�(�'2�-5�"�'G�$(�$,�	
�
�����
��"�*�*�3��>�	�������G�S�#�.�����D�	���=�>���
�
�	
r6c
��d}d}d}td|dz|zidd|dd	�}tj|d
��}|j||d	d	d	d	t	|�d	d	d	d	g|�y	)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�rQr1r6r�NTr-r)rEr
rr�r�r
s      r4�test_singlePartWithMissingz0GetBodyStructureTests.test_singlePartWithMissingOs|��
�������
�U�S�[�5�0�1�2�s�D�#�t�
���*�*�3��>�	����
�E�4��t�T�3�t�9�d�D�$�PT�U��	
r6c
��d}d}d}d}d}d}d}t|dz|zd	z|zd
z|||d�dd
|dd�}tj|�}	|j||d|ddg|||t	|�t	|j��g|	�y)z�
        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
rFr�r�r�r�r�rQr�rrr1r6r�Nrr\r)r�rrrBr�rgr	s
          r4�
test_textPartz#GetBodyStructureTests.test_textPart`s���
8��������&�
�%����� %���e� 3�l� B�W� L�w� V�(�'2�-5�	
�
�����
���*�*�3�/�	�������G�S�#�.�����D�	��D�O�O�%�&�	
�
�	
r6c
�@�d}d}d}d}d}d}d}t|dz|zd	z|zd
zdd|||d
�dd|dd�}tddidddd|g�}	tj|	�}
|jdddddddtj|�tj|�dg
|
�y)z�
        For a I{message/rfc822} message, the common basic fields are followed
        by information about the contained message.
        r5rFr�r�r�r�r�rQr�rzAlice <alice@example.com>zBob <bob@example.com>)r�r�r�rrrr1r(r�Nr��message/rfc822r6r�r�rr�)r�rrrB�getEnvelope)rEr�r
rrrJrr�r��	containerr
s           r4�test_rfc822Messagez(GetBodyStructureTests.test_rfc822Message�s���
8��������&�
�%����� %���e� 3�l� B�W� L�w� V�3�-�(�'2�-5�

�
�����
�� !�� 0�
�
����
�E�	
�	��*�*�9�5�	������������!�!�#�&��&�&�s�+��
�
�	
r6c	��tddddd�dddd	d
�}tddiddd
dd
�}tddidddd||g�}|jtj|�tj|�dgtj|��y
)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.
        zimage/jpeg; x=yr�r�r�rr1r6�hello worldr�Nr�ztext/plain; charset=us-ascii�
some stuff�Azmultipart/related�+�related�r�rBrr�rE�
oneSubPart�anotherSubPartr:s    r4�test_multiPartz$GetBodyStructureTests.test_multiPart�s���"� 1�/�'6�-6�	
�
�����
�
�&�� >�
�
�����	
��!�� 3�
�
����
��(�	
�	�	
����&�&�z�2��&�&�~�6��
�

�"�"�9�-�
	
r6c	�<�tddddd�dddd	d
�}tddiddd
dd
�}tddddd�dddd||g�}|jtj|d��tj|d��dddgdddggddgtj|d���y
)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.
        simage/jpeg; x=yssome kind of ids
great justicesmaximum)�content-types
content-idscontent-descriptionscontent-transfer-encodingr1r6r=r�NrHstext/plain; charset=us-asciir>r?zmultipart/related; foo=bar�es�Spainzattachment; name=monkeys)r�r+r,r*r@Tr-rArHrIr/r��monkeysrBrCs    r4�test_multiPartExtendedz,GetBodyStructureTests.test_multiPartExtended�s���"�!3�1�(8�.8�	
�
�����
�
�&��!@�
�
�����	
��!� <�$(�$+�'A�	
�
����
��(�
�	�	
����&�&�z�D�A��&�&�~��E�������	�2�3���
�
�"�"�9�t�<�	
r6N)
rsrtrur3rrr#r1r3r6r;rFrLr1r6r4r�r��s9���&
�P*�0
'�/
�b
�"&
�P6
�p1
�f9
r6r�c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd-d�Z	d�Z
d-d	�Zd
�Ze
je
jd�Z	e
je
jd�e
je
je�d
Zeed�d��Zd-d�Zd�Zd-d�Zd�Zd-d�Zd-d�Zd�Zd-d�Zd�Zd-d�Zd�Zd�Z d-d�Z!d�Z"d-d�Z#d �Z$d-d!�Z%d"�Z&d#�Z'd$�Z(d-d%�Z)d&�Z*d-d'�Z+d(�Z,d-d)�Z-d*�Z.d-d+�Z/d,�Z0y#e
j$$rdZY��wxYw).�
NewFetchTestsc�
�dx|_|_d|_tj�|_d|j
_||j
_tj�|_
t|j�|_yr�)
r�r�r2rr�r�rRr^rrr�r�r�rRs r4rzNewFetchTests.setUp0s_��59�9����!2�����'�'�)���$�������������)���"�4�>�>�2��r6c��yr0r1r�s  r4rhzNewFetchTests.addListener:rr6c��yr0r1r�s  r4rjzNewFetchTests.removeListener=rr6c	��||_||_ttt	t|j��|j��Sr0)r�r��iterr�rnr��msgObjsr�s   r4r�zNewFetchTests.fetch@s6��!)�������C��c�$�,�,�/�0�$�,�,�?�@�@r6c�����rcttt�j���j�D].\}}t	|j���j|d<�0�fd�}�jj��fd��j|�j�j�j�j�tj�j�jd��}|j�fd��|S)Nr�c���|�_yr0r�r�s �r4r2z(NewFetchTests._fetchWork.<locals>.resultJr�r6c�<���j�j��Sr0�r�r)r&rEr�s ��r4r5z*NewFetchTests._fetchWork.<locals>.<lambda>Ns���d�m�m�D�M�M�3�7�r6Fr�c�P���j�j�j�Sr0�rBr2rh)r\rEs �r4r5z*NewFetchTests._fetchWork.<locals>.<lambda>Ts���� 0� 0����d�m�m� L�r6)r�rnr�rTr�r�rhr�r�rr'r
r#r�r�r�)rEr�r�r�r2r�s``    r4�
_fetchWorkzNewFetchTests._fetchWorkEs������e�C����$5�6����E�
<���3�*-�c�j�j�l�*;��
�
�a� ��'�
<�	�	
���"�"�7�	
�
�+�f�
�k�k�$�*<�*<�=�j�j��O�O�?
�
� � ����d�k�k��G��	�
�
�L�M��r6c
�����fd��_d�_tiddddd�tiddddd�tiddddd�g�_dd	idd
iddid��_�jd
�S)Nc�:���jj|�Sr0�r�r7)r��urEs  �r4r5z,NewFetchTests.testFetchUID.<locals>.<lambda>Xs���T�[�[�%9�%9�!�%<�r6rCr1r6r4���u'r��12345�999�10101)rr�r�r)r�rr�rTrhr[rRs`r4�testFetchUIDzNewFetchTests.testFetchUIDWs����<��
���
���R��c�5�$�7���R��c�3��5���R��c�5�$�7�
����w���u�~��w��
��
�
���q�!�!r6c	���|jj|_d|_t	igd�dddd�t	igd�dddd�g|_dgd�idgd�id�|_|j|�S)	Nr_)�FlagA�FlagB�\FlagCr6�1�)rirgrhr4r��rr�)r��
fetchFlagsr�rr�rTrhr[�rEr�s  r4�testFetchFlagszNewFetchTests.testFetchFlagsgsw�����.�.��
���
���:�C��e�T�R���:�C��e�T�R�
���
�6�7��6�7�
��
����s�#�#r6c�$�|jd�Srs)rnrRs r4�testFetchFlagsUIDzNewFetchTests.testFetchFlagsUIDts���"�"�1�%�%r6c��|jj|_d|_t	iddddd�t	iddddd�t	idddd	d�t	idd
ddd�g|_dd
iddiddiddid�|_|j|�S)N�13r1sFri, 02 Nov 2003 21:25:10 GMTr6i�ZsThu, 29 Dec 2013 11:31:52 EST�esMon, 10 Mar 1992 02:44:30 CST��sSat, 11 Jan 2000 14:40:24 PSTi/r�z02-Nov-2003 21:25:10 +0000z29-Dec-2013 11:31:52 -0500z10-Mar-1992 02:44:30 -0600z11-Jan-2000 14:40:24 -0800)rr�r�r�)r��fetchInternalDater�rr�rTrhr[rms  r4�testFetchInternalDatez#NewFetchTests.testFetchInternalDatews������5�5��
���
���R�!A�3��t�T���R�!A�3��T�R���R�!A�3��T�R���R�!A�3��T�R�	
���� <�=�� <�=�� <�=�� <�=�	
��
����s�#�#r6c�$�|jd�Srs)rvrRs r4�testFetchInternalDateUIDz&NewFetchTests.testFetchInternalDateUID�s���)�)�!�,�,r6N�
es_AR.UTF8FTz'The es_AR.UTF8 locale is not installed.c��tjtjd�}tjtjd�|jtjtj|�|j	d�S)zC
        The month name in the date is locale independent.
        Nryr�)�locale�	setlocale�LC_ALLr�rv)rE�
currentLocales  r4�'test_fetchInternalDateLocaleIndependentz5NewFetchTests.test_fetchInternalDateLocaleIndependent�sY���(�(�����=�
��������5�����(�(�&�-�-��G��)�)�!�,�,r6c���|jj|_d|_t	dddddd�dd	d	d
d�g|_ddddgd
�ggd
�ggd
�ggd�gddddg
ii|_|j|�S)N�15zuser@domainzresu@domain�thursdayzit is a messagezid-id-id-yayaya)r�r�r�r�z
message-idr1r6ixrr�)NNrv�domain)NN�resur�)r��
fetchEnveloper�rr�rTrhr[rms  r4�testFetchEnvelopezNewFetchTests.testFetchEnvelope�s������1�1��
���
��)�'�&�0�"3�������

�
���"
���%�3�4�3�4�3�4�3�4����%��
�
��
� ���s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchEnvelopeUIDz"NewFetchTests.testFetchEnvelopeUID�s���%�%�a�(�(r6c���|jj|_d|_t	dddddddd	d
�ddd
dd�g|_ddddgd�dddddddddggdd	gii|_|j|�S)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:*�#text/plain; name=thing; key="value"�this-is-the-content-id�!describing-the-content-goes-here!�8BIT�abcdef123456zattachment; filename=monkeysrIzhttp://example.com/monkeysr(r1r(�Body
Text
Goes
Here
�Nrr�rF�plain�rNrr��thing�20rWr/�filenamerK�r��fetchBodyStructurer�rr�rTrhr[rms  r4�test_fetchBodyStructurez%NewFetchTests.test_fetchBodyStructure�s������6�6��
�"��
��$I�":�+N�17�#1�+I�(,�(D�	���+���
�
���(
����5�,�7����"�!�J�	�#:�;��0�
"��
��
�$���s�#�#r6c�$�|jd�S)z�
        If passed C{True} for the C{uid} argument, C{fetchBodyStructure} can
        also issue a I{UID FETCH BODYSTRUCTURE} command.
        r�)r�rRs r4�testFetchBodyStructureUIDz'NewFetchTests.testFetchBodyStructureUID�s��
�+�+�A�.�.r6c��|jj|_d|_t	dddddddd	d
�ddd
dd�}t	dddd�dddd|g�g|_ddddgd�ddddddddgdd	gdddgdddgii|_|j|�S)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&�123456abcdef�inlinezouter space)r�rrrr+r)r*r,r1r6r�r�Nzmultipart/mixed; boundary="xyz"�en�nearby)r�r+r,rr�rFr�r�r�rW�mixed�boundary�xyzr�)rEr��innerMessages   r4� test_fetchBodyStructureMultipartz.NewFetchTests.test_fetchBodyStructureMultiparts���
���6�6��
�"��
�#� E�6�'J�-3�$(�-�'/�$1�	
�
��'���
��$
�$E�(,�(0��
������
�

���
����9�0�;����&�!�4�(��%�
����'����'"��
��
�2���s�#�#r6c���|jj|_d|_t	iddddt	ddiddddd�g�g|_d	d
gd�ii|_|j|�S)N�21r1r6�Yea whatever�fr��	image/jpg�Body Body Bodyrr��NNNNNN�12�r��fetchSimplifiedBodyr�rr�rTrhr[rms  r4�testFetchSimplifiedBodyz%NewFetchTests.testFetchSimplifiedBodyEs������7�7��
���
������� �'��5���)���
�	�

�
���&�V�%O�P�Q��
����s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchSimplifiedBodyUIDz(NewFetchTests.testFetchSimplifiedBodyUID_s���+�+�A�.�.r6c��|jj|_d|_t	ddiddddd�g|_dd	gd
�ii|_|j|�S)Nr�r�r�r1r6r�r�rr�)rFr�NNNNr�r�r�rms  r4�testFetchSimplifiedBodyTextz)NewFetchTests.testFetchSimplifiedBodyTextbse�����7�7��
���
����.��C��%�QU�
�
���
��L�M�
��
����s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchSimplifiedBodyTextUIDz,NewFetchTests.testFetchSimplifiedBodyTextUIDps���/�/��2�2r6c��|jj|_d|_t	ddiddddt	ddidd	d
dd�g�g|_ddd
ddddddddgd�ggd�gddddddg
gd�dg
ii|_|j|�S)Nr�r�r8r1r6r�r�r�r(r�rr�r�r�r��NNN)r��jpgNNNN�14r�r�rms  r4�testFetchSimplifiedBodyRFC822z+NewFetchTests.testFetchSimplifiedBodyRFC822ss������7�7��
���
���!1�2����� �'��5���)���
�	�

�
���(
�����������+�,�+�,��������C��+��
��
�8���s�#�#r6c�$�|jd�Srs)r�rRs r4� testFetchSimplifiedBodyRFC822UIDz.NewFetchTests.testFetchSimplifiedBodyRFC822UID�s���1�1�!�4�4r6c	�2�|jj|_d|_t	ddiddddd�t	dd	iddd
dd�g}t	ddidd
dd|�}t	ddidd
dd|g�}|g|_ddgd�gd�dgdgii|_|jd�S)ah
        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�r1sdatesStuffrjNr�sThingsi�~r�r6s
Irrelevantr4zmultipart/mixedsRootOfírr�)rFr�NNNN�5r�)rF�htmlNNNNrIr��alternativer�Fr�)rE�singlesr�r�s    r4�!test_fetchSimplifiedBodyMultipartz/NewFetchTests.test_fetchSimplifiedBodyMultipart�s������7�7��
���
�
���.��G�X�u�d�
�
���-�r�7�I�u�d�
�	
��#�
�4�5������

���
�.�/�����
�M�
���w���
��K�J�%��
�
�	�
��
����u�%�%r6c��|jj|_d|_t	ddiddddd�g|_dd	d
ii|_|j|�S)Nz1,3,7,10101r��Valuer1r6sBODY TEXT
�[rr�zHeader: Value

BODY TEXT
)r�r�r�rr�rTrhr[rms  r4�testFetchMessagezNewFetchTests.testFetchMessage�s^�����0�0��
�%��
��(�G�,�b�#�7G��T�R�
����X�'K�L�M��
����s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchMessageUIDz!NewFetchTests.testFetchMessageUID�����$�$�Q�'�'r6c���|jj|_d|_t	ddd�ddddd�g|_t
tjddd���}dd	|ii|_	|j|�S)
Nz9,6,2�V1�V2)�H1�H2r1r6�crr�)r��fetchHeadersr�rr�rTr(rrerhr[)rEr�r�s   r4�testFetchHeaderszNewFetchTests.testFetchHeaders�s|�����0�0��
���
���D�1�2�s�C��T�J�
����u�3�3�4�t�4L�M�N��
���)�
��
����s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchHeadersUIDz!NewFetchTests.testFetchHeadersUIDr�r6c��|jj|_d|_t	ddiddddd�g|_dd	d
ii|_|j|�S)Nz
1,2,3,4,5,6,7r�r�r1r(sBody goes here
�rr�zBody goes here
)r�r@r�rr�rTrhr[rms  r4�
testFetchBodyzNewFetchTests.testFetchBodysc�����-�-��
�'��
��(�G�,�b�"�6K�S�RV�W�
���
�
�3�4�
��
����s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchBodyUIDzNewFetchTests.testFetchBodyUID����!�!�!�$�$r6c����jj�_d�_d}d}d}t	�}d|d<d|d<d	|d
<d|d<t	�}d
|d
<d|d<t	�}d|d
<d|d<t|dd|dt|dd|dd�t|dd|dd�g�g�_dddgdggi�_�fd�}�jj�fd���jj|��jj�j��jj�j�tj�j�jd��}|j�fd��|S)zT
        Test the server's handling of requests for specific body sections.
        r�r(r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1Nr�rr�z&Contained body message text.  Squarge.c���|�_yr0r�r�s �r4r2z0NewFetchTests.testFetchBodyParts.<locals>.result8r�r6c�>���j�jd��S)Nr�rLrXr;s �r4r5z2NewFetchTests.testFetchBodyParts.<locals>.<lambda><s���d�m�m�D�M�M��m�B�r6Fr�c�P���j�j�j�Sr0rZ��ignrEs �r4r5z2NewFetchTests.testFetchBodyParts.<locals>.<lambda>C����$�"2�"2�4�;�;��
�
�"N�r6�r�r�r�rrr�rTrhr�r�rr'r
r#r�r�)	rEr�r�r�r�r�r�r2r�s	`        r4�testFetchBodyPartsz NewFetchTests.testFetchBodyPartss������1�1��
���
��	�>�
�F�
��-��'����*���
�.��	��"I����"�}��"8��Y��'3��^�$�#�
�
�#;�
�i� �(3�
�n�%������� ��r�4��T�4�P� ���D�*�d�D�Q��

�
����f�s�e�-U�V�W�X��
�	�	
���"�"�B�	
�	
���"�"�6�*����"�"�4�#5�#5�6����!�!�$�/�/�2�� � ����d�k�k��G��	�
�
�N�O��r6c�n����jj�_d�_dg�d}t	�}d|d<d|d<d|d	<d
|d<t|dd
|dd
�g�_dddgdggi�_�fd�}�jj��fd���jj|��jj�j��jj�j�tj�j�jd��}|j�fd��|S)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�r�sDA bodyr�r�r�r�r�r�r�r�r1Nr�rr�zDA bodyc���|�_yr0r�r�s �r4r2z>NewFetchTests.test_fetchBodyPartOfNonMultipart.<locals>.resultZr�r6c�>���j�j���S)NrLrX)r&�partsrEs ��r4r5z@NewFetchTests.test_fetchBodyPartOfNonMultipart.<locals>.<lambda>^s���d�m�m�D�M�M��m�F�r6Fr�c�P���j�j�j�Sr0rZr�s �r4r5z@NewFetchTests.test_fetchBodyPartOfNonMultipart.<locals>.<lambda>er�r6r�)rEr�r�r2r�r�s`    @r4� test_fetchBodyPartOfNonMultipartz.NewFetchTests.test_fetchBodyPartOfNonMultipartFs������1�1��
���
�����	��-��'����*���
�.��	��".����$�W�b�$�	�3��M�N����f�s�e�Y�7�8�9��
�	�	
���"�"�F�	
�	
���"�"�6�*����"�"�4�#5�#5�6����!�!�$�/�/�2�� � ����d�k�k��G��	�
�
�N�O��r6c��|jj|_d|_t	iddddd�g|_dddii|_|j|�S)	Nz	1:100,2:*r1r6sxxxxxxxxxxxxxxxxxxxxr�rr�r�)r��	fetchSizer�rr�rTrhr[rms  r4�
testFetchSizezNewFetchTests.testFetchSizehs[�����-�-��
�#��
���R��i��d�;�
���
�
�t�$�
��
����s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchSizeUIDzNewFetchTests.testFetchSizeUIDsr�r6c�.�|jj|_d|_t	iddddd�t	idddd	d�g|_gd�d
dddgd�ggd�gddddddg
gd
�d�gd�ddddgd�ggd�gddddddg
gd�d�d�|_|j|�S)Nz1,3)z\XYZz\YZX�Abcs%Sun, 25 Jul 2010 06:20:30 -0400 (EDT)sxyzxyzi�)z\Onez\Two�ThreesMon, 14 Apr 2003 19:43:44 -0400sabcabcabcabcr@z25-Jul-2010 06:20:30 -0400rIr�)NNNNNNrI)r�r�r�r�r�z14-Apr-2003 19:43:44 -0400r�r�rk)r��	fetchFullr�rr�rTrhr[rms  r4�
testFetchFullzNewFetchTests.testFetchFullvs������-�-��
���
���)�8����

�
��+�2����

�
���(3� <�"���'�(�'�(��������B�!�&5� <�#���'�(�'�(��������C�!�'%
��
�L���s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchFullUIDzNewFetchTests.testFetchFullUID�r�r6c��|jj|_d|_t	iddddd�t	iddddd�g|_ddgd	�ggd	�gddddddg
d
dgd�ddgd	�ggd	�gddddddg
d
d
gd�d�|_|j|�S)Nz1,2:3r1sMon, 14 Apr 2003 19:43:44 +0400sLalalarasTue, 15 Apr 2003 19:43:44 +0200sAlalali�Nr�rIz14-Apr-2003 19:43:44 +0400)r�r�r�r�z15-Apr-2003 19:43:44 +0200rk)r��fetchAllr�rr�rTrhr[rms  r4�testFetchAllzNewFetchTests.testFetchAll�s������,�,��
���
���B�:�I�u�d�
�
��B�:�I�u�d�
�	
�����'�(�'�(�������� #� <���&��'�(�'�(�������� #� <���%#
��
�H���s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchAllUIDzNewFetchTests.testFetchAllUID�s��� � ��#�#r6c��|jj|_d|_t	iddddd�g|_ddgdd	d
�i|_|j|�S)Nr�)�\Xs19 Mar 2003 19:22:21 -0500r6r�rr�z19-Mar-2003 19:22:21 -0500�0)r�r�r�)r��	fetchFastr�rr�rTrhr[rms  r4�
testFetchFastzNewFetchTests.testFetchFast�se�����-�-��
���
���X�'D�c�1�d�S�
���
��� <�"��
��
����s�#�#r6c�$�|jd�Srs)r�rRs r4�testFetchFastUIDzNewFetchTests.testFetchFastUID�r�r6r�)1rsrtrurrhrjr�r[rernrprvrxr{r|r}r~�noEsARLocale�Errorr
rr�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	r1r6r4rNrN/sR��3�
�
�A�
�$"� $�&�$�"-�%�F�$�$�V�]�]�D�9�M����������5�	�������
�6����L�C�D�-�E�-�#$�J)�/$�b/�?$�B$�4/�$�3�2$�h5�>&�@$�(�$�(�	$�%�/�b �D	$�%�;$�z%�/$�b$�
$�%��M�<�<�����s�C0�0D�DrNc�p�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zy)�DefaultSearchTestszz
    Test the behavior of the server's SEARCH implementation, particularly in
    the face of unhandled search terms.
    c��tj�|_d|j_||j_tj�|_t|j�|_	tiddddd�tiddddd�tiddddd�tiddddd�tiddddd�g|_y)	Nr�r1r6r`rar4i!Ni"N)rr�r�rRr^rrr�r�r�r�rTrRs r4rzDefaultSearchTests.setUps����'�'�)���$�������������)���"�4�>�>�2�����R��c�3��5���R��c�5�$�7���R��c�5�$�7���R��c�5�$�7���R��c�5�$�7�
��r6c
��tttdt|j�dz�|j��S)zW
        Pretend to be a mailbox and let C{self.server} lookup messages on me.
        r�)r�r�rnr�rTr�s   r4r�zDefaultSearchTests.fetchs/���C��a��T�\�\�!2�Q�!6�7����F�G�Gr6c�������fd�}�jjt|��}��fd�}|j|�|j�j�|j	�j
��j
�|S)a�
        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�:���jj��Sr0�r�r ��
queryTermsrEs��r4r z8DefaultSearchTests._messageSetSearchTest.<locals>.search"r�r6c�*���j|��yr0r%)rI�expectedMessagesrEs ��r4�searchedz:DefaultSearchTests._messageSetSearchTest.<locals>.searched's������W�&6�7r6)r�r�r7rr'r
r#)rEr	r	r r�r	s```   r4�_messageSetSearchTestz(DefaultSearchTests._messageSetSearchTestse���	2�
�N�N�&�&�u�V�}�5��	8�	
�
�
�h��	�
�
�d�(�(�)�	���T�_�_�%��
�
���r6c�(�|jddg�S)z�
        Test that a search which starts with a message set properly limits
        the search results to messages in that set.
        r�r��r	rRs r4�test_searchMessageSetz(DefaultSearchTests.test_searchMessageSet0s��
�)�)�#��s�3�3r6c�*�|jdgd��S)zv
        If the search filter ends with a star, all the message from the
        starting point are returned.
        z2:*r6r	rRs r4�test_searchMessageSetWithStarz0DefaultSearchTests.test_searchMessageSetWithStar7���
�)�)�%��>�>r6c�*�|jdgd��S)z�
        If the search filter starts with a star, the result should be identical
        with if the filter would end with a star.
        z*:2r6r	rRs r4�"test_searchMessageSetWithStarFirstz5DefaultSearchTests.test_searchMessageSetWithStarFirst>r	r6c�*�|jdgd��S)z�
        If the search filter ends with a star, all the message from the
        starting point are returned (also for the SEARCH UID case).
        zUID 10000:*r6r	rRs r4� test_searchMessageSetUIDWithStarz3DefaultSearchTests.test_searchMessageSetUIDWithStarE���
�)�)�-��F�Fr6c�*�|jdgd��S)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).
        zUID *:10000r6r	rRs r4�%test_searchMessageSetUIDWithStarFirstz8DefaultSearchTests.test_searchMessageSetUIDWithStarFirstLr	r6c�(�|jddg�S)z�
        A search filter of 1234:* should include the UID of the last message in
        the mailbox, even if its UID is less than 1234.
        zUID 30000:*r�r	rRs r4�,test_searchMessageSetUIDWithStarAndHighStartz?DefaultSearchTests.test_searchMessageSetUIDWithStarAndHighStartSs���)�)�-�!��=�=r6c�(�|jddg�S)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:*)r�r	rRs r4�test_searchMessageSetWithListz0DefaultSearchTests.test_searchMessageSetWithList[s���)�)�'�A�3�7�7r6c�*�|jdddg�S)z�
        If the search filter contains an I{OR} term, all messages
        which match either subexpression are returned.
        zOR 1 2r�r�r	rRs r4rlz DefaultSearchTests.test_searchOres��
�)�)�(�Q��F�;�;r6c�*�|jdgd��S)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:*r6r	rRs r4�test_searchOrMessageSetz*DefaultSearchTests.test_searchOrMessageSetls���)�)�,��E�Er6c�*�|jdgd��S)z�
        If the search filter contains a I{NOT} term, all messages
        which do not match the subexpression are returned.
        zNOT 3)r�r�r�r�r	rRs r4roz!DefaultSearchTests.test_searchNotus��
�)�)�'�<�@�@r6c�(�|jddg�S)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.
        zNOT 2:*r�r	rRs r4�test_searchNotMessageSetz+DefaultSearchTests.test_searchNotMessageSet|s���)�)�)�a�S�9�9r6c�(�|jddg�S)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.
        z2:* 3r�r	rRs r4�test_searchAndMessageSetz+DefaultSearchTests.test_searchAndMessageSet�s���)�)�'�A�3�7�7r6c�$���d���fd�}�jjt|��}�j|tj
�}�fd�}|j|�|j
�j��j�|S)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�:���jj��Sr0r
	r	s��r4r z=DefaultSearchTests.test_searchInvalidCriteria.<locals>.search�r�r6c�R���jjj��jjj��j	t
j�}�jt|�d��jtd�t|��y)��
            Verify that the server logs an IllegalQueryError and the
            client raises an IMAP4Exception with 'Search failed:...'
            r�s)SEARCH failed: Invalid search command FOON�
r�r�r�r�r~rr$rBr�r��rIr{rEs  �r4�
errorReceivedzDDefaultSearchTests.test_searchInvalidCriteria.<locals>.errorReceived�s}���

�K�K�!�!�0�0�2��K�K�!�!�0�0�2��+�+�E�,C�,C�D�F����S��[�!�,�
����@�A��G��
r6�	r�r�r7r�rrr'r
r#)rEr r�r1	r	s`   @r4�test_searchInvalidCriteriaz-DefaultSearchTests.test_searchInvalidCriteria�sr����
�	2�
�N�N�&�&�u�V�}�5�����q�%�"6�"6�7��	�$	
�
�
�m�$�	���T�_�_�%��
�
���r6N)rsrtrur3rr�r	r	r	r	r	r	r	r!	rlr$	ror'	r)	r3	r1r6r4r	r	�s\���

�H��24�?�?�G�G�>�8�<�F�A�:�8�#r6r	c�L�eZdZd�Zd�Zd�ZeZd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
y)�FetchSearchStoreTestsc�4�dx|_|_d|_d|_d|_d|_t
j�|_d|j_	||j_
tj�|_
t|j�|_yr�)rhr2�server_received_query�server_received_uid�server_received_parts�server_received_messagesrr�r�rRr^rrr�r�r�rRs r4rzFetchSearchStoreTests.setUp�sv��&*�*��
���%)��"�#'�� �%)��"�(,��%��'�'�)���$�������������)���"�4�>�>�2��r6c�l�|dgk(rtjd��||_||_|jS)Nr~z"FOO is not a valid search criteria)rr$r7	r8	rh)rErr�s   r4r zFetchSearchStoreTests.search�s8���V�H���)�)�*N�O�O�%*��"�#&�� ��}�}�r6c��yr0r1)rEr�r�s   r4rhz!FetchSearchStoreTests.addListener�rr6c�n�����fd�}�fd�}�jjt|��j|�j�j�j	�j
��fd�}t
j�j�jd��}|j|�|S)Nc�R���jj�j���S)Nr
)r�r rrms��r4r z1FetchSearchStoreTests._searchWork.<locals>.search�s!����;�;�%�%�d�j�j�c�%�:�:r6c���|�_yr0r�r�s �r4r2z1FetchSearchStoreTests._searchWork.<locals>.result�r�r6c�|���j�j�ju��j�j�j��j�j�j
��jt
j�jjd���j�y)N�charmap)rTr2rhrBr�r8	rr�rrCr7	r�s �r4r�z0FetchSearchStoreTests._searchWork.<locals>.check�s�������T�[�[�D�M�M�9�:����T�[�[�$�-�-�8����T�X�X�t�'?�'?�@�����'�'��
�
�(9�(9�)�(D�E��*�*�	
r6Fr�r�)rEr�r r2r�r�s``    r4�_searchWorkz!FetchSearchStoreTests._searchWork�s����	;�	�	
���"�"�5��=�1�=�=�f�E�Q�Q����	
�
�*�T�_�_�
%�	�
� � ����d�k�k��G��	�
�
�e���r6c���tjtjd��tjdd���|_gd�|_d|_|j
d�S)N�r��	substring�r����rr	)r�r�r�r�r)rrrrrhr�rB	rRs r4�
testSearchz FetchSearchStoreTests.testSearch�sN���X�X��K�K�7�8��K�K�t�T�2�
��
�%��
��������"�"r6c���tjtjd��tjdd���|_d|_gd�|_|j
d�S)NrD	rF	rG	rH	rI	r�r�)rrrrr�rhrB	rRs r4�
testUIDSearchz#FetchSearchStoreTests.testUIDSearch�sN���X�X��K�K�7�8��K�K�t�T�2�
��
����!��
�����"�"r6c��	|j|dS#ttf$r|j|dz
cYSt$rYywxYw)Nr�r�rq)rhr��
IndexError�KeyError�rEr�s  r4r�zFetchSearchStoreTests.getUID�sM��	��=�=��%�e�,�,���:�&�	*��=�=��q��)�)��	��	�s��!A�A�Ac�H�||_t|�|_|jSr0)r8	r�r:	rhr�s   r4r�zFetchSearchStoreTests.fetchs ��#&�� �(+�H�
��%��}�}�r6c�`���fd�}�jjt|��j|�j�j�j	�j
��fd�}t
j�j�jd��}|j|�|S)Nc���|�_yr0r�r�s �r4r2z0FetchSearchStoreTests._fetchWork.<locals>.resultr�r6c�����j�j�ju��jxr�jj	��j
xr�j
j	��jr0�jj�D]\}}t|�|d<��j�j�j��j�j�j��j�j�j
��jtj�j�tj�j��y)Nr�)rTr2rhr�r�r9	r�rPr�rBr8	rr�rr:	)rT�k�vrEs   �r4r�z/FetchSearchStoreTests._fetchWork.<locals>.checks
������T�[�[�D�M�M�9�:��J�J�,�4�:�:�?�?�,���&�&�L�4�+E�+E�+J�+J�+L���x�x� �M�M�/�/�1�&�D�A�q�"�1�v�A�e�H�&�
���T�[�[�$�-�-�8����T�X�X�t�'?�'?�@����T�Z�Z��)C�)C�D�����!�!�$�-�-�0��!�!�$�"?�"?�@�
r6Fr�r�)rEr�r2r�r�s`    r4r[z FetchSearchStoreTests._fetchWorks����	�	
���"�"�5��<�0�<�<�V�D�P�P����	
�
�*�T�_�_�
%�	�&
� � ����d�k�k��G��	�
�
�e���r6c�$���d���fd�}�jjt|��}�j|tj
�}�fd�}|j|�|j
�j��j�|S)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�:���jj��Sr0r
	)rrEs��r4r z6FetchSearchStoreTests.test_invalidTerm.<locals>.search2s����;�;�%�%�e�,�,r6c�R���jjj��jjj��j	t
j�}�jt|�d��jtd�t|��y)r.	r�s1SEARCH failed: FOO is not a valid search criteriaNr/	r0	s  �r4r1	z=FetchSearchStoreTests.test_invalidTerm.<locals>.errorReceived8s|���

�K�K�!�!�0�0�2��K�K�!�!�0�0�2��+�+�E�,C�,C�D�F����S��[�!�,�
����H�I�3�w�<�
r6r2	)rEr r�r1	rs`   @r4�test_invalidTermz&FetchSearchStoreTests.test_invalidTerm*sr�����	-�
�N�N�&�&�u�V�}�5�����q�%�"6�"6�7��	�"	
�
�
�m�$�	���T�_�_�%��
�
���r6N)rsrtrurr rhrjrB	rJ	rL	r�r�r[rZ	r1r6r4r5	r5	�s;��3��
�!�N��8#�#���
�>"r6r5	c��eZdZd�Zd�Zy)�FakeMailboxc��g|_yr0)r�rRs r4rzzFakeMailbox.__init__P�	����	r6c�h�|jj|||f�tjd�Sr0)r�r|rr[)rEr�r�r�s    r4r�zFakeMailbox.addMessageSs*���	�	���$��t�,�-��}�}�T�"�"r6N)rsrtrurzr�r1r6r4r\	r\	Os���#r6r\	c��eZdZd�Zd�Zd�Zy)�FeaturefulMessagec��y)Nr�r1rRs r4rnzFeaturefulMessage.getFlagsZs��r6c��y)Nr�r1rRs r4r�z!FeaturefulMessage.getInternalDate]s��r6c��td�S)N�openrrRs r4ryzFeaturefulMessage.open`s
���w��r6N)rsrtrurnr�ryr1r6r4ra	ra	Xs���� r6ra	c��eZdZd�Zd�Zy)�MessageCopierMailboxc��g|_yr0)�msgsrRs r4rzzMessageCopierMailbox.__init__fr^	r6c�b�|jj|�t|j�Sr0)ri	r|r�rP	s  r4r�zMessageCopierMailbox.copyis"���	�	������4�9�9�~�r6N)rsrtrurzr�r1r6r4rg	rg	ds���r6rg	c��eZdZd�Zd�Zd�Zy)�CopyWorkerTestsc�����tj�}|j}t��|t	dd�D�cgc]}|t�f��c}d��}��fd�}|j
|�Scc}w)Nr�r?r�c����jD]O}�j|dj�d��j|dd��j|dd��Q|D](\}}�j|��j|d��*y)Nrre	r�r�r�r�)r�rBrWrV)rIr�rbr2r�rEs    ��r4�cbCopyz5CopyWorkerTests.testFeaturefulMessage.<locals>.cbCopys�����V�V�
7��� � ��1�����g�6�� � ��1��w�/�� � ��1��~�6�
7�
#*�
/��������'�� � ���.�
/r6)rr��_IMAP4Server__cbCopyr\	rnra	r�)rEr|r3r�r�ro	r�s`     @r4�testFeaturefulMessagez%CopyWorkerTests.testFeaturefulMessageosh��������
�"�"���M��
��q�"��>�A��$�&�'�>��q�I��	/��}�}�V�$�$��?s�A0c�f���tj�}|j}t��t	dd�D�cgc]$}tdt
|�iddd|fz|dzd���&}}|tt	dd�|�D�cgc]}|��c}d��}��fd	�}|j|�Scc}wcc}w)
Nr�r?zHeader-Counterr1�DatesBody %dr�r�c���g}�jD]N}|j|dj���j|dd��j|dd��P|j	�td�t
dd�D��}�j||�|D](\}}�j|��j|d��*y)Nrr�r1r�rs	c3�*K�|]}d||fz���
y�w)sHeader-Counter: %d

Body %dNr1r+s  r4r-zJCopyWorkerTests.testUnfeaturefulMessage.<locals>.cbCopy.<locals>.<genexpr>�s�����BC�4��1�v�=��s�r?)r�r|rWrBr�rfrnrV)rI�seenr��exprbr2r�rEs      ��r4ro	z7CopyWorkerTests.testUnfeaturefulMessage.<locals>.cbCopy�s�����D��V�V�
0�����A�a�D�I�I�K�(�� � ��1��r�*�� � ��1��w�/�
0�

�I�I�K���GL�Q�PR�|���C�
���T�3�'�")�
/��������'�� � ���.�
/r6)	rr�rp	r\	rnr�r�r�r�)	rEr|r3r�ri	�imr�ro	r�s	`       @r4�testUnfeaturefulMessagez'CopyWorkerTests.testUnfeaturefulMessage�s���������
�"�"���M��
�1�b�\�	
��
�!�3�q�6�*�B���q�d�9J�A�PR�F�TX�
�
��
�
�C��a���d�3�4�b�r�4�e�Q�?��	/�"�}�}�V�$�$��3
��5s�)B)�	B.c�<����tj�}|j}t��t	dd�D�cgc]}t���c}�|t
t	dd���D�cgc]}|��c}d��}���fd�}|j|�Scc}wcc}w)Nr�r?stagc�����j|ttdgdztdd����t��j�D]\}}�j||��y)Nr�r�r?)rBr�r�rnri	r�)rI�origrr�ri	rEs   ���r4ro	z1CopyWorkerTests.testMessageCopier.<locals>.cbCopy�sY������W�d�3��s�R�x��q�"��+F�&G�H� ��q�v�v�.�
0�	��c��$�$�T�3�/�
0r6)rr�rp	rg	rn�objectr�r�)	rEr|r3r�rx	r�ro	r�ri	s	`      @@r4�testMessageCopierz!CopyWorkerTests.testMessageCopier�s���������
�"�"�� �"��"'��2�,�/�Q���/��
�C��a���d�3�4�b�r�4�f�a�@��	0�
�}�}�V�$�$��0��4s�B�*	BN)rsrtrurq	ry	r~	r1r6r4rl	rl	ns��%�8 %�D%r6rl	zOpenSSL not presentzReactor doesn't support SSLc�v�eZdZdZdZere�Zere�Zd�Zd�Zd�Z	d�Z
d�Zdd�Zd�Z
d	�Zd
�Zd�Zy)
�TLSTestsNc�Z�tj|j|jd��S)NFr�)r#r�r�r�rRs r4r#zTLSTests.loopback�s���#�#�D�K�K����E�J�Jr6c���	�
�tjjd�g�	�	�fd�}�	�fd�}�	�fd�}�	�fd�}�	�fd�}d�j_|||||g�
�
D]&}�j
j
t|���(�j
j�j�j��	�
�fd�}�j�}|j
|�|S)	Nr�c�^���jd��jjdd�SrG)r|r�rH��calledrEs��r4rHz)TLSTests.testAPileOfThings.<locals>.login�s'����M�M�$���;�;�$�$�[�2B�C�Cr6c�^���jd��jjdd�S)Nr��%)r|r�r�r�	s��r4r�z(TLSTests.testAPileOfThings.<locals>.list�s&����M�M�$���;�;�#�#�H�d�3�3r6c�^���jd��jjdd�S)Nr�rS)r|r�rbr�	s��r4rbz*TLSTests.testAPileOfThings.<locals>.status�s&����M�M�$���;�;�%�%�h�	�:�:r6c�\���jd��jjd�S)Nr�)r|r�r�r�	s��r4r�z+TLSTests.testAPileOfThings.<locals>.examine�s$����M�M�$���;�;�&�&�x�0�0r6c�Z���jd��jj�Sr0)r|r�r9r�	s��r4r9z*TLSTests.testAPileOfThings.<locals>.logout�s"����M�M�$���;�;�%�%�'�'r6Tc�����j�jjd��j�jjd��jt	��t	���yr�)rBr��
startedTLSr�r�)rTr�	�methodsrEs ���r4r�z)TLSTests.testAPileOfThings.<locals>.check�sO������T�[�[�3�3�T�:����T�[�[�3�3�T�:����S��[�#�g�,�7r6)r�r�r�r��requireTransportSecurityr�r�r7r�rr
r#)rErHr�rbr�r9r�r�r�r�	r�	s`        @@r4�testAPileOfThingszTLSTests.testAPileOfThings�s�������*�*�8�4���	D�	4�	;�	1�	(�04����,��$����8���	6�F��N�N�&�&�u�V�}�5�	6�	
���#�#�D�$6�$6����H�	8�

�M�M�O��	�
�
�e���r6c�����jjjdd�g��jj	tjd���jj�fd��j�fd��j�j�j�j�j�j��j�}|j��fd��|S)Nr�r�c�:���jjd�S)Nr�r�r;s �r4r5z)TLSTests.testLoginLogin.<locals>.<lambda>�s���d�k�k�.�.�/?�@�r6c�8���jj�Sr0)r�r9r;s �r4r5z)TLSTests.testLoginLogin.<locals>.<lambda>�s������ 2� 2� 4�r6c�:���jt��d�Srs)rBr��r\rE�successs ��r4r5z)TLSTests.testLoginLogin.<locals>.<lambda>s���� 0� 0��W��q� A�r6)r�r�r�r�r�rr�r�r�r|rr'r
r#)rEr�r�	s` @r4�testLoginLoginzTLSTests.testLoginLogin�s���������#�#�K�1A�B������)�)�%�*B�*B�;�*O�P����"�"�@�	
�
�+�4�
5�k�k��N�N�7
�
�+����
�
�*��O�O�
�
�M�M�O��	�
�
�A�B��r6c����g��jjt�jj���fd�}�jj|��jj�j
��j
�}|j��fd��tj|�jg�S)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����jtjj�jj
��yr0)rVr�
ISSLTransport�
providedByr�r�r�s �r4�checkSecurez6TLSTests.startTLSAndAssertSession.<locals>.checkSecures*����O�O�J�4�4�?�?����@U�@U�V�Wr6c�&���j��Sr0)rVr�	s ��r4r5z3TLSTests.startTLSAndAssertSession.<locals>.<lambda>s������� 8�r6)	r�r�r7r��startTLSr|r#rr()rEr�	r�r�	s`  @r4�startTLSAndAssertSessionz!TLSTests.startTLSAndAssertSessions���������"�"�5����)=�)=�#>�?�	X�	
���"�"�;�/����"�"�7�>�>�2��M�M�O��	�
�
�8�9��"�"�A�t�~�~�#6�7�7r6c��|j�}|jj|j�|jj	|j
�|S)z�
        L{IMAP4Client.startTLS} triggers TLS negotiation and returns a
        L{Deferred} which fires after the client's transport is using
        encryption.
        )r�	r�r�rr'r
�rE�disconnecteds  r4�
test_startTLSzTLSTests.test_startTLSsF���4�4�6�����"�"�4�#5�#5�6����!�!�$�/�/�2��r6c�&�|j|jj�d|j_|j�}|jj|j�|jj|j�|S)zd
        L{IMAPClient.startTLS} supplies a default TLS context if none is
        supplied.
        N)	�assertIsNotNoner��contextr�	r�r�rr'r
r�	s  r4�test_startTLSDefaultzTLSTests.test_startTLSDefault'sj��
	
���T�[�[�0�0�1�"�����)-�)F�)F�)H�����"�"�4�#5�#5�6����!�!�$�/�/�2��r6c���Gd�dt�}||j|j��|_|j	�}|jjt
|jj��|jj|jd�|jj|j�|jj|j�|S)z]
        A server that receives a second C{STARTTLS} sends a C{NO}
        response.
        c��eZdZd�Zy)�:TLSTests.test_doubleSTARTTLS.<locals>.DoubleSTARTTLSClientc��|jstj|�S|jt	j
d��S)NsSTARTTLS)r�	r�r�	r�rr8rRs r4r�	zCTLSTests.test_doubleSTARTTLS.<locals>.DoubleSTARTTLSClient.startTLS:s4�����'�0�0��6�6��'�'��
�
�k�(B�C�Cr6N)rsrtrur�	r1r6r4�DoubleSTARTTLSClientr�	9s��
Dr6r�	r�sTLS already negotiated)r�r�r�r�r�	r�r7r�	r'rrr
)rEr�	r�	s   r4�test_doubleSTARTTLSzTLSTests.test_doubleSTARTTLS3s���	D�<�	D�+��N�N�4�>�>�
����4�4�6�����"�"�5����)=�)=�#>�?����!�!��+�+�-F�	
�	
���"�"�4�#5�#5�6����!�!�$�/�/�2��r6c����tjtjd��j_t
j�fd��}�jjt|���j�}�jjt|���jj�j��jj�j�|S)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�c3��K��jj���}�jd|��jd|d��jd|d�y�w)Nr/r�r�)r�rrrqs �r4�assertLOGINandPLAINzJTLSTests.test_startTLSWithExistingChallengers.<locals>.assertLOGINandPLAIN[sP�����!%���!<�!<�!>�>�L��M�M�'�<�0��M�M�(�L��$9�:��M�M�(�L��$9�:�s�AA)rr�rr�r2rrr�r�r7r�	rr'r
)rEr�	r�	s`  r4�$test_startTLSWithExistingChallengersz-TLSTests.test_startTLSWithExistingChallengersPs�����,�,��,�,�#
�����

�	�	�	;�
�	;�	
���"�"�5�)<�#=�>��4�4�6�����"�"�5�)<�#=�>����"�"�4�#5�#5�6����!�!�$�/�/�2��r6c���d��j_�jj�fd���jj	�j
d��jj�j��jj	�j�tj�j��jg�S)z|
        A client that attempts to log in before issuing the
        C{STARTTLS} command receives a C{NO} response.
        c�0�tjgdf�S)NzOK Begin TLS negotiation now)rr[r1r6r4r5z3TLSTests.test_loginBeforeSTARTTLS.<locals>.<lambda>ss��u�}�}�
�/�0�(
�r6c�<���jjdd�S)Nswrongstimerzr;s �r4r5z3TLSTests.test_loginBeforeSTARTTLS.<locals>.<lambda>ws���d�k�k�'�'��'�:�r6s!LOGIN is disabled before STARTTLS)r�r�	r�r�r'rrr
rr(r#rRs`r4�test_loginBeforeSTARTTLSz!TLSTests.test_loginBeforeSTARTTLSms���� 
�����	
���"�"�:�	
�	
���!�!��+�+�0�	
�
	
���"�"�4�#5�#5�6����!�!�$�/�/�2��"�"�D�M�M�O�T�^�^�#D�E�Er6c����g��fd�}�jj|��jj�fd���jj�fd���jj�j��jj�j���fd�}�j�j|�S)Nc�(��d�j_yr�)r��canStartTLSr�s �r4�breakServerTLSz3TLSTests.testFailedStartTLS.<locals>.breakServerTLS�s���&+�D�K�K�#r6c�8���jj�Sr0)r�r�	r�s �r4r5z-TLSTests.testFailedStartTLS.<locals>.<lambda>�s���t�{�{�/C�/C�/E�r6c�`���j|jtj��Sr0)r|rrr)r	r�s �r4r5z-TLSTests.testFailedStartTLS.<locals>.<lambda>�s����������1E�1E�(F�G�r6c�n���j���j�dtj�yr�)rVr�rr)rTr�rEs ��r4r�z*TLSTests.testFailedStartTLS.<locals>.check�s)����O�O�H�%�� � ��!��e�.B�.B�Cr6)r�r�r'rr
r#)rEr�	r�r�s`  @r4�testFailedStartTLSzTLSTests.testFailedStartTLS�s������	,�	
���"�"�>�2����"�"�#E�F����!�!�G�	
�	
���"�"�4�#5�#5�6����!�!�$�/�/�2�	D��}�}��*�*�5�1�1r6)�returnzDeferred[object])rsrtrur�r�r-r,r#r�	r�	r�	r�	r�	r�	r�	r�	r�	r1r6r4r�	r�	�sY���I��I��$�&�	��$�&�	�K�'�R�$8�*	�
��:�:F�.2r6r�	c��eZdZdZdZdZd�Zy)�SlowMailboxr�Nc��tj�}|j|j|jd�|j
j	d�|S)Nr1)rr�	callLater�howSlowr��
fetchDeferred)rErr�r�s    r4r�zSlowMailbox.fetch�s?���N�N������t�|�|�Q�Z�Z��4����#�#�D�)��r6)rsrtrur�	r�	r�	r�r1r6r4r�	r�	�s���G��I��M�r6r�	c�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)�TimeoutTestsc�����t��d�j_d�j_�j
�j_d�_���fd�}�fd���jjt|��}|j�j�tj|�j�g�S)z{
        The *client* has a timeout mechanism which will close connections that
        are inactive for a period.
        Tr�Nc����jjdd�}�jd�|j��|S)Nr�r�r�)r�rH�advancer')r�r�rE�timedOuts ���r4rHz.TimeoutTests.test_serverTimeout.<locals>.login�s6������!�!�+�/?�@�A�
�I�I�a�L�
�L�L��"��Hr6c�h���jd�|jtj�yr0)rrr�TimeoutErrorr�s �r4r�	z1TimeoutTests.test_serverTimeout.<locals>.timedOut�s%������t�$��G�L�L��+�+�,r6)rr�r�r�r�r�	r�r�r�r7r'r
rr(r#)rErHr�r�r�	s`  @@r4�test_serverTimeoutzTimeoutTests.test_serverTimeout�s����

�G��"&���������� !������� ���	�	-�
�N�N�&�&�u�U�|�4��	���T�_�_�%��"�"�A�t�}�}��#7�8�8r6c�,���t���j�j_�fd�}��fd�}�jj	t|��}|j	t|��t
j|�j�g�S)z4
        The server times out a connection.
        c�<���jjdd�SrGrzrRs�r4rHz/TimeoutTests.test_serverTimesOut.<locals>.login�r{r6c�V���j�jjdz�y�Nr��r�	r��POSTAUTH_TIMEOUT�r�rEs��r4�
expireTimez4TimeoutTests.test_serverTimesOut.<locals>.expireTime�����
�I�I�d�k�k�2�2�Q�6�7r6)	rr�	r�r�r�r7rr(r#)rErHr�	r�r�s`   @r4�test_serverTimesOutz TimeoutTests.test_serverTimesOut�sp���
�G�� !�������	D�	8�
�N�N�&�&�u�U�|�4��	�
�
�e�J�'�(�
�"�"�A�t�}�}��#7�8�8r6c�������jtjdt�tjj	d�tjj
d��j
tj���t���j�j_
�fd�}�fd�}��fd�}��fd�}�fd�}�jjt|��}|jt|��|jt|��|jt|��|jt|��tj |�j#�g�S)	z^
        The server unsets the selected mailbox when timing out a
        connection.
        r��mailbox-test�MAILBOX-TESTc�<���jjdd�SrGrzrRs�r4rHz7TimeoutTests.test_serverUnselectsMailbox.<locals>.login�r{r6c�:���jjd�S�Nr�	r�rRs�r4r�z8TimeoutTests.test_serverUnselectsMailbox.<locals>.select�r�r6c�R���j��jj�yr0)rr�r^�r^rEs��r4�	assertSetz;TimeoutTests.test_serverUnselectsMailbox.<locals>.assertSet�s����M�M�$���� 0� 0�1r6c�V���j�jjdz�yr�	r�	r�	s��r4r�	z<TimeoutTests.test_serverUnselectsMailbox.<locals>.expireTime�r�	r6c�P���j�jj�yr0)rTr�r^rRs�r4�assertUnsetz=TimeoutTests.test_serverUnselectsMailbox.<locals>.assertUnset�s������T�[�[�-�-�.r6)r�r�r�r�r�r�rTr"r�	rr�	r�r�r�r7rr(r#)	rErHr�r�	r�	r�	r�r�r^s	`      @@r4�test_serverUnselectsMailboxz(TimeoutTests.test_serverUnselectsMailbox�s
���
	
�
�
�<�*�*�,<�>P�Q����*�*�>�:��&�&�0�0��@�����.�9�9�$�?�@��G�� !�������	D�	6�	2�	8�	/�
�N�N�&�&�u�U�|�4��	�
�
�e�F�m�$�	�
�
�e�I�&�'�	�
�
�e�J�'�(�	�
�
�e�K�(�)�
�"�"�A�t�}�}��#7�8�8r6c�����tjjd�tjjd�t	t
��t
���j�j_�fd�}�fd�}��fd�}��fd�}��fd�}�jjt|��}|jt|��|jt|��|jt|��|jt|��tj|�j�g�S)zi
        The server closes the selected, closeable mailbox when timing
        out a connection.
        r�	r�	c�<���jjdd�SrGrzrRs�r4rHz?TimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.login	r{r6c�:���jjd�Sr�	r�rRs�r4r�z@TimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.selectr�r6c�<���j�j�yr0)rTr�r�	s��r4�assertMailboxOpenzKTimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.assertMailboxOpens������T�[�[�)r6c�V���j�jjdz�yr�	r�	r�	s��r4r�	zDTimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.expireTimer�	r6c�<���j�j�yr0)rVr�r�	s��r4�assertMailboxClosedzMTimeoutTests.test_serverTimesOutAndClosesMailbox.<locals>.assertMailboxCloseds����O�O�D�K�K�(r6)r�r�r�r�r
r"rr�	r�r�r�r7rr(r#)	rErHr�r�	r�	r�	r�r�r^s	`      @@r4�#test_serverTimesOutAndClosesMailboxz0TimeoutTests.test_serverTimesOutAndClosesMailbox�s����
	���*�*�>�:��&�&�0�0��@���*�D�1��G�� !�������	D�	6�	*�	8�	)�
�N�N�&�&�u�U�|�4��	�
�
�e�F�m�$�	�
�
�e�-�.�/�	�
�
�e�J�'�(�	�
�
�e�/�0�1�
�"�"�A�t�}�}��#7�8�8r6c�h���t���jt_tj�t_�j�j_ttj_	tjjd��jjd��fd�}�fd�}�fd�}�fd�}�fd�}tj
j|��jjt|��}|jt|��|jt|��|jt|��|j�j�|j!�j"�tj$|�j'�g�}|S)zM
        The connection timeout does not take effect during fetches.
        r�	r�c�<���jjdd�SrGrzrRs�r4rHz7TimeoutTests.test_longFetchDoesntTimeout.<locals>.login0r{r6c�p���jjd��jjd�S)Nr�r�	)r��
setTimeoutr�r�rRs�r4r�z8TimeoutTests.test_longFetchDoesntTimeout.<locals>.select3s*����K�K�"�"�1�%��;�;�%�%�n�5�5r6c�:���jjd�S)Nr�r^rRs�r4r�z7TimeoutTests.test_longFetchDoesntTimeout.<locals>.fetch7s����;�;�'�'��.�.r6c�R���j�jjd�y)Nr�)r�r�rRrRs�r4�stillConnectedz@TimeoutTests.test_longFetchDoesntTimeout.<locals>.stillConnected:s��������� 1� 1�9�=r6c�H��td�D]}�jd��y)Nr�g�?)rnr�	)rTr�r�s  �r4�	cbAdvancez;TimeoutTests.test_longFetchDoesntTimeout.<locals>.cbAdvance=s!����1�X�
���	�	�#��
r6)rr�	r�	rrr�	r�r�r�r�r�r�	r�r�r7rr'r
r(r#)	rErHr�r�r�	r�	r)r�r�s	`       @r4�test_longFetchDoesntTimeoutz(TimeoutTests.test_longFetchDoesntTimeout#s&���
�G�� !�����$)�N�N�$4��!� !�������1<����.����*�*�>�:������q�!�	D�	6�	/�	>�	�	�!�!�-�-�i�8�
�^�^�
'�
'��e��
5��
���u�V�}�%�
���u�U�|�$�
���u�^�,�-�
���t�)�)�*�
�
�
�d�o�o�&�����T�]�]�_� 5�6���r6c����t�}t�}|j|_|j|j_|jj|�g�|jj���fd�|j_|jdg|jjdzgdzz�|j���|jd|jjdzg�|j��y)z{
        The *server* has a timeout mechanism which will close connections that
        are inactive for a period.
        c�<���jd��|�fdSrs)r|)�reason�connLost�losts ��r4r5z<TimeoutTests.test_idleClientDoesDisconnect.<locals>.<lambda>[s(����K�K����V��5
��5
�r6gg@r�g@N)rrr�rkr�	r�r��pump�timeOutrTrV)rEr�r�r�	r�	s   @@r4�test_idleClientDoesDisconnectz*TimeoutTests.test_idleClientDoesDisconnectLs����

�G��4�6�	�!�[�[�	�� !����������"�"�9�-����;�;�-�-��&
����"�	
����u����+�+�c�1�2�Q�6�6�7�����t�$�	
����T�[�[�(�(�3�.�/�0�����r6N)	rsrtrur�	r�	r�	r�	r�	r�	r1r6r4r�	r�	�s#��9�29�*%9�N$9�L'�Rr6r�	c��eZdZd�Zy)�DisconnectionTestsc��tj�}t�}|j|�|j	|jdd�tj�}|jt
jd��|S)Nr�zexample.com�Connection closed)	rr�rr�r�rHrr�r�)rEr��tr�s    r4�"testClientDisconnectFailsDeferredsz5DisconnectionTests.testClientDisconnectFailsDeferredsjsm�������,�.��	��������
�G�G�K��/��1E�1E�
��	
����-�-�.A�B�C��r6N)rsrtrur
r1r6r4r
r
is��r6r
c��eZdZdZd�Zd�Zy)�SynchronousMailboxzb
    Trivial, in-memory mailbox implementation which can produce a message
    synchronously.
    c��||_yr0r)rErs  r4rzzSynchronousMailbox.__init__{s	�� ��
r6c#�XK�|rJd��|D]}||j|dz
f���y�w)NzCannot handle uid requests.r�r)rEr`r�r�s    r4r�zSynchronousMailbox.fetch~s;�����5�5�5�w��	.�C��t�}�}�S�1�W�-�-�-�	.�s�(*N)rsrtrur3rzr�r1r6r4r
r
us���
!�.r6r
c
��eZdZdZeigdddd�eigdddd�eigdddd�gZd�Zd�Zd	�fd
�Zd�Z	d�Z
d
�Zy)�PipeliningTestszM
    Tests for various aspects of the IMAP4 server's pipelining support.
    r6r:Nr=�2c�h�g|_t�|_tjdd|j
�|_|jj|j�t|j�}d|j_
||j_|jj�yr�)
�	iteratorsrr�rr��iterateInReactorr�r�r
rrRr^r�)rErWs  r4rzPipeliningTests.setUp�s�����(�*����'�'��d�D�4I�4I�J������"�"�4�>�>�2�$�T�]�]�3��%�����"�����	
�����r6c�h�tj�}|jj||f�|S)z�
        A fake L{imap4.iterateInReactor} that records the iterators it
        receives.

        @param iterator: An iterator.

        @return: A L{Deferred} associated with this iterator.
        )rrr
r|)rE�iteratorr�s   r4r
z PipeliningTests.iterateInReactor�s+��
�N�N��������x��m�,��r6c��yr�r1r1r6r4r5zPipeliningTests.<lambda>�rhr6c��|jr�|�r�|jddD]T}|jjs�|jjj�|jjr�;�V|jj	d�djd�|jr	|�r��yyyy)a�
        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}.
        rr�N)r
r��producerr~rTr�)rE�asLongAs�es   r4�flushPendingzPipeliningTests.flushPending�s����n�n����^�^�A�&�q�)�
8���n�n�-�-��N�N�+�+�;�;�=��n�n�-�-�
8����"�"�1�%�a�(�1�1�$�7��n�n���n��nr6c��|jjtjt	j
���yr0r�rRs r4rzPipeliningTests.tearDown�r�r6c�L�|jjd�|j�|j|jj�dj
dtdt|jdj�j�����dtdt|jdj�j�����d	td
t|jdj�j�����g��y)
z�
        Test that pipelined FETCH commands which can be responded to
        synchronously are responded to correctly.
        s901 FETCH 1 BODY[]
02 FETCH 2 BODY[]
03 FETCH 3 BODY[]
r6�* 1 FETCH (BODY[] )
� 01 OK FETCH completed
{5}


r�* 2 FETCH (BODY[] )
z 02 OK FETCH completed
{5}


r�s* 3 FETCH (BODY[] )
z 03 OK FETCH completed
{5}


r�N)r�r�r
rBr�rr�r)r(rr�rWrRs r4�test_synchronousFetchz%PipeliningTests.test_synchronousFetch�s���	
��� � �V�	
�	
��������N�N� � �"��H�H�.�!�'��
�
�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���
�	
r6c�l�|jjd�tjttgd���}|j
|��|j|jj�djdtdt|jdj�j�����g��|jj!�|jj#d�	�|j%|jj��|j
�|j|jj�djd
dtdt|jd
j�j�����g��y)z�
        When a server status change occurs during an ongoing FETCH
        command, the server status is buffered until the FETCH
        completes.
        s01 FETCH 1,2 BODY[]
)TTF)r
r6r
z	{5}


rT)r�r
s* [READ-WRITE]
r
r�N)r�r��	functools�partial�nextrSr
rBr�rr�r)r(rr�rWr�r�rT)rE�twices  r4�test_bufferedServerStatusz)PipeliningTests.test_bufferedServerStatus�sa��	
��� � �!;�<��!�!�$��-@�(A�B�����5��)�����N�N� � �"��H�H�/�!�'��
�
�a�(8�(D�(D�(F�(K�(K�(M�N�Q��	�

�
	
�	
������	
�����$��/�	
������-�-�/�0���������N�N� � �"��H�H�/�)�!�'��
�
�a�(8�(D�(D�(F�(K�(K�(M�N�Q��
�
�	
r6)rsrtrur3r�rrr
r
rr
r"
r1r6r4r

r

�sk���
	�R��S�$��d�3��R��S�$��d�3��R��S�$��d�3��H�� �%1�8�"L�!
�F5
r6r

c��eZdZdZd�Zd�Zy)�IMAP4ServerFetchTestszV
    This test case is for the FETCH tests that require
    a C{StringTransport}.
    c��t�|_tj�|_d|j_|jj
|j�yr�)rr�rr�r�rRr�rRs r4rzIMAP4ServerFetchTests.setUp!s>��(�*����'�'�)���$��������"�"�4�>�>�2r6c�V�|jj�|jjd�d}|j	|jj�|�|jj�|jj
tjd��y)a
        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,
        s0001 FETCH 1 FULLL
s+0001 BAD Illegal syntax: Invalid Argument
r
N)	r�r�r�r�rBrr�rr�)rErhs  r4�"test_fetchWithPartialValidArgumentz8IMAP4ServerFetchTests.test_fetchWithPartialValidArgument'sw��	
��������� � �!:�;�C��������-�-�/��:����������"�"�5�#7�#7�8K�#L�Mr6N)rsrtrur3rr'
r1r6r4r$
r$
s���
3�Nr6r$
c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�LiteralTestsMixinz�
    Shared tests for literal classes.

    @ivar literalFactory: A callable that returns instances of the
        literal under test.
    c�6�tj�|_y)z
        Shared setup.
        N)rrr�rRs r4rzLiteralTestsMixin.setUpBs�����(��
r6c��|jd|j�}|jd|jd��|j	|j�y)ze
        The literal returns L{None} when given less data than the
        literal requires.
        rG	Ns
incomplete)�literalFactoryr�rr\�assertNoResult)rE�literals  r4�test_partialWritez#LiteralTestsMixin.test_partialWriteHsC��
�%�%�d�D�M�M�:���
�
�d�G�M�M�-�8�9����D�M�M�*r6c��d}|jt|�|j�}|j|�}|j	|t
�|j
|�|j|j�y)zz
        The literal returns an empty L{bytes} instance when given
        exactly the data the literal requires.
        �completeN)r,
r�r�r\r�rLrTr-
�rE�datar.
�leftovers    r4�test_exactWritez!LiteralTestsMixin.test_exactWriteQsa��
���%�%�c�$�i����?���=�=��&�����h��.�����"����D�M�M�*r6c��d}|jtd�|j�}|j|�}|j	|d�y)zt
        The literal returns any left over L{bytes} when given more
        data than the literal requires.
        scompleteleftoverr1
�leftoverN)r,
r�r�r\rBr2
s    r4�test_overlongWritez$LiteralTestsMixin.test_overlongWrite^sB��
#���%�%�c�+�&6��
�
�F���=�=��&������;�/r6c��|jd|j�}d}|j|�}|j||�y)zo
        The literal returns an empty L{bytes} instance
        when given an empty L{bytes} instance.
        rr7
N)r,
r�r\rB)rEr.
r3
r4
s    r4�test_emptyLiteralz#LiteralTestsMixin.test_emptyLiteraljs=��
�%�%�a����7�����=�=��&������4�(r6N)	rsrtrur3rr/
r5
r8
r:
r1r6r4r)
r)
:s ���)�+�+�
0�
)r6r)
c�.�eZdZdZej
Zd�Zy)�LiteralStringTestsz+
    Tests for L{self.literalFactory}.
    c� �d}d}tjt|�|j�}t	|�D]}|j|��|j
d�|j|j�}|j|||f�y)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.
        �datar7N)	r�
LiteralStringr�r�r'r\r�r�rB)rEr3
�extrar.
r�r2s      r4�
test_callbackz LiteralStringTests.test_callback~s�������%�%�c�$�i����?���4��	�A��M�M�!��	�	����"��%�%�d�m�m�4������$���/r6N)rsrtrur3rr?
r,
rA
r1r6r4r<
r<
ws����(�(�N�0r6r<
c�4�eZdZdZej
Zd�Zd�Zy)�LiteralFileTestsz)
    Tests for L{imap4.LiteralFile}.
    c�x�d}d}tjt|�|j�}t	|�D]}|j|��|j
d�|j|j�}|jt|�d�|\}}|j|j�d�y)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>
r7r�N)
r�LiteralFiler�r�r'r\r�r�rBrW�rEr3
r@
r.
r�r2�dataFiles       r4rA
zLiteralFileTests.test_callback�s��������#�#�C��I�t�}�}�=���4��	�A��M�M�!��	�	����"��%�%�d�m�m�4������V��a�(� ���%��������'�2r6c��d}d}|jtjdd�tjt|�|j�}t|�D]}|j
|��|jd�|j|j�}|jt|�d�|\}}|j|j�d�y)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>
r7�_memoryFileLimitr�r�N)r�rrE
r�r�r'r\r�r�rBrWrF
s       r4�test_callbackSpooledToDiskz+LiteralFileTests.test_callbackSpooledToDisk�s��������
�
�5�$�$�&8�!�<��#�#�C��I�t�}�}�=���4��	�A��M�M�!��	�	����"��%�%�d�m�m�4������V��a�(� ���%��������'�2r6N)	rsrtrur3rrE
r,
rA
rJ
r1r6r4rC
rC
�s����&�&�N�3�,3r6rC
c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�WriteBufferTestsz)
    Tests for L{imap4.WriteBuffer}.
    c�"�t�|_yr0)rr�rRs r4rzWriteBufferTests.setUp�s��(�*��r6c���tj|j�}d|jz}|j	|�|j|jj
��y)zd
        L{imap4.WriteBuffer} buffers writes that are smaller than its
        buffer size.
        �xN)r�WriteBufferr��
bufferSizer\rTr�rE�bufr3
s   r4r/
z"WriteBufferTests.test_partialWrite�sL��
������/���c�n�n�$���	�	�$��������-�-�/�0r6c���tj|j�}d|jdzz}|j	|�|j|jj
�|�y)z�
        L{imap4.WriteBuffer} writes data without buffering it when
        the size of the data exceeds the size of its buffer.
        rO
r�N)rrP
r�rQ
r\rBrrR
s   r4r8
z#WriteBufferTests.test_overlongWrite�sS��
������/���s�~�~��)�*���	�	�$��������-�-�/��6r6c�T�tj|j�}d|jz}d}|j	|�|j|jj
��|j	|�|j|jj
�||z�y)zp
        L{imap4.WriteBuffer} buffers writes until its buffer's size
        exceeds its maximum value.
        rO
�yN)rrP
r�rQ
r\rTrrB)rErS
�	firstData�
secondDatas    r4�test_writesImplyFlushz&WriteBufferTests.test_writesImplyFlush�s���
������/���3�>�>�)�	��
��	�	�)��������-�-�/�0��	�	�*��������-�-�/��Z�1G�Hr6c�H�tj|j�}d|jz}|j	|�|j|jj
��|j�|j|jj
�|�y)z{
        L{imap4.WriteBuffer.flush} flushes the buffer even when its
        size is smaller than the buffer size.
        rO
N)	rrP
r�rQ
r\rTr�flushrBrR
s   r4�test_explicitFlushz#WriteBufferTests.test_explicitFlush�sr��
������/���s�~�~�&���	�	�$��������-�-�/�0��	�	��������-�-�/��6r6c��tj|j�}|j�|j	|jj��y)z_
        L{imap4.WriteBuffer.flush} has no effect if when the buffer is
        empty.
        N)rrP
r�r[
rTr)rErS
s  r4�test_explicitFlushEmptyBufferz.WriteBufferTests.test_explicitFlushEmptyBuffers<��
������/���	�	��������-�-�/�0r6N)
rsrtrur3rr/
r8
rY
r\
r^
r1r6r4rL
rL
�s&���+�
1�
7�I�"7� 	1r6rL
)�r3�
__future__rr�rUr
r{r�r��collectionsr�ior�	itertoolsr�typingrr	�unittestr
�zope.interfacer�zope.interface.verifyrr
�twisted.cred.checkersr�twisted.cred.credentialsrrr�twisted.cred.errorr�twisted.cred.portalrr�twisted.internetrrrr�twisted.internet.deferr�twisted.internet.taskr�twisted.internet.testingrr�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-�ImportErrorr7r9rwr�r�r5�IMailboxInfo�IMailbox�ICloseableMailboxrVr��MemoryAccountWithoutNamespacesr�r�r�r�r�r�r�r�rr�rOr�r�r�r%r0rir�r�r�r�r
rrrr+rur�r�r��IMessage�
FancyStrMixinr�r�r�rNr	�ISearchableMailboxr5	r\	�IMessageFilera	�IMessageCopierrg	rl	�IReactorSSLr�	r�	r�	r
r
r

r$
r)
r<
rC
rL
r1r6r4�<module>r�
s���#�
�
��
�	��#���!��&�;�I���
1�.�>�>�+�'�V��)���
'�-�-�H�H�@��K�#�b;�X�b;�J��"d)�.�d)�NHV�)�HV�V
q+�x�q+�h
�U�
�
�����1H�1H�I�P
�P
�J�P
�f
�U�
�
����0�T
�T
�1�T
�n�u�C�C��"�&��(;�(;��3�5�$�$�3�,(�5�$�$�(�,.,�.,�b_/�'��_/�Da2�1�a2�H
dX�-�x�dX�N
�V��@�@��@�:"�"�"h4�)�8�h4�V
/
�X�/
�ddT�/��dT�NL"�H�L"�^
$��*�*�
$�L�'��L�^B�B�6EI�1�EI�P�1�3F��(�0�2E��*+=�5�7J�+=�\/=�4�6I�/=�d\
�3�5H�\
�~JT�3�X�JT�Z,=�4�6I�,=�^KS�2�4G�KS�\
�%�#�#�
�
�U�^�^��$"�4�%�%�$"��$"�N?!�H�.�?!�Da
�H�a
�HK%�H�.�K%�\s�)�8�s�l
�U�
%�
%�&�X�H�&6�X�'�X�v#�#�
�U�
�
� � � �!� �
�U�
!�
!�"���#��N%�h�N%�b���3�4��"�J�"�"�7�D�1�1�3P�Q�U2���U2�R�5�U2�p�-���#�X��D	��	�.�.�T
�h�T
�nN�H�N�>:)�:)�z0�*�,?�0�653�(�(�53�pJ1�*�J1��mt�������s�Q�	Q"�!Q"

Zerion Mini Shell 1.0