Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/imaplib.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@sdZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	dddddd	gZ
d
ZdZdZ
d
ZddfZdZi&ddfd6dfd6ddddfd6dfd6dfd6dfd6ddfd6ddfd6ddfd6ddfd6dfd6dfd6ddfd 6ddfd!6ddfd"6ddfd#6ddfd$6ddfd%6dfd&6ddddfd6ddfd'6ddfd(6ddddfd)6dfd*6dfd+6ddfd,6dfd-6ddfd.6ddfd/6ddfd06ddfd16dfd26ddfd36dfd46ddfd56dfd66dfd76ddfd86Zejd9�Zejd:�Zejd;�Zejd<�Zejd=�Zejd>�Zejd?�Zejd@�ZdfdA��YZyddlZWnek
r8n$XdBefdC��YZe
jdB�defdD��YZ dEfdF��YZ!idGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6dUdV6dWdX6dYdZ6d[d\6d]d^6Z"d_�Z#d`�Z$da�Z%db�Z&e'dckrddl(Z(ddl)Z)y#e(j(ej*dGdd�\Z+Z,Wn(e(j-k
rtZ.fff\Z+Z,nXe/Z0xWe+D]O\Z1Z.e1dekr�e2e.�Zn(e1dfkr�e.Z0e,r�e0fZ,nnq�We,r�gfZ,ne,dZ3e)j4�Z5e)j)dhe5e3pdif�Z6djie5dk6dldm6Z7dne5e6ffdodpffdqdpdrffddsffdtdse/e/e7ffdudvdwffdxdsffdye/dzd{ffd|d}d~ffdd}d�d�ffd�ffd�ffd�ffd�fffZ8dxffd�d�ffd�d-d�ffd�d�ffdte/e/e/e7ffd�ffd�fffZ9d��Z:y�e0rve e0�Z;nee3�Z;e;j<dkr�e8dGZ8ne;j=d�e;j>�e;j=d�e;j?f�x!e8D]\Z@Z,e:e@e,�q�Wxge:dud�d�f�D]PZAejBd�eA�ZCeCr3eCjDdG�ZEneAjF�dZEe:d�eEf�qWx�e9D]z\Z@Z,e:e@e,�ZGe@e,fd�d-d�ffkr�q^neGdjF�ZHeHr�q^ne:d�dd�eHdd�f�q^Wd�GHWn)d�GHerd�ej*dGHn�nXndS(�s�IMAP4 client.

Based on RFC 2060.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate
s2.58i�NtIMAP4tIMAP4_streamtInternaldate2tupletInt2APt
ParseFlagstTime2Internaldates
ii�i�t	IMAP4REV1i'tAUTHtSELECTEDtAPPENDtNONAUTHtAUTHENTICATEtLOGOUTt
CAPABILITYtCHECKtCLOSEtCOPYtCREATEtDELETEt	DELETEACLtEXAMINEtEXPUNGEtFETCHtGETACLt
GETANNOTATIONtGETQUOTAtGETQUOTAROOTtMYRIGHTStLISTtLOGINtLSUBt	NAMESPACEtNOOPtPARTIALt	PROXYAUTHtRENAMEtSEARCHtSELECTtSETACLt
SETANNOTATIONtSETQUOTAtSORTtSTATUStSTOREt	SUBSCRIBEtTHREADtUIDtUNSUBSCRIBEs\+( (?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>.*))?cBs�eZdZdefd��YZdefd��YZdefd��YZejd�Z	de
d	�Zd
�Zde
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"d#d$�Z$d%�Z%d&�Z&d'�Z'd(�Z(d"d#d)�Z)d*�Z*d+�Z+d,�Z,d-�Z-d.�Z.d/�Z/d0�Z0d1e1d2�Z2d3�Z3d4�Z4d5�Z5d6�Z6d7�Z7d8�Z8d9�Z9d:�Z:d;�Z;d<�Z<d=�Z=d>�Z>d?�Z?d@�Z@dA�ZAdB�ZBdC�ZCdD�ZDdE�ZEdF�ZFdG�ZGdH�ZHdI�ZIdJ�ZJRS(Ks�IMAP4 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.
    terrorcBseZRS((t__name__t
__module__(((s/sys/lib/python2.7/imaplib.pyR0�stabortcBseZRS((R1R2(((s/sys/lib/python2.7/imaplib.pyR3�streadonlycBseZRS((R1R2(((s/sys/lib/python2.7/imaplib.pyR4�ss[^\w!#$%&'*+,.:;<=>?^`|~-]tcCs|t|_d|_d|_i|_i|_d|_t|_	d|_
|j||�tt
jdd��|_tjd|jd�|_|j�|_d|jkr�d	|_n-d
|jkr�d|_n|j|j��|j�\}}|dgkr|jd��nt|d
j�j��|_x-tD]%}||jkr[q@n||_dSW|jd��dS(NRR5iii�s(?P<tag>s"\d+) (?P<type>[A-Z]+) (?P<data>.*)tPREAUTHRtOKR
s"no CAPABILITY response from serveri�sserver not IMAP4 compliant(tDebugtdebugtstatetNonetliteralttagged_commandstuntagged_responsestcontinuation_responsetFalsetis_readonlyttagnumtopenRtrandomtrandintttagpretretcompilettagret
_get_responsetwelcomeR0t
capabilityttupletuppertsplittcapabilitiestAllowedVersionstPROTOCOL_VERSION(tselfthosttportttyptdattversion((s/sys/lib/python2.7/imaplib.pyt__init__�s8								

	cCs3|tkrt||j��Std|��dS(NsUnknown IMAP4 command: '%s'(tCommandstgetattrtlowertAttributeError(RStattr((s/sys/lib/python2.7/imaplib.pyt__getattr__�scCsC||_||_tj||f�|_|jjd�|_dS(s�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.
        trbN(RTRUtsockettcreate_connectiontsocktmakefiletfile(RSRTRU((s/sys/lib/python2.7/imaplib.pyRC�s		cCs|jj|�S(sRead 'size' bytes from remote.(Retread(RStsize((s/sys/lib/python2.7/imaplib.pyRf�scCsB|jjtd�}t|�tkr>|jdt��n|S(sRead line from remote.isgot more than %d bytes(Retreadlinet_MAXLINEtlenR0(RStline((s/sys/lib/python2.7/imaplib.pyRh�scCs|jj|�dS(sSend data to remote.N(Rctsendall(RStdata((s/sys/lib/python2.7/imaplib.pytsend�scCsn|jj�zLy|jjtj�Wn.tjk
rW}|jtjkrX�qXnXWd|jj�XdS(s Close I/O established in "open".N(	RetcloseRctshutdownRat	SHUT_RDWRR0terrnotENOTCONN(RSte((s/sys/lib/python2.7/imaplib.pyRps
cCs|jS(sfReturn socket instance used to connect to IMAP4 server.

        socket = <instance>.socket()
        (Rc(RS((s/sys/lib/python2.7/imaplib.pyRascCs]d}|jddg|�\}}|dr8||fS|j�\}}|j|||�S(sReturn 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.
        tRECENTR7i�N(t_untagged_responseR;tnoop(RStnameRVRW((s/sys/lib/python2.7/imaplib.pytrecents	

cCs|j|dg|j��S(s�Return data for response 'code' if received, or None.

        Old value for response 'code' is cleared.

        (code, [data]) = <instance>.response(code)
        N(RvR;RN(RStcode((s/sys/lib/python2.7/imaplib.pytresponse.scCs�d}|sd}n|rE|d|dfdkrKd|}qKnd	}|r`t|�}nd	}tjt|�|_|j||||�S(
s�Append message to named mailbox.

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

                All args except `message' can be None.
        R	tINBOXii�t(t)s(%s)(R}R~N(R;RtMapCRLFtsubtCRLFR<t_simple_command(RStmailboxtflagst	date_timetmessageRx((s/sys/lib/python2.7/imaplib.pytappend<s	cCsk|j�}t|�j|_|jd|�\}}|dkrX|j|d��nd|_||fS(s,Authenticate 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.
        It should return data that will be encoded and sent to server.
        It should return None if the client abort response '*' should
        be sent instead.
        RR7i�R(RNt_AuthenticatortprocessR<R�R0R:(RSt	mechanismt
authobjecttmechRVRW((s/sys/lib/python2.7/imaplib.pytauthenticateSs	cCs.d}|j|�\}}|j|||�S(sT(typ, [data]) = <instance>.capability()
        Fetch capabilities list from server.R
(R�Rv(RSRxRVRW((s/sys/lib/python2.7/imaplib.pyRLpscCs
|jd�S(sRCheckpoint mailbox on server.

        (typ, [data]) = <instance>.check()
        R(R�(RS((s/sys/lib/python2.7/imaplib.pytcheckyscCs0z|jd�\}}Wdd|_X||fS(s�Close currently selected mailbox.

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

        (typ, [data]) = <instance>.close()
        RNR(R�R:(RSRVRW((s/sys/lib/python2.7/imaplib.pyRo�s
cCs|jd||�S(s�Copy 'message_set' messages onto end of 'new_mailbox'.

        (typ, [data]) = <instance>.copy(message_set, new_mailbox)
        R(R�(RStmessage_settnew_mailbox((s/sys/lib/python2.7/imaplib.pytcopy�scCs|jd|�S(sPCreate new mailbox.

        (typ, [data]) = <instance>.create(mailbox)
        R(R�(RSR�((s/sys/lib/python2.7/imaplib.pytcreate�scCs|jd|�S(sPDelete old mailbox.

        (typ, [data]) = <instance>.delete(mailbox)
        R(R�(RSR�((s/sys/lib/python2.7/imaplib.pytdelete�scCs|jd||�S(s�Delete the ACLs (remove any rights) set for who on mailbox.

        (typ, [data]) = <instance>.deleteacl(mailbox, who)
        R(R�(RSR�twho((s/sys/lib/python2.7/imaplib.pyt	deleteacl�scCs.d}|j|�\}}|j|||�S(s�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.
        R(R�Rv(RSRxRVRW((s/sys/lib/python2.7/imaplib.pytexpunge�s	cCs4d}|j|||�\}}|j|||�S(s#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�Rv(RSR�t
message_partsRxRVRW((s/sys/lib/python2.7/imaplib.pytfetch�s
cCs+|jd|�\}}|j||d�S(sXGet the ACLs for a mailbox.

        (typ, [data]) = <instance>.getacl(mailbox)
        RtACL(R�Rv(RSR�RVRW((s/sys/lib/python2.7/imaplib.pytgetacl�scCs1|jd|||�\}}|j||d�S(sa(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
        Retrieve ANNOTATIONs.Rt
ANNOTATION(R�Rv(RSR�tentryt	attributeRVRW((s/sys/lib/python2.7/imaplib.pyt
getannotation�scCs+|jd|�\}}|j||d�S(s�Get the quota root's resource usage and limits.

        Part of the IMAP4 QUOTA extension defined in rfc2087.

        (typ, [data]) = <instance>.getquota(root)
        RtQUOTA(R�Rv(RStrootRVRW((s/sys/lib/python2.7/imaplib.pytgetquota�scCs^|jd|�\}}|j||d�\}}|j||d�\}}|||gfS(s�Get the list of quota roots for the named mailbox.

        (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = <instance>.getquotaroot(mailbox)
        RR�t	QUOTAROOT(R�Rv(RSR�RVRWtquotat	quotaroot((s/sys/lib/python2.7/imaplib.pytgetquotaroot�ss""t*cCs4d}|j|||�\}}|j|||�S(s�List mailbox names in directory matching pattern.

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

        'data' is list of LIST responses.
        R(R�Rv(RSt	directorytpatternRxRVRW((s/sys/lib/python2.7/imaplib.pytlist�scCsY|jd||j|��\}}|dkrF|j|d��nd|_||fS(s�Identify client using plaintext password.

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

        NB: 'password' will be quoted.
        RR7i�R(R�t_quoteR0R:(RStusertpasswordRVRW((s/sys/lib/python2.7/imaplib.pytlogin�s
$	cCs&|||_|_|jd|j�S(sr Force use of CRAM-MD5 authentication.

        (typ, [data]) = <instance>.login_cram_md5(user, password)
        sCRAM-MD5(R�R�R�t_CRAM_MD5_AUTH(RSR�R�((s/sys/lib/python2.7/imaplib.pytlogin_cram_md5scCs0ddl}|jd|j|j|�j�S(s1 Authobject to use with CRAM-MD5 authentication. i�Nt (thmacR�tHMACR�t	hexdigest(RSt	challengeR�((s/sys/lib/python2.7/imaplib.pyR�scCs~d|_y|jd�\}}Wn%ddtj�d g}}nX|j�d|jkrtd|jdfS||fS(s|Shutdown connection to server.

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

        Returns server 'BYE' response.
        RtNOs%s: %sitBYE(R:R�tsystexc_infoRpR>(RSRVRW((s/sys/lib/python2.7/imaplib.pytlogouts	"
cCs4d}|j|||�\}}|j|||�S(s�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�Rv(RSR�R�RxRVRW((s/sys/lib/python2.7/imaplib.pytlsub+scCs+|jd|�\}}|j||d�S(s�Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).

        (typ, [data]) = <instance>.myrights(mailbox)
        R(R�Rv(RSR�RVRW((s/sys/lib/python2.7/imaplib.pytmyrights6scCs.d}|j|�\}}|j|||�S(sb Returns IMAP namespaces ala rfc2342

        (typ, [data, ...]) = <instance>.namespace()
        R(R�Rv(RSRxRVRW((s/sys/lib/python2.7/imaplib.pyt	namespace>scCs
|jd�S(sFSend NOOP command.

        (typ, [data]) = <instance>.noop()
        R (R�(RS((s/sys/lib/python2.7/imaplib.pyRwHscCs:d}|j|||||�\}}|j||d�S(s�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�Rv(RStmessage_numtmessage_parttstarttlengthRxRVRW((s/sys/lib/python2.7/imaplib.pytpartialSs!cCsd}|jd|�S(s�Assume authentication as "user".

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

        (typ, [data]) = <instance>.proxyauth(user)
        R"(R�(RSR�Rx((s/sys/lib/python2.7/imaplib.pyt	proxyauth_s	cCs|jd||�S(skRename old mailbox name to new.

        (typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
        R#(R�(RSt
oldmailboxt
newmailbox((s/sys/lib/python2.7/imaplib.pytrenamelscGsXd}|r-|j|d||�\}}n|j||�\}}|j|||�S(s�Search mailbox for matching messages.

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

        'data' is space separated list of matching message numbers.
        R$tCHARSET(R�Rv(RStcharsettcriteriaRxRVRW((s/sys/lib/python2.7/imaplib.pytsearchts
!R|cCs�i|_||_|r!d}nd}|j||�\}}|dkr^d|_||fSd|_d|jkr�|r�|jd|��n||jjdd	g�fS(
stSelect 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%R7RRs	READ-ONLYs%s is not writabletEXISTSN(R>RAR�R:R4tgetR;(RSR�R4RxRVRW((s/sys/lib/python2.7/imaplib.pytselect�s				
	cCs|jd|||�S(sZSet a mailbox acl.

        (typ, [data]) = <instance>.setacl(mailbox, who, what)
        R&(R�(RSR�R�twhat((s/sys/lib/python2.7/imaplib.pytsetacl�scGs+|jd|�\}}|j||d�S(s_(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
        Set ANNOTATIONs.R'R�(R�Rv(RStargsRVRW((s/sys/lib/python2.7/imaplib.pyt
setannotation�scCs.|jd||�\}}|j||d�S(siSet the quota root's resource limits.

        (typ, [data]) = <instance>.setquota(root, limits)
        R(R�(R�Rv(RSR�tlimitsRVRW((s/sys/lib/python2.7/imaplib.pytsetquota�scGs^d}|d|dfdkr-d|}n|j||||�\}}|j|||�S(s�IMAP4rev1 extension SORT command.

        (typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
        R)ii�R}R~s(%s)(R}R~(R�Rv(RSt
sort_criteriaR�tsearch_criteriaRxRVRW((s/sys/lib/python2.7/imaplib.pytsort�s

cCs4d}|j|||�\}}|j|||�S(spRequest named status conditions for mailbox.

        (typ, [data]) = <instance>.status(mailbox, names)
        R*(R�Rv(RSR�tnamesRxRVRW((s/sys/lib/python2.7/imaplib.pytstatus�scCsX|d|dfdkr'd|}n|jd|||�\}}|j||d�S(	s�Alters flag dispositions for messages in mailbox.

        (typ, [data]) = <instance>.store(message_set, command, flags)
        ii�R}R~s(%s)R+R(R}R~(R�Rv(RSR�tcommandR�RVRW((s/sys/lib/python2.7/imaplib.pytstore�s
cCs|jd|�S(sYSubscribe to new mailbox.

        (typ, [data]) = <instance>.subscribe(mailbox)
        R,(R�(RSR�((s/sys/lib/python2.7/imaplib.pyt	subscribe�scGs7d}|j||||�\}}|j|||�S(s�IMAPrev1 extension THREAD command.

        (type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
        R-(R�Rv(RStthreading_algorithmR�R�RxRVRW((s/sys/lib/python2.7/imaplib.pytthread�scGs�|j�}|tkr.|jd|��n|jt|krp|jd||jdjt|�f��nd}|j|||�\}}|d	kr�|}nd}|j|||�S(
s�Execute "command arg ..." with messages identified by UID,
                rather than message number.

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

        Returns response appropriate to 'command'.
        sUnknown IMAP4 UID command: %ss9command %s illegal in state %s, only allowed in states %ss, R.R$R)R-R(sSEARCHsSORTsTHREAD(RNRZR0R:tjoinR�Rv(RSR�R�RxRVRW((s/sys/lib/python2.7/imaplib.pytuid�s			cCs|jd|�S(s_Unsubscribe from old mailbox.

        (typ, [data]) = <instance>.unsubscribe(mailbox)
        R/(R�(RSR�((s/sys/lib/python2.7/imaplib.pytunsubscribescGs;|j�}|tkr+|jft|<n|j||�S(sAllow 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'.
        (RNRZR:R�(RSRxR�((s/sys/lib/python2.7/imaplib.pytxatoms
cCsO|dkrd}n|j}||kr>||j|�n
|g||<dS(NR5(R;R>R�(RSRVRWtur((s/sys/lib/python2.7/imaplib.pyt_append_untagged*s		cCs2|jjd�}|r.|j|d��ndS(NR�i�(R>R�R3(RStbye((s/sys/lib/python2.7/imaplib.pyt
_check_bye8sc
GsY|jt|krKd|_|jd||jdjt|�f��nx*dD]"}||jkrR|j|=qRqRWd|jkr�|jr�|jd��n|j	�}d||f}x9|D]1}|dkr�q�nd||j
|�f}q�W|j}|dk	r\d|_t|�t|j�kr=|}q\d}d	|t
|�f}ny|jd
|tf�Wn/tjtfk
r�}	|jd|	��nX|dkr�|Sx�x!|j�r�|j|r�|Sq�W|r�|j�}ny|j|�|jt�Wn/tjtfk
rG}	|jd|	��nX|s�Pq�q�|S(
Ns9command %s illegal in state %s, only allowed in states %ss, R7R�tBADs	READ-ONLYs#mailbox status changed to READ-ONLYs%s %ss%s {%s}s%s%sssocket error: %s(sOKsNOR�(R:RZR;R<R0R�R>RAR4t_new_tagt_checkquotettypet_commandRjRnR�RatOSErrorR3RJR=R?(
RSRxR�RVttagRmtargR<t	literatortval((s/sys/lib/python2.7/imaplib.pyR�>sX			


			

cCs�|dkr|j�ny|j|�\}}Wn]|jk
rc}|jd||f��n/|jk
r�}|jd||f��nX|dkr�|j�n|dkr�|jd|||f��n||fS(NRscommand: %s => %sR�s%s command error: %s %s(R�t_get_tagged_responseR3R0(RSRxR�RVRmR�((s/sys/lib/python2.7/imaplib.pyt_command_complete�s

cCs6|j�}|j|j|�r�|jjd�}||jkrX|jd|��n|jjd�}|jjd�}||gf|j|<nTd}|jt|�s�|jt	|�r�|jjd�}q�n|jdkr'|jt
|�r|jjd�|_dS|jd|��n|jjd�}|jjd�}|dkr`d}n|rw|d|}nx_|jt|�r�t
|jjd	��}|j|�}|j|||f�|j�}qzW|j||�|d
kr2|jt|�r2|j|jjd�|jjd��n|S(NR�sunexpected tagged response: %sR�Rmtdata2sunexpected response: '%s'R5R�RgR7R�R�(sOKsNOsBAD(t	_get_linet_matchRItmotgroupR=R3R;tUntagged_responsetUntagged_statustContinuationR?tLiteraltintRfR�t
Response_code(RStrespR�RVRWtdat2RgRm((s/sys/lib/python2.7/imaplib.pyRJ�s@	+cCsex^|j|}|dk	r*|j|=|S|j�y|j�Wq|jk
r]}�qXqdS(N(R=R;R�RJR3(RSR�tresultR�((s/sys/lib/python2.7/imaplib.pyR��s


cCsS|j�}|s$|jd��n|jd�sE|jd��n|d }|S(Nssocket error: EOFs
ssocket error: unterminated linei�(RhR3tendswith(RSRk((s/sys/lib/python2.7/imaplib.pyR�s
cCs|j|�|_|jdk	S(N(tmatchR�R;(RStcrets((s/sys/lib/python2.7/imaplib.pyR�scCs7d|j|jf}|jd|_d|j|<|S(Ns%s%si(RFRBR;R=(RSR�((s/sys/lib/python2.7/imaplib.pyR�s
cCs�t|�td�k	r|St|�dkrR|d|dfdd	fkrR|S|rt|jj|�dkrt|S|j|�S(
NR5iii�R}R~t"(R}R~(RR(R�Rjt	mustquoteR�R;R�(RSR�((s/sys/lib/python2.7/imaplib.pyR�'s2cCs,|jdd�}|jdd�}d|S(Ns\s\\Rs\"s"%s"(treplace(RSR�((s/sys/lib/python2.7/imaplib.pyR�5scGs|j||j||��S(N(R�R�(RSRxR�((s/sys/lib/python2.7/imaplib.pyR�=scCsN|dkr||fS||jkr2|dgfS|jj|�}||fS(NR�(R>R;tpop(RSRVRWRxRm((s/sys/lib/python2.7/imaplib.pyRvBs

(KR1R2t__doc__t	ExceptionR0R3R4RGRHRt
IMAP4_PORTRYR_RCRfRhRnRpRaRyR{R�R�RLR�RoR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RwR�R�R�R�R@R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RJR�R�R�R�R�R�R�Rv(((s/sys/lib/python2.7/imaplib.pyRls�,;					
																											
			
		 									
						J		L								
t	IMAP4_SSLcBsheZdZded
d
d�Zded�Zd�Zd�Zd�Z	d�Z
d�Zd	�ZRS(s�IMAP4 client class over SSL connection

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

                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);

        for more documentation see the docstring of the parent class IMAP4.
        R5cCs)||_||_tj|||�dS(N(tkeyfiletcertfileRRY(RSRTRURR((s/sys/lib/python2.7/imaplib.pyRY�s		cCsd||_||_tj||f�|_tj|j|j|j�|_	|j	j
d�|_dS(s�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.
            R`N(RTRURaRbRctssltwrap_socketRRtsslobjRdRe(RSRTRU((s/sys/lib/python2.7/imaplib.pyRC�s
		!cCs|jj|�S(sRead 'size' bytes from remote.(ReRf(RSRg((s/sys/lib/python2.7/imaplib.pyRf�scCs
|jj�S(sRead line from remote.(ReRh(RS((s/sys/lib/python2.7/imaplib.pyRh�scCsYt|�}xF|dkrT|jj|�}||kr=Pn||}||}qWdS(sSend data to remote.iN(RjRtwrite(RSRmtbytestsent((s/sys/lib/python2.7/imaplib.pyRn�s
cCs|jj�|jj�dS(s Close I/O established in "open".N(ReRoRc(RS((s/sys/lib/python2.7/imaplib.pyRp�s
cCs|jS(snReturn socket instance used to connect to IMAP4 server.

            socket = <instance>.socket()
            (Rc(RS((s/sys/lib/python2.7/imaplib.pyRa�scCs|jS(s�Return SSLObject instance used to communicate with the IMAP4 server.

            ssl = ssl.wrap_socket(<instance>.socket)
            (R(RS((s/sys/lib/python2.7/imaplib.pyR
�sN(
R1R2RtIMAP4_SSL_PORTR;RYRCRfRhRnRpRaR
(((s/sys/lib/python2.7/imaplib.pyR
{s
					cBsJeZdZd�Zddd�Zd�Zd�Zd�Zd�Z	RS(s�IMAP4 client class over a stream

    Instantiate with: IMAP4_stream(command)

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

    for more documentation see the docstring of the parent class IMAP4.
    cCs||_tj|�dS(N(R�RRY(RSR�((s/sys/lib/python2.7/imaplib.pyRY�s	c
Csyd|_d|_d|_d|_tj|jdtjdtjdt	dt	�|_
|j
j|_|j
j
|_dS(s�Setup a stream connection.
        This connection will be used by the routines:
            read, readline, send, shutdown.
        tstdintstdouttshellt	close_fdsN(R;RTRURcRet
subprocesstPopenR�tPIPEtTrueR�Rt	writefileRtreadfile(RSRTRU((s/sys/lib/python2.7/imaplib.pyRC�s				cCs|jj|�S(sRead 'size' bytes from remote.(RRf(RSRg((s/sys/lib/python2.7/imaplib.pyRf�scCs
|jj�S(sRead line from remote.(RRh(RS((s/sys/lib/python2.7/imaplib.pyRh�scCs!|jj|�|jj�dS(sSend data to remote.N(RRtflush(RSRm((s/sys/lib/python2.7/imaplib.pyRn�scCs+|jj�|jj�|jj�dS(s Close I/O established in "open".N(RRoRR�twait(RS((s/sys/lib/python2.7/imaplib.pyRp�s

N(
R1R2RRYR;RCRfRhRnRp(((s/sys/lib/python2.7/imaplib.pyR�s					R�cBs2eZdZd�Zd�Zd�Zd�ZRS(scPrivate class to provide en/decoding
            for base64-based authentication conversation.
    cCs
||_dS(N(R�(RStmechinst((s/sys/lib/python2.7/imaplib.pyRY	scCs5|j|j|��}|dkr(dS|j|�S(NR�(R�tdecodeR;tencode(RSRmtret((s/sys/lib/python2.7/imaplib.pyR�scCsrd}xe|rmt|�dkr8|d }|d}n|}d}tj|�}|r	||d }q	q	W|S(NR5i0i�(Rjtbinasciit
b2a_base64(RStinptoupttRt((s/sys/lib/python2.7/imaplib.pyR"s		

cCs|s
dStj|�S(NR5(R$t
a2b_base64(RSR&((s/sys/lib/python2.7/imaplib.pyR!(s(R1R2RRYR�R"R!(((s/sys/lib/python2.7/imaplib.pyR�s
			itJanitFebitMaritApritMayitJunitJulitAugi	tSepi
tOctitNovitDecc	Csvtj|�}|sd
St|jd�}|jd�}t|jd��}t|jd��}t|jd��}t|jd��}t|jd��}t|jd��}	t|jd	��}
|	d
|
d
}|dkr�}n||||||dddf	}tj|�}
tj|
�}tj	rX|drX|tj
}n
|tj}tj|
|�S(s�Parse an IMAP4 INTERNALDATE string.

    Return corresponding local time.  The return value is a
    time.struct_time instance or None if the string has wrong format.
    tmontzonentdaytyearthourtmintsectzonehtzonemi<t-i�N(tInternalDateRR;tMon2numR�R�ttimetmktimet	localtimetdaylighttaltzonettimezone(R�R�R6R7R8R9R:R;R<R=R>tzonettttutctlt((s/sys/lib/python2.7/imaplib.pyR2s,
!
cCsRd}d}tt|��}x-|rMt|d�\}}|||}q!W|S(s-Convert integer to A-P string representation.R5tABCDEFGHIJKLMNOPi(R�tabstdivmod(tnumR�tAPtmod((s/sys/lib/python2.7/imaplib.pyR_s	cCs2tj|�}|sdSt|jd�j��S(s-Convert IMAP4 flags response to python tuple.R�((tFlagsRRMR�RO(R�R�((s/sys/lib/python2.7/imaplib.pyRlscCs�t|ttf�r'tj|�}nZt|ttjf�rH|}n9t|t�ru|d|dfdkru|Std��tj	d|�}|ddkr�d|d}ntj
r�|dr�tj}n
tj}d|d	t
|d
d
�dS(s�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 (as returned by time.localtime()), or a
    double-quoted string.  In the last case, it is assumed to already
    be in the correct format.
    ii�Rsdate_time not of a known types%d-%b-%Y %H:%M:%St0R�is
 %+03d%02di<(RR(t
isinstanceR�tfloatRBRDRMtstruct_timetstrt
ValueErrortstrftimeRERFRGRN(R�RItdtRH((s/sys/lib/python2.7/imaplib.pyRws	)

t__main__sd:s:s-ds-sR5sIMAP password for %s on %s: t	localhostsJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)sR�s
tlfR�R�s
/tmp/xxx 1R�s/tmp/yyys
/tmp/yyz 2R�R�s/tmpsyy*R�R�tSUBJECTttestR�t1s(FLAGS INTERNALDATE RFC822)R�tFLAGSs
(\Deleted)R�R�RyRoR{tUIDVALIDITYR�tALLR�R�cCsitjd||f�tt|�|�\}}tjd|||f�|dkre|d�n|S(Ns%s %ss%s => %s %sR�i(tMt_mesgR[(tcmdR�RVRW((s/sys/lib/python2.7/imaplib.pytrun�s
sPROTOCOL_VERSION = %ssCAPABILITIES = %rs/tmp/syy%s.*"([^"]+)"$R�s%ss:(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)s
All tests OK.s
Tests failed.s8
If you would like to see debugging output,
try: %s -d5
(IRt__version__R$RrRDRGRaRR�RBt__all__R�R8R	RRQRiRZRHR�RRR@R�RR�R�R�RR
tImportErrorR
R�RR�RARRRRR1tgetopttgetpasstargvtoptlistR�R0R�R;tstream_commandtoptR�RTtgetusertUSERtPASSWDt	test_mesgt	test_seq1t	test_seq2RgRdR:ReRRRPRftmlRR�R�tpathRORWR�(((s/sys/lib/python2.7/imaplib.pyt<module>s*`	

































��
L
9,--	-	
		 #
						
	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].