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‘„ZJdgS)’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ƒ|_|jƒ|_ d|j krhd|_ n-d|j krƒd|_ n|j |j ƒ‚|j ƒx-tD]%}||jkrÁq¦n||_dSW|j d ƒ‚dS) Niiÿÿs(?Ps"\d+) (?P[A-Z]+) (?P.*)ZPREAUTHr ÚOKrzserver not IMAP4 compliant)r ÚrandomZrandintÚtagpreÚreÚcompileÚASCIIÚtagreÚ _get_responseZwelcomerErBr<Ú_get_capabilitiesÚAllowedVersionsÚ capabilitiesÚPROTOCOL_VERSION)rOÚversionr:r:r;rKÂs       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)rPrQrgÚsockÚmakefileÚfile)rOrPrQr:r:r;rJús  z IMAP4.opencCs|jj|ƒS)zRead 'size' bytes from remote.)rkÚread)rOÚsizer:r:r;rlsz IMAP4.readcCsB|jjtdƒ}t|ƒtkr>|jdtƒ‚n|S)zRead line from remote.ézgot more than %d bytes)rkÚreadlineÚ_MAXLINEÚlenr<)rOÚliner:r:r;ro szIMAP4.readlinecCs|jj|ƒdS)zSend data to remote.N)riZsendall)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) rkÚcloserirMrfZ SHUT_RDWRrNÚerrnoZENOTCONN)rOÚer:r:r;rMs zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )ri)rOr:r:r;rf%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. ZRECENTrSNrnéÿÿÿÿ)Ú_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)ryÚ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ÚINBOXrrnú(ú)z(%s)Nrx)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. rrSrnr rx)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ˆry)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;ru•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ˆry)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ˆry)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ˆry)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ˆry)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ˆry)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ˆry)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ˆry)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#rSrnr rx)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. rNrXú 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ˆry)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ˆry)rOr‰r|r}r:r:r;ÚmyrightsLszIMAP4.myrightscCs.d}|j|ƒ\}}|j|||ƒS)zb Returns IMAP namespaces ala rfc2342 (typ, [data, ...]) = .namespace() r%)rˆry)rOr{r|r}r:r:r;Ú namespaceTszIMAP4.namespacecCs |jdƒS)zFSend NOOP command. (typ, [data]) = .noop() r&)rˆ)rOr:r:r;rz^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ˆry)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ˆry)rOÚcharsetZcriteriar{r|r}r:r:r;ÚsearchŠs !z IMAP4.searchr‚FcCs¯i|_||_|r!d}nd}|j||ƒ\}}|dkr^d|_||fSd|_d|jkr“| r“|jd|ƒ‚n||jjdd 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+rSr rz READ-ONLYz%s is not writableÚEXISTSN)rErGrˆrBr>Ú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ˆry)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ˆry)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/rrnrƒr„z(%s)rx)rƒr„)rˆry)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 serverrSÚserver_hostnamerhTzCouldn't establish TLS session)ÚHAVE_SSLr<rIr=r]ÚsslÚ_create_stdlib_contextrˆÚ wrap_socketrirPrjrkr[ry)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ˆry)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) rrnrƒr„z(%s)r2rrx)rƒr„)rˆry)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ˆry)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)rr`r<rBÚjoinrˆry)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'. )rr`rBrˆ)rOr{rÈr:r:r;ÚxatomAs  z IMAP4.xatomcCsO|dkrd}n|j}||kr>||j|ƒn |g|||jjdƒ}|r:|j|djddƒƒ‚ndS)Nr¶rnÚasciiÚreplacerx)rErÅr=Údecode)rOZbyer:r:r;Ú _check_byeeszIMAP4._check_byec Gs�|jt|krKd|_|jd||jdjt|ƒfƒ‚nx*d D]"}||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ƒ}ny|j|tƒWn8tk rÕ} z|jd | ƒ‚WYdd} ~ XnX|dkræ|Sx£x!|jƒr |j|rì|SqìW|r%||jƒ}ny|j|ƒ|jtƒWn8tk r}} z|jd | ƒ‚WYdd} ~ XnX|séPqéqéW|S) Nz9command %s illegal in state %s, only allowed in states %sz, rSr´ÚBADz READ-ONLYz#mailbox status changed to READ-ONLYrXó z {%s}zsocket error: %s)zOKzNOrä)rBr`rCr<rÚrErGr>Ú_new_tagÚbytesr°r±ÚtypeÚ_commandrqrtr‡rNr=rZrDrF) rOr{rÈr|ÚtagrsÚargrCZ literatorÚvalr:r:r;réks^             &   &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|rsrìr:r:r;Ú_command_complete¸s  +,   zIMAP4._command_completecCsk|jƒ\}}|dgkr3|jdƒ‚nt|ddƒ}|jƒ}t|jƒƒ|_dS)Nz"no CAPABILITY response from serverrnrXrx)r’r<r±rÚtupleÚsplitr])rOr|r}r:r:r;r[És  zIMAP4._get_capabilitiescCsi|jƒ}|j|j|ƒr¤|jjdƒ}||jkrX|jd|ƒ‚n|jjdƒ}t|dƒ}|jjdƒ}||gf|j|Ú IMAP4_PORTrRrKrergrJrlrortrMrfr~r�r�r‘r’r“rur•r–r—r™ršr›rœrŸr¢r£r§r«r­r¬r¹rºr»r¼rzr¾r¿rÀrÃrÆrÇrÉrÊrÌrÓrÕr×rØrÙrÛrÜrÝrßrãrérîr[rZrírñròrær¨rˆryr: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)Ú ValueErrorrrrÏrÐrÒrrR)rOrPrQrrrÒr:r:r;rR¸s     zIMAP4_SSL.__init__cCs(tj|ƒ}|jj|d|jƒS)NrÍ)rrgrÒrÑrP)rOrir:r:r;rgÈ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_PORTrRrgrJr:r:r:r;r¥s  rc@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)rPrQrirkÚ subprocessÚPopenrÖrÚPIPEr�r Ú writefiler Úreadfile)rOrPrQr:r:r;rJés    zIMAP4_stream.opencCs|jj|ƒS)zRead 'size' bytes from remote.)rrl)rOrmr:r:r;rlùszIMAP4_stream.readcCs |jjƒS)zRead line from remote.)rro)rOr:r:r;roþszIMAP4_stream.readlinecCs!|jj|ƒ|jjƒdS)zSend data to remote.N)rÚwriteÚflush)rOrsr:r:r;rtszIMAP4_stream.sendcCs+|jjƒ|jjƒ|jjƒdS)z Close I/O established in "open".N)rrurr�Úwait)rOr:r:r;rM s  zIMAP4_stream.shutdown) r7r8r9rrRrJrlrortrMr: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²)rOrsZretr: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ÞrXé0rnrx)r°r±r²rqÚbinasciiZ b2a_base64)rOÚinpZoupÚtrwr:r:r;r² s  z_Authenticator.encodecCs|s dStj|ƒS)NrÞ)rZ a2b_base64)rOrr:r:r;râ8sz_Authenticator.decodeN)r7r8r9rrRr�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)rn)r²)Ú.0Únrr:r:r;ú >s rrnc 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é<ó-rnrxrxrx) Ú InternalDaterÿÚMon2numrôrùÚcalendarZtimegmÚtimeÚ localtime)rûrórr r!r"r#r$r%r&r'ZzoneZttÚ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érn)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ïrôrð)rûrór: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. érnZsecondsÚtzinfoNézdate_time must be awarerrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"rxrx)rr)r°rùÚfloatrZ fromtimestamprr/Z astimezonerïZ tm_gmtoffrcr-Zdaylightr.ZmktimeZaltzonerr6r r±ÚformatÚMonthsZmonthZstrftime)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~rur�Z UIDVALIDITYrÛZALLrÄr¹cCsitjd||fƒtt|ƒ|Œ\}}tjd|||fƒ|dkre|d‚n|S)Nz%s %sz %s => %s %sr´r)ÚMÚ_mesgra)ÚcmdrÈr|r}r:r:r;ÚrunÜs  rBzPROTOCOL_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Ú __version__rrvrTrVrfrr·r-r,rrrÚiorrÏrÎÚ ImportErrorÚ__all__r‡r@rr r\rpr`rWr÷r4r*rXrør…rúrõrörrr�rrŽrðr:Ú enumerater+rr r r r7ZgetoptZgetpassÚargvZoptlistrÈr<rìZstream_commandZoptrùrPZgetuserZUSERZPASSWDZ test_mesgZ test_seq1Z test_seq2rBr?rBr@r^r]rAZmlrÿrórôÚpathr}rÛÚprintr:r:r:r;Ú s8 l                                         ÿÿÿÿ009,# # ) )%