HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //usr/lib/python3.5/__pycache__/imaplib.cpython-35.pyc


Fa Y@sbdZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZm
Z
ddlmZyddlZdZWnek
rdZYnXdd	d
ddd
gZdZdZdZdZddfZdZdddfddfdddddfddfddfddfdddfdddfdddfd dfd!ddfd"dfd#dfd$ddfd%ddfd&ddfd'ddfd(ddfd)ddfd*dfdddddfd+ddfd,ddfd-ddddfd.dfd/dfd0ddfd1dfd2ddfd3ddfd4ddfd5ddfd6dfd7dfd8ddfd9dfd:ddfd;dfd<dfd=ddfi(Zejd>Zejd?Zejd@ZejdAejZ ejdBZ!ejdCZ"ejdDZ#ejdEejZ$dAZ%dEZ&GdFddZ'erGdGdHdHe'Z(ej)dHGdId	d	e'Z*GdJdKdKZ+dLj,dMZ-dNdOe.e-dPdDZ/dQd
Z0dRdZ1dSdZ2dTd
Z3e4dUkr^ddl5Z5ddl6Z6y)e5j5ej7dPddV\Z8Z9Wn:e5j:k
rZ;zfff\Z8Z9WYddZ;[;XnXdZ<xQe8D]I\Z=Z;e=dWkre>e;Zn"e=dXkre;Z<e9re<fZ9qWe9r*dYfZ9e9dZ?e6j@ZAe6j6dZeAe?pUd[fZBd\d]eAd^d_iZCd`eAeBffdadbffdcdbddffddeffdfdeddeCffdgdhdiffdjdeffdkddldmffdndodpffdqdodrdsffdtffduffdvffdwfffZDdjffdxdyffdzd1d{ffdxd|ffdfdddeCffdvffd}fffZEd~dZFye<re*e<ZGne'e?ZGeGjHdkreDdPdZDeGjIdeGjJeGjIdeGjKfx!eDD]\ZLZ9eFeLe9qWxheFdgddfD]QZMejNdeMZOeOryeOjPdPZQneMj,dPZQeFdeQfqIWx~eED]v\ZLZ9eFeLe9ZReLe9fdzd1d{ffkrqeRdPj,ZSeSrqeFdzd#deSdPdfqWeTdWn1eTderVeTdej7dYnXdS)zIMAP4 client.

Based on RFC 2060.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate
z2.58N)datetimetimezone	timedelta)DEFAULT_BUFFER_SIZETFIMAP4IMAP4_streamInternaldate2tupleInt2AP
ParseFlagsTime2Internaldates
iZ	IMAP4REV1i@BAPPENDAUTHSELECTEDAUTHENTICATENONAUTH
CAPABILITYLOGOUTCHECKCLOSECOPYCREATEDELETE	DELETEACLENABLEEXAMINEEXPUNGEFETCHGETACL
GETANNOTATIONGETQUOTAGETQUOTAROOTMYRIGHTSLISTLOGINLSUB	NAMESPACENOOPPARTIAL	PROXYAUTHRENAMESEARCHSELECTSETACL
SETANNOTATIONSETQUOTASORTSTARTTLSSTATUSSTORE	SUBSCRIBETHREADUIDUNSUBSCRIBEs\+( (?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@seZdZdZGdddeZGdddeZGdddeZded	d
Z	ddZ
d
dZddZddZ
ddZddZddZdeddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Z d9d:Z!d;d<Z"d=d>Z#d?d@Z$dAdBZ%dCdDZ&dEdFZ'dGdHZ(dIdJdKdLZ)dMdNZ*dOdPZ+dQdRZ,dSdTZ-dIdJdUdVZ.dWdXZ/dYdZZ0d[d\Z1d]d^Z2d_d`Z3dadbZ4dcddZ5dedfdgdhZ6didjZ7dkdlZ8dmdnZ9dodpZ:dqdrdsZ;dtduZ<dvdwZ=dxdyZ>dzd{Z?d|d}Z@d~dZAddZBddZCddZDddZEddZFddZGddZHddZIddZJddZKddZLddZMddZNddZOdqddZPddZQddZRddZSdqS)raIMAP4 client class.

    Instantiate with: IMAP4([host[, port]])

            host - host's name (default: localhost);
            port - port number (default: standard IMAP4 port).

    All IMAP4rev1 commands are supported by methods of the same
    name (in lower-case).

    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@seZdZdS)zIMAP4.errorN)__name__
__module____qualname__r;r;/usr/lib/python3.5/imaplib.pyerrorsr=c@seZdZdS)zIMAP4.abortN)r8r9r:r;r;r;r<abortsr>c@seZdZdS)zIMAP4.readonlyN)r8r9r:r;r;r;r<readonlysr?cCst|_d|_d|_i|_i|_d|_d|_d|_d|_	|j
|j||y|jWn8t
k
ry|jWntk
rYnXYnXdS)Nrr@Fr)Debugdebugstateliteraltagged_commandsuntagged_responsescontinuation_responseis_readonlytagnum_tls_established_mode_asciiopen_connect	ExceptionshutdownOSError)selfhostportr;r;r<__init__s&									


zIMAP4.__init__cCsFd|_d|_tjttj|_tjttj|_dS)NFascii)	utf8_enabled	_encodingrecompile_LiteralASCIILiteral_Untagged_statusUntagged_status)rQr;r;r<rKs		zIMAP4._mode_asciicCs:d|_d|_tjt|_tjt|_dS)NTzutf-8)rVrWrXrYrZr\r]r^)rQr;r;r<
_mode_utf8s		zIMAP4._mode_utf8cCsTttjdd|_tjd|jdtj|_d|_d|_	i|_
|jdkr|jdt
|jd	|j|j|_d
|jkrd|_n-d|jkrd
|_n|j|j|j|jdkr|jd|jfx*tD]"}||jkr3q||_dSW|jddS)Niis(?P<tag>s"\d+) (?P<type>[A-Z]+) (?P<data>.*)
rzimaplib version %sznew IMAP4 connection, tag=%sZPREAUTHrOKrzCAPABILITIES: %rzserver not IMAP4 compliant)r	randomZrandinttagprerXrYr[tagre_cmd_log_len_cmd_log_idx_cmd_logrB_mesg__version__
_get_responseZwelcomerFrCr=_get_capabilitiescapabilitiesAllowedVersionsPROTOCOL_VERSION)rQversionr;r;r<rMs0			

	zIMAP4._connectcCs3|tkrt||jStd|dS)NzUnknown IMAP4 command: '%s')CommandsgetattrlowerAttributeError)rQattrr;r;r<__getattr__szIMAP4.__getattr__cCs|S)Nr;)rQr;r;r<	__enter__szIMAP4.__enter__cGs'y|jWntk
r"YnXdS)N)logoutrP)rQargsr;r;r<__exit__	s
zIMAP4.__exit__cCstj|j|jfS)N)socketZcreate_connectionrRrS)rQr;r;r<_create_socketszIMAP4._create_socketcCs:||_||_|j|_|jjd|_dS)zSetup 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)rRrSr}sockmakefilefile)rQrRrSr;r;r<rLs		z
IMAP4.opencCs|jj|S)zRead 'size' bytes from remote.)rread)rQsizer;r;r<r"sz
IMAP4.readcCs?|jjtd}t|tkr;|jdt|S)zRead line from remote.razgot more than %d bytes)rreadline_MAXLINElenr=)rQliner;r;r<r'szIMAP4.readlinecCs|jj|dS)zSend data to remote.N)rZsendall)rQdatar;r;r<send/sz
IMAP4.sendcCsz|jjzXy|jjtjWn:tk
rc}z|jtjkrQWYdd}~XnXWd|jjXdS)z Close I/O established in "open".N)	rcloserrOr|Z	SHUT_RDWRrPerrnoZENOTCONN)rQer;r;r<rO4s
zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server.

        socket = <instance>.socket()
        )r)rQr;r;r<r|AszIMAP4.socketcCs]d}|jddg|\}}|dr8||fS|j\}}|j|||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.
        ZRECENTrbNra)_untagged_responsenoop)rQnametypdatr;r;r<recentMs	

zIMAP4.recentcCs|j|dg|jS)zReturn data for response 'code' if received, or None.

        Old value for response 'code' is cleared.

        (code, [data]) = <instance>.response(code)
        N)rupper)rQcoder;r;r<response^szIMAP4.responsecCsd}|sd}|r?|d|dfdkrEd|}nd}|rZt|}nd}tjt|}|jrd	|d
}||_|j||||S)
zAppend message to named mailbox.

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

                All args except `message' can be None.
        r
INBOXrra()z(%s)NsUTF8 ()r)rr)rMapCRLFsubCRLFrVrD_simple_command)rQmailboxflags	date_timemessagerrDr;r;r<appendls
		zIMAP4.appendcCst|j}t|j|_|jd|\}}|dkra|j|djddd|_||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.
        rrbrazutf-8replacerr)r_AuthenticatorprocessrDrr=decoderC)rQZ	mechanismZ
authobjectmechrrr;r;r<authenticates	zIMAP4.authenticatecCs.d}|j|\}}|j|||S)zT(typ, [data]) = <instance>.capability()
        Fetch capabilities list from server.r)rr)rQrrrr;r;r<
capabilityszIMAP4.capabilitycCs
|jdS)zRCheckpoint mailbox on server.

        (typ, [data]) = <instance>.check()
        r)r)rQr;r;r<checkszIMAP4.checkcCs0z|jd\}}Wdd|_X||fS)zClose currently selected mailbox.

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

        (typ, [data]) = <instance>.close()
        rNr)rrC)rQrrr;r;r<rs
zIMAP4.closecCs|jd||S)zCopy 'message_set' messages onto end of 'new_mailbox'.

        (typ, [data]) = <instance>.copy(message_set, new_mailbox)
        r)r)rQmessage_setZnew_mailboxr;r;r<copysz
IMAP4.copycCs|jd|S)zPCreate new mailbox.

        (typ, [data]) = <instance>.create(mailbox)
        r)r)rQrr;r;r<createszIMAP4.createcCs|jd|S)zPDelete old mailbox.

        (typ, [data]) = <instance>.delete(mailbox)
        r)r)rQrr;r;r<deleteszIMAP4.deletecCs|jd||S)zDelete the ACLs (remove any rights) set for who on mailbox.

        (typ, [data]) = <instance>.deleteacl(mailbox, who)
        r)r)rQrwhor;r;r<	deleteaclszIMAP4.deleteaclcCshd|jkrtjd|jd|\}}|dkr^d|jkr^|j||fS)zkSend an RFC5161 enable string to the server.

        (typ, [data]) = <intance>.enable(capability)
        rzServer does not support ENABLErbzUTF8=ACCEPT)rnrr=rrr_)rQrrrr;r;r<enables
zIMAP4.enablecCs.d}|j|\}}|j|||S)zPermanently 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.
        r)rr)rQrrrr;r;r<expunges	z
IMAP4.expungecCs4d}|j|||\}}|j|||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)rr)rQrZ
message_partsrrrr;r;r<fetchs
zIMAP4.fetchcCs+|jd|\}}|j||dS)zXGet the ACLs for a mailbox.

        (typ, [data]) = <instance>.getacl(mailbox)
        rZACL)rr)rQrrrr;r;r<getacl
szIMAP4.getaclcCs1|jd|||\}}|j||dS)za(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
        Retrieve ANNOTATIONs.r
ANNOTATION)rr)rQrentryZ	attributerrr;r;r<
getannotationszIMAP4.getannotationcCs+|jd|\}}|j||dS)zGet the quota root's resource usage and limits.

        Part of the IMAP4 QUOTA extension defined in rfc2087.

        (typ, [data]) = <instance>.getquota(root)
        r QUOTA)rr)rQrootrrr;r;r<getquotaszIMAP4.getquotacCs^|jd|\}}|j||d\}}|j||d\}}|||gfS)zGet the list of quota roots for the named mailbox.

        (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = <instance>.getquotaroot(mailbox)
        r!rZ	QUOTAROOT)rr)rQrrrZquotaZ	quotarootr;r;r<getquotaroot&szIMAP4.getquotarootz""*cCs4d}|j|||\}}|j|||S)zList mailbox names in directory matching pattern.

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

        'data' is list of LIST responses.
        r#)rr)rQ	directorypatternrrrr;r;r<list1sz
IMAP4.listcCsV|jd||j|\}}|dkrC|j|dd|_||fS)zIdentify client using plaintext password.

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

        NB: 'password' will be quoted.
        r$rbrarr)r_quoter=rC)rQuserpasswordrrr;r;r<login=s
$	zIMAP4.logincCs&|||_|_|jd|jS)zr Force use of CRAM-MD5 authentication.

        (typ, [data]) = <instance>.login_cram_md5(user, password)
        zCRAM-MD5)rrr_CRAM_MD5_AUTH)rQrrr;r;r<login_cram_md5KszIMAP4.login_cram_md5cCs]ddl}t|jtr0|jjdn|j}|jd|j||djS)z1 Authobject to use with CRAM-MD5 authentication. rNzutf-8 Zmd5)hmac
isinstancerstrencoderZHMACZ	hexdigest)rQZ	challengerpwdr;r;r<rTs$	zIMAP4._CRAM_MD5_AUTHcCsd|_y|jd\}}Wn,ddtjddg}}YnX|jd|jkr{d|jdfS||fS)z|Shutdown connection to server.

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

        Returns server 'BYE' response.
        rNOz%s: %sNBYE)rCrsysexc_inforOrF)rQrrr;r;r<ry\s	)
zIMAP4.logoutcCs4d}|j|||\}}|j|||S)zList 'subscribed' mailbox names in directory matching pattern.

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

        'data' are tuples of message part envelope and data.
        r%)rr)rQrrrrrr;r;r<lsublsz
IMAP4.lsubcCs+|jd|\}}|j||dS)zShow my ACLs for a mailbox (i.e. the rights that I have on mailbox).

        (typ, [data]) = <instance>.myrights(mailbox)
        r")rr)rQrrrr;r;r<myrightswszIMAP4.myrightscCs.d}|j|\}}|j|||S)zb Returns IMAP namespaces ala rfc2342

        (typ, [data, ...]) = <instance>.namespace()
        r&)rr)rQrrrr;r;r<	namespaceszIMAP4.namespacecCs,|jdkr|j|j|jdS)zFSend NOOP command.

        (typ, [data]) = <instance>.noop()
        rcr')rB_dump_urrFr)rQr;r;r<rsz
IMAP4.noopcCs:d}|j|||||\}}|j||dS)zFetch 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)rr)rQZmessage_numZmessage_partstartZlengthrrrr;r;r<partials!z
IMAP4.partialcCsd}|jd|S)zAssume authentication as "user".

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

        (typ, [data]) = <instance>.proxyauth(user)
        r))r)rQrrr;r;r<	proxyauths	zIMAP4.proxyauthcCs|jd||S)zkRename old mailbox name to new.

        (typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
        r*)r)rQZ
oldmailboxZ
newmailboxr;r;r<renameszIMAP4.renamecGspd}|rE|jr$tjd|j|d||\}}n|j||\}}|j|||S)zSearch 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 modeCHARSET)rVrr=rr)rQcharsetZcriteriarrrr;r;r<searchs	!zIMAP4.searchrFcCsi|_||_|r!d}nd}|j||\}}|dkr^d|_||fSd|_d|jkr|r|jdkr|j|j|jd|||jjd	d
gfS)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.
        rr,rbrrz	READ-ONLYraz%s is not writableEXISTSN)rFrHrrCrBrr?get)rQrr?rrrr;r;r<selects 				
	zIMAP4.selectcCs|jd|||S)zZSet a mailbox acl.

        (typ, [data]) = <instance>.setacl(mailbox, who, what)
        r-)r)rQrrZwhatr;r;r<setaclszIMAP4.setaclcGs+|jd|\}}|j||dS)z_(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
        Set ANNOTATIONs.r.r)rr)rQrzrrr;r;r<
setannotationszIMAP4.setannotationcCs.|jd||\}}|j||dS)ziSet the quota root's resource limits.

        (typ, [data]) = <instance>.setquota(root, limits)
        r/r)rr)rQrZlimitsrrr;r;r<setquotaszIMAP4.setquotacGs[d}|d|dfdkr*d|}|j||||\}}|j|||S)	zIMAP4rev1 extension SORT command.

        (typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
        r0rrarrz(%s)r)rr)rr)rQZ
sort_criteriarsearch_criteriarrrr;r;r<sorts

z
IMAP4.sortNcCsd}ts|jd|jr3|jd||jkrQ|jd|dkritj}|j|\}}|dkr|j|j	d|j
|_	|j	jd|_d|_|j
n|jd	|j|||S)
Nr1zSSL support missingzTLS session already establishedzTLS not supported by serverrbserver_hostnamer~TzCouldn't establish TLS session)HAVE_SSLr=rJr>rnssl_create_stdlib_contextrwrap_socketrrRrrrmr)rQssl_contextrrrr;r;r<starttlss$		
zIMAP4.starttlscCs4d}|j|||\}}|j|||S)zpRequest named status conditions for mailbox.

        (typ, [data]) = <instance>.status(mailbox, names)
        r2)rr)rQrnamesrrrr;r;r<status%szIMAP4.statuscCsU|d|dfd	kr$d|}|jd|||\}}|j||dS)
zAlters flag dispositions for messages in mailbox.

        (typ, [data]) = <instance>.store(message_set, command, flags)
        rrarrz(%s)r3rr)rr)rr)rQrcommandrrrr;r;r<store1s
zIMAP4.storecCs|jd|S)zYSubscribe to new mailbox.

        (typ, [data]) = <instance>.subscribe(mailbox)
        r4)r)rQrr;r;r<	subscribe<szIMAP4.subscribecGs7d}|j||||\}}|j|||S)zIMAPrev1 extension THREAD command.

        (type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
        r5)rr)rQZthreading_algorithmrrrrrr;r;r<threadDszIMAP4.threadcGs|j}|tkr+|jd||jt|krj|jd||jdjt|fd}|j|||\}}|d	kr|}nd}|j|||S)
zExecute "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: %sz9command %s illegal in state %s, only allowed in states %sz, r6r+r0r5r)r+r0r5)rrrr=rCjoinrr)rQrrzrrrr;r;r<uidNs			z	IMAP4.uidcCs|jd|S)z_Unsubscribe from old mailbox.

        (typ, [data]) = <instance>.unsubscribe(mailbox)
        r7)r)rQrr;r;r<unsubscribegszIMAP4.unsubscribecGs8|j}|tkr(|jft|<|j||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'.
        )rrrrCr)rQrrzr;r;r<xatomos
zIMAP4.xatomcCs|dkrd}|j}|jdkrV|jd|t|j|d|f||krv||j|n
|g||<dS)Nz#untagged_responses[%s] %s += ["%r"]r@)rFrBrjrrr)rQrrZurr;r;r<_append_untaggeds		#zIMAP4._append_untaggedcCs>|jjd}|r:|j|dj|jddS)Nrrarr)rFrr>rrW)rQZbyer;r;r<
_check_byeszIMAP4._check_byec
Gs|jt|krHd|_|jd||jdjt|fx'dD]}||jkrO|j|=qOWd|jkr|jr|jd|j}t	||j
}|d|}xL|D]D}|dkrqt|trt	||j
}|d|}qW|j}|dk	r}d|_t
|t
|jkrW|}n&d}|t	d	t||j
}|jd
kr|jd|n|jd|y|j|tWn8tk
r}	z|jd|	WYdd}	~	XnX|dkr|Sxx!|jr7|j|r|SqW|rM||j}|jd
krs|jd
t|y|j||jtWn8tk
r}	z|jd|	WYdd}	~	XnX|sPqW|S)Nz9command %s illegal in state %s, only allowed in states %sz, rbrBADz	READ-ONLYz#mailbox status changed to READ-ONLY z {%s}z> %rzsocket error: %szwrite literal size %s)rbrr)rCrrrDr=rrFrHr?_new_tagbytesrWrrtype_commandrrBrj_logrrrPr>rlrErG)
rQrrzrtagrargrDZ	literatorvalr;r;r<rsh			


			 &

&zIMAP4._commandcCs|dkr|jy|j|\}}Wn|jk
rr}z|jd||fWYdd}~XnA|jk
r}z|jd||fWYdd}~XnX|dkr|j|dkr|jd|||f||fS)Nrzcommand: %s => %srz%s command error: %s %s)r_get_tagged_responser>r=)rQrrrrrr;r;r<_command_completes
+,
zIMAP4._command_completecCsk|j\}}|dgkr0|jdt|d|j}|j}t|j|_dS)Nz"no CAPABILITY response from serverrar)rr=rrWrtuplesplitrn)rQrrr;r;r<rmszIMAP4._get_capabilitiescCs|j}|j|j|r|jjd}||jkrU|jd||jjd}t||j}|jjd}||gf|j|<n}d}|jt	|s|j|j
|r|jjd}|jdkr0|jt|r|jjd|_dS|jd||jjd}t||j}|jjd}|dkrxd}|r|d|}x|j|j
|rt|jjd	}|jd
kr|jd||j|}|j|||f|j}qW|j|||dkr|jt|r|jjd}t||j}|j||jjd|jdkr|dkr|jd||f|S)Nrzunexpected tagged response: %rrrZdata2zunexpected response: %rrrrrzread literal size %srbrrrarz%s response: %r)rbrr)rrr)	_get_line_matchrfmogrouprEr>rrWUntagged_responser^ContinuationrGr\intrBrjrr
Response_code)rQresprrrZdat2rrr;r;r<rlsPzIMAP4._get_responsecCsx|j|}|dk	r*|j|=|S|jy|jWq|jk
r}z!|jdkrs|jWYdd}~XqXqWdS)Nra)rErrlr>rB	print_log)rQrresultrr;r;r<rPs



zIMAP4._get_tagged_responsecCs|j}|s!|jd|jdsC|jd||dd}|jdkrv|jd|n|jd||S)Nzsocket error: EOFs
z#socket error: unterminated line: %rrrz< %r)rr>endswithrBrjr)rQrr;r;r<r	kszIMAP4._get_linecCs`|j||_|jdk	rS|jdkrS|jd|j|jjf|jdk	S)Nrz	matched r'%r' => %r)matchrrBrjrgroups)rQZcresr;r;r<r
~s#zIMAP4._matchcCsC|jtt|j|j}|jd|_d|j|<|S)Nra)rerrrIrWrE)rQrr;r;r<rs"
zIMAP4._new_tagcCs0|jdd}|jdd}d|dS)N\z\\"z\")r)rQrr;r;r<rszIMAP4._quotecGs|j||j||S)N)rr)rQrrzr;r;r<rszIMAP4._simple_commandcCst|dkr||fS||jkr2|dgfS|jj|}|jdkrj|jd||f||fS)Nrrzuntagged_responses[%s] => %s)rFpoprBrj)rQrrrrr;r;r<rs

zIMAP4._untagged_responsecCsi|dkrtj}tjdtj|}tjjd||dd|ftjjdS)Nz%M:%Sz
  %s.%02d %s
d)timestrftime	localtimerstderrwriteflush)rQrZsecsZtmr;r;r<rjs
%zIMAP4._mesgcCsU|j}|sdSd}tdd|}|jd||j|fdS)Nz
		cSs3d|d|ddr+dj|dp.dfS)Nz%s: "%s"rraz" "r@)r)xr;r;r<<lambda>sz IMAP4._dump_ur.<locals>.<lambda>zuntagged responses dump:%s%s)itemsmaprjr)rQdictltr;r;r<rszIMAP4._dump_urcCsJ|tjf|j|j<|jd7_|j|jkrFd|_dS)Nrar)rrirhrg)rQrr;r;r<rsz
IMAP4._logc	Cs|jdt|j|j|j}}xV|ry|j|j|WnYnX|d7}||jkrxd}|d8}q0WdS)Nzlast %d IMAP4 interactions:rar)rjrrirhrg)rQinr;r;r<rs	
zIMAP4.print_log)Tr8r9r:__doc__rNr=r>r?
IMAP4_PORTrTrKr_rMrwrxr{r}rLrrrrOr|rrrrrrrrrrrrrrrrrrrrrrryrrrrrrrrrrrrrrrrrrrrrrrrrrmrlrr	r
rrrrrjrrrr;r;r;r<r}s,*

			

 	
M	Pc@sOeZdZdZdedddddZddZdedd	ZdS)
	IMAP4_SSLa3IMAP4 client class over SSL connection

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

                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.

        for more documentation see the docstring of the parent class IMAP4.
        r@NcCs|dk	r$|dk	r$td|dk	rH|dk	rHtd||_||_|dkr~tjd|d|}||_tj|||dS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusivecertfilekeyfile)
ValueErrorr0r/rrrrrT)rQrRrSr0r/rr;r;r<rTs				zIMAP4_SSL.__init__cCs(tj|}|jj|d|jS)Nr)rr}rrrR)rQrr;r;r<r}szIMAP4_SSL._create_socketcCstj|||dS)zSetup 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)rrL)rQrRrSr;r;r<rLszIMAP4_SSL.open)r8r9r:r,IMAP4_SSL_PORTrTr}rLr;r;r;r<r.s
	r.c@sdeZdZdZddZddddZddZd	d
ZddZd
dZ	dS)rzIMAP4 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.
    cCs||_tj|dS)N)rrrT)rQrr;r;r<rTs	zIMAP4_stream.__init__NcCsd|_d|_d|_d|_tj|jdtdtjdtjdddd|_	|j	j
|_|j	j|_
dS)zSetup a stream connection.
        This connection will be used by the routines:
            read, readline, send, shutdown.
        NbufsizestdinstdoutshellTZ	close_fds)rRrSrr
subprocessPopenrrPIPErr4	writefiler5readfile)rQrRrSr;r;r<rLs				zIMAP4_stream.opencCs|jj|S)zRead 'size' bytes from remote.)r;r)rQrr;r;r<r(szIMAP4_stream.readcCs
|jjS)zRead line from remote.)r;r)rQr;r;r<r-szIMAP4_stream.readlinecCs!|jj||jjdS)zSend data to remote.N)r:r!r")rQrr;r;r<r2szIMAP4_stream.sendcCs+|jj|jj|jjdS)z Close I/O established in "open".N)r;rr:rwait)rQr;r;r<rO8s

zIMAP4_stream.shutdown)
r8r9r:r,rTrLrrrrOr;r;r;r<rs	c@sFeZdZdZddZddZddZdd	Zd
S)rzcPrivate class to provide en/decoding
            for base64-based authentication conversation.
    cCs
||_dS)N)r)rQZmechinstr;r;r<rTFsz_Authenticator.__init__cCs5|j|j|}|dkr(dS|j|S)N*)rrr)rQrZretr;r;r<rIsz_Authenticator.processcCsd}t|tr$|jd}xt|rt|dkrb|dd}|dd}n|}d}tj|}|r'||dd}q'W|S)Nrzutf-80rar)rrrrbinasciiZ
b2a_base64)rQinpZoupr)rr;r;r<rOs		z_Authenticator.encodecCs|s
dStj|S)Nr)r?Z
a2b_base64)rQr@r;r;r<rgsz_Authenticator.decodeN)r8r9r:r,rTrrrr;r;r;r<r@s
rz0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrcCs)i|]\}}|d|jqS)ra)r).0r+rr;r;r<
<dictcomp>ms	rBrac	Cs4tj|}|sdSt|jd}|jd}t|jd}t|jd}t|jd}t|jd}t|jd}t|jd	}	t|jd
}
|	d|
d}|dkr|}||||||dddf	}tj||}
tj|
S)zParse 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.
    Nmonzonendayyearhourminseczonehzonem<-rarrr)	InternalDaterMon2numrrcalendarZtimegmrr)rrrCrDrErFrGrHrIrJrKZzoneZttutcr;r;r<ros$!cCs\d}d}tt|}x7|rWt|d\}}|||d|}q!W|S)z-Convert integer to A-P string representation.rsABCDEFGHIJKLMNOPra)rabsdivmod)ZnumrZAPmodr;r;r<r	s	cCs2tj|}|sfSt|jdjS)z-Convert IMAP4 flags response to python tuple.r)Flagsrrrr)rrr;r;r<r
sc
Cst|ttfr3tj|tjj}n0t|try
|j	}Wnqt
k
rtjr|d}|dkrtj
tj|d}tjtjf|}n
tj}YnXtd|}t|dddt|}nlt|tr*|jdkr!td|}n9t|trW|d|d
fdkrW|Std
djt|j}|j|S)aConvert 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.
    raZsecondsNtzinfozdate_time must be awarerrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"rr)rr)rrfloatrZ
fromtimestamprrQZ
astimezonerZ	tm_gmtoffrurZdaylightrZmktimeZaltzonerrYr1rformatMonthsZmonthr)rZdtZgmtoffZdstZdeltaZfmtr;r;r<rs0	

	
%	)__main__zd:s:z-dz-sr@zIMAP password for %s on %s: Z	localhostzJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)srZlf
rrz
/tmp/xxx 1rz/tmp/yyyz
/tmp/yyz 2rrz/tmpzyy*rrZSUBJECTZtestr1z(FLAGS INTERNALDATE RFC822)rFLAGSz
(\Deleted)rrrrrZUIDVALIDITYrZALLrrycCsftjd||ftt||\}}tjd|||f|dkrb|d|S)Nz%s %sz%s => %s %srr)Mrjrs)cmdrzrrr;r;r<runs
rczPROTOCOL_VERSION = %szCAPABILITIES = %rz/tmp/zyy%z.*"([^"]+)"$rz%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,rkr?rrdrXr|r7rrrPrrriorrrImportError__all__rrAr-r2rorrrrYrrVrNr[r\rrr
r^rZr]rr.rrrrr\	enumeraterOrr	r
rr8ZgetoptZgetpassargvZoptlistrzr=rZstream_commandZoptrrRZgetuserZUSERZPASSWDZ	test_mesgZ	test_seq1Z	test_seq2rcrarCrjrprnrbZmlrrrpathrrprintr;r;r;r<<module>s<l

																		X1
9,##
))%