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@seZdZdZGdd„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›„ZOdqdœd�„ZPdždŸ„ZQd d¡„ZRd¢d£„ZSdqS)¤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_utf8cCsTttjddƒƒ|_tjd|jdtjƒ|_d|_d|_ i|_ |j dkr�|j dt ƒ|j d |jƒ|jƒ|_d |jkr·d |_n-d |jkrÒd |_n|j|jƒ‚|jƒ|j dkr|j d|jfƒx*tD]"}||jkr3q||_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ÚtagprerXrYr[ÚtagreÚ _cmd_log_lenÚ _cmd_log_idxÚ_cmd_logrBÚ_mesgÚ __version__Ú _get_responseZwelcomerFrCr=Ú_get_capabilitiesÚ capabilitiesÚAllowedVersionsÚPROTOCOL_VERSION)rQÚversionr;r;r<rMÖs0        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)rRrSr}ÚsockÚmakefileÚfile)rQrRrSr;r;r<rLs  z IMAP4.opencCs|jj|ƒS)zRead 'size' bytes from remote.)r�Úread)rQÚsizer;r;r<r‚"sz IMAP4.readcCs?|jjtdƒ}t|ƒtkr;|jdtƒ‚|S)zRead line from remote.razgot more than %d bytes)r�ÚreadlineÚ_MAXLINEÚlenr=)rQÚliner;r;r<r„'szIMAP4.readlinecCs|jj|ƒdS)zSend data to remote.N)rZsendall)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) r�ÚcloserrOr|Z SHUT_RDWRrPÚerrnoZENOTCONNrs)rQÚexcr;r;r<rO4s zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )r)rQr;r;r<r|Dsz 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. ZRECENTrbNraéÿÿÿÿ)Ú_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 ÚINBOXrraú(ú)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. rrbrazutf-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 ENABLErbz UTF8=ACCEPT)rnrr=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$rbrarr�)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<ry_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,|jdkr|j|jƒ|jdƒS)zFSend NOOP command. (typ, [data]) = .noop() rcr')rBÚ_dump_urrFrž)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¯|jdkrœ|j|jƒ|jd|ƒ‚||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,rbrrz READ-ONLYraz%s is not writableÚEXISTSN)rFrHržrCrBrÕr?Ú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Ž)rQrzr‘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, ...) r0rrar˜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 serverrbÚserver_hostnamer~TzCouldn't establish TLS session)ÚHAVE_SSLr=rJr>rnÚsslÚ_create_stdlib_contextržÚ wrap_socketrrRr€r�rmrŽ)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) rrar˜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”rrr=rCÚjoinržrŽ)rQrîrzr�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”rrrCrž)rQr�rzr;r;r<Úxatomrs  z IMAP4.xatomcCs‡|dkrd}|j}|jdkrV|jd|t|j|dƒƒ|fƒ||krv||j|ƒn |g|||jjdƒ}|r:|j|dj|jdƒƒ‚dS)NrÏrar¤r�)rFrÞr>r§rW)rQZbyer;r;r<Ú _check_bye–szIMAP4._check_byec GsÛ|jt|krHd|_|jd||jdjt|ƒfƒ‚x'dD]}||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 ƒ}|jd kr |jd |ƒn|jd |ƒy|j|tƒWn8tk r} z|jd | ƒ‚WYdd} ~ XnX|dkr|SxÃx!|jƒr7|j|r|SqW|rM||jƒ}|jd krs|jd t|ƒƒy|j|ƒ|jtƒWn8tk rË} z|jd | ƒ‚WYdd} ~ XnX|sPqW|S)Nz9command %s illegal in state %s, only allowed in states %sz, rbrÍÚBADz READ-ONLYz#mailbox status changed to READ-ONLYó z {%s}éz> %rzsocket error: %szwrite literal size %s)rbrÍrú)rCrrrDr=ròrFrHr?Ú_new_tagÚbytesrWrÉrÊÚtypeÚ_commandr†rBrjÚ_logr‰r�rPr>rlrErG) rQr�rzr‘ÚtagrˆÚargrDZ literatorÚvalr;r;r<rœsh             &   &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�rr‘rˆrr;r;r<Ú_command_completeés  +,   zIMAP4._command_completecCsk|jƒ\}}|dgkr0|jdƒ‚t|d|jƒ}|jƒ}t|jƒƒ|_dS)Nz"no CAPABILITY response from serverrar�)rªr=rÊrWr”ÚtupleÚsplitrn)rQr‘r’r;r;r<rmús  zIMAP4._get_capabilitiescCsµ|jƒ}|j|j|ƒr¤|jjdƒ}||jkrU|jd|ƒ‚|jjdƒ}t||jƒ}|jjdƒ}||gf|j|rÊrWÚUntagged_responser^Ú ContinuationrGr\ÚintrBrjr‚røÚ Response_code)rQÚresprr‘r’Zdat2rƒrˆr;r;r<rlsP  zIMAP4._get_responsecCs‘xŠ|j|}|dk r*|j|=|S|jƒy|jƒWq|jk rˆ}z!|jdkrs|jƒ‚WYdd}~XqXqWdS)Nra)rErùrlr>rBÚ print_log)rQrÚresultrr;r;r<rSs     zIMAP4._get_tagged_responsecCs‹|jƒ}|s!|jdƒ‚|jdƒsC|jd|ƒ‚|dd…}|jdkrv|jd|ƒn|jd|ƒ|S)Nzsocket error: EOFs z#socket error: unterminated line: %rrÎrüz< %réþÿÿÿ)r„r>ÚendswithrBrjr)rQr‡r;r;r<r ns zIMAP4._get_linecCs`|j|ƒ|_|jdk rS|jdkrS|jd|j|jjƒfƒ|jdk S)Nr÷z matched r'%r' => %r)Úmatchr rBrjr¿Úgroups)rQZcreÚsr;r;r<r �s#z IMAP4._matchcCsC|jtt|jƒ|jƒ}|jd|_d|j|<|S)Nra)rerþrÊrIrWrE)rQrr;r;r<rý�s" zIMAP4._new_tagcCs0|jddƒ}|jddƒ}d|dS)Nú\z\\ú"z\")r¤)rQrr;r;r<rÁ•sz IMAP4._quotecGs|j||j||ŒƒS)N)rr)rQr�rzr;r;r<rž�szIMAP4._simple_commandcCst|dkr||fS||jkr2|dgfS|jj|ƒ}|jdkrj|jd||fƒ||fS)NrÍr÷zuntagged_responses[%s] => %s)rFÚpoprBrj)rQr‘r’r�rˆr;r;r<rŽ¢s   zIMAP4._untagged_responsecCsi|dkrtjƒ}tjdtj|ƒƒ}tjjd||dd|fƒtjjƒdS)Nz%M:%Sz %s.%02d %s éd)ÚtimeÚstrftimeÚ localtimerÐÚstderrÚwriteÚflush)rQrZsecsZtmr;r;r<rj°s   %z IMAP4._mesgcCsU|jƒ}|sdSd}tdd„|ƒ}|jd||j|ƒfƒdS)Nz cSs3d|d|ddr+dj|dƒp.dfS)Nz%s: "%s"rraz" "r@)rò)Úxr;r;r<Ú¼sz IMAP4._dump_ur..zuntagged responses dump:%s%s)ÚitemsÚmaprjrò)rQÚdictÚlÚtr;r;r<rÕ·s  zIMAP4._dump_urcCsJ|tjƒf|j|j<|jd7_|j|jkrFd|_dS)Nrar)rrirhrg)rQr‡r;r;r<r¿sz IMAP4._logc CsŠ|jdt|jƒƒ|j|j}}xV|r…y|j|j|ŒWnYnX|d7}||jkrxd}|d8}q0WdS)Nzlast %d IMAP4 interactions:rar)rjr†rirhrg)rQÚiÚnr;r;r<rÆs  zIMAP4.print_log)Tr8r9r:Ú__doc__rNr=r>r?Ú IMAP4_PORTrTrKr_rMrwrxr{r}rLr‚r„r‰rOr|r“r–r£r©rªr«rŠr­r®r¯r±r²r³r´rµr¸r»r¼rÀrÄrÆrÅryrÒrÓrÔr�r×rØrÙrÜrßràrárârärërírïrðrñrórôrõrørùrrrmrlrr r rýrÁržrŽrjrÕrrr;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)Ú ValueErrorr0r/rçrèrêrrT)rQrRrSr0r/rêr;r;r<rTés       zIMAP4_SSL.__init__cCs(tj|ƒ}|jj|d|jƒS)Nrå)rr}rêrérR)rQrr;r;r<r}ú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_PORTrTr}rLr;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) "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)rRrSrr�Ú subprocessÚPopenrîrÚPIPEr¦r4Ú writefiler5Úreadfile)rQrRrSr;r;r<rLs    zIMAP4_stream.opencCs|jj|ƒS)zRead 'size' bytes from remote.)r;r‚)rQrƒr;r;r<r‚+szIMAP4_stream.readcCs |jjƒS)zRead line from remote.)r;r„)rQr;r;r<r„0szIMAP4_stream.readlinecCs!|jj|ƒ|jjƒdS)zSend data to remote.N)r:r!r")rQrˆr;r;r<r‰5szIMAP4_stream.sendcCs+|jjƒ|jjƒ|jjƒdS)z Close I/O established in "open".N)r;rŠr:r¦Úwait)rQr;r;r<rO;s  zIMAP4_stream.shutdown) r8r9r:r,rTrLr‚r„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é0rar�)rÉrÊrËr†ÚbinasciiZ b2a_base64)rQÚinpZoupr)Ú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:r,rTr¦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)ra)rË)Ú.0r+rr;r;r<ú ps rCrac 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é<ó-rar�r�r�) Ú InternalDaterÚMon2numr rÚcalendarZtimegmrr)rr rDrErFrGrHrIrJrKrLZzoneZttÚ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éra)rÚabsÚdivmod)ZnumrZAPÚmodr;r;r<r •s cCs2tj|ƒ}|sfSt|jdƒjƒƒS)z-Convert IMAP4 flags response to python tuple.r )ÚFlagsrrr r)rr r;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. éraZsecondsNéÚtzinfozdate_time must be awarerrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"r�r�)rr)rÉrÚfloatrZ fromtimestamprrRZ astimezonerZ tm_gmtoffrurZdaylightrZmktimeZaltzonerrZr1rÊÚ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Â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ÝrycCsftjd||fƒtt|ƒ|Œ\}}tjd|||fƒ|dkrb|d‚|S)Nz%s %sz %s => %s %srÍr)ÚMrjrs)Úcmdrzr‘r’r;r;r<Úruns  rdzPROTOCOL_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,rkr?r‹rdrXr|r7rÐrrQrrrÚiorrçræÚ ImportErrorÚ__all__r�rAr-r2ror…rrrYrrWrOr[r\r›rr r^rZr]rr.r£rr¥rr]Ú enumeraterPrr r r r8ZgetoptZgetpassÚargvZoptlistrzr=rZstream_commandZoptrrRZgetuserZUSERZPASSWDZ test_mesgZ test_seq1Z test_seq2rdrbrCrjrprnrcZmlrr r Úpathr’róÚprintr;r;r;r<Ú s< l                                          ÿÿÿÿ[1 9,# # ) )%