File: //proc/thread-self/root/lib/python3/dist-packages/twisted/mail/__pycache__/imap4.cpython-38.pyc
U
��W[=9 � ( @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Zddlm
Z
ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lmZ dd
lmZ ddlmZmZ ddlmZmZ m!Z"m#Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- dd
lm.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z8m9Z:m;Z<m=Z>m?Z@mAZBmCZDmEZFmGZHmIZJ ddlKmLZLmMZMmNZNmOZOmPZP ddlQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZa ebeceddd�d�e� ��Zfdd� Zgdd� ZhG dd� dei�ZjG dd� d�ZkG dd� d�ZlG d d!� d!�ZmG d"d#� d#�Znd$Zod%�pd&d'� e
edd(�edd)d*��D ��Zqd+eo eq Zre,�rzer�sd,�ZtnerZte�ud-et d. �Zvd%�pd/d'� ewedd*��D ��ZxeeJ�G d0d1� d1ejyejz��Z{e�|� Z}eeJ�G d2d3� d3ejyejz��Z~d�d4d5�Zd6Z�d7Z�e�Z�d�d8d9�Z�d:d;� Z�d<d=� Z�d�d>d?�Z�d@dA� Z�dBdC� Z�dDdE� Z�d�dFdG�Z�dHdI� Z�dJdK� Z�G dLdM� dM�Z�dNZ�dOdP� Z�dQdR� Z�dSdT� Z�dUdV� Z�dWdX� Z�ee8�G dYdZ� dZei��Z�ee6�G d[d\� d\e���Z�d]d^d_d`dadb�Z�dcdd� Z�dedf� Z�dgdh� Z�didj� Z�dkdl� Z�dmdn� Z�dodp� Z�G dqdr� drei�Z�G dsdt� dte��Z�G dudv� dve��Z�G dwdx� dxe��Z�G dydz� dze��Z�d�d|d}�Z�d~d� Z�d�d�� Z�d�d�� Z�G d�d�� d��Z�G d�d�� d��Z�G d�d�� d��Z�d�d�� Z�e�e�d�d�d�� �Z�d�d�� Z�d�d�� Z�d�d�d��Z�d�d�d��Z�G d�d�� d�ej��Z�G d�d�� d�ej��Z�e��e�e�e�e��Z�d�d�� Z�e��e�� d1d3d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d9d=d;d\ddg(Z�dS )�a�
An IMAP4 protocol implementation
@author: Jp Calderone
To do::
Suspend idle timeout while server is processing
Use an async message parser instead of buffering in memory
Figure out a way to not queue multi-message client requests (Flow? A simple callback?)
Clarify some API docs (Query, etc)
Make APPEND recognize (again) non-existent mailboxes before accepting the literal
� N)�chain)�BytesIO)�implementer)�basic)�policies)�defer)�error)�
maybeDeferred)�log�text)
� _bytesChr�unichr�_b64decodebytes�_b64encodebytes�
intToBytes� iterbytes�long�nativeString�
networkString�unicode�_matchingString�_PY3�_get_async_param)�
interfaces)�credentials)�UnauthorizedLogin�UnhandledCredentials)�IClientAuthentication�INamespacePresenter�IAccountIMAP�IMessageIMAPPart�IMessageIMAP�IMessageIMAPFile�ISearchableIMAPMailbox�IMessageIMAPCopier�IMailboxIMAPInfo�IMailboxIMAP�ICloseableMailboxIMAP�IMailboxIMAPListener)�CramMD5ClientAuthenticator�LOGINAuthenticator�LOGINCredentials�PLAINAuthenticator�PLAINCredentials)�IMAP4Exception�IllegalClientResponse�IllegalOperation�MailboxException�IllegalMailboxEncoding�MailboxCollision�
NoSuchMailbox�ReadOnlyMailbox�UnhandledResponse�NegativeResponse�NoSupportedAuthentication�IllegalIdentifierError�IllegalQueryError�MismatchedNesting�MismatchedQuoting�IllegalServerResponse� �
z/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Decc C s | |kr|S | S )z�
Swap C{this} with C{that} if C{this} is C{ifIs}.
@param this: The object that may be replaced.
@param that: The object that may replace C{this}.
@param ifIs: An object whose identity will be compared to
C{this}.
� )�this�that�ifIsr@ r@ �4/usr/lib/python3/dist-packages/twisted/mail/imap4.py�_swapT s rE c s � �fdd�| D �S )a�
Swap each element in each pair in C{of} with C{that} it is
C{ifIs}.
@param of: A list of 2-L{tuple}s, whose members may be the object
C{that}
@type of: L{list} of 2-L{tuple}s
@param ifIs: An object whose identity will be compared to members
of each pair in C{of}
@return: A L{list} of 2-L{tuple}s with all occurences of C{ifIs}
replaced with C{that}
c s( g | ] \}}t |�� �t |�� �f�qS r@ )rE )�.0�first�second�rC rB r@ rD �
<listcomp>q s �z!_swapAllPairs.<locals>.<listcomp>r@ )ZofrB rC r@ rI rD �
_swapAllPairsb s �rK c @ s� e Zd ZdZg Zed�Zeefdd�Zdd� Ze e� � Zefdd�Z
d d
� Zdd� Zd
d� Z
dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd!S )"�
MessageSeta
A set of message identifiers usable by both L{IMAP4Client} and
L{IMAP4Server} via L{IMailboxIMAP.store} and
L{IMailboxIMAP.fetch}.
These identifiers can be either message sequence numbers or unique
identifiers. See Section 2.3.1, "Message Numbers", RFC 3501.
This represents the C{sequence-set} described in Section 9,
"Formal Syntax" of RFC 3501:
- A L{MessageSet} can describe a single identifier, e.g.
C{MessageSet(1)}
- A L{MessageSet} can describe C{*} via L{None}, e.g.
C{MessageSet(None)}
- A L{MessageSet} can describe a range of identifiers, e.g.
C{MessageSet(1, 2)}. The range is inclusive and unordered
(see C{seq-range} in RFC 3501, Section 9), so that
C{Message(2, 1)} is equivalent to C{MessageSet(1, 2)}, and
both describe messages 1 and 2. Ranges can include C{*} by
specifying L{None}, e.g. C{MessageSet(None, 1)}. In all
cases ranges are normalized so that the smallest identifier
comes first, and L{None} always comes last; C{Message(2, 1)}
becomes C{MessageSet(1, 2)} and C{MessageSet(None, 1)}
becomes C{MessageSet(1, None)}
- A L{MessageSet} can describe a sequence of single
identifiers and ranges, constructed by addition.
C{MessageSet(1) + MessageSet(5, 10)} refers the message
identified by C{1} and the messages identified by C{5}
through C{10}.
B{NB: The meaning of * varies, but it always represents the
largest number in use}.
B{For servers}: Your L{IMailboxIMAP} provider must set
L{MessageSet.last} to the highest-valued identifier (unique or
message sequence) before iterating over it.
B{For clients}: C{*} consumes ranges smaller than it, e.g.
C{MessageSet(1, 100) + MessageSet(50, None)} is equivalent to
C{1:*}.
@type getnext: Function taking L{int} returning L{int}
@ivar getnext: A function that returns the next message number,
used when iterating through the L{MessageSet}. By default, a
function returning the next integer is supplied, but as this
can be rather inefficient for sparse UID iterations, it is
recommended to supply one when messages are requested by UID.
The argument is provided as a hint to the implementation and
may be ignored if it makes sense to do so (eg, if an iterator
is being used that maintains its own state, it is guaranteed
that it will not be called out-of-order).
�infc C sX | j | _g | _dd� | _|| j kr&dS t|t�rH|dd� | _| �� n| �||� dS )z�
Create a new MessageSet()
@type start: Optional L{int}
@param start: Start of range, or only message number
@type end: Optional L{int}
@param end: End of range.
c S s | d S �Nr>