grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ”qc×ËãY@sbdZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZyddlZdZWnek rÔdZYnXdd d d d d gZdZdZdZdZddfZdZdddfddfdddddfddfddfddfdddfdddfdddfd dfd!ddfd"dfd#dfd$ddfd%ddfd&ddfd'ddfd(ddfd)ddfd*dfdddddfd+ddfd,ddfd-ddddfd.dfd/dfd0ddfd1dfd2ddfd3ddfd4ddfd5ddfd6dfd7dfd8ddfd9dfd:ddfd;dfd<dfd=ddfi(Zejd>ƒZejd?ƒZejd@ƒZejdAejƒZ ejdBƒZ!ejdCƒZ"ejdDƒZ#ejdEejƒZ$dAZ%dEZ&GdFd„dƒZ'er«GdGdH„dHe'ƒZ(ej)dHƒGdId „d e'ƒZ*GdJdK„dKƒZ+dLj,dMƒZ-dNdO„e.e-dPd…ƒDƒZ/dQd „Z0dRd „Z1dSd „Z2dTd „Z3e4dUkr^ddl5Z5ddl6Z6y)e5j5ej7dPd…dVƒ\Z8Z9Wn:e5j:k r¿Z;zfff\Z8Z9WYddZ;[;XnXdZ<xQe8D]I\Z=Z;e=dWkrôe>e;ƒZn"e=dXkre;Z<e9 re<fZ9qÍWe9 r*dYfZ9e9dZ?e6j@ƒZAe6j6dZeAe?pUd[fƒZBd\d]eAd^d_iZCd`eAeBffdadbffdcdbddffddeffdfdeddeCffdgdhdiffdjdeffdkddldmffdndodpffdqdodrdsffdtffduffdvffdwfffZDdjffdxdyffdzd1d{ffdxd|ffdfdddeCffdvffd}fffZEd~d„ZFy‰e<r¹e*e<ƒZGn e'e?ƒZGeGjHdkräeDdPd…ZDeGjId€eGjJƒeGjId�eGjKfƒx!eDD]\ZLZ9eFeLe9ƒqWxheFdgd‚dƒfƒD]QZMejNd„eMƒZOeOryeOjPdPƒZQneMj,ƒdP ZQeFd…eQfƒqIWx~eED]v\ZLZ9eFeLe9ƒZReLe9fdzd1d{ffkráq¥eRdP j,ƒZSeS rüq¥eFdzd#d†eSdP d‡fƒq¥WeTdˆƒWn1eTd‰ƒe rVeTdŠej7dƒ‚YnXdS)‹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ÚAPPENDÚAUTHÚSELECTEDÚ AUTHENTICATEÚNONAUTHÚ CAPABILITYÚLOGOUTÚCHECKÚCLOSEÚCOPYÚCREATEÚDELETEÚ DELETEACLÚENABLEÚ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 dd„Z dd„Zdd„Zdd„Zdedd„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@„Z$dAdB„Z%dCdD„Z&dEdF„Z'dGdH„Z(dIdJdKdL„Z)dMdN„Z*dOdP„Z+dQdR„Z,dSdT„Z-dIdJdUdV„Z.dWdX„Z/dYdZ„Z0d[d\„Z1d]d^„Z2d_d`„Z3dadb„Z4dcdd„Z5dedfdgdh„Z6didj„Z7dkdl„Z8dmdn„Z9dodp„Z:dqdrds„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‘„ZJd’d“„ZKd”d•„ZLd–d—„ZMd˜d™„ZNdšd›„ZOdqS)œ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/python35/lib64/python3.5/imaplib.pyÚerror«s r=c@seZdZdS)z IMAP4.abortN)r8r9r:r;r;r;r<Úabort¬s r>c@seZdZdS)zIMAP4.readonlyN)r8r9r:r;r;r;r<Úreadonly­s r?ÚcCs¸t|_d|_d|_i|_i|_d|_d|_d|_d|_ |j ƒ|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Ú _mode_asciiÚopenÚ_connectÚ ExceptionÚshutdownÚOSError)ÚselfÚhostÚportr;r;r<Ú__init__¯s&            zIMAP4.__init__cCsFd|_d|_tjttjƒ|_tjttjƒ|_dS)NFÚascii) Ú utf8_enabledÚ _encodingÚreÚcompileÚ_LiteralÚASCIIÚLiteralÚ_Untagged_statusÚUntagged_status)rQr;r;r<rKÈs  zIMAP4._mode_asciicCs:d|_d|_tjtƒ|_tjtƒ|_dS)NTzutf-8)rVrWrXrYrZr\r]r^)rQr;r;r<Ú _mode_utf8Ïs  zIMAP4._mode_utf8cCsßttjddƒƒ|_tjd|jdtjƒ|_|jƒ|_ d|j krhd|_ n-d|j krƒd|_ n|j |j ƒ‚|j ƒx*tD]"}||jkr¾q¦||_dSW|j d ƒ‚dS) Niiÿÿs(?Ps"\d+) (?P[A-Z]+) (?P.*)ZPREAUTHrÚOKrzserver not IMAP4 compliant)r ÚrandomZrandintÚtagprerXrYr[ÚtagreÚ _get_responseZwelcomerFrCr=Ú_get_capabilitiesÚAllowedVersionsÚ capabilitiesÚPROTOCOL_VERSION)rQÚversionr;r;r<rMÖs       zIMAP4._connectcCs3|tkrt||jƒƒStd|ƒ‚dS)NzUnknown IMAP4 command: '%s')ÚCommandsÚgetattrÚlowerÚAttributeError)rQÚattrr;r;r<Ú __getattr__s zIMAP4.__getattr__cCs|S)Nr;)rQr;r;r<Ú __enter__szIMAP4.__enter__c Gs'y|jƒWntk r"YnXdS)N)ÚlogoutrP)rQÚargsr;r;r<Ú__exit__ s zIMAP4.__exit__cCstj|j|jfƒS)N)ÚsocketZcreate_connectionrRrS)rQr;r;r<Ú_create_socketszIMAP4._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)rRrSruÚsockÚmakefileÚfile)rQrRrSr;r;r<rLs  z IMAP4.opencCs|jj|ƒS)zRead 'size' bytes from remote.)ryÚread)rQÚsizer;r;r<rz"sz IMAP4.readcCs?|jjtdƒ}t|ƒtkr;|jdtƒ‚|S)zRead line from remote.ézgot more than %d bytes)ryÚreadlineÚ_MAXLINEÚlenr=)rQÚliner;r;r<r}'szIMAP4.readlinecCs|jj|ƒdS)zSend data to remote.N)rwZsendall)rQÚdatar;r;r<Úsend/sz IMAP4.sendcCs’|jjƒzpy|jjtjƒWnRtk r{}z2|jtjkrit |ddƒdkri‚WYdd}~XnXWd|jjƒXdS)z Close I/O established in "open".Zwinerrorri&'N) ryÚcloserwrOrtZ SHUT_RDWRrPÚerrnoZENOTCONNrk)rQÚexcr;r;r<rO4s zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )rw)rQr;r;r<rtDsz 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. ZRECENTr`Nr|éÿÿÿÿ)Ú_untagged_responseÚnoop)rQÚnameÚtypÚdatr;r;r<ÚrecentPs   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)rQÚcoder;r;r<ÚresponseaszIMAP4.responsecCs¨d}|sd}|r?|d|d fd krEd|}nd}|rZt|ƒ}nd}tjt|ƒ}|jr‰d |d }||_|j||||ƒS) z°Append message to named mailbox. (typ, [data]) = .append(mailbox, flags, date_time, message) All args except `message' can be None. r ÚINBOXrr|ú(ú)z(%s)NsUTF8 (ó)r†)r‘r’)r ÚMapCRLFÚsubÚCRLFrVrDÚ_simple_command)rQÚmailboxÚflagsÚ date_timeÚmessager‰rDr;r;r<Úappendos   z IMAP4.appendcCst|jƒ}t|ƒj|_|jd|ƒ\}}|dkra|j|djddƒƒ‚d|_||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. rr`r|zutf-8Úreplacerr†)r�Ú_AuthenticatorÚprocessrDr—r=ÚdecoderC)rQZ mechanismZ authobjectÚmechrŠr‹r;r;r<Ú authenticate‰s   zIMAP4.authenticatecCs.d}|j|ƒ\}}|j|||ƒS)zT(typ, [data]) = .capability() Fetch capabilities list from server.r)r—r‡)rQr‰rŠr‹r;r;r<Ú capability¦szIMAP4.capabilitycCs |jdƒS)zRCheckpoint mailbox on server. (typ, [data]) = .check() r)r—)rQr;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—rC)rQrŠ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—)rQÚ message_setZ new_mailboxr;r;r<ÚcopyÆsz IMAP4.copycCs|jd|ƒS)zPCreate new mailbox. (typ, [data]) = .create(mailbox) r)r—)rQr˜r;r;r<ÚcreateÎsz IMAP4.createcCs|jd|ƒS)zPDelete old mailbox. (typ, [data]) = .delete(mailbox) r)r—)rQr˜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—)rQr˜Úwhor;r;r<Ú deleteaclÝszIMAP4.deleteaclcCshd|jkrtjdƒ‚|jd|ƒ\}}|dkr^d|jƒkr^|jƒ||fS)zkSend an RFC5161 enable string to the server. (typ, [data]) = .enable(capability) rzServer does not support ENABLEr`z UTF8=ACCEPT)rgrr=r—r�r_)rQr£rŠr�r;r;r<Úenableäs  z IMAP4.enablecCs.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‡)rQr‰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‡)rQr¥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‡)rQr˜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‡)rQr˜ÚentryZ attributerŠr‹r;r;r<Ú getannotationszIMAP4.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‡)rQÚrootrŠr‹r;r;r<ÚgetquotaszIMAP4.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‡)rQr˜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‡)rQÚ directoryÚpatternr‰rŠr‹r;r;r<Úlist4sz IMAP4.listcCsV|jd||j|ƒƒ\}}|dkrC|j|dƒ‚d|_||fS)z”Identify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. r$r`r|rr†)r—Ú_quoter=rC)rQÚuserÚpasswordrŠr‹r;r;r<Úlogin@s $  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)rQr»r¼r;r;r<Úlogin_cram_md5NszIMAP4.login_cram_md5cCs]ddl}t|jtƒr0|jjdƒn|j}|jd|j||dƒjƒS)z1 Authobject to use with CRAM-MD5 authentication. rNzutf-8ú Zmd5)ÚhmacÚ isinstancer¼ÚstrÚencoder»ZHMACZ hexdigest)rQZ challengerÁÚpwdr;r;r<r¾Ws $ 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)rCr—ÚsysÚexc_inforOrF)rQrŠr‹r;r;r<rq_s ) 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‡)rQr·r¸r‰rŠr‹r;r;r<Úlsubosz 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‡)rQr˜rŠr‹r;r;r<ÚmyrightszszIMAP4.myrightscCs.d}|j|ƒ\}}|j|||ƒS)zb Returns IMAP namespaces ala rfc2342 (typ, [data, ...]) = .namespace() r&)r—r‡)rQr‰rŠr‹r;r;r<Ú namespace‚szIMAP4.namespacecCs |jdƒS)zFSend NOOP command. (typ, [data]) = .noop() r')r—)rQr;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‡)rQZ message_numZ message_partÚstartZlengthr‰rŠr‹r;r;r<Úpartial—s!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—)rQr»r‰r;r;r<Ú proxyauth£s zIMAP4.proxyauthcCs|jd||ƒS)zkRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) r*)r—)rQZ oldmailboxZ newmailboxr;r;r<Úrename°sz IMAP4.renamecGspd}|rE|jr$tjdƒ‚|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. If UTF8 is enabled, charset MUST be None. r+z'Non-None charset not valid in UTF8 modeÚCHARSET)rVrr=r—r‡)rQÚcharsetZcriteriar‰rŠr‹r;r;r<Úsearch¸s !z IMAP4.searchr�FcCs¬i|_||_|r!d}nd}|j||ƒ\}}|dkr^d|_||fSd|_d|jkr�| r�|jd|ƒ‚||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,r`rrz READ-ONLYz%s is not writableÚEXISTSN)rFrHr—rCr?Úget)rQr˜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—)rQr˜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‡)rQrrrŠ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‡)rQr³ZlimitsrŠr‹r;r;r<ÚsetquotaúszIMAP4.setquotacGs[d}|d|dfdkr*d|}|j||||Œ\}}|j|||ƒS) z�IMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) r0rr|r‘r’z(%s)r†)r‘r’)r—r‡)rQZ sort_criteriarÓÚsearch_criteriar‰rŠr‹r;r;r<Úsorts  z IMAP4.sortNcCsõd}ts|jdƒ‚|jr3|jdƒ‚||jkrQ|jdƒ‚|dkritjƒ}|j|ƒ\}}|dkrÓ|j|j d|j ƒ|_ |j j dƒ|_ d|_|j ƒn|jd ƒ‚|j|||ƒS) Nr1zSSL support missingzTLS session already establishedzTLS not supported by serverr`Úserver_hostnamervTzCouldn't establish TLS session)ÚHAVE_SSLr=rJr>rgÚsslÚ_create_stdlib_contextr—Ú wrap_socketrwrRrxryrer‡)rQÚ ssl_contextr‰rŠr‹r;r;r<Ústarttlss$      zIMAP4.starttlscCs4d}|j|||ƒ\}}|j|||ƒS)zpRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) r2)r—r‡)rQr˜Únamesr‰rŠr‹r;r;r<Ústatus(sz IMAP4.statuscCsU|d|dfd kr$d|}|jd|||ƒ\}}|j||dƒS) z�Alters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) rr|r‘r’z(%s)r3rr†)r‘r’)r—r‡)rQr¥Úcommandr™rŠr‹r;r;r<Ústore4s z IMAP4.storecCs|jd|ƒS)zYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) r4)r—)rQr˜r;r;r<Ú subscribe?szIMAP4.subscribecGs7d}|j||||Œ\}}|j|||ƒS)z‹IMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) r5)r—r‡)rQZthreading_algorithmrÓrÛr‰rŠr‹r;r;r<ÚthreadGsz IMAP4.threadcGs¹|jƒ}|tkr+|jd|ƒ‚|jt|krj|jd||jdjt|ƒfƒ‚d}|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, r6r+r0r5r)r+r0r5)r�rjr=rCÚjoinr—r‡)rQrærrr‰rŠr‹r;r;r<ÚuidQs      z IMAP4.uidcCs|jd|ƒS)z_Unsubscribe from old mailbox. (typ, [data]) = .unsubscribe(mailbox) r7)r—)rQr˜r;r;r<Ú unsubscribejszIMAP4.unsubscribecGs8|jƒ}|tkr(|jft|<|j||ŒS)aAllow simple extension commands notified by server in CAPABILITY response. Assumes command is legal in current state. (typ, [data]) = .xatom(name, arg, ...) Returns response appropriate to extension command `name'. )r�rjrCr—)rQr‰rrr;r;r<Úxatomrs  z IMAP4.xatomcCsL|dkrd}|j}||kr;||j|ƒn |g|||jjdƒ}|r:|j|dj|jdƒƒ‚dS)NrÈr|r�r†)rFrÖr>r rW)rQZbyer;r;r<Ú _check_bye–szIMAP4._check_byec Gs�|jt|krHd|_|jd||jdjt|ƒfƒ‚x'd D]}||jkrO|j|=qOWd|jkrš|j rš|jdƒ‚|jƒ}t ||j ƒ}|d|}xL|D]D}|dkrâqÍt |t ƒrt ||j ƒ}|d|}qÍW|j}|dk r}d|_t |ƒt |jƒkrW|}n&d}|t d t|ƒ|j ƒ}y|j|tƒWn8tk rÌ} z|jd | ƒ‚WYdd} ~ XnX|dkrÝ|Sx�x!|jƒr|j|rã|SqãW|r||jƒ}y|j|ƒ|jtƒWn8tk rq} z|jd | ƒ‚WYdd} ~ XnX|sàPqàW|S) Nz9command %s illegal in state %s, only allowed in states %sz, r`rÆÚBADz READ-ONLYz#mailbox status changed to READ-ONLYó z {%s}zsocket error: %s)r`rÆrñ)rCrjrDr=rêrFrHr?Ú_new_tagÚbytesrWrÂrÃÚtypeÚ_commandrr‚r–rPr>rdrErG) rQr‰rrrŠÚtagr�ÚargrDZ literatorÚvalr;r;r<röœs^             &   &zIMAP4._commandcCsû|dkr|jƒy|j|ƒ\}}Wn�|jk rr}z|jd||fƒ‚WYdd}~XnA|jk r²}z|jd||fƒ‚WYdd}~XnX|dkrÉ|jƒ|dkrñ|jd|||fƒ‚||fS)Nrzcommand: %s => %srñz%s command error: %s %s)rðÚ_get_tagged_responser>r=)rQr‰r÷rŠr�rùr;r;r<Ú_command_completeés  +,   zIMAP4._command_completecCsk|jƒ\}}|dgkr0|jdƒ‚t|d|jƒ}|jƒ}t|jƒƒ|_dS)Nz"no CAPABILITY response from serverr|r†)r£r=rÃrWr�ÚtupleÚsplitrg)rQrŠr‹r;r;r<reús  zIMAP4._get_capabilitiescCsc|jƒ}|j|j|ƒr¤|jjdƒ}||jkrU|jd|ƒ‚|jjdƒ}t||jƒ}|jjdƒ}||gf|j|rÃrWÚUntagged_responser^Ú ContinuationrGr\ÚintrzrïÚ Response_code)rQÚrespr÷rŠr‹Zdat2r{r�r;r;r<rdsH  zIMAP4._get_responsecCsxxq|j|}|dk r*|j|=|S|jƒy|jƒWq|jk ro}z‚WYdd}~XqXqWdS)N)rErðrdr>)rQr÷Úresultrùr;r;r<rúSs    zIMAP4._get_tagged_responsecCsW|jƒ}|s!|jdƒ‚|jdƒsC|jd|ƒ‚|dd…}|S)Nzsocket error: EOFs z#socket error: unterminated line: %rrÇéþÿÿÿ)r}r>Úendswith)rQr€r;r;r<rþns zIMAP4._get_linecCs|j|ƒ|_|jdk S)N)Úmatchr)rQZcreÚsr;r;r<rÿ�sz IMAP4._matchcCsC|jtt|jƒ|jƒ}|jd|_d|j|<|S)Nr|)rbrôrÃrIrWrE)rQr÷r;r;r<ró�s" zIMAP4._new_tagcCs0|jddƒ}|jddƒ}d|dS)Nú\z\\ú"z\")r�)rQrør;r;r<rº•sz IMAP4._quotecGs|j||j||ŒƒS)N)rûrö)rQr‰rrr;r;r<r—�szIMAP4._simple_commandcCsN|dkr||fS||jkr2|dgfS|jj|ƒ}||fS)NrÆ)rFÚpop)rQrŠr‹r‰r�r;r;r<r‡¢s    zIMAP4._untagged_response)Pr8r9r:Ú__doc__rNr=r>r?Ú IMAP4_PORTrTrKr_rMrorprsrurLrzr}r‚rOrtrŒr�rœr¢r£r¤rƒr¦r§r¨rªr«r¬r­r®r±r´rµr¹r½r¿r¾rqrËrÌrÍrˆrÏrÐrÑrÔr×rØrÙrÚrÜrãrårçrèrérërìrírïrðrörûrerdrúrþrÿrórºr—r‡r;r;r;r<r}s˜ ,   *                                     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ƒ‚|dk rH|dk rHtdƒ‚||_||_|dkr~tjd|d|ƒ}||_tj|||ƒdS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusiveÚcertfileÚkeyfile)Ú ValueErrorrrrßràrârrT)rQrRrSrrrâr;r;r<rTés       zIMAP4_SSL.__init__cCs(tj|ƒ}|jj|d|jƒS)NrÝ)rrurârárR)rQrwr;r;r<ruú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)rrL)rQrRrSr;r;r<rLÿszIMAP4_SSL.open)r8r9r:rÚIMAP4_SSL_PORTrTrurLr;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) "command" - a string that can be passed to subprocess.Popen() for more documentation see the docstring of the parent class IMAP4. cCs||_tj|ƒdS)N)rærrT)rQrær;r;r<rTs 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)rRrSrwryÚ subprocessÚPopenrærÚPIPErŸrÚ writefilerÚreadfile)rQrRrSr;r;r<rLs    zIMAP4_stream.opencCs|jj|ƒS)zRead 'size' bytes from remote.)rrz)rQr{r;r;r<rz+szIMAP4_stream.readcCs |jjƒS)zRead line from remote.)rr})rQr;r;r<r}0szIMAP4_stream.readlinecCs!|jj|ƒ|jjƒdS)zSend data to remote.N)rÚwriteÚflush)rQr�r;r;r<r‚5szIMAP4_stream.sendcCs+|jjƒ|jjƒ|jjƒdS)z Close I/O established in "open".N)rrƒrrŸÚwait)rQr;r;r<rO;s  zIMAP4_stream.shutdown) r8r9r:rrTrLrzr}r‚rOr;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¡)rQZmechinstr;r;r<rTIsz_Authenticator.__init__cCs5|j|j|ƒƒ}|dkr(dS|j|ƒS)Nó*)r¡r rÄ)rQr�Zretr;r;r<rŸLs z_Authenticator.processcCsŸd}t|tƒr$|jdƒ}xt|ršt|ƒdkrb|dd…}|dd…}n |}d}tj|ƒ}|r'||dd…}q'W|S)Nrîzutf-8é0r|r†)rÂrÃrÄrÚbinasciiZ b2a_base64)rQÚinpZoupÚtÚer;r;r<rÄRs  z_Authenticator.encodecCs|s dStj|ƒS)Nrî)r$Z a2b_base64)rQr%r;r;r<r jsz_Authenticator.decodeN)r8r9r:rrTrŸrÄr r;r;r;r<ržCs    ržz0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrÀcCs)i|]\}}|d|jƒ“qS)r|)rÄ)Ú.0Únr r;r;r<ú ps r*r|c Cs4tj|ƒ}|sdSt|jdƒ}|jdƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jd ƒƒ} t|jd ƒƒ} | d | d } |d kró| } ||||||dddf } tj| ƒ| } tj| ƒS)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é<ó-r|r†r†r†) Ú InternalDater ÚMon2numrrÚcalendarZtimegmÚtimeÚ localtime)rrr+r,r-r.r/r0r1r2r3ZzoneZttÚutcr;r;r<rrs$ !cCs\d}d}tt|ƒƒ}x7|rWt|dƒ\}}|||d…|}q!W|S)z-Convert integer to A-P string representation.rîsABCDEFGHIJKLMNOPér|)rÚabsÚdivmod)ZnumrùZAPÚmodr;r;r<r •s cCs2tj|ƒ}|sfSt|jdƒjƒƒS)z-Convert IMAP4 flags response to python tuple.r™)ÚFlagsr rürrý)rrr;r;r<r ¢sc Cs†t|ttfƒr3tj|tjƒjƒ}n0t|tƒr÷y |j }Wnqt k rÂt j r´|d}|d kršt j t j|ƒƒd}t jt jf| }n t j }YnXtd|ƒ}t|dd…dt|ƒŒ}nlt|tƒr*|jdkr!tdƒ‚|}n9t|tƒrW|d|d fdkrW|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. ér|ZsecondsNéÚtzinfozdate_time must be awarerr zdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"r†r†)r r )rÂrÚfloatrZ fromtimestamprr;Z astimezonerüZ tm_gmtoffrmr9Zdaylightr:ZmktimeZaltzonerrCrrÃÚ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»ZlfÚ r½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ÕrqcCsftjd||fƒtt|ƒ|Œ\}}tjd|||fƒ|dkrb|d‚|S)Nz%s %sz %s => %s %srÆr)ÚMÚ_mesgrk)ÚcmdrrrŠr‹r;r;r<Úruns  rNzPROTOCOL_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 )UrÚ __version__r$r„rarXrtrrÉr9r8rrrÚiorrßrÞÚ ImportErrorÚ__all__r–rArrrfr~rjrYrr@r6r[r\r”rrr^rZr]rrrœrržrýrFÚ enumerater7rr r r r8ZgetoptZgetpassÚargvZoptlistrrr=rùZstream_commandZoptrrRZgetuserZUSERZPASSWDZ test_mesgZ test_seq1Z test_seq2rNrKrCrLrhrgrMZmlr rrÚpathr‹rëÚprintr;r;r;r<Ú s< l                                          ÿÿÿÿ[1 9,# # ) )%