grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î ¤ f[Äã%@s‘dZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZyddlZdZWnek rÔdZYnXdd d d d d gZdZdZdZdZddfZdZi'ddfd6dfd6ddddfd6dfd6dfd6dfd6ddfd6ddfd6ddfd6ddfd 6dfd!6dfd"6ddfd#6ddfd$6ddfd%6ddfd&6ddfd'6ddfd(6dfd)6ddddfd6ddfd*6ddfd+6ddddfd,6dfd-6dfd.6ddfd/6dfd06ddfd16ddfd26ddfd36ddfd46dfd56dfd66ddfd76dfd86ddfd96dfd:6dfd;6ddfd<6Zejd=ƒZejd>ƒZejd?ƒZejd@ejƒZ ejdAƒZ!ejdBƒZ"ejdCƒZ#ejdDejƒZ$GdEd„dƒZ%erÀGdFdG„dGe%ƒZ&ej'dGƒnGdHd „d e%ƒZ(GdIdJ„dJƒZ)dKj*dLƒZ+dMdN„e,e+dOd…ƒDƒZ-dPd „Z.dQd „Z/dRd „Z0dSd „Z1e2dTkr�ddl3Z3ddl4Z4y)e3j3ej5dOd…dUƒ\Z6Z7Wn:e3j8k rÔZ9zfff\Z6Z7WYddZ9[9XnXdZ:xWe6D]O\Z;Z9e;dVkr e<e9ƒZn(e;dWkr1e9Z:e7 r.e:fZ7nnqâWe7 rHdXfZ7ne7dZ=e4j>ƒZ?e4j4dYe?e=psdZfƒZ@d[ie?d\6d]d^6ZAd_e?e@ffd`daffdbdadcffdddffdeddddeAffdfdgdhffdiddffdjddkdlffdmdndoffdpdndqdrffdsffdtffduffdvfffZBdiffdwdxffdyd0dzffdwd{ffdedddeAffduffd|fffZCd}d~„ZDy’e:rÙe(e:ƒZEn e%e=ƒZEeEjFdkreBdOd…ZBneEjGdeEjHƒeEjGd€eEjIfƒx!eBD]\ZJZ7eDeJe7ƒq9WxheDdfd�d‚fƒD]QZKejLdƒeKƒZMeMrœeMjNdOƒZOneKj*ƒdO ZOeDd„eOfƒqlWx„eCD]|\ZJZ7eDeJe7ƒZPeJe7fdyd0dzffkrqÈnePdO j*ƒZQeQ r%qÈneDdyd"d…eQdO d†fƒqÈWeRd‡ƒWn4eRdˆƒe r‚eRd‰ej5dƒn‚YnXndS)Š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ÚTime2Internaldates é�iáZ IMAP4REV1i@BÚAUTHÚSELECTEDÚAPPENDÚNONAUTHÚ AUTHENTICATEÚLOGOUTÚ CAPABILITYÚCHECKÚCLOSEÚCOPYÚCREATEÚDELETEÚ DELETEACLÚEXAMINEÚEXPUNGEÚFETCHÚGETACLÚ GETANNOTATIONÚGETQUOTAÚ GETQUOTAROOTÚMYRIGHTSÚLISTÚLOGINÚLSUBÚ NAMESPACEÚNOOPÚPARTIALÚ PROXYAUTHÚRENAMEÚSEARCHÚSELECTÚSETACLÚ SETANNOTATIONÚSETQUOTAÚSORTÚSTARTTLSÚSTATUSÚSTOREÚ SUBSCRIBEÚTHREADÚUIDÚ UNSUBSCRIBEs\+( (?P.*))?s.*FLAGS \((?P[^\)]*)\)sÕ.*INTERNALDATE "(?P[ 0123][0-9])-(?P[A-Z][a-z][a-z])-(?P[0-9][0-9][0-9][0-9]) (?P[0-9][0-9]):(?P[0-9][0-9]):(?P[0-9][0-9]) (?P[-+])(?P[0-9][0-9])(?P[0-9][0-9])"s.*{(?P\d+)}$s \r\n|\r|\ns)\[(?P[A-Z-]+)( (?P[^\]]*))?\]s$\* (?P[A-Z-]+)( (?P.*))?s3\* (?P\d+) (?P[A-Z-]+)( (?P.*))?c@sÄeZdZdZGdd„deƒZGdd„deƒZGdd„deƒZded d „Z d d „Z d d„Z dd„Z dedd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Z d9d:„Z!d;d<„Z"d=d>„Z#d?d@dAdB„Z$dCdD„Z%dEdF„Z&dGdH„Z'dIdJ„Z(d?d@dKdL„Z)dMdN„Z*dOdP„Z+dQdR„Z,dSdT„Z-dUdV„Z.dWdX„Z/dYdZ„Z0d[d\d]d^„Z1d_d`„Z2dadb„Z3dcdd„Z4dedf„Z5dgdhdi„Z6djdk„Z7dldm„Z8dndo„Z9dpdq„Z:drds„Z;dtdu„Z<dvdw„Z=dxdy„Z>dzd{„Z?d|d}„Z@d~d„ZAd€d�„ZBd‚dƒ„ZCd„d…„ZDd†d‡„ZEdˆd‰„ZFdŠd‹„ZGdŒd�„ZHdŽd�„ZId�d‘„ZJdgd’d“„ZKd”d•„ZLd–d—„ZMd˜d™„ZNdgS)šraë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 .error(""). IMAP4 server errors raise .abort(""), which is a sub-class of 'error'. Mailbox status changes from READ-WRITE to READ-ONLY raise the exception class .readonly(""), 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)z IMAP4.errorN)Ú__name__Ú __module__Ú __qualname__©r:r:ú,/opt/alt/python34/lib64/python3.4/imaplib.pyÚerror¥s r<c@seZdZdS)z IMAP4.abortN)r7r8r9r:r:r:r;Úabort¦s r=c@seZdZdS)zIMAP4.readonlyN)r7r8r9r:r:r:r;Úreadonly§s r>ÚcCs®t|_d|_d|_i|_i|_d|_d|_d|_d|_ |j ||ƒy|j ƒWn8t k r©y|j ƒWntk r¡YnX‚YnXdS)Nrr?Fr)ÚDebugÚdebugÚstateÚliteralÚtagged_commandsÚuntagged_responsesÚcontinuation_responseÚ is_readonlyÚtagnumÚ_tls_establishedÚopenÚ_connectÚ ExceptionÚshutdownÚOSError)ÚselfÚhostÚportr:r:r;Ú__init__©s$           zIMAP4.__init__cCs]ttjddƒƒ|_tjd|jdtjƒ|_d|_d|_ i|_ |j dkr�|j dt ƒ|j d |jƒn|jƒ|_d |jkrºd |_n-d |jkrÕd |_n|j|jƒ‚|jƒ|j dkr|j d|jfƒnx-tD]%}||jkr<q!n||_dSW|jdƒ‚dS)Niiÿÿs(?Ps"\d+) (?P[A-Z]+) (?P.*)é rézimaplib version %sznew IMAP4 connection, tag=%sZPREAUTHr ÚOKrézCAPABILITIES: %rzserver not IMAP4 compliant)r ÚrandomZrandintÚtagpreÚreÚcompileÚASCIIÚtagreÚ _cmd_log_lenÚ _cmd_log_idxÚ_cmd_logrAÚ_mesgÚ __version__Ú _get_responseZwelcomerErBr<Ú_get_capabilitiesÚ capabilitiesÚAllowedVersionsÚPROTOCOL_VERSION)rOÚversionr:r:r;rKÂs0        zIMAP4._connectcCs3|tkrt||jƒƒStd|ƒ‚dS)NzUnknown IMAP4 command: '%s')ÚCommandsÚgetattrÚlowerÚAttributeError)rOÚattrr:r:r;Ú __getattr__ìs zIMAP4.__getattr__cCstj|j|jfƒS)N)ÚsocketZcreate_connectionrPrQ)rOr:r:r;Ú_create_socket÷szIMAP4._create_socketcCs:||_||_|jƒ|_|jjdƒ|_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)rPrQroÚsockÚmakefileÚfile)rOrPrQr:r:r;rJús  z IMAP4.opencCs|jj|ƒS)zRead 'size' bytes from remote.)rsÚread)rOÚsizer:r:r;rtsz IMAP4.readcCsB|jjtdƒ}t|ƒtkr>|jdtƒ‚n|S)zRead line from remote.rTzgot more than %d bytes)rsÚreadlineÚ_MAXLINEÚlenr<)rOÚliner:r:r;rv szIMAP4.readlinecCs|jj|ƒdS)zSend data to remote.N)rqZsendall)rOÚdatar:r:r;Úsendsz IMAP4.sendcCs}|jjƒz[y|jjtjƒWn=tk rf}z|jtjkrT‚nWYdd}~XnXWd|jjƒXdS)z Close I/O established in "open".N) rsÚcloserqrMrnZ SHUT_RDWRrNÚerrnoZENOTCONN)rOÚer:r:r;rMs zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )rq)rOr:r:r;rn%sz 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]) = .recent() 'data' is None if no new messages, else list of RECENT responses, most recent last. ZRECENTrUNrTéÿÿÿÿ)Ú_untagged_responseÚnoop)rOÚnameÚtypÚdatr:r:r;Úrecent1s   z IMAP4.recentcCs|j|dg|jƒƒS)z¥Return data for response 'code' if received, or None. Old value for response 'code' is cleared. (code, [data]) = .response(code) N)r€Úupper)rOÚcoder:r:r;ÚresponseBszIMAP4.responsecCs‘d}|sd}n|rE|d|d fd krKd|}qKnd}|r`t|ƒ}nd}tjt|ƒ|_|j||||ƒS) z°Append message to named mailbox. (typ, [data]) = .append(mailbox, flags, date_time, message) All args except `message' can be None. rÚINBOXrrTú(ú)z(%s)Nr)rŠr‹)r ÚMapCRLFÚsubÚCRLFrCÚ_simple_command)rOÚmailboxÚflagsÚ date_timeÚmessager‚r:r:r;ÚappendPs z IMAP4.appendcCsk|jƒ}t|ƒj|_|jd|ƒ\}}|dkrX|j|dƒ‚nd|_||fS)asAuthenticate command - requires response processing. 'mechanism' specifies which authentication mechanism is to be used - it must appear in .capabilities in the form AUTH=. '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. rrUrTr r)r†Ú_AuthenticatorÚprocessrCr�r<rB)rOZ mechanismZ authobjectÚmechrƒr„r:r:r;Ú authenticategs   zIMAP4.authenticatecCs.d}|j|ƒ\}}|j|||ƒS)zT(typ, [data]) = .capability() Fetch capabilities list from server.r)r�r€)rOr‚rƒr„r:r:r;Ú capability„szIMAP4.capabilitycCs |jdƒS)zRCheckpoint mailbox on server. (typ, [data]) = .check() r)r�)rOr:r:r;Úcheck�sz IMAP4.checkc Cs0z|jdƒ\}}Wdd|_X||fS)zÌClose currently selected mailbox. Deleted messages are removed from writable mailbox. This is the recommended command before 'LOGOUT'. (typ, [data]) = .close() rNr )r�rB)rOrƒr„r:r:r;r|•s z IMAP4.closecCs|jd||ƒS)z‚Copy 'message_set' messages onto end of 'new_mailbox'. (typ, [data]) = .copy(message_set, new_mailbox) r)r�)rOÚ message_setZ new_mailboxr:r:r;Úcopy¤sz IMAP4.copycCs|jd|ƒS)zPCreate new mailbox. (typ, [data]) = .create(mailbox) r)r�)rOr�r:r:r;Úcreate¬sz IMAP4.createcCs|jd|ƒS)zPDelete old mailbox. (typ, [data]) = .delete(mailbox) r)r�)rOr�r:r:r;Údelete´sz IMAP4.deletecCs|jd||ƒS)z€Delete the ACLs (remove any rights) set for who on mailbox. (typ, [data]) = .deleteacl(mailbox, who) r)r�)rOr�Úwhor:r:r;Ú deleteacl»szIMAP4.deleteaclcCs.d}|j|ƒ\}}|j|||ƒS)z÷Permanently remove deleted items from selected mailbox. Generates 'EXPUNGE' response for each deleted message. (typ, [data]) = .expunge() 'data' is list of 'EXPUNGE'd message numbers in order received. r)r�r€)rOr‚rƒr„r:r:r;ÚexpungeÂs z IMAP4.expungecCs4d}|j|||ƒ\}}|j|||ƒS)a#Fetch (parts of) messages. (typ, [data, ...]) = .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�r€)rOr›Z message_partsr‚rƒr„r:r:r;ÚfetchÐs z IMAP4.fetchcCs+|jd|ƒ\}}|j||dƒS)zXGet the ACLs for a mailbox. (typ, [data]) = .getacl(mailbox) rZACL)r�r€)rOr�rƒr„r:r:r;Úgetaclßsz IMAP4.getaclcCs1|jd|||ƒ\}}|j||dƒS)za(typ, [data]) = .getannotation(mailbox, entry, attribute) Retrieve ANNOTATIONs.rÚ ANNOTATION)r�r€)rOr�ÚentryZ attributerƒr„r:r:r;Ú getannotationèszIMAP4.getannotationcCs+|jd|ƒ\}}|j||dƒS)zªGet the quota root's resource usage and limits. Part of the IMAP4 QUOTA extension defined in rfc2087. (typ, [data]) = .getquota(root) rÚQUOTA)r�r€)rOÚrootrƒr„r:r:r;ÚgetquotaðszIMAP4.getquotacCs^|jd|ƒ\}}|j||dƒ\}}|j||dƒ\}}|||gfS)zœGet the list of quota roots for the named mailbox. (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = .getquotaroot(mailbox) r r§Z QUOTAROOT)r�r€)rOr�rƒr„ZquotaZ quotarootr:r:r;Ú getquotarootûszIMAP4.getquotarootz""Ú*cCs4d}|j|||ƒ\}}|j|||ƒS)z«List mailbox names in directory matching pattern. (typ, [data]) = .list(directory='""', pattern='*') 'data' is list of LIST responses. r")r�r€)rOÚ directoryÚpatternr‚rƒr„r:r:r;Úlistsz IMAP4.listcCsY|jd||j|ƒƒ\}}|dkrF|j|dƒ‚nd|_||fS)z”Identify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. r#rUrTr r)r�Ú_quoter<rB)rOÚuserÚpasswordrƒr„r:r:r;Úlogins $  z IMAP4.logincCs&|||_|_|jd|jƒS)zr Force use of CRAM-MD5 authentication. (typ, [data]) = .login_cram_md5(user, password) zCRAM-MD5)r°r±r˜Ú_CRAM_MD5_AUTH)rOr°r±r:r:r;Úlogin_cram_md5 szIMAP4.login_cram_md5cCs]ddl}t|jtƒr0|jjdƒn|j}|jd|j||dƒjƒS)z1 Authobject to use with CRAM-MD5 authentication. rNr[ú Zmd5)ÚhmacÚ isinstancer±ÚstrÚencoder°ZHMACZ hexdigest)rOZ challenger¶Úpwdr:r:r;r³)s $ zIMAP4._CRAM_MD5_AUTHc Cs…d|_y|jdƒ\}}Wn,ddtjƒdd…g}}YnX|jƒd|jkr{d|jdfS||fS)z|Shutdown connection to server. (typ, [data]) = .logout() Returns server 'BYE' response. rÚNOz%s: %sNéÚBYE)rBr�ÚsysÚexc_inforMrE)rOrƒr„r:r:r;Úlogout1s ) z IMAP4.logoutcCs4d}|j|||ƒ\}}|j|||ƒS)zÐList 'subscribed' mailbox names in directory matching pattern. (typ, [data, ...]) = .lsub(directory='""', pattern='*') 'data' are tuples of message part envelope and data. r$)r�r€)rOr¬r­r‚rƒr„r:r:r;ÚlsubAsz IMAP4.lsubcCs+|jd|ƒ\}}|j||dƒS)zƒShow my ACLs for a mailbox (i.e. the rights that I have on mailbox). (typ, [data]) = .myrights(mailbox) r!)r�r€)rOr�rƒr„r:r:r;ÚmyrightsLszIMAP4.myrightscCs.d}|j|ƒ\}}|j|||ƒS)zb Returns IMAP namespaces ala rfc2342 (typ, [data, ...]) = .namespace() r%)r�r€)rOr‚rƒr„r:r:r;Ú namespaceTszIMAP4.namespacecCs/|jdkr"|j|jƒn|jdƒS)zFSend NOOP command. (typ, [data]) = .noop() rVr&)rAÚ_dump_urrEr�)rOr:r:r;r�^sz IMAP4.noopcCs:d}|j|||||ƒ\}}|j||dƒS)zÂFetch truncated part of a message. (typ, [data, ...]) = .partial(message_num, message_part, start, length) 'data' is tuple of message part envelope and data. r'r)r�r€)rOZ message_numZ message_partÚstartZlengthr‚rƒr„r:r:r;Úpartialis!z IMAP4.partialcCsd}|jd|ƒS)z³Assume authentication as "user". Allows an authorised administrator to proxy into any user's mailbox. (typ, [data]) = .proxyauth(user) r()r�)rOr°r‚r:r:r;Ú proxyauthus zIMAP4.proxyauthcCs|jd||ƒS)zkRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) r))r�)rOZ oldmailboxZ newmailboxr:r:r;Úrename‚sz IMAP4.renamecGsXd}|r-|j|d||Œ\}}n|j||Œ\}}|j|||ƒS)z·Search mailbox for matching messages. (typ, [data]) = .search(charset, criterion, ...) 'data' is space separated list of matching message numbers. r*ÚCHARSET)r�r€)rOÚcharsetZcriteriar‚rƒr„r:r:r;ÚsearchŠs !z IMAP4.searchr‰FcCsÑi|_||_|r!d}nd}|j||ƒ\}}|dkr^d|_||fSd|_d|jkrµ| rµ|jdkrŸ|j|jƒn|jd|ƒ‚n||jjd d gƒfS) atSelect a mailbox. Flush all untagged responses. (typ, [data]) = .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 .response('FLAGS') etc. rr+rUr rz READ-ONLYrTz%s is not writableÚEXISTSN)rErGr�rBrArÄr>Úget)rOr�r>r‚rƒr„r:r:r;Úselect™s       z IMAP4.selectcCs|jd|||ƒS)zZSet a mailbox acl. (typ, [data]) = .setacl(mailbox, who, what) r,)r�)rOr�rŸZwhatr:r:r;Úsetacl¹sz IMAP4.setaclcGs+|jd|Œ\}}|j||dƒS)z_(typ, [data]) = .setannotation(mailbox[, entry, attribute]+) Set ANNOTATIONs.r-r¤)r�r€)rOÚargsrƒr„r:r:r;Ú setannotationÁszIMAP4.setannotationcCs.|jd||ƒ\}}|j||dƒS)ziSet the quota root's resource limits. (typ, [data]) = .setquota(root, limits) r.r§)r�r€)rOr¨Zlimitsrƒr„r:r:r;ÚsetquotaÉszIMAP4.setquotacGs^d}|d|dfdkr-d|}n|j||||Œ\}}|j|||ƒS) z�IMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) r/rrTrŠr‹z(%s)r)rŠr‹)r�r€)rOZ sort_criteriarÊÚsearch_criteriar‚rƒr„r:r:r;ÚsortÒs  z IMAP4.sortNcCsd}ts|jdƒ‚n|jr9|jdƒ‚n||jkrZ|jdƒ‚n|dkrutjƒ}n|j|ƒ\}}|dkrß|j|j d|j ƒ|_ |j j dƒ|_ d|_|j ƒn|jd ƒ‚|j|||ƒS) Nr0zSSL support missingzTLS session already establishedzTLS not supported by serverrUÚserver_hostnamerpTzCouldn't establish TLS session)ÚHAVE_SSLr<rIr=rdÚsslÚ_create_stdlib_contextr�Ú wrap_socketrqrPrrrsrcr€)rOÚ ssl_contextr‚rƒr„r:r:r;Ústarttlsàs$     zIMAP4.starttlscCs4d}|j|||ƒ\}}|j|||ƒS)zpRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) r1)r�r€)rOr�Únamesr‚rƒr„r:r:r;Ústatus÷sz IMAP4.statuscCsX|d|dfd kr'd|}n|jd|||ƒ\}}|j||dƒS) z�Alters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) rrTrŠr‹z(%s)r2rr)rŠr‹)r�r€)rOr›Úcommandr‘rƒr„r:r:r;Ústores z IMAP4.storecCs|jd|ƒS)zYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) r3)r�)rOr�r:r:r;Ú subscribeszIMAP4.subscribecGs7d}|j||||Œ\}}|j|||ƒS)z‹IMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) r4)r�r€)rOZthreading_algorithmrÊrÓr‚rƒr„r:r:r;Úthreadsz IMAP4.threadcGs¿|jƒ}|tkr.|jd|ƒ‚n|jt|krp|jd||jdjt|ƒfƒ‚nd}|j|||Œ\}}|d kr¦|}nd}|j|||ƒS) zåExecute "command arg ..." with messages identified by UID, rather than message number. (typ, [data]) = .uid(command, arg1, arg2, ...) Returns response appropriate to 'command'. zUnknown IMAP4 UID command: %sz9command %s illegal in state %s, only allowed in states %sz, r5r*r/r4r)zSEARCHzSORTzTHREAD)r†rhr<rBÚjoinr�r€)rOrÞrÐr‚rƒr„r:r:r;Úuid s      z IMAP4.uidcCs|jd|ƒS)z_Unsubscribe from old mailbox. (typ, [data]) = .unsubscribe(mailbox) r6)r�)rOr�r:r:r;Ú unsubscribe9szIMAP4.unsubscribecGs;|jƒ}|tkr+|jft|.xatom(name, arg, ...) Returns response appropriate to extension command `name'. )r†rhrBr�)rOr‚rÐr:r:r;ÚxatomAs  z IMAP4.xatomcCs�|dkrd}n|j}|jdkr\|jd|t|j|dƒƒ|fƒn||kr|||j|ƒn |g|||jjdƒ}|r:|j|djddƒƒ‚ndS)Nr½rTÚasciiÚreplacer)rErÍr=Údecode)rOZbyer:r:r;Ú _check_byeeszIMAP4._check_byec Gsí|jt|krKd|_|jd||jdjt|ƒfƒ‚nx*dD]"}||jkrR|j|=qRqRWd|jkr£|j r£|jdƒ‚n|jƒ}t |dƒ}|d |}xO|D]G}|dkrëqÓnt |t ƒr t |dƒ}n|d |}qÓW|j}|dk r†d|_t |ƒt |j ƒkr`|}q†d}|t d t|ƒdƒ}n|jd kr©|jd |ƒn|jd |ƒy|j|tƒWn8tk r } z|jd | ƒ‚WYdd} ~ XnX|dkr|SxÌx!|jƒr@|j|r |Sq W|rY||jƒ}n|jd kr‚|jdt|ƒƒny|j|ƒ|jtƒWn8tk rÚ} z|jd | ƒ‚WYdd} ~ XnX|sPqqW|S)Nz9command %s illegal in state %s, only allowed in states %sz, rUr»ÚBADz READ-ONLYz#mailbox status changed to READ-ONLYr[ó z {%s}éz> %rzsocket error: %szwrite literal size %s)zOKzNOrí)rBrhrCr<rârErGr>Ú_new_tagÚbytesr·r¸ÚtypeÚ_commandrxrAr`Ú_logr{rŽrNr=rbrDrF) rOr‚rÐrƒÚtagrzÚargrCZ literatorÚvalr:r:r;róksh             &   &zIMAP4._commandcCs|dkr|jƒny|j|ƒ\}}Wn�|jk ru}z|jd||fƒ‚WYdd}~XnA|jk rµ}z|jd||fƒ‚WYdd}~XnX|dkrÏ|jƒn|dkrú|jd|||fƒ‚n||fS)Nrzcommand: %s => %sríz%s command error: %s %s)rìÚ_get_tagged_responser=r<)rOr‚rõrƒrzr÷r:r:r;Ú_command_complete¸s  +,   zIMAP4._command_completecCsk|jƒ\}}|dgkr3|jdƒ‚nt|ddƒ}|jƒ}t|jƒƒ|_dS)Nz"no CAPABILITY response from serverrTr[r)r™r<r¸r†ÚtupleÚsplitrd)rOrƒr„r:r:r;rcÉs  zIMAP4._get_capabilitiescCsÁ|jƒ}|j|j|ƒr¤|jjdƒ}||jkrX|jd|ƒ‚n|jjdƒ}t|dƒ}|jjdƒ}||gf|j| %r)ÚmatchrrAr`r­Úgroups)rOZcreÚsr:r:r;rÿPs&z IMAP4._matchcCs@|jtt|jƒdƒ}|jd|_d|j|<|S)Nr[rT)rXrñr¸rHrD)rOrõr:r:r;rð\s zIMAP4._new_tagcCs0|jddƒ}|jddƒ}d|dS)Nú\z\\ú"z\")rê)rOrör:r:r;r¯dsz IMAP4._quotecGs|j||j||ŒƒS)N)rùró)rOr‚rÐr:r:r;r�lszIMAP4._simple_commandcCsw|dkr||fS||jkr2|dgfS|jj|ƒ}|jdkrm|jd||fƒn||fS)Nr»rçzuntagged_responses[%s] => %s)rEÚpoprAr`)rOrƒr„r‚rzr:r:r;r€qs   zIMAP4._untagged_responsecCsl|dkrtjƒ}ntjdtj|ƒƒ}tjjd||dd|fƒtjjƒdS)Nz%M:%Sz %s.%02d %s éd)ÚtimeÚstrftimeÚ localtimer¾ÚstderrÚwriteÚflush)rOrZsecsZtmr:r:r;r`s  %z IMAP4._mesgcCsU|jƒ}|sdSd}tdd„|ƒ}|jd||j|ƒfƒdS)Nz cSs3d|d|ddr+dj|dƒp.dfS)Nz%s: "%s"rrTz" "r?)râ)Úxr:r:r;Ú‹sz IMAP4._dump_ur..zuntagged responses dump:%s%s)ÚitemsÚmapr`râ)rOÚdictÚlÚtr:r:r;rĆs  zIMAP4._dump_urcCsM|tjƒf|j|j<|jd7_|j|jkrId|_ndS)NrTr)rr_r^r])rOryr:r:r;rôŽsz IMAP4._logc Cs�|jdt|jƒƒ|j|j}}xY|rˆy|j|j|ŒWnYnX|d7}||jkr{d}n|d8}q0WdS)Nzlast %d IMAP4 interactions:rTr)r`rxr_r^r])rOÚiÚnr:r:r;r •s   zIMAP4.print_log)Or7r8r9Ú__doc__rLr<r=r>Ú IMAP4_PORTrRrKrmrorJrtrvr{rMrnr…rˆr”r˜r™ršr|rœr�ržr r¡r¢r£r¦r©rªr®r²r´r³rÀrÁrÂrÃr�rÆrÇrÈrËrÎrÏrÑrÒrÔrÛrÝrßràrárãrärårèrìrórùrcrbrørþrÿrðr¯r�r€r`rÄrôr r:r:r:r;rws” , *                                  M  P        c@sOeZdZdZdeddddd„Zdd„Zdedd „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ƒ‚n|dk rN|dk rNtdƒ‚n||_||_|dkr‡tjd|d|ƒ}n||_tj|||ƒdS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusiveÚcertfileÚkeyfile)Ú ValueErrorr'r&r×rØrÚrrR)rOrPrQr'r&rÚr:r:r;rR¸s     zIMAP4_SSL.__init__cCs(tj|ƒ}|jj|d|jƒS)NrÕ)rrorÚrÙrP)rOrqr:r:r;roÈszIMAP4_SSL._create_socketcCstj|||ƒ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)rrJ)rOrPrQr:r:r;rJÍszIMAP4_SSL.open)r7r8r9r#ÚIMAP4_SSL_PORTrRrorJr:r:r:r;r%¥s  r%c@sdeZdZdZdd„Zdddd„Zdd„Zd d „Zd d „Zd d„Z dS)rzí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ÞrrR)rOrÞr:r:r;rRäs zIMAP4_stream.__init__Nc Csd|_d|_d|_d|_tj|jdtdtjdtjddddƒ|_ |j j |_ |j j |_ dS)z…Setup a stream connection. This connection will be used by the routines: read, readline, send, shutdown. NÚbufsizeÚstdinÚstdoutÚshellTZ close_fds)rPrQrqrsÚ subprocessÚPopenrÞrÚPIPEr–r+Ú writefiler,Úreadfile)rOrPrQr:r:r;rJés    zIMAP4_stream.opencCs|jj|ƒS)zRead 'size' bytes from remote.)r2rt)rOrur:r:r;rtùszIMAP4_stream.readcCs |jjƒS)zRead line from remote.)r2rv)rOr:r:r;rvþszIMAP4_stream.readlinecCs!|jj|ƒ|jjƒdS)zSend data to remote.N)r1rr)rOrzr:r:r;r{szIMAP4_stream.sendcCs+|jjƒ|jjƒ|jjƒdS)z Close I/O established in "open".N)r2r|r1r–Úwait)rOr:r:r;rM s  zIMAP4_stream.shutdown) r7r8r9r#rRrJrtrvr{rMr:r:r:r;rØs     c@sFeZdZdZdd„Zdd„Zdd„Zdd „Zd S) r•zcPrivate class to provide en/decoding for base64-based authentication conversation. cCs ||_dS)N)r—)rOZmechinstr:r:r;rRsz_Authenticator.__init__cCs5|j|j|ƒƒ}|dkr(dS|j|ƒS)Nó*)r—rër¹)rOrzZretr:r:r;r–s z_Authenticator.processcCs¥d}t|tƒr'|jdƒ}nxw|r t|ƒdkre|dd…}|dd…}n |}d}tj|ƒ}|r*||dd…}q*q*W|S)Nrær[é0rTr)r·r¸r¹rxÚbinasciiZ b2a_base64)rOÚinpZoupr r~r:r:r;r¹ s  z_Authenticator.encodecCs|s dStj|ƒS)Nræ)r6Z a2b_base64)rOr7r:r:r;rë8sz_Authenticator.decodeN)r7r8r9r#rRr–r¹rër:r:r:r;r•s    r•z0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrµcCs)i|]\}}|d|jƒ“qS)rT)r¹)Ú.0r"rr:r:r;ú >s r9rTc Cs7tj|ƒ}|sdSt|jdƒ}|jdƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jd ƒƒ} t|jd ƒƒ} | d | d } |d krö| } n||||||dddf } tj| ƒ| } 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é<ó-rTrrr) Ú InternalDater ÚMon2numrrÚcalendarZtimegmrr)rrr:r;r<r=r>r?r@rArBZzoneZttÚutcr:r:r;r@s$  !cCs\d}d}tt|ƒƒ}x7|rWt|dƒ\}}|||d…|}q!W|S)z-Convert integer to A-P string representation.ræsABCDEFGHIJKLMNOPérT)rÚabsÚdivmod)Znumr÷ZAPÚmodr:r:r;r cs cCs2tj|ƒ}|sfSt|jdƒjƒƒS)z-Convert IMAP4 flags response to python tuple.r‘)ÚFlagsr rúrrû)rrr:r:r;r pscCsŒt|ttfƒr3tj|tjƒjƒ}n6t|tƒrúy |j }Wntt k rÅt j r·|d}|d kr�t j t j|ƒƒd}nt jt jf| }n t j }YnXtd|ƒ}tdt|ƒ|dd…Œ}not|tƒr0|jdkr'tdƒ‚n|}n9t|tƒr]|d|d fdkr]|Std ƒ‚d jt|jƒ}|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. érTZsecondsÚtzinfoNézdate_time must be awarerrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"rr)rr)r·rÚfloatrZ fromtimestamprrHZ astimezonerúZ tm_gmtoffrkrZdaylightrZmktimeZaltzonerrOr(r¸ÚformatÚMonthsZmonthr)r’ZdtZgmtoffZdstZdeltaZfmtr:r:r;r {s0       % ) Ú__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)sr°Ú Zlfr²r�z /tmp/xxx 1rÈz/tmp/yyyz /tmp/yyz 2r”r®z/tmpzyy*rÎrËZSUBJECTZtestr¢Ú1z(FLAGS INTERNALDATE RFC822)rßÚFLAGSz (\Deleted)rÃr¡r…r|rˆZ UIDVALIDITYrãZALLrÌrÀcCsitjd||fƒtt|ƒ|Œ\}}tjd|||fƒ|dkre|d‚n|S)Nz%s %sz %s => %s %sr»r)ÚMr`ri)ÚcmdrÐrƒr„r:r:r;ÚrunÜs  rZzPROTOCOL_VERSION = %szCAPABILITIES = %rz/tmp/zyy%z .*"([^"]+)"$ržz%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 )Sr#rar6r}rWrYrnr.r¾rrGrrrÚiorr×rÖÚ ImportErrorÚ__all__rŽr@r$r)rerwrhrZrrMrEr[rrŒrrrrr%r”rr•rûrSÚ enumeraterFrr r r r7ZgetoptZgetpassÚargvZoptlistrÐr<r÷Zstream_commandZoptrrPZgetuserZUSERZPASSWDZ test_mesgZ test_seq1Z test_seq2rZrXrBr`rfrdrYZmlr rrÚpathr„rãÚprintr:r:r:r;Ú s8 l                                         ÿÿÿÿ009,# # ) )%