Sh3ll
OdayForums


Server : Apache
System : Linux server1.cgrithy.com 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User : nobody ( 99)
PHP Version : 8.1.23
Disable Function : NONE
Directory :  /opt/alt/python311/lib64/python3.11/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python311/lib64/python3.11/__pycache__/imaplib.cpython-311.opt-1.pyc
�

�,dQ���l�dZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZm
Z
ddlmZ	ddlZdZn
#e$rdZYnwxYwgd�Zd	ZdZd
ZdZdZd
Zidd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�d d�d!d�d"d�d#d�id$d�d%d�d&d�d'd�d(d�d)d�d*d�d+d�d,d�d-d�d.d�d/d�d0d�d1d�d2d�d3d�d4d��ddddddddd5��Zejd6��Zejd7��Zejd8��Zejd9ej��Z ejd:��Z!ejd;��Z"ejd<��Z#ejd=ej��Z$d9Z%d=Z&Gd>�d?��Z'er#Gd@�dAe'��Z(e�)dA��GdB�dCe'��Z*GdD�dE��Z+dF�,dG��Z-dH�e.e-dId���D��Z/dJ�Z0dK�Z1dL�Z2dM�Z3e4dNk�r?ddl5Z5ddl6Z6	e5j5ej7dId�dO��\Z8Z9n#e5j:$rZ;dP\Z8Z9YdZ;[;ndZ;[;wwxYwdZ<e8D]$\Z=Z;e=dQkre>e;��Z�e=dRkre;Z<e9se<fZ9�%e9sdSZ9e9dZ?e6j@��ZAe6j6dTeA�dUe?pdV�dW���ZBdXeAdYdZ�zZCd[eAeBffd\d]d^d_d`ddeCffdadbdcdddedfdgdhdifZDdjdkdldmd_dddeCffdhdnfZEdo�ZF	e<re*e<��ZGne'e?��ZGeGjHdpkr
eDdId�ZDeG�IdqeGjJz��eG�IdreGjK����eDD]\ZLZ9eFeLe9���eFdsdt��D]RZMejNdueM��ZOeOreO�PdI��ZQneM�,��dvZQeFdweQf���SeED]O\ZLZ9eFeLe9��ZReLe9fdlkr�eRdv�,��ZSeSs�7eFdxddyeSdvzdzf���PeTd{��dS#eTd|��eseTd}ej7dz���xYwdS)~z�IMAP4 client.

Based on RFC 2060.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate
z2.58�N)�datetime�timezone�	timedelta)�DEFAULT_BUFFER_SIZETF)�IMAP4�IMAP4_stream�Internaldate2tuple�Int2AP�
ParseFlags�Time2Internaldate�
�i�)�	IMAP4REV1ri@B�APPEND)�AUTH�SELECTED�AUTHENTICATE)�NONAUTH�
CAPABILITY)rrr�LOGOUT�CHECK)r�CLOSE�COPY�CREATE�DELETE�	DELETEACL�ENABLE)r�EXAMINE�EXPUNGE�FETCH�GETACL�
GETANNOTATION�GETQUOTA�GETQUOTAROOT�MYRIGHTS�LIST�LOGINr�LSUB�MOVE�	NAMESPACE�NOOP�PARTIAL�	PROXYAUTH�RENAME�SEARCH�SELECT�SETACL�
SETANNOTATION�SETQUOTA�SORT)�STARTTLS�STATUS�STORE�	SUBSCRIBE�THREAD�UID�UNSUBSCRIBE�UNSELECTs\+( (?P<data>.*))?s.*FLAGS \((?P<flags>[^\)]*)\)s�.*INTERNALDATE "(?P<day>[ 0123][0-9])-(?P<mon>[A-Z][a-z][a-z])-(?P<year>[0-9][0-9][0-9][0-9]) (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9]) (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])"s.*{(?P<size>\d+)}$s
\r\n|\r|\ns%\[(?P<type>[A-Z-]+)( (?P<data>.*))?\]s$\* (?P<type>[A-Z-]+)( (?P<data>.*))?s3\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?c�0�eZdZdZGd�de��ZGd�de��ZGd�de��Zded	fd
�Z	d�Z
d�Zd
�Zd�Z
d�Zd�Zd�Zded	fd�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(dZd,�Z)d-�Z*d.�Z+d/�Z,d0�Z-dZd1�Z.d2�Z/d3�Z0d4�Z1d5�Z2d6�Z3d7�Z4d8�Z5d[d;�Z6d<�Z7d=�Z8d>�Z9d?�Z:d\d@�Z;dA�Z<dB�Z=dC�Z>dD�Z?dE�Z@dF�ZAdG�ZBdH�ZCdI�ZDdJ�ZEdK�ZFdL�ZGdM�ZHdN�ZId]dO�ZJdP�ZKdQ�ZLdR�ZMdS�ZNdT�ZOdU�ZPd	S)^ra�IMAP4 client class.

    Instantiate with: IMAP4([host[, port[, timeout=None]]])

            host - host's name (default: localhost);
            port - port number (default: standard IMAP4 port).
            timeout - socket timeout (default: None)
                      If timeout is not given or is None,
                      the global default socket timeout is used

    All IMAP4rev1 commands are supported by methods of the same
    name (in lowercase).

    All arguments to commands are converted to strings, except for
    AUTHENTICATE, and the last argument to APPEND which is passed as
    an IMAP4 literal.  If necessary (the string contains any
    non-printing characters or white-space and isn't enclosed with
    either parentheses or double quotes) each string is quoted.
    However, the 'password' argument to the LOGIN command is always
    quoted.  If you want to avoid having an argument string quoted
    (eg: the 'flags' argument to STORE) then enclose the string in
    parentheses (eg: "(\Deleted)").

    Each command returns a tuple: (type, [data, ...]) where 'type'
    is usually 'OK' or 'NO', and 'data' is either the text from the
    tagged response, or untagged results from command. Each 'data'
    is either a string, or a tuple. If a tuple, then the first part
    is the header of the response, and the second part contains
    the data (ie: 'literal' value).

    Errors raise the exception class <instance>.error("<reason>").
    IMAP4 server errors raise <instance>.abort("<reason>"),
    which is a sub-class of 'error'. Mailbox status changes
    from READ-WRITE to READ-ONLY raise the exception class
    <instance>.readonly("<reason>"), which is a sub-class of 'abort'.

    "error" exceptions imply a program error.
    "abort" exceptions imply the connection should be reset, and
            the command re-tried.
    "readonly" exceptions imply the command should be re-tried.

    Note: to use this module, you must read the RFCs pertaining to the
    IMAP4 protocol, as the semantics of the arguments to each IMAP4
    command are left to the invoker, not to mention the results. Also,
    most IMAP servers implement a sub-set of the commands available here.
    c��eZdZdS)�IMAP4.errorN��__name__�
__module__�__qualname__���./opt/alt/python311/lib64/python3.11/imaplib.py�errorr?���������rErGc��eZdZdS)�IMAP4.abortNr@rDrErF�abortrJ�rHrErKc��eZdZdS)�IMAP4.readonlyNr@rDrErF�readonlyrM�rHrErN�Nc�x�t|_d|_d|_i|_i|_d|_d|_d|_d|_	|�
��|�|||��	|���dS#t$r(	|���n#t$rYnwxYw�wxYw)NrrOFr)�Debug�debug�state�literal�tagged_commands�untagged_responses�continuation_response�is_readonly�tagnum�_tls_established�_mode_ascii�open�_connect�	Exception�shutdown�OSError��self�host�port�timeouts    rF�__init__zIMAP4.__init__�s�����
���
����!���"$���%'��"� ������ %���������	
�	�	�$��g�&�&�&�	��M�M�O�O�O�O�O���	�	�	�
��
�
�������
�
�
���
�����	���s0�1B�
B9�B'�&B9�'
B4�1B9�3B4�4B9c���d|_d|_tjttj��|_tjttj��|_dS)NF�ascii)	�utf8_enabled�	_encoding�re�compile�_Literal�ASCII�Literal�_Untagged_status�Untagged_status�rbs rFr[zIMAP4._mode_ascii�sC��!��� ����z�(�B�H�5�5���!�z�*:�B�H�E�E����rEc��d|_d|_tjt��|_tjt��|_dS)NT�utf-8)rirjrkrlrmrorprqrrs rF�
_mode_utf8zIMAP4._mode_utf8�s;�� ��� ����z�(�+�+���!�z�*:�;�;����rEc���ttjdd����|_t	jd|jzdztj��|_	|���|_d|jvrd|_n+d
|jvrd|_n|�|j���|���	t*D]}||jvr�||_dS|�d���)Nii��s(?P<tag>s"\d+) (?P<type>[A-Z]+) (?P<data>.*)F�
r�zimaplib version %sznew IMAP4 connection, tag=%s�PREAUTHr�OKr�zCAPABILITIES: zserver not IMAP4 compliant)r
�random�randint�tagprerkrlrn�tagre�_cmd_log_len�_cmd_log_idx�_cmd_logrR�_mesg�__version__�
_get_response�welcomerVrSrG�_get_capabilities�capabilities�AllowedVersions�PROTOCOL_VERSION)rb�versions  rFr]zIMAP4._connect�s���V�^�D�%�8�8�9�9����Z���+�!&�@�!A�BD�(�L�L��
�	I��)�)�+�+�����/�/�/��D�J�J�
�T�,�
,�
,�"�D�J�J��*�*�T�\�*�*�*���� � � �	F�'�	�	�G��d�/�/�/��$+�D�!��F�F��j�j�5�6�6�6rEc�|�|tvr"t||�����Std|z���)NzUnknown IMAP4 command: '%s')�Commands�getattr�lower�AttributeError)rb�attrs  rF�__getattr__zIMAP4.__getattr__
s9���8����4������.�.�.��:�T�A�B�B�BrEc��|S�NrDrrs rF�	__enter__zIMAP4.__enter__s���rEc�l�|jdkrdS	|���dS#t$rYdSwxYw)Nr)rS�logoutr`)rb�argss  rF�__exit__zIMAP4.__exit__sL���:��!�!��F�	��K�K�M�M�M�M�M���	�	�	��D�D�	���s�%�
3�3c���|�|std���|jsdn|j}tjd||j|j��||jf}|�tj||��Stj|��S)Nz0Non-blocking socket (timeout=0) is not supportedzimaplib.open)�
ValueErrorrc�sys�auditrd�socket�create_connection)rbrerc�addresss    rF�_create_socketzIMAP4._create_socket#s�����w���O�P�P�P��9�3�t�t�$�)���	�.�$��	�4�9�=�=�=����#�����+�G�W�=�=�=��'��0�0�0rEc��||_||_|�|��|_|j�d��|_dS)z�Setup connection to remote server on "host:port"
            (default: localhost:standard IMAP4 port).
        This connection will be used by the routines:
            read, readline, send, shutdown.
        �rbN)rcrdr��sock�makefile�fileras    rFr\z
IMAP4.open0sB����	���	��'�'��0�0��	��I�&�&�t�,�,��	�	�	rEc�6�|j�|��S�zRead 'size' bytes from remote.)r��read�rb�sizes  rFr�z
IMAP4.read<s���y�~�~�d�#�#�#rEc��|j�tdz��}t|��tkr|�dtz���|S)�Read line from remote.rxzgot more than %d bytes)r��readline�_MAXLINE�lenrG�rb�lines  rFr�zIMAP4.readlineAsI���y�!�!�(�Q�,�/�/���t�9�9�x����*�*�5��@�A�A�A��rEc�f�tjd||��|j�|��dS)�Send data to remote.zimaplib.sendN)r�r�r��sendall�rb�datas  rF�sendz
IMAP4.sendIs2���	�.�$��-�-�-��	���$�����rEc�v�|j���	|j�tj��nB#t$r5}|jtjkrt|dd��dkr�Yd}~nd}~wwxYw|j���dS#|j���wxYw)� Close I/O established in "open".�winerrorri&'N)
r��closer�r_r��	SHUT_RDWRr`�errno�ENOTCONNr�)rb�excs  rFr_zIMAP4.shutdownOs����	������
	��I���v�/�0�0�0�0���	�	�	��	�U�^�+�+��3�
�A�.�.�%�7�7�����������
	����
�I�O�O�������D�I�O�O�������s.�$A�B�
A?�
+A:�5B�:A?�?B�B8c��|jS)zfReturn socket instance used to connect to IMAP4 server.

        socket = <instance>.socket()
        )r�rrs rFr�zIMAP4.socket_s��
�y�rEc��d}|�ddg|��\}}|dr||fS|���\}}|�|||��S)aReturn most recent 'RECENT' responses if any exist,
        else prompt server for an update using the 'NOOP' command.

        (typ, [data]) = <instance>.recent()

        'data' is None if no new messages,
        else list of RECENT responses, most recent last.
        �RECENTrzN���)�_untagged_response�noop�rb�name�typ�dats    rF�recentzIMAP4.recentksd�����*�*�4�$���>�>���S��r�7�	���8�O��9�9�;�;���S��&�&�s�C��6�6�6rEc�V�|�|dg|�����S)z�Return data for response 'code' if received, or None.

        Old value for response 'code' is cleared.

        (code, [data]) = <instance>.response(code)
        N)r��upper)rb�codes  rF�responsezIMAP4.response|s&���&�&�t�d�V�T�Z�Z�\�\�B�B�BrEc��d}|sd}|r|d|dfdkrd|z}nd}|rt|��}nd}t�t|��}|jrd|zd	z}||_|�||||��S)
z�Append message to named mailbox.

        (typ, [data]) = <instance>.append(mailbox, flags, date_time, message)

                All args except `message' can be None.
        r�INBOXrr���(�)�(%s)NsUTF8 (�))r�MapCRLF�sub�CRLFrirT�_simple_command)rb�mailbox�flags�	date_time�messager�rTs       rF�appendzIMAP4.append�s������	��G��	��a���r��#�y�0�0�������E��	�)�)�4�4�I�I��I��+�+�d�G�,�,����	1��'�)�D�0�G�����#�#�D�'�5�)�D�D�DrEc��|���}t|��j|_|�d|��\}}|dkr/|�|d�dd�����d|_||fS)asAuthenticate command - requires response processing.

        'mechanism' specifies which authentication mechanism is to
        be used - it must appear in <instance>.capabilities in the
        form AUTH=<mechanism>.

        'authobject' must be a callable object:

                data = authobject(response)

        It will be called to process server continuation responses; the
        response argument it is passed will be a bytes.  It should return bytes
        data that will be base64 encoded and sent to the server.  It should
        return None if the client abort response '*' should be sent instead.
        rrzr�rt�replacer)r��_Authenticator�processrTr�rG�decoderS)rb�	mechanism�
authobject�mechr�r�s      rF�authenticatezIMAP4.authenticate�s}�� ��� � ��
&�j�1�1�9����'�'���=�=���S��$�;�;��*�*�S��W�^�^�G�Y�?�?�@�@�@���
��C�x�rEc�d�d}|�|��\}}|�|||��S)zT(typ, [data]) = <instance>.capability()
        Fetch capabilities list from server.r�r�r�r�s    rF�
capabilityzIMAP4.capability�s8�����'�'��-�-���S��&�&�s�C��6�6�6rEc�,�|�d��S)zRCheckpoint mailbox on server.

        (typ, [data]) = <instance>.check()
        r�r�rrs rF�checkzIMAP4.check�s��
�#�#�G�,�,�,rEc�d�	|�d��\}}d|_n#d|_wxYw||fS)z�Close currently selected mailbox.

        Deleted messages are removed from writable mailbox.
        This is the recommended command before 'LOGOUT'.

        (typ, [data]) = <instance>.close()
        rr�r�rS�rbr�r�s   rFr�zIMAP4.close�sC��	 ��+�+�G�4�4�H�C���D�J�J���D�J������C�x���"�	+c�0�|�d||��S)z�Copy 'message_set' messages onto end of 'new_mailbox'.

        (typ, [data]) = <instance>.copy(message_set, new_mailbox)
        rr�)rb�message_set�new_mailboxs   rF�copyz
IMAP4.copy�s��
�#�#�F�K��E�E�ErEc�.�|�d|��S)zPCreate new mailbox.

        (typ, [data]) = <instance>.create(mailbox)
        rr��rbr�s  rF�createzIMAP4.create����
�#�#�H�g�6�6�6rEc�.�|�d|��S)zPDelete old mailbox.

        (typ, [data]) = <instance>.delete(mailbox)
        rr�r�s  rF�deletezIMAP4.delete�r�rEc�0�|�d||��S)z�Delete the ACLs (remove any rights) set for who on mailbox.

        (typ, [data]) = <instance>.deleteacl(mailbox, who)
        rr�)rbr��whos   rF�	deleteaclzIMAP4.deleteacl�s��
�#�#�K��#�>�>�>rEc���d|jvrt�d���|�d|��\}}|dkr*d|���vr|���||fS)zlSend an RFC5161 enable string to the server.

        (typ, [data]) = <instance>.enable(capability)
        rzServer does not support ENABLErzzUTF8=ACCEPT)r�rrGr�r�ru)rbr�r�r�s    rF�enablezIMAP4.enable�sw��
�4�,�,�,��+�+�>�?�?�?��(�(��:�>�>�	��T��$�;�;�=�J�,<�,<�,>�,>�>�>��O�O�����D�y�rEc�d�d}|�|��\}}|�|||��S)z�Permanently remove deleted items from selected mailbox.

        Generates 'EXPUNGE' response for each deleted message.

        (typ, [data]) = <instance>.expunge()

        'data' is list of 'EXPUNGE'd message numbers in order received.
        rr�r�s    rF�expungez
IMAP4.expunges8�����'�'��-�-���S��&�&�s�C��6�6�6rEc�h�d}|�|||��\}}|�|||��S)a#Fetch (parts of) messages.

        (typ, [data, ...]) = <instance>.fetch(message_set, message_parts)

        'message_parts' should be a string of selected parts
        enclosed in parentheses, eg: "(UID BODY[TEXT])".

        'data' are tuples of message part envelope and data.
        r r�)rbr��
message_partsr�r�r�s      rF�fetchzIMAP4.fetchs<�����'�'��k�=�I�I���S��&�&�s�C��6�6�6rEc�b�|�d|��\}}|�||d��S)zXGet the ACLs for a mailbox.

        (typ, [data]) = <instance>.getacl(mailbox)
        r!�ACLr��rbr�r�r�s    rF�getaclzIMAP4.getacl(s5��
�'�'��'�:�:���S��&�&�s�C��7�7�7rEc�f�|�d|||��\}}|�||d��S)za(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
        Retrieve ANNOTATIONs.r"�
ANNOTATIONr�)rbr��entry�	attributer�r�s      rF�
getannotationzIMAP4.getannotation1s9���'�'���%��S�S���S��&�&�s�C��>�>�>rEc�b�|�d|��\}}|�||d��S)z�Get the quota root's resource usage and limits.

        Part of the IMAP4 QUOTA extension defined in rfc2087.

        (typ, [data]) = <instance>.getquota(root)
        r#�QUOTAr�)rb�rootr�r�s    rF�getquotazIMAP4.getquota9s5���'�'�
�D�9�9���S��&�&�s�C��9�9�9rEc��|�d|��\}}|�||d��\}}|�||d��\}}|||gfS)z�Get the list of quota roots for the named mailbox.

        (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = <instance>.getquotaroot(mailbox)
        r$r�	QUOTAROOTr�)rbr�r�r��quota�	quotaroots      rF�getquotarootzIMAP4.getquotarootDsc��
�'�'���@�@���S��,�,�S�#�w�?�?�
��U��0�0��c�;�G�G���Y��Y��&�&�&rE�""�*c�h�d}|�|||��\}}|�|||��S)z�List mailbox names in directory matching pattern.

        (typ, [data]) = <instance>.list(directory='""', pattern='*')

        'data' is list of LIST responses.
        r&r��rb�	directory�patternr�r�r�s      rF�listz
IMAP4.listO�<�����'�'��i��A�A���S��&�&�s�C��6�6�6rEc��|�d||�|����\}}|dkr|�|d���d|_||fS)z�Identify client using plaintext password.

        (typ, [data]) = <instance>.login(user, password)

        NB: 'password' will be quoted.
        r'rzr�r)r��_quoterGrS)rb�user�passwordr�r�s     rF�loginzIMAP4.login[sZ���'�'���t�{�{�8�7L�7L�M�M���S��$�;�;��*�*�S��W�%�%�%���
��C�x�rEc�V�||c|_|_|�d|j��S)zr Force use of CRAM-MD5 authentication.

        (typ, [data]) = <instance>.login_cram_md5(user, password)
        zCRAM-MD5)r#r$r��_CRAM_MD5_AUTH)rbr#r$s   rF�login_cram_md5zIMAP4.login_cram_md5is-��
$(�� ��	�4�=�� � ��T�-@�A�A�ArEc���ddl}t|jt��r|j�d��n|j}|jdz|�||d�����zS)z1 Authobject to use with CRAM-MD5 authentication. rNrt� �md5)�hmac�
isinstancer$�str�encoder#�HMAC�	hexdigest)rb�	challenger,�pwds    rFr'zIMAP4._CRAM_MD5_AUTHrsl������0:�4�=�#�0N�0N�@�t�}�#�#�G�,�,�,�26�-�	��y�3�����3�	�5�!A�!A�!K�!K�!M�!M�M�MrEc�p�d|_|�d��\}}|���||fS)z|Shutdown connection to server.

        (typ, [data]) = <instance>.logout()

        Returns server 'BYE' response.
        r)rSr�r_r�s   rFr�zIMAP4.logoutzs8����
��'�'��1�1���S��
�
�����C�x�rEc�h�d}|�|||��\}}|�|||��S)z�List 'subscribed' mailbox names in directory matching pattern.

        (typ, [data, ...]) = <instance>.lsub(directory='""', pattern='*')

        'data' are tuples of message part envelope and data.
        r(r�rs      rF�lsubz
IMAP4.lsub�r rEc�b�|�d|��\}}|�||d��S)z�Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).

        (typ, [data]) = <instance>.myrights(mailbox)
        r%r�r	s    rF�myrightszIMAP4.myrights�s5��
�&�&�z�7�;�;���C��&�&�s�C��<�<�<rEc�d�d}|�|��\}}|�|||��S)zb Returns IMAP namespaces ala rfc2342

        (typ, [data, ...]) = <instance>.namespace()
        r*r�r�s    rF�	namespacezIMAP4.namespace�s8��
���'�'��-�-���S��&�&�s�C��6�6�6rEc�.�	|�d��S)zFSend NOOP command.

        (typ, [data]) = <instance>.noop()
        Fr{r+)rR�_dump_urrVr�rrs rFr�z
IMAP4.noop�s��
	7��#�#�F�+�+�+rEc�l�d}|�|||||��\}}|�||d��S)z�Fetch truncated part of a message.

        (typ, [data, ...]) = <instance>.partial(message_num, message_part, start, length)

        'data' is tuple of message part envelope and data.
        r,r r�)rb�message_num�message_part�start�lengthr�r�r�s        rF�partialz
IMAP4.partial�sA�����'�'��k�<��PV�W�W���S��&�&�s�C��9�9�9rEc�2�d}|�d|��S)z�Assume authentication as "user".

        Allows an authorised administrator to proxy into any user's
        mailbox.

        (typ, [data]) = <instance>.proxyauth(user)
        r-r�)rbr#r�s   rF�	proxyauthzIMAP4.proxyauth�s�����#�#�K��6�6�6rEc�0�|�d||��S)zkRename old mailbox name to new.

        (typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
        r.r�)rb�
oldmailbox�
newmailboxs   rF�renamezIMAP4.rename�s��
�#�#�H�j�*�E�E�ErEc���d}|r5|jrt�d���|j|d|g|�R�\}}n|j|g|�R�\}}|�|||��S)z�Search mailbox for matching messages.

        (typ, [data]) = <instance>.search(charset, criterion, ...)

        'data' is space separated list of matching message numbers.
        If UTF8 is enabled, charset MUST be None.
        r/z'Non-None charset not valid in UTF8 mode�CHARSET)rirrGr�r�)rb�charset�criteriar�r�r�s      rF�searchzIMAP4.search�s������	=�� �
M��k�k�"K�L�L�L�+�t�+�D�)�W�P�x�P�P�P�H�C���+�t�+�D�<�8�<�<�<�H�C���&�&�s�C��6�6�6rEr�Fc��i|_||_|rd}nd}|�||��\}}|dkrd|_||fSd|_d|jvr|s	|�d	|z���||j�d
dg��fS)atSelect a mailbox.

        Flush all untagged responses.

        (typ, [data]) = <instance>.select(mailbox='INBOX', readonly=False)

        'data' is count of messages in mailbox ('EXISTS' response).

        Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so
        other responses should be obtained via <instance>.response('FLAGS') etc.
        rr0rzrr�	READ-ONLYFrxz%s is not writable�EXISTSN)rVrXr�rSrRr<rN�get)rbr�rNr�r�r�s      rF�selectzIMAP4.select�s���#%���#����	��D�D��D��'�'��g�6�6���S��$�;�;��D�J���8�O���
��$�1�1�1� �2�
;��-�-� 4�w� >�?�?�?��D�+�/�/��4�&�A�A�A�ArEc�2�|�d|||��S)zZSet a mailbox acl.

        (typ, [data]) = <instance>.setacl(mailbox, who, what)
        r1r�)rbr�r��whats    rF�setaclzIMAP4.setacls��
�#�#�H�g�s�D�A�A�ArEc�R�|jdg|�R�\}}|�||d��S)z_(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
        Set ANNOTATIONs.r2rr�)rbr�r�r�s    rF�
setannotationzIMAP4.setannotation
s:��(�4�'��?�$�?�?�?���S��&�&�s�C��>�>�>rEc�d�|�d||��\}}|�||d��S)ziSet the quota root's resource limits.

        (typ, [data]) = <instance>.setquota(root, limits)
        r3rr�)rbr�limitsr�r�s     rF�setquotazIMAP4.setquotas7��
�'�'�
�D�&�A�A���S��&�&�s�C��9�9�9rEc��d}|d|dfdkrd|z}|j|||g|�R�\}}|�|||��S)z�IMAP4rev1 extension SORT command.

        (typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
        r4rr�r�r�r�)rb�
sort_criteriarK�search_criteriar�r�r�s       rF�sortz
IMAP4.sortsi��
��
�!��]�2�.�/�9�<�<�"�]�2�M�'�4�'��m�W�W��W�W�W���S��&�&�s�C��6�6�6rEc�2�d}ts|�d���|jr|�d���||jvr|�d���|�tj��}|�|��\}}|dkra|�|j	|j
���|_	|j	�d��|_d|_|�
��n|�d	���|�|||��S)
Nr5zSSL support missingzTLS session already establishedzTLS not supported by serverrz��server_hostnamer�TzCouldn't establish TLS session)�HAVE_SSLrGrZrKr��ssl�_create_stdlib_contextr��wrap_socketr�rcr�r�r�r�)rb�ssl_contextr�r�r�s     rF�starttlszIMAP4.starttls)s�����	4��*�*�2�3�3�3�� �	@��*�*�>�?�?�?��t�(�(�(��*�*�:�;�;�;����4�6�6�K��'�'��-�-���S��$�;�;�#�/�/��	�@D�	�0�K�K�D�I��	�*�*�4�0�0�D�I�$(�D�!��"�"�$�$�$�$��*�*�=�>�>�>��&�&�s�C��6�6�6rEc�h�d}|�|||��\}}|�|||��S)zpRequest named status conditions for mailbox.

        (typ, [data]) = <instance>.status(mailbox, names)
        r6r�)rbr��namesr�r�r�s      rF�statuszIMAP4.status@s>��
���'�'��g�u�=�=���S��&�&�s�C��6�6�6rEc��|d|dfdkrd|z}|�d|||��\}}|�||d��S)z�Alters flag dispositions for messages in mailbox.

        (typ, [data]) = <instance>.store(message_set, command, flags)
        rr�r�r�r7r r�)rbr��commandr�r�r�s      rF�storezIMAP4.storeLsZ��

�!�H�U�2�Y��9�,�,��U�N�E��'�'���g�u�M�M���S��&�&�s�C��9�9�9rEc�.�|�d|��S)zYSubscribe to new mailbox.

        (typ, [data]) = <instance>.subscribe(mailbox)
        r8r�r�s  rF�	subscribezIMAP4.subscribeWs��
�#�#�K��9�9�9rEc�Z�d}|j|||g|�R�\}}|�|||��S)z�IMAPrev1 extension THREAD command.

        (type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
        r9r�)rb�threading_algorithmrKr]r�r�r�s       rF�threadzIMAP4.thread_sD��
��'�4�'��.A�7�]�_�]�]�]���S��&�&�s�C��6�6�6rEc�~�|���}|tvr|�d|z���|jt|vrA|�d|�d|j�dd�t|�������d}|j||g|�R�\}}|dvr|}nd}|�|||��S)	z�Execute "command arg ..." with messages identified by UID,
                rather than message number.

        (typ, [data]) = <instance>.uid(command, arg1, arg2, ...)

        Returns response appropriate to 'command'.
        zUnknown IMAP4 UID command: %s�command � illegal in state �, only allowed in states �, r:)r/r4r9r )r�r�rGrS�joinr�r�)rbrlr�r�r�r�s      rF�uidz	IMAP4.uidis����-�-�/�/���(�"�"��*�*�<�w�F�G�G�G��:�X�g�.�.�.��*�*�*�%�g�g�t�z�z�z�"�i�i���(9�:�:�:�<�=�=�
=���'�4�'��g�=��=�=�=���S��2�2�2��D�D��D��&�&�s�C��6�6�6rEc�.�|�d|��S)z_Unsubscribe from old mailbox.

        (typ, [data]) = <instance>.unsubscribe(mailbox)
        r;r�r�s  rF�unsubscribezIMAP4.unsubscribe�s��
�#�#�M�7�;�;�;rEc�d�	|�d��\}}d|_n#d|_wxYw||fS)aMFree server's resources associated with the selected mailbox
        and returns the server to the authenticated state.
        This command performs the same actions as CLOSE, except
        that no messages are permanently removed from the currently
        selected mailbox.

        (typ, [data]) = <instance>.unselect()
        r<rr�)rbr�r�s   rF�unselectzIMAP4.unselect�sD��	 ��,�,�Z�8�8�I�C���D�J�J���D�J������D�y�r�c�x�|���}|tvr|jft|<|j|g|�R�S)aAllow simple extension commands
                notified by server in CAPABILITY response.

        Assumes command is legal in current state.

        (typ, [data]) = <instance>.xatom(name, arg, ...)

        Returns response appropriate to extension command `name'.
        )r�r�rSr��rbr�r�s   rF�xatomzIMAP4.xatom�sF���z�z�|�|���x���"�j�]�H�T�N�#�t�#�D�0�4�0�0�0�0rEc�l�|�d}|j}	||vr||�|��dS|g||<dS�NrE)rVrRr�r�rQr�)rbr�r��urs    rF�_append_untaggedzIMAP4._append_untagged�sO���;��C�
�
$��	9��"�9�9��s�G�N�N�3�������e�B�s�G�G�GrEc��|j�d��}|r4|�|d�|jd�����dS)N�BYEr�r�)rVrQrKr�rj)rb�byes  rF�
_check_byezIMAP4._check_bye�sS���%�)�)�%�0�0���	H��*�*�S��W�^�^�D�N�I�F�F�G�G�G�	H�	HrEc��|jt|vrHd|_|�d|�d|j�dd�t|�������dD]}||jvr|j|=�d|jvr|js|�d���|���}t||j
��}|dz|z}|D]7}|��t|t��rt||j
��}|dz|z}�8|j}|�Wd|_t|��t|j��ur|}n*d}|td	t|��z|j
��z}		|�|t(z��n*#t*$r}	|�d
|	z���d}	~	wwxYw|�|S	|���r#|j|r|S|����#|r||j��}		|�|��|�t(��n*#t*$r}	|�d
|	z���d}	~	wwxYw|sn��|S)Nrtrurvrw�rz�NO�BADrOz#mailbox status changed to READ-ONLY� z {%s}F�z> %rzsocket error: %s)rSr�rTrGrxrVrXrN�_new_tag�bytesrjr-r.�type�_commandr�rRr��_logr�r�r`rKr�rUrW)
rbr�r�r��tagr��argrT�	literator�vals
          rFr�zIMAP4._command�s����:�X�d�^�+�+��D�L��*�*�*�"�d�d�D�J�J�J�"�i�i����7�7�7�9�:�:�
:�
'�	1�	1�C��d�-�-�-��+�C�0���$�1�1�1�� �2��-�-� E�F�F�F��m�m�o�o���T�4�>�*�*���T�z�D� ���	%�	%�C��{�H��#�s�#�#�
1��C���0�0���$�;��$�D�D��,�����D�L��G�}�}��T�]� 3� 3�3�3�#�	�	� �	��e�G�c�'�l�l�$:�D�N�K�K�K��	)�	7��I�I�d�T�k�"�"�"�"���	7�	7�	7��*�*�/�#�5�6�6�6�����	7�����?��J�	��$�$�&�&�
��'��,���J��$�$�&�&�
��
@�#�)�D�$>�?�?��
G�
;��	�	�'�"�"�"��	�	�$�������
;�
;�
;��j�j�!3�c�!9�:�:�:�����
;�����
��/	�2�
s0�%F�
F*�
F%�%F*�=/H-�-
I�7I�Ic��|dk}|s|���	|�||���\}}nU#|j$r }|�d|�d|�����d}~w|j$r }|�d|�d|�����d}~wwxYw|s|���|dkr|�|�d|�d|�����||fS)Nr)�
expect_byez	command: � => r�z command error: r*)r��_get_tagged_responserKrG)rbr�r�r�r�r�r�s       rF�_command_completezIMAP4._command_completes���(�"���	��O�O����	@��1�1�#�&�1�I�I�I�C�����z�	@�	@�	@��*�*�*�D�D�D�#�#�>�?�?�?������z�	@�	@�	@��*�*�*�D�D�D�#�#�>�?�?�?�����	@�����	��O�O�����%�<�<��*�*�$�$�$����T�T�J�K�K�K��D�y�s!�9�
B�A�
B�+B�Bc��|���\}}|dgkr|�d���t|d|j��}|���}t|�����|_dS)Nz"no CAPABILITY response from serverr�)r�rGr.rjr��tuple�splitr�r�s   rFr�zIMAP4._get_capabilities#ss���?�?�$�$���S��4�&�=�=��*�*�A�B�B�B��#�b�'�4�>�*�*���i�i�k�k��!�#�)�)�+�+�.�.����rEc��|���}|�|j|��r�|j�d��}||jvr|�d|z���|j�d��}t||j��}|j�d��}||gf|j|<�n�d}|�t|��s5|�|j
|��r|j�d��}|j�T|�t|��r!|j�d��|_dS|�d|z���|j�d��}t||j��}|j�d��}|�d}|r|dz|z}|�|j
|��r�t|j�d	����}	|�|��}|�|||f��|���}|�|j
|����|�||��|d
vrx|�t&|��r]|j�d��}t||j��}|�||j�d����	|S)Nr�zunexpected tagged response: %rr�r��data2zunexpected response: %rrEr�r�Fr�zread literal size %sr�)�	_get_line�_matchr�mo�grouprUrKr.rj�Untagged_responserq�ContinuationrWro�intrRr�r�r��
Response_code)rb�respr�r�r��dat2r�r�s        rFr�zIMAP4._get_response,s����~�~�����;�;�t�z�4�(�(�5	,��'�-�-��&�&�C��$�.�.�.��j�j�!A�D�!H�I�I�I��'�-�-��'�'�C��c�4�>�*�*�C��'�-�-��'�'�C�),�s�e��D� ��%�%��D��;�;�0�$�7�7�
2��;�;�t�3�T�:�:�2��7�=�=��1�1�D��w���;�;�|�T�2�2� �15����v�1F�1F�D�.��4��j�j�!:�T�!A�B�B�B��'�-�-��'�'�C��c�4�>�*�*�C��'�-�-��'�'�C��{�#�C��,�3��:��,�S��+�+�d�l�C�0�0�
'��4�7�=�=��0�0�1�1��B��y�y������%�%�c�C��;�7�7�7��n�n�&�&��!�+�+�d�l�C�0�0�
'�$
�!�!�#�s�+�+�+��%�%�%�$�+�+�m�S�*I�*I�%��'�-�-��'�'�C��c�4�>�*�*�C��!�!�#�t�w�}�}�V�'<�'<�=�=�=�	;��rEc��	|j|}|�
|j|=|S|r#d}|j�|d��}|�||fS|���	|���n#|j$r}	�d}~wwxYw�})Nrxr�)rUrV�popr�r�rKrR�	print_log)rbr�r��resultr�r�r�s       rFr�zIMAP4._get_tagged_response|s���	��)�#�.�F��!��(��-��
��
&����-�1�1�#�t�<�<���?���:�%�
�O�O����
��"�"�$�$�$�$���:�
�
�
�)������	
����1	s�A*�*
A;�4A6�6A;c���|���}|s|�d���|�d��s|�d|z���|dd�}	|S)Nzsocket error: EOFr
z#socket error: unterminated line: %r���)r�rK�endswithrRr�r�r�s  rFr�zIMAP4._get_line�sr���}�}�����	2��*�*�0�1�1�1��}�}�W�%�%�	K��*�*�B�T�I�J�J�J��C�R�C�y��	)�
�rEc�J�|�|��|_	|jduSr�)�matchr�rRr�r�groups)rb�cre�ss   rFr�zIMAP4._match�s*��
�)�)�A�,�,���	S��w�d�"�"rEc��|jtt|j��|j��z}|jdz|_d|j|<|S)Nrx)r~r�r.rYrjrU)rbr�s  rFr�zIMAP4._new_tag�sC���k�E�#�d�k�"2�"2�D�N�C�C�C���k�A�o���$(���S�!��
rEc�j�|�dd��}|�dd��}d|zdzS)N�\z\\�"z\")r�)rbr�s  rFr"zIMAP4._quote�s6���k�k�$��'�'���k�k�#�u�%�%���S�y�3��rEc�F�|�||j|g|�R���Sr�)r�r�rs   rFr�zIMAP4._simple_command�s,���%�%�d�M�D�M�$�,F��,F�,F�,F�G�G�GrEc�p�|dkr||fS||jvr|dgfS|j�|��}	||fS)Nr�)rVr�rRr�)rbr�r�r�r�s     rFr�zIMAP4._untagged_response�sV���$�;�;���8�O��t�.�.�.����;���&�*�*�4�0�0��	J��D�y�rEc��|�tj��}tjdtj|����}tj�d||dzdz|fz��tj���dS)Nz%M:%Sz
  %s.%02d %s
�d)�time�strftime�	localtimer��stderr�write�flush)rbr��secs�tms    rFr�zIMAP4._mesg�sr���|��y�{�{����w���t�(<�(<�=�=�B��J���-��d�3�h��^�Q�0G�G�H�H�H��J�������rEc��|sdSd�|���D��}|�dd�|��z��dS)Nc3�*K�|]\}}|�d|��V��dS)�: NrD)�.0�key�values   rF�	<genexpr>z!IMAP4._dump_ur.<locals>.<genexpr>�sP����B�B�"��U��(�(�u�(�(�B�B�B�B�B�BrEzuntagged responses dump:z
		)�itemsr�rx)rb�untagged_resp_dictr�s   rFr<zIMAP4._dump_ur�sh��%�
���B�B�&8�&>�&>�&@�&@�B�B�B�E��J�J�1�H�M�M�%�4H�4H�H�I�I�I�I�IrEc��|tj��f|j|j<|xjdz
c_|j|jkr	d|_dSdS)Nrxr)r�r�r�r�r�s  rFr�z
IMAP4._log�sW��04�d�i�k�k�/B�D�M�$�+�,�����"���� �D�$5�5�5�$%��!�!�!�6�5rEc���|�dt|j��z��|j|j}}|r9	|j|j|�n#YnxYw|dz
}||jkrd}|dz}|�7dSdS)Nzlast %d IMAP4 interactions:rxr)r�r�r�r�r�)rb�i�ns   rFr�zIMAP4.print_log�s����J�J�4�s�4�=�7I�7I�I�J�J�J��$�d�&7�q�A��
���D�J��
�a� 0�1�1�1����D�����Q�����)�)�)��A��Q����
�
�
�
�
s�A�A)rr)r�Fr�)F)UrArBrC�__doc__r^rGrKrN�
IMAP4_PORTrfr[rur]r�r�r�r�r\r�r�r�r_r�r�r�r�r�r�r�r�r�r�r�r�rrrr
rrrrr%r(r'r�r6r8r:r�rBrDrHrMrRrUrWrZr^rgrjrmrorrryr{r}r�r�r�r�r�r�r�r�r�r�r�r"r�r�r�r<r�r�rDrErFrr�s
������-�-�^!� � � � �	� � � ���������������5�����Z������2F�F�F�<�<�<�'7�'7�'7�TC�C�C�������1�1�1���T�	-�	-�	-�	-�$�$�$�
��� � � �
�
�
� ���7�7�7�"C�C�C�E�E�E�4���:7�7�7�-�-�-����F�F�F�7�7�7�7�7�7�?�?�?�
�
�
�7�7�7�7�7�7�8�8�8�?�?�?�:�:�:�'�'�'�	7�	7�	7�	7����B�B�B�N�N�N�
�
�
�	7�	7�	7�	7�=�=�=�7�7�7�,�,�,�	:�	:�	:�
7�
7�
7�F�F�F�7�7�7�$B�B�B�B�@B�B�B�?�?�?�:�:�:�7�7�7�7�7�7�7�.	7�	7�	7�:�:�:�:�:�:�7�7�7�7�7�7�2<�<�<�
�
�
� 1�1�1�,���H�H�H�J�J�J�Z���$/�/�/�M�M�M�`����B���&	#�	#�	#�������H�H�H�
	�	�	�"�"rErc�:�eZdZdZdeddddfd�Zd�Zdedfd�ZdS)�	IMAP4_SSLa�IMAP4 client class over SSL connection

        Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile[, ssl_context[, timeout=None]]]]]])

                host - host's name (default: localhost);
                port - port number (default: standard IMAP4 SSL port);
                keyfile - PEM formatted file that contains your private key (default: None);
                certfile - PEM formatted certificate chain file (default: None);
                ssl_context - a SSLContext object that contains your certificate chain
                              and private key (default: None)
                Note: if ssl_context is provided, then parameters keyfile or
                certfile should not be set otherwise ValueError is raised.
                timeout - socket timeout (default: None) If timeout is not given or is None,
                          the global default socket timeout is used

        for more documentation see the docstring of the parent class IMAP4.
        rONc�.�|�|�td���|�|�td���|�|� ddl}|�dtd��||_||_|�t
j||���}||_t�
||||��dS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusiverzEkeyfile and certfile are deprecated, use a custom ssl_context instead�)�certfile�keyfile)r��warnings�warn�DeprecationWarningr�r�rcrdrfrrf)rbrcrdr�r�rfrer�s        rFrfzIMAP4_SSL.__init__s����&�7�+>� �"-�.�.�.��&�8�+?� �"-�.�.�.��"�h�&:������
�
�;�<N�PQ�S�S�S�"�D�L�$�D�M��"�!�8�(�AH�J�J�J��*�D���N�N�4��t�W�5�5�5�5�5rEc�z�t�||��}|j�||j���S)Nr`)rr�rfrerc)rbrer�s   rFr�zIMAP4_SSL._create_socket-sA���'�'��g�6�6�D��#�/�/��@D�	�0�K�K�
KrEc�@�t�||||��dS)z�Setup connection to remote server on "host:port".
                (default: localhost:standard IMAP4 SSL port).
            This connection will be used by the routines:
                read, readline, send, shutdown.
            N)rr\ras    rFr\zIMAP4_SSL.open2s"��
�J�J�t�T�4��1�1�1�1�1rE)rArBrCr��IMAP4_SSL_PORTrfr�r\rDrErFr�r�sq������	�	�&!#���"��d�	6�	6�	6�	6�(	K�	K�	K�
�^�T�	2�	2�	2�	2�	2�	2rEr�c�8�eZdZdZd�Zd	d�Zd�Zd�Zd�Zd�Z	dS)
rz�IMAP4 client class over a stream

    Instantiate with: IMAP4_stream(command)

            "command" - a string that can be passed to subprocess.Popen()

    for more documentation see the docstring of the parent class IMAP4.
    c�H�||_t�|��dSr�)rlrrf)rbrls  rFrfzIMAP4_stream.__init__Is!�����
���t�����rENc��d|_d|_d|_d|_t	j|jttjtjdd���|_	|j	j
|_|j	j|_
dS)z�Setup a stream connection.
        This connection will be used by the routines:
            read, readline, send, shutdown.
        NT)�bufsize�stdin�stdout�shell�	close_fds)rcrdr�r��
subprocess�Popenrlr�PIPEr�r��	writefiler��readfileras    rFr\zIMAP4_stream.openNsl��
��	���	���	���	�!�'���'��/�*�/��$�(�(�(�����+�����+��
�
�
rEc�6�|j�|��Sr�)r�r�r�s  rFr�zIMAP4_stream.read^s���}�!�!�$�'�'�'rEc�4�|j���S)r�)r�r�rrs rFr�zIMAP4_stream.readlinecs���}�%�%�'�'�'rEc�l�|j�|��|j���dS)r�N)r�r�r�r�s  rFr�zIMAP4_stream.sendhs2������T�"�"�"���������rEc��|j���|j���|j���dS)r�N)r�r�r�r��waitrrs rFr_zIMAP4_stream.shutdownnsD���
���������������������rE)NNN)
rArBrCr�rfr\r�r�r�r_rDrErFrr=s}�����������
,�,�,�,� (�(�(�
(�(�(�
�������rErc�*�eZdZdZd�Zd�Zd�Zd�ZdS)r�zcPrivate class to provide en/decoding
            for base64-based authentication conversation.
    c��||_dSr�)r�)rb�mechinsts  rFrfz_Authenticator.__init__|s
����	�	�	rEc��|�|�|����}|�dS|�|��S)N�*)r�r�r/)rbr��rets   rFr�z_Authenticator.processs;���i�i����D�)�)�*�*���;��4��{�{�3���rEc��d}t|t��r|�d��}|rQt|��dkr|dd�}|dd�}n|}d}t	j|��}|r
||dd�z}|�Q|S)NrErt�0r�)r-r.r/r��binascii�
b2a_base64)rb�inp�oup�t�es     rFr/z_Authenticator.encode�s������c�3���	&��*�*�W�%�%�C��		#��3�x�x�"�}�}�����H���"�#�#�h��������#�A�&�&�A��
#��A�c�r�c�F�l���		#��
rEc�2�|sdStj|��Sr�)r��
a2b_base64)rbr�s  rFr�z_Authenticator.decode�s ���	��3��"�3�'�'�'rEN)rArBrCr�rfr�r/r�rDrErFr�r�vsZ����������� � � ����0(�(�(�(�(rEr�z0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Decr*c�D�i|]\}}|���|dz��S)rx)r/)r�r�r�s   rF�
<dictcomp>r�s*��
<�
<�
<�d�a��1�8�8�:�:�a��c�
<�
<�
<rErxc	��t�|��}|sdSt|�d��}|�d��}t	|�d����}t	|�d����}t	|�d����}t	|�d����}t	|�d����}t	|�d	����}	t	|�d
����}
|	dz|
zdz}|dkr|}||||||d
d
d
f	}tj|��|z
}
tj|
��S)z�Parse an IMAP4 INTERNALDATE string.

    Return corresponding local time.  The return value is a
    time.struct_time tuple or None if the string has wrong format.
    N�mon�zonen�day�year�hour�min�sec�zoneh�zonem�<�-r�)	�InternalDater��Mon2numr�r��calendar�timegmr�r�)r�r�rr	r
rrr
rrr�zone�tt�utcs              rFr	r	�sS��
�	�	�D�	!�	!�B�
���t�
�"�(�(�5�/�/�
"�C��H�H�W���E�

�b�h�h�u�o�o�
�
�C��r�x�x���� � �D��r�x�x���� � �D�

�b�h�h�u�o�o�
�
�C�

�b�h�h�u�o�o�
�
�C������!�!�"�"�E������!�!�"�"�E�
�"�H�u��b� �D���}�}��u��
��S�$��S�"�b�"�	5�B�
�/�"�
�
��
$�C��>�#���rEc��d}d}tt|����}|r%t|d��\}}|||dz�|z}|�%|S)z-Convert integer to A-P string representation.rEsABCDEFGHIJKLMNOP�rx)r��abs�divmod)�numr��AP�mods    rFr
r
�s_���C�'�r�

�c�#�h�h�-�-�C�

�"��#�r�?�?���S���S��U��m�c�!���"��JrEc��t�|��}|sdSt|�d�������S)z-Convert IMAP4 flags response to python tuple.rDr�)�Flagsr�r�r�r�)r�r�s  rFrr�sH��
���T�	�	�B�
���r�����'�"�"�(�(�*�*�+�+�+rEc��t|ttf��r3tj|t
j�����}�n;t|t��r�	|j	}n�#t$rvtjrZ|d}|dkr,tj
tj|����d}tjtjf|}n
tj}YnwxYwt!|���}t|dd�dt|��i�}nht|t��r|j�t%d���|}n:t|t&��r|d|dfd	kr|St%d
���d�t*|j��}|�|��S)a�Convert date_time to IMAP4 INTERNALDATE representation.

    Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'.  The
    date_time argument can be a number (int or float) representing
    seconds since epoch (as returned by time.time()), a 9-tuple
    representing local time, an instance of time.struct_time (as
    returned by time.localtime()), an aware datetime instance or a
    double-quoted string.  In the last case, it is assumed to already
    be in the correct format.
    �r�)�secondsN��tzinfozdate_time must be awarer)r�r�zdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z")r-r��floatr�
fromtimestamprr�
astimezoner��	tm_gmtoffr�r��daylightr��mktime�altzonerr'r�r.�format�Months�monthr�)r��dt�gmtoff�dst�delta�fmts      rFrr�s����)�c�5�\�*�*�:�
�
#�I�$,�L�2�2�2<�*�,�,�	��	�I�u�	%�	%�:�		(��(�F�F���	(�	(�	(��}�
(���l���"�9�9��.���Y�)?�)?�@�@��C�C��=�$�,�7��<�<����-�����	(�����&�)�)�)��
�y��!��}�
=�X�e�_�_�
=�
=���	�I�x�	(�	(�:���#��6�7�7�7�
���	�I�s�	#�	#�:��1��i��m�(D�	�(Q�(Q����8�9�9�9�
"�
)�
)�&���*:�
;�
;�C�
�;�;�s���s�&A.�.A=C.�-C.�__main__zd:s:)rDrDz-dz-s)rOzIMAP password for z on �	localhostr�zJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)s�
)r#�lfr%)r�)�
/tmp/xxx 1)rH)r;z/tmp/yyy)r��
/tmp/yyz 2r�r=)r)z/tmpzyy*)rRr<)rM)N�SUBJECT�test)r)�1z(FLAGS INTERNALDATE RFC822))rm)r@�FLAGSz
(\Deleted))r:rD)rrD)r�rD)r�rD)rRrD)r�)�UIDVALIDITY)ry)r/�ALL)r�)rP)r�rDc���t�|�d|����tt|��|�\}}t�|�d|�d|����|dkr|d�|S)Nr*r�r�r)�Mr�r�)�cmdr�r�r�s    rF�runrGAsp��	���3�3�3���%�&�&�&�"�7�1�c�?�?�D�)���S�	������c�c�c�3�3�/�0�0�0��$�;�;�c�!�f���
rErzPROTOCOL_VERSION = %szCAPABILITIES = r)z/tmp/zyy%z.*"([^"]+)"$r�r�ryz%sz:(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)z
All tests OK.z
Tests failed.z8
If you would like to see debugging output,
try: %s -d5
)Ur�r�r�r�r|rkr�r�r�r�rrrr�iorrcrb�ImportError�__all__r�rQr�r�r�r�r�rlr�r"rrnror�r�r�rqrmrprr�r�rr�r�r0�	enumeraterr	r
rrrA�getopt�getpass�argv�optlistr�rGr��stream_command�optr�rc�getuser�USER�PASSWD�	test_mesg�	test_seq1�	test_seq2rGrErSr�r�r�rF�mlr�r�r��pathr�ry�printrDrErF�<module>r[s���
�
�,��K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�K�2�2�2�2�2�2�2�2�2�2�"�"�"�"�"�"���J�J�J��H�H�������H�H�H�����8�8�8��
��	��
�
���(����
,
��,�,
�	��,
�	�A�	,
�
	�
�,
�	�
�
,
�	�
�,
�	�,�,
�	�,�,
�	�,�,
�	�
�,
�	�,�,
�	�
�,
�	�
�,
�	�,�,
� 	�,�!,
�"	�,�#,
�$	�,�%,
�,
�&	�,�',
�(	�,�),
�*	��+,
�,	�A�-,
�.	�,�/,
�0	�
�1,
�2	�,�3,
�4	�A�5,
�6	�
�7,
�8	�	�9,
�:	�,�;,
�<	�
�=,
�>	�,�?,
�@	�,�A,
�B	�,�C,
�D	�,�E,
�F	�
�G,
�,
�H%�,�%�,�%�%�,�%�W,
�,
�,
��`�r�z�0�1�1����
�4�5�5���r�z������"�*�+�R�X�
6�
6��
�"�*�^�
$�
$����
�D�E�E�
��B�J�G�H�H���"�*�;�R�X�G�G��"��J��x�x�x�x�x�x�x�x�v#�8 �42�42�42�42�42�E�42�42�42�l�N�N�;����5�5�5�5�5�5�5�5�5�r*(�*(�*(�*(�*(�*(�*(�*(�X
<�	A�	A�#�	F�	F��
<�
<�i�i��q�r�r�
�&;�&;�
<�
<�
<�����F	�	�	�,�,�,�%�%�%�R�z������������%��
�c�h�q�r�r�l�F�;�;�
������<�����
�����������������N��2�2���C��$�;�;��C��H�H�E�E�
�D�[�[� �N��1�� 1���������7�D��7�?���D�
�W�_�_�t�t�t�T�EX�[�EX�EX�Y�
Z�
Z�F�\�gk�rv�_w�_w�w�I��t�V�n���*��
��d�D�)�4�5���)�3�,������I�$�!���
��d�D�)�,�-����I����)��	���^�,�,�A�A���d���A��7�f���!�!�"�"�
�I�	���'�!�*<�<�=�=�=�	����q�~�~�7�8�8�8�!�	�	�H�C���C��T�N�N�N�N��#�f�.�/�/�	#�	#�B����/�2�.�.�B��
(�"�(�(�1�+�+�4�4������B��$��C��4�'�"�"�"�"�!�		S�		S�H�C���#�c�4�.�.�C��D�z�7�7�7���b�'�-�-�/�/�C�� ���C�����B���P�R�
S�
S�
S�
S�	��� � � � � ��	�
��� � � ��	��E��
�h�q�k��
�
�
�
	����Q�s6�A�A�
A�>!H � 
H9�*H4�4H9�D8P�)P1

ZeroDay Forums Mini