python (3.12.0)

(root)/
lib/
python3.12/
__pycache__/
imaplib.cpython-312.pyc

ˑeddZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZm
Z
ddlmZ	ddlZdZgdZd	ZdZd
ZdZdZd
Ziddddddddddddddddddddddddddd dd!dd"dd#did$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4dddddddddd5Zej6d6Zej6d7Zej6d8Zej6d9ej>Z ej6d:Z!ej6d;Z"ej6d<Z#ej6d=ej>Z$d9Z%d=Z&Gd>d?Z'erGd@dAe'Z(ejSdAGdBdCe'Z*GdDdEZ+dFjYdGZ-e.e-dHdDcic]\}}|j_|dHzc}}Z0dIZ1dJZ2dKZ3dLZ4e5dMk(rddl6Z6ddl7Z7	e6jlejpdHddN\Z9Z:dZ=e9D]!\Z>Z<e>dPk(r	e?e<Ze>dQk(se<Z=e:re=fZ:#e:sdRZ:e:dZ@e7jZBe7jndSeBdTe@xsdUdVZCdWeBdXdYzZDdZeBeCffd[d\d]d^d_ddeDffd`dadbdcdddedfdgdhfZEdidjdkdld^dddeDffdgdmfZFdnZG	e=r	e*e=ZHne'e@ZHeHjdok(reEdHdZEeHjdpeHjzeHjdqeHjeED]\ZMZ:eGeMe:eGdrdsD]FZNejdteNZPePrePjdHZRneNjYduZReGdveRfHeFD]>\ZMZ:eGeMe:ZSeMe:fdkk7reSdujYZTeTs-eGdwddxeTduzdyf@eUdzyy#e$rdZYwxYwcc}}w#e6jv$rZ<dO\Z9Z:YdZ<[<dZ<[<wwxYw#eUd{eseUd|ejpdzxYw)}zIMAP4 client.

Based on RFC 2060.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate
z2.58N)datetimetimezone	timedelta)DEFAULT_BUFFER_SIZETF)IMAP4IMAP4_streamInternaldate2tupleInt2AP
ParseFlagsTime2Internaldate
i)	IMAP4REV1ri@BAPPEND)AUTHSELECTEDAUTHENTICATE)NONAUTH
CAPABILITY)rrrLOGOUTCHECK)rCLOSECOPYCREATEDELETE	DELETEACLENABLE)rEXAMINEEXPUNGEFETCHGETACL
GETANNOTATIONGETQUOTAGETQUOTAROOTMYRIGHTSLISTLOGINrLSUBMOVE	NAMESPACENOOPPARTIAL	PROXYAUTHRENAMESEARCHSELECTSETACL
SETANNOTATIONSETQUOTASORT)STARTTLSSTATUSSTORE	SUBSCRIBETHREADUIDUNSUBSCRIBEUNSELECTs\+( (?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>.*))?c8eZdZdZGddeZGddeZGddeZded	fd
Z	dZ
dZd
ZdZ
dZdZdZded	fdZdZdZdZdZdZdZdZdZdZdZdZdZdZd Zd!Z d"Z!d#Z"d$Z#d%Z$d&Z%d'Z&d(Z'd)Z(dVd*Z)d+Z*d,Z+d-Z,d.Z-dVd/Z.d0Z/d1Z0d2Z1d3Z2d4Z3d5Z4d6Z5dWd7Z6d8Z7d9Z8d:Z9d;Z:dXd<Z;d=Z<d>Z=d?Z>d@Z?dAZ@dBZAdCZBdDZCdEZDdFZEdGZFdHZGdIZHdJZIdYdKZJdLZKdMZLdNZMdOZNdPZOdQZP	dXdRZQdSZRdTZSdUZTy	)ZraIMAP4 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eZdZy)IMAP4.errorN__name__
__module____qualname__;/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/imaplib.pyerrorr?rErGceZdZy)IMAP4.abortNr@rDrErFabortrJrHrErKceZdZy)IMAP4.readonlyNr@rDrErFreadonlyrMrHrErNNcNt|_d|_d|_i|_i|_d|_d|_d|_d|_	|j|j|||	|jy#t$r"	|j#t$rYwxYwwxYw)NrrOFr)Debugdebugstateliteraltagged_commandsuntagged_responsescontinuation_responseis_readonlytagnum_tls_established_mode_asciiopen_connect	ExceptionshutdownOSErrorselfhostporttimeouts    rF__init__zIMAP4.__init__s

!"$%'"  %	
		$g&	MMO	





	s0(A99	B$BB$	B B$B  B$cd|_d|_tjttj
|_tjttj
|_y)NFascii)	utf8_enabled	_encodingrecompile_LiteralASCIILiteral_Untagged_statusUntagged_statusrbs rFr[zIMAP4._mode_asciis?! zz(BHH5!zz*:BHHErEcd|_d|_tjt|_tjt|_y)NTutf-8)rirjrkrlrmrorprqrrs rF
_mode_utf8zIMAP4._mode_utf8s3  zz(+!zz*:;rEcttjdd|_t	j
d|jzdztj|_	d|_d|_	i|_
|jdk\r6|jdtz|jd	|jz|j|_d
|j vrd|_n1d|j vrd
|_n|j%|j|j'	|jdk\r|jd|j(t*D]}||j(vr||_y|j%d)Niis(?P<tag>s"\d+) (?P<type>[A-Z]+) (?P<data>.*)
rzimaplib version %sznew IMAP4 connection, tag=%sPREAUTHrOKrzCAPABILITIES: zserver not IMAP4 compliant)r
randomrandinttagprerkrlrntagre_cmd_log_len_cmd_log_idx_cmd_logrR_mesg__version__
_get_responsewelcomerVrSrG_get_capabilitiescapabilitiesAllowedVersionsPROTOCOL_VERSION)rbversions  rFr]zIMAP4._connectsRV^^D%89ZZ++!&@!ABD((L
 "D !DDMzzQ

/+=>

9DKKGH))+///DJ
T,,
,"DJ**T\\** zzQ

1B1BDE&	Gd///$+D!		jj566rEcb|tvrt||jStd|z)NzUnknown IMAP4 command: '%s')CommandsgetattrlowerAttributeError)rbattrs  rF__getattr__zIMAP4.__getattr__
s.84..:TABBrEc|SNrDrrs rF	__enter__zIMAP4.__enter__srEcd|jdk(ry	|jy#t$rYywxYw)Nr)rSlogoutr`)rbargss  rF__exit__zIMAP4.__exit__s1::!	KKM		s#	//c"|
|std|jsdn|j}tjd||j|j||jf}|tj||Stj|S)Nz0Non-blocking socket (timeout=0) is not supportedzimaplib.open)
ValueErrorrcsysauditrdsocketcreate_connection)rbrercaddresss    rF_create_socketzIMAP4._create_socket#s{wOPP99t$))		.$		499=#++GW==''00rEc||_||_|j||_|jj	d|_y)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)rcrdrsockmakefilefileras    rFr\z
IMAP4.open0s:		''0	II&&t,	rEc8|jj|SzRead 'size' bytes from remote.)rreadrbsizes  rFrz
IMAP4.read<syy~~d##rEc|jjtdz}t|tkDr|j	dtz|S)Read line from remote.rxzgot more than %d bytes)rreadline_MAXLINElenrGrblines  rFrzIMAP4.readlineAs@yy!!(Q,/t9x**5@AArEchtjd|||jj|y)Send data to remote.zimaplib.sendN)rrrsendallrbdatas  rFsendz
IMAP4.sendIs$		.$-		$rEc|jj	|jjtj
|jjy#t$r8}|jtjk7rt|dddk7rYd}~Wd}~wwxYw#|jjwxYw) Close I/O established in "open".winerrorri&'N)
rcloserr_r	SHUT_RDWRr`errnoENOTCONNr)rbexcs  rFr_zIMAP4.shutdownOs		
	IIv//0
IIOO			U^^+3
A.%7
	
IIOOs))A  	B!).BB$B!!B$$Cc|jS)zfReturn socket instance used to connect to IMAP4 server.

        socket = <instance>.socket()
        )rrrs rFrzIMAP4.socket_s
yyrEcd}|jddg|\}}|dr||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.
        RECENTrzN)_untagged_responsenooprbnametypdats    rFrecentzIMAP4.recentksW**4$>Sr78O99;S&&sC66rEcF|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)rbcodes  rFresponsezIMAP4.response|s!&&tdVTZZ\BBrEcd}|sd}|r|d|dfdk7rd|z}nd}|rt|}nd}tjt|}|jrd|zd	z}||_|j
||||S)
zAppend message to named mailbox.

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

                All args except `message' can be None.
        rINBOXrr()(%s)NsUTF8 ())rMapCRLFsubCRLFrirT_simple_command)rbmailboxflags	date_timemessagerrTs       rFappendzIMAP4.appendsGar#y0E))4II++dG,')D0G##D'5)DDrEc|j}t|j|_|j	d|\}}|dk7r$|j|dj
ddd|_||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.
        rrzrrtreplacer)r_AuthenticatorprocessrTrrGdecoderS)rb	mechanism
authobjectmechrrs      rFauthenticatezIMAP4.authenticateso  
&j199''=S$;**SW^^GY?@@
CxrEcTd}|j|\}}|j|||S)zT(typ, [data]) = <instance>.capability()
        Fetch capabilities list from server.rrrrs    rF
capabilityzIMAP4.capabilitys2''-S&&sC66rEc$|jdS)zRCheckpoint mailbox on server.

        (typ, [data]) = <instance>.check()
        rrrrs rFcheckzIMAP4.checks
##G,,rEcZ	|jd\}}d|_||fS#d|_wxYw)zClose currently selected mailbox.

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

        (typ, [data]) = <instance>.close()
        rrrrSrbrrs   rFrzIMAP4.closes6	 ++G4HCDJCx DJ!	*c(|jd||S)zCopy 'message_set' messages onto end of 'new_mailbox'.

        (typ, [data]) = <instance>.copy(message_set, new_mailbox)
        rr)rbmessage_setnew_mailboxs   rFcopyz
IMAP4.copys
##FKEErEc&|jd|S)zPCreate new mailbox.

        (typ, [data]) = <instance>.create(mailbox)
        rrrbrs  rFcreatezIMAP4.create
##Hg66rEc&|jd|S)zPDelete old mailbox.

        (typ, [data]) = <instance>.delete(mailbox)
        rrrs  rFdeletezIMAP4.deleterrEc(|jd||S)zDelete the ACLs (remove any rights) set for who on mailbox.

        (typ, [data]) = <instance>.deleteacl(mailbox, who)
        rr)rbrwhos   rF	deleteaclzIMAP4.deleteacls
##K#>>rEcd|jvrtjd|jd|\}}|dk(r"d|j	vr|j||fS)zlSend an RFC5161 enable string to the server.

        (typ, [data]) = <instance>.enable(capability)
        rzServer does not support ENABLErzzUTF8=ACCEPT)rrrGrrru)rbrrrs    rFenablezIMAP4.enablesc
4,,,++>??((:>	T$;=J,<,<,>>OODyrEcTd}|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.
        rrrs    rFexpungez
IMAP4.expunges2''-S&&sC66rEcXd}|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 r)rbr
message_partsrrrs      rFfetchzIMAP4.fetchs6''k=IS&&sC66rEcR|jd|\}}|j||dS)zXGet the ACLs for a mailbox.

        (typ, [data]) = <instance>.getacl(mailbox)
        r!ACLrrbrrrs    rFgetaclzIMAP4.getacl(s/
''':S&&sC77rEcV|jd|||\}}|j||dS)za(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
        Retrieve ANNOTATIONs.r"
ANNOTATIONr)rbrentry	attributerrs      rF
getannotationzIMAP4.getannotation1s3''%SS&&sC>>rEcR|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#QUOTAr)rbrootrrs    rFgetquotazIMAP4.getquota9s/''
D9S&&sC99rEc|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$r	QUOTAROOTr)rbrrrquota	quotaroots      rFgetquotarootzIMAP4.getquotarootDsZ
''@S,,S#w?
U00c;GYY&&&rEcXd}|j|||\}}|j|||S)zList mailbox names in directory matching pattern.

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

        'data' is list of LIST responses.
        r&rrb	directorypatternrrrs      rFlistz
IMAP4.listO6''iAS&&sC66rEc|jd||j|\}}|dk7r|j|dd|_||fS)zIdentify client using plaintext password.

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

        NB: 'password' will be quoted.
        r'rzrr)r_quoterGrS)rbuserpasswordrrs     rFloginzIMAP4.login[sO''t{{87LMS$;**SW%%
CxrEcX||c|_|_|jd|jS)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   rFlogin_cram_md5zIMAP4.login_cram_md5is-
$( 	4=  T-@-@AArEcddl}t|jtr|jj	dn|j}|j
dz|j
||djzS)z1 Authobject to use with CRAM-MD5 authentication. rNrt md5)hmac
isinstancer"strencoder!HMAC	hexdigest)rb	challenger*pwds    rFr%zIMAP4._CRAM_MD5_AUTHrsY0:4==#0Nt}}##G,26--	yy33	5!A!K!K!MMMrEc`d|_|jd\}}|j||fS)z|Shutdown connection to server.

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

        Returns server 'BYE' response.
        r)rSrr_rs   rFrzIMAP4.logoutzs1
''1S

CxrEcXd}|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(rrs      rFlsubz
IMAP4.lsubrrEcR|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	s    rFmyrightszIMAP4.myrightss/
&&z7;C&&sC<<rEcTd}|j|\}}|j|||S)zb Returns IMAP namespaces ala rfc2342

        (typ, [data, ...]) = <instance>.namespace()
        r*rrs    rF	namespacezIMAP4.namespaces2
''-S&&sC66rEcz	|jdk\r|j|j|jdS)zFSend NOOP command.

        (typ, [data]) = <instance>.noop()
        r{r+)rR_dump_urrVrrrs rFrz
IMAP4.noops5
zzQ

d556##F++rEc\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 r)rbmessage_nummessage_partstartlengthrrrs        rFpartialz
IMAP4.partials;''k<PVWS&&sC99rEc*d}|jd|S)zAssume authentication as "user".

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

        (typ, [data]) = <instance>.proxyauth(user)
        r-r)rbr!rs   rF	proxyauthzIMAP4.proxyauths##K66rEc(|jd||S)zkRename old mailbox name to new.

        (typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
        r.r)rb
oldmailbox
newmailboxs   rFrenamezIMAP4.renames
##Hj*EErEcd}|r:|jrtjd|j|d|g|\}}n|j|g|\}}|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)rirrGrr)rbcharsetcriteriarrrs      rFsearchzIMAP4.searchst  kk"KLL+t++D)WPxPHC+t++D<8<HC&&sC66rEc`i|_||_|rd}nd}|j||\}}|dk7rd|_||fSd|_d|jvrA|s?	|jdk\r|j|j|j
d|z||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.
        rr0rzrr	READ-ONLYrxz%s is not writableEXISTSN)rVrXrrSrRr:rNget)rbrrNrrrs      rFselectzIMAP4.selects#%#DD''g6S$;DJ8O
$111 ::?MM$"9"9:-- 4w >??D++//4&AAArEc*|jd|||S)zZSet a mailbox acl.

        (typ, [data]) = <instance>.setacl(mailbox, who, what)
        r1r)rbrrwhats    rFsetaclzIMAP4.setacls
##HgsDAArEcT|jdg|\}}|j||dS)z_(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
        Set ANNOTATIONs.r2rr)rbrrrs    rF
setannotationzIMAP4.setannotation
s4(4''?$?S&&sC>>rEcT|jd||\}}|j||dS)ziSet the quota root's resource limits.

        (typ, [data]) = <instance>.setquota(root, limits)
        r3rr)rbrlimitsrrs     rFsetquotazIMAP4.setquotas1
''
D&AS&&sC99rEcd}|d|dfdk7rd|z}|j|||g|\}}|j|||S)zIMAP4rev1 extension SORT command.

        (typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
        r4rrrrr)rb
sort_criteriarIsearch_criteriarrrs       rFsortz
IMAP4.sorts`

!]2./9<"]2M'4''mWWWS&&sC66rEcd}ts|jd|jr|jd||jvr|jd|tj}|j|\}}|dk(rd|j|j|j|_	|jjd|_d|_|jn|jd	|j|||S)
Nr5zSSL support missingzTLS session already establishedzTLS not supported by serverrzserver_hostnamerTzCouldn't establish TLS session)HAVE_SSLrGrZrKrssl_create_stdlib_contextrwrap_socketrrcrrrr)rbssl_contextrrrs     rFstarttlszIMAP4.starttls)s**233  **>??t(((**:;;446K''-S$;#//		@D		0KDI		**40DI$(D!""$**=>>&&sC66rEcXd}|j|||\}}|j|||S)zpRequest named status conditions for mailbox.

        (typ, [data]) = <instance>.status(mailbox, names)
        r6r)rbrnamesrrrs      rFstatuszIMAP4.status@s8
''gu=S&&sC66rEcz|d|dfdk7rd|z}|jd|||\}}|j||dS)zAlters flag dispositions for messages in mailbox.

        (typ, [data]) = <instance>.store(message_set, command, flags)
        rrrrr7r r)rbrcommandrrrs      rFstorezIMAP4.storeLsQ

!HU2Y9,UNE''guMS&&sC99rEc&|jd|S)zYSubscribe to new mailbox.

        (typ, [data]) = <instance>.subscribe(mailbox)
        r8rrs  rF	subscribezIMAP4.subscribeWs
##K99rEc\d}|j|||g|\}}|j|||S)zIMAPrev1 extension THREAD command.

        (type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
        r9r)rbthreading_algorithmrIr[rrrs       rFthreadzIMAP4.thread_s>
'4''.A7]_]S&&sC66rEcb|j}|tvr|jd|z|jt|vr:|jd|d|jddj	t|d}|j
||g|\}}|dvr|}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: %scommand  illegal in state , only allowed in states , r:)r/r4r9r )rrrGrSjoinrr)rbrjrrrrs      rFuidz	IMAP4.uidis--/("**<wFGG::Xg..**%tzz"ii(9:<=
='4''g==S22DD&&sC66rEc&|jd|S)z_Unsubscribe from old mailbox.

        (typ, [data]) = <instance>.unsubscribe(mailbox)
        r;rrs  rFunsubscribezIMAP4.unsubscribes
##M7;;rEcZ	|jd\}}d|_||fS#d|_wxYw)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)rbrrs   rFunselectzIMAP4.unselects7	 ,,Z8ICDJDy DJrc|j}|tvr|jft|<|j|g|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'.
        )rrrSrrbrrs   rFxatomzIMAP4.xatoms@zz|x"jj]HTN#t##D0400rEc|d}|j}	|jdk\r4|jd|dt|j	|dd|d||vr||j|y|g||<y)NrEuntagged_responses[z] rOz += ["z"])rVrRrrrOr)rbrrurs    rF_append_untaggedzIMAP4._append_untaggedsn;C

$
$zzQ

c"&&R.1389"9sGNN3eBsGrEc|jjd}|r.|j|dj|jdy)NBYErr)rVrOrKrrj)rbbyes  rF
_check_byezIMAP4._check_byesB%%))%0**SW^^DNNIFGGrEcV|jt|vrAd|_|jd|d|jddj	t|dD]}||j
vs|j
|= d|j
vr|js|jd|j}t||j}|dz|z}|D]3}|t|trt||j}|dz|z}5|j}|Qd|_t|t|jur|}n'd}|td	t|z|jz}	|j d
k\r|j#d|zn|j%d|z	|j'|t(z||S	|j/r"|j0|r|S|j/r"r||j2}	|j d
k\r|j#d
t|z	|j'||j't(|s	|S#t*$r}	|j-d|	zd}	~	wwxYw#t*$r}	|j-d|	zd}	~	wwxYw)NrrrsrtrurzNOBADrMz#mailbox status changed to READ-ONLY z {%s}z> %rzsocket error: %szwrite literal size %s)rSrrTrGrvrVrXrN_new_tagbytesrjr+r,type_commandrrRr_logrrr`rKrrUrW)
rbrrrtagrargrT	literatorvals
          rFrzIMAP4._commands::Xd^+DL**"DJJ"ii79:
:
'	1Cd---++C0	1$111  -- EFFmmoT4>>*TzD 	%C{H#s#C0$;$D		%,,DLG}T]] 33#	 	eGc'l$:DNNKKzzQ

6D=)		&4-(	7IIdTk"?J$$&'',J$$&#D$>$>?::?JJ6WEF
;		'"		$
3
	7**/#566	72
;jj!3c!9::
;s0$I!5&J!	J*I>>J	J(J##J(ct|dk(}|s|j	|j||\}}|s|j|dk(r|j|d|d|||fS#|j$r}|jd|d|d}~w|j$r}|jd|d|d}~wwxYw)Nr)
expect_byez	command:  => rz command error: r()r_get_tagged_responserKrG)rbrrrrrrs       rF_command_completezIMAP4._command_completes("OO	@11#&1IIC
OO%<**$TJKKDyzz	@**D#>??zz	@**D#>??	@s#A##B72B		B7B22B7c|j\}}|dgk(r|jdt|d|j}|j	}t|j
|_y)Nz"no CAPABILITY response from serverr)rrGr,rjrtuplesplitrrs   rFrzIMAP4._get_capabilities#s]??$S4&=**ABB#b'4>>*iik!#))+.rEch|j}|j|j|r|jj	d}||j
vr|j
d|z|jj	d}t||j}|jj	d}||gf|j
|<nd}|jt|s7|j|j|r|jj	d}|jK|jt|r!|jj	d|_y|j
d|z|jj	d}t||j}|jj	d}|d}|r|dz|z}|j|j|rt|jj	d	}	|jd
k\r|j!d|z|j#|}|j%|||f|j}|j|j|r|j%|||dvrr|jt&|r\|jj	d}t||j}|j%||jj	d	|jd
k\r|dvr|j!|d||S)Nrzunexpected tagged response: %rrrdata2zunexpected response: %rrErrrzread literal size %srrx)rrrz response: )	_get_line_matchrmogrouprUrKr,rjUntagged_responserqContinuationrWrointrRrrr
Response_code)rbresprrrdat2rrs        rFrzIMAP4._get_response,s~~;;tzz4(''--&C$...jj!AD!HII''--'Cc4>>*C''--'C),seD  %D;;0$7;;t33T:77==1Dww;;|T215v1FD.jj!:T!ABB''--'Cc4>>*C''--'C{#C3:,S++dllC0477==01zzQ

#9D#@Ayy%%cC;7nn&!++dllC0$
!!#s+%%$++mS*I''--'Cc4>>*C!!#tww}}V'<=zzQ3*>#>

S9:rEcD	|j|}||j|=|S|r$d}|jj|d}|||fS|j	|j	h#|j
$r&}	|jdk\r|jd}~wwxYw)Nrxr)rUrVpoprrrKrR	print_log)rbrrresultrrrs       rFrzIMAP4._get_tagged_response|s))#.F!((-
--11#t<?:%
OO
""$/0::
zzQ(	
sA**B9!BBc|j}|s|jd|jds|jd|z|dd}	|jdk\r|j	d|z|S|jd|z|S)Nzsocket error: EOFr
z#socket error: unterminated line: %rrz< %r)rrKendswithrRrrrs  rFrzIMAP4._get_lines}}**011}}W%**BTIJJCRyzzQ

6D=)		&4-(rEc|j||_	|jH|jdk\r9|jd|jd|jj|jduS)Nrz		matched r)matchrrRrrgroups)rbcress   rFrzIMAP4._matchsY
))A,ww"tzzQ

3;;@PQRwwd""rEc|jtt|j|jz}|jdz|_d|j
|<|S)Nrx)r~rr,rYrjrU)rbrs  rFrzIMAP4._new_tagsHkkE#dkk"2DNNCCkkAo$(S!
rEcZ|jdd}|jdd}d|zdzS)N\z\\"z\")r)rbrs  rFr zIMAP4._quotes0kk$'kk#u%Sy3rEcH|j||j|g|Sr)rrr}s   rFrzIMAP4._simple_commands%%%dMDMM$,F,FGGrEc|dk(r||fS||jvr|dgfS|jj|}	|jdk\r|jd|d|||fS)Nrrrz] => )rVrrRr)rbrrrrs     rFrzIMAP4._untagged_responsesk$;8Ot...;&&**40zzQ

T4HIDyrEc|tj}tjdtj|}tjjd||dzdz|fztjj
y)Nz%M:%Sz
  %s.%02d %s
d)timestrftime	localtimerstderrwriteflush)rbrsecstms    rFrzIMAP4._mesgsb|yy{wt(<=BJJ-d3h^Q0GGHJJrEc~|syd|jD}|jddj|zy)Nc30K|]\}}|d|yw): NrD).0keyvalues   rF	<genexpr>z!IMAP4._dump_ur.<locals>.<genexpr>s)B"UuBui(Bszuntagged responses dump:z
		)itemsrrv)rbuntagged_resp_dictrs   rFr:zIMAP4._dump_urs=%B&8&>&>&@BEJJ1HMM%4HHIrEc|tjf|j|j<|xjdz
c_|j|jk\rd|_yy)Nrxr)rrrrrs  rFrz
IMAP4._logsS04diik/BDMM$++,"  D$5$55$%!6rEc|jdt|jz|j|j}}|r<	|j|j||dz
}||jk\rd}|dz}|r;yy#Y$xYw)Nzlast %d IMAP4 interactions:rxr)rrrrr)rbins   rFrzIMAP4.print_logsJJ4s4==7IIJ$$d&7&7qADJJ

a 01Q)))AQsA??B)z""*)rFr)F)UrArBrC__doc__r^rGrKrN
IMAP4_PORTrfr[rur]rrrrr\rrrr_rrrrrrrrrrrrrrrr
rrrrr#r&r%rr4r6r8rr@rBrFrKrPrSrUrXr\rerhrkrmrprwryr{r~rrrrrrrrrrr rrrr:rrrDrErFrrs-^!	 5Z2F<'7TC1T	-$
 
 7"CE4:7-F77?
778?:'	7BN
	7=7,	:
7F7$B@B?:77.	7::772<
 1,HJZ$/M`B&	#H
			J	&	rErc8eZdZdZdefddddZdZdedfdZy)	IMAP4_SSLaIMAP4 client class over SSL connection

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

                host - host's name (default: localhost);
                port - port number (default: standard IMAP4 SSL port);
                ssl_context - a SSLContext object that contains your certificate chain
                              and private key (default: None)
                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.
        rON)rdrecn|tj}||_tj	||||yr)rarbrdrrf)rbrcrdrdres     rFrfzIMAP4_SSL.__init__s0"!88:*DNN4tW5rEc|tj||}|jj||jS)Nr^)rrrdrcrc)rbrers   rFrzIMAP4_SSL._create_sockets=''g6D##//@D		0K
KrEc4tj||||y)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)rr\ras    rFr\zIMAP4_SSL.open!s
JJtT41rE)rArBrCrIMAP4_SSL_PORTrfrr\rDrErFrrs1	!#	6$($	6	K
^T	2rErc6eZdZdZdZd	dZdZdZdZdZ	y)
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.
    c<||_tj|yr)rjrrf)rbrjs  rFrfzIMAP4_stream.__init__8s
trENc<d|_d|_d|_d|_t	j
|jttjtjdd|_	|jj|_|jj|_
y)zSetup a stream connection.
        This connection will be used by the routines:
            read, readline, send, shutdown.
        NT)bufsizestdinstdoutshell	close_fds)rcrdrr
subprocessPopenrjrPIPErr	writefilerreadfileras    rFr\zIMAP4_stream.open=sq
				!'''//*//$(++++
rEc8|jj|Sr)rrrs  rFrzIMAP4_stream.readMs}}!!$''rEc6|jjS)r)rrrrs rFrzIMAP4_stream.readlineRs}}%%''rEcn|jj||jjy)rN)rrrrs  rFrzIMAP4_stream.sendWs$T"rEc|jj|jj|jj	y)rN)rrrrwaitrrs rFr_zIMAP4_stream.shutdown]s2

rE)NNN)
rArBrCrrfr\rrrr_rDrErFrr,s%
, (
(
rErc(eZdZdZdZdZdZdZy)rzcPrivate class to provide en/decoding
            for base64-based authentication conversation.
    c||_yr)r)rbmechinsts  rFrfz_Authenticator.__init__ks		rEcj|j|j|}|y|j|S)N*)rrr-)rbrrets   rFrz_Authenticator.processns0iiD)*;{{3rEcd}t|tr|jd}|r?t|dkDr|dd}|dd}n|}d}t	j
|}|r||ddz}|r?|S)NrErt0r)r+r,r-rbinascii
b2a_base64)rbinpouptes     rFr-z_Authenticator.encodets}c3**W%C3x"}H"#h##A&AAcrFl
rEc2|sytj|S)NrE)r
a2b_base64)rbrs  rFrz_Authenticator.decodes""3''rEN)rArBrCrrfrr-rrDrErFrres 0(rErz0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Decr(rxc	tj|}|syt|jd}|jd}t	|jd}t	|jd}t	|jd}t	|jd}t	|jd}t	|jd	}	t	|jd
}
|	dz|
zdz}|dk(r|}||||||d
d
d
f	}tj||z
}
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<-r)	InternalDaterMon2numrrcalendartimegmrr)rrrrrrrrrrrzonettutcs              rFr	r	s
		D	!B

"((5/
"CHHWE

bhhuo
Crxx Drxx D

bhhuo
C

bhhuo
C!"E!"E
"Hub D}u
S$S"b"	5B
//"

$C>>#rEctd}d}tt|}|rt|d\}}|||dz|z}|r|S)z-Convert integer to A-P string representation.rEsABCDEFGHIJKLMNOPrx)rabsdivmod)numrAPmods    rFr
r
sMC'r

c#h-C

#r?SSUmc!JrEctj|}|syt|jdj	S)z-Convert IMAP4 flags response to python tuple.rDr)Flagsrrrr)rrs  rFrrs5
T	B
'"((*++rEc:t|ttfr3tj|t
jj}nt|tr1	|j}t!|}t|dddt|i}nTt|tr|j"t%d|}n*t|t&r|d|dfd	k(r|St%d
dj)t*|j,}|j/|S#t$rtjrZ|d}|dk(r+tjtj|d}tj
tjf|}ntj
}Y2wxYw)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.
    r)secondsNtzinfozdate_time must be awarer)rrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z")r+rfloatr
fromtimestamprr
astimezoner	tm_gmtoffrrdaylightrmktimealtzonerrrr,formatMonthsmonthr)rdtgmtoffdstdeltafmts      rFrrs])c5\*

#
#I$,LL22<*,		Iu	%		(((F&)
y!}
=Xe_
=	Ix	(#677
	Is	#1im(D	(Q899
"
)
)&*:
;C
;;s'	(}}l"9..Y)?@CC==$,,7<<--	(sDBFF__main__zd:s:)rDrDz-dz-s)rOzIMAP password for z on 	localhostrzJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)s
)r!lfr#)r)
/tmp/xxx 1)rF)r3z/tmp/yyy)r
/tmp/yyz 2rr5)r)z/tmpzyy*)rPr4)rK)NSUBJECTtest)r)1z(FLAGS INTERNALDATE RFC822))rk)r8FLAGSz
(\Deleted))r8rD)rrD)rrD)rrD)rPrD)r)UIDVALIDITY)rw)r/ALL)r)rN)rrDctj|d|tt||\}}tj|d|d||dk(r|d|S)Nr(rrr)Mrr)cmdrrrs    rFrunr?0sP	3%&"71c?D)S	c3/0$;c!f
rErzPROTOCOL_VERSION = %szCAPABILITIES = r)z/tmp/zyy%z.*"([^"]+)"$rrrwz%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
)Vrrrrr|rkrrrrr
rrriorrar`ImportError__all__rrQrrrrrrlrrrrnrorrrrqrmrprrrrrrr(	enumerater-rr	r
rrrAgetoptgetpassargvoptlistrrGrstream_commandoptrrcgetuserUSERPASSWD	test_mesg	test_seq1	test_seq2r?r=rSrrrr>mlrrrpathrrwprint)rrs00rF<module>rSsv
,KKKKK22"H8
	

(
,
,,
	,
	A	,

	
,
	

,
	
,
	,,
	,,
	,,
	
,
	,,
	
,
	
,
	,,
 	,!,
"	,#,
$	,%,
&	,',
(	,),
*	+,
,	A-,
.	,/,
0	
1,
2	,3,
4	A5,
6	
7,
8		9,
:	,;,
<	
=,
>	,?,
@	,A,
B	,C,
D	,E,
F	
G,
H%,%,%%,%W,
`rzz01

45rzz"**+RXX
6
"**^
$

DE
BJJGH"**;RXXG"Jxxv##2E#2JNN;555r*(*(X
<	A	A#	F&/qr
&;
<da188:ac>
<F	,%Rz%

chhqrlF;
N2C$;HE
D[ N 127D7??D
W__tTEX[EXY
ZF\gkrv_wwItVn*
dD)45)3,I$!
dD),-I)^,AdA77f!!"
I	'!*<*<<=	q~~78!	HCTN	f./	#B/2.B"((1+4B$4'"		#"		SHCc4.CDz77b'--/CBPR
S		S	 {q.Hd+=`<<
j	
 
hhqk

	s<OO"#O(?DP
OO(P7PP
%P/