o ?OgRÖã@s$dZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZzddlZdZWn eyKdZYnwgd¢Zd ZdZd Zd Zd Zd Zidd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“d d“d!d“d"d“d#d“id$d“d%d“d&d“d'd“d(d“d)d“d*d“d+d“d,d“d-d“d.d“d/d“d0d“d1d“d2d“d3d“d4d“¥ddddddddd5œ¥Ze d6¡Ze d7¡Ze d8¡Ze d9ej¡Z e d:¡Z!e d;¡Z"e d<¡Z#e d=ej¡Z$d9Z%d=Z&Gd>d?„d?ƒZ'erGd@dA„dAe'ƒZ(e )dA¡GdBdC„dCe'ƒZ*GdDdE„dEƒZ+dF ,dG¡Z-dHdI„e.e-dJd…ƒDƒZ/dKdL„Z0dMdN„Z1dOdP„Z2dQdR„Z3e4dSkrddl5Z5ddl6Z6ze5 5ej7dJd…dT¡\Z8Z9Wne5j:y}Z;z dU\Z8Z9WYdZ;[;ndZ;[;wwdZe;ƒZq‚e=dWkrže;Z.*))?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 fd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zded fdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Z d:d;„Z!dd?„Z#d@dA„Z$dBdC„Z%dDdE„Z&dFdG„Z'dHdI„Z(d§dLdM„Z)dNdO„Z*dPdQ„Z+dRdS„Z,dTdU„Z-d§dVdW„Z.dXdY„Z/dZd[„Z0d\d]„Z1d^d_„Z2d`da„Z3dbdc„Z4ddde„Z5d¨dhdi„Z6djdk„Z7dldm„Z8dndo„Z9dpdq„Z:d©drds„Z;dtdu„Zdzd{„Z?d|d}„Z@d~d„ZAd€d„ZBd‚dƒ„ZCd„d…„ZDd†d‡„ZEdˆd‰„ZFdŠd‹„ZGdŒd„ZHdŽd„ZIdªdd‘„ZJd’d“„ZKd”d•„ZLd–d—„ZMd˜d™„ZNdšd›„ZOdœd„ZP d©dŸd „ZQd¡d¢„ZRd£d¤„ZSd¥d¦„ZTd S)«raªIMAP4 client class. Instantiate with: IMAP4([host[, port[, timeout=None]]]) host - host's name (default: localhost); port - port number (default: standard IMAP4 port). timeout - socket timeout (default: None) If timeout is not given or is None, the global default socket timeout is used All IMAP4rev1 commands are supported by methods of the same name (in 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@ó eZdZdS)z IMAP4.errorN©Ú__name__Ú __module__Ú __qualname__©r?r?ú./opt/alt/python310/lib64/python3.10/imaplib.pyÚerror¸ó rAc@r:)z IMAP4.abortNr;r?r?r?r@Úabort¹rBrCc@r:)zIMAP4.readonlyNr;r?r?r?r@ÚreadonlyºrBrDÚNc CsŠt|_d|_d|_i|_i|_d|_d|_d|_d|_ |  ¡|  |||¡z|  ¡WdSt yDz| ¡W‚tyCY‚ww)NrrEFr)ÚDebugÚdebugÚstateÚliteralÚtagged_commandsÚuntagged_responsesÚcontinuation_responseÚ is_readonlyÚtagnumÚ_tls_establishedÚ _mode_asciiÚopenÚ_connectÚ ExceptionÚshutdownÚOSError©ÚselfÚhostÚportÚtimeoutr?r?r@Ú__init__¼s,   þþýzIMAP4.__init__cCs0d|_d|_t ttj¡|_t ttj¡|_dS)NFÚascii) Ú utf8_enabledÚ _encodingÚreÚcompileÚ_LiteralÚASCIIÚLiteralÚ_Untagged_statusÚUntagged_status©rWr?r?r@rPÕszIMAP4._mode_asciicCs(d|_d|_t t¡|_t t¡|_dS)NTúutf-8)r]r^r_r`rarcrdrerfr?r?r@Ú _mode_utf8Üs zIMAP4._mode_utf8cCsòtt dd¡ƒ|_t d|jdtj¡|_ d|_d|_ i|_ |j dkr4|  d t ¡|  d |j¡| ¡|_d |jvrBd |_nd |jvrKd|_n| |j¡‚| ¡ |j dkrd|  d|jf¡tD] }||jvrnqf||_dS| d¡‚)Niiÿÿs(?Ps"\d+) (?P[A-Z]+) (?P.*)Té rézimaplib version %sznew IMAP4 connection, tag=%sZPREAUTHrÚOKrézCAPABILITIES: %rzserver not IMAP4 compliant)r ÚrandomZrandintÚtagprer_r`rbÚtagreÚ _cmd_log_lenÚ _cmd_log_idxÚ_cmd_logrGÚ_mesgÚ __version__Ú _get_responseZwelcomerKrHrAÚ_get_capabilitiesÚ capabilitiesÚAllowedVersionsÚPROTOCOL_VERSION)rWÚversionr?r?r@rRãs>ÿþþ        zIMAP4._connectcCs"|tvr t|| ¡ƒStd|ƒ‚)NzUnknown IMAP4 command: '%s')ÚCommandsÚgetattrÚlowerÚAttributeError)rWÚattrr?r?r@Ú __getattr__ s zIMAP4.__getattr__cCs|S©Nr?rfr?r?r@Ú __enter__szIMAP4.__enter__cGs2|jdkrdSz| ¡WdStyYdSw)Nr)rHÚlogoutrU)rWÚargsr?r?r@Ú__exit__s  ÿzIMAP4.__exit__cCs`|dur |s tdƒ‚|jsdn|j}t d||j|j¡||jf}|dur+t ||¡St |¡S)Nz0Non-blocking socket (timeout=0) is not supportedz imaplib.open)Ú ValueErrorrXÚsysÚauditrYÚsocketZcreate_connection)rWrZrXZaddressr?r?r@Ú_create_socket#s    zIMAP4._create_socketcCs*||_||_| |¡|_|j d¡|_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)rXrYrŠÚsockÚmakefileÚfilerVr?r?r@rQ0s z IMAP4.opencCó |j |¡S©zRead 'size' bytes from remote.)rŽÚread©rWÚsizer?r?r@r‘<ó z IMAP4.readcCs.|j td¡}t|ƒtkr| dt¡‚|S)úRead line from remote.rjzgot more than %d bytes)rŽÚreadlineÚ_MAXLINEÚlenrA©rWÚliner?r?r@r–As zIMAP4.readlinecCst d||¡|j |¡dS)úSend data to remote.z imaplib.sendN)r‡rˆrŒZsendall©rWÚdatar?r?r@ÚsendIsz IMAP4.sendc CsŽ|j ¡z;z |j tj¡Wn!ty0}z|jtjkr&t |ddƒdkr&‚WYd}~n d}~wwW|j ¡dSW|j ¡dS|j ¡w)ú Close I/O established in "open".Zwinerrorri&'N) rŽÚcloserŒrTr‰Z SHUT_RDWRrUÚerrnoZENOTCONNr|)rWÚexcr?r?r@rTOs  €úÿ €zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )rŒrfr?r?r@r‰_sz IMAP4.socketcCsBd}| ddg|¡\}}|dr||fS| ¡\}}| |||¡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. ZRECENTrkNéÿÿÿÿ)Ú_untagged_responseÚnoop©rWÚnameÚtypÚdatr?r?r@Úrecentks   z IMAP4.recentcCs| |dg| ¡¡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)rWÚcoder?r?r@Úresponse|szIMAP4.responsecCsxd}|sd}|r|d|dfdkrd|}nd}|r t|ƒ}nd}t t|¡}|jr1d|d }||_| ||||¡S) z°Append message to named mailbox. (typ, [data]) = .append(mailbox, flags, date_time, message) All args except `message' can be None. rÚINBOXrr£©ú(ú)ú(%s)NsUTF8 (ó))r ÚMapCRLFÚsubÚCRLFr]rIÚ_simple_command)rWÚmailboxÚflagsÚ date_timeÚmessager§rIr?r?r@ÚappendŠs €   z IMAP4.appendcCsP| ¡}t|ƒj|_| d|¡\}}|dkr!| |d dd¡¡‚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. rrkr£rgÚreplacer)r«Ú_AuthenticatorÚprocessrIr·rAÚdecoderH)rWZ mechanismZ authobjectÚmechr¨r©r?r?r@Ú authenticate¤s zIMAP4.authenticatecCó d}| |¡\}}| |||¡S)zT(typ, [data]) = .capability() Fetch capabilities list from server.r©r·r¤r¦r?r?r@Ú capabilityÁszIMAP4.capabilitycCs | d¡S)zRCheckpoint mailbox on server. (typ, [data]) = .check() r©r·rfr?r?r@ÚcheckÊs z IMAP4.checkcCó(z| d¡\}}Wd|_||fSd|_w)zÌClose currently selected mailbox. Deleted messages are removed from writable mailbox. This is the recommended command before 'LOGOUT'. (typ, [data]) = .close() rr©r·rH©rWr¨r©r?r?r@r Òs ÿz IMAP4.closecCó| d||¡S)z‚Copy 'message_set' messages onto end of 'new_mailbox'. (typ, [data]) = .copy(message_set, new_mailbox) rrÆ)rWÚ message_setZ new_mailboxr?r?r@Úcopyáóz IMAP4.copycCó | d|¡S)zPCreate new mailbox. (typ, [data]) = .create(mailbox) rrÆ©rWr¸r?r?r@Úcreateéó z IMAP4.createcCrÏ)zPDelete old mailbox. (typ, [data]) = .delete(mailbox) rrÆrÐr?r?r@ÚdeleteñrÒz IMAP4.deletecCrË)z€Delete the ACLs (remove any rights) set for who on mailbox. (typ, [data]) = .deleteacl(mailbox, who) rrÆ)rWr¸Úwhor?r?r@Ú deleteaclørÎzIMAP4.deleteaclcCsHd|jvr t d¡‚| d|¡\}}|dkr d| ¡vr | ¡||fS)zlSend an RFC5161 enable string to the server. (typ, [data]) = .enable(capability) rzServer does not support ENABLErkz UTF8=ACCEPT)rwrrAr·r«rh)rWrÅr¨rr?r?r@Úenableÿs  z IMAP4.enablecCrÃ)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. rrÄr¦r?r?r@Úexpunge s z IMAP4.expungecCó$d}| |||¡\}}| |||¡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. rrÄ)rWrÌZ message_partsr§r¨r©r?r?r@Úfetchs z IMAP4.fetchcCó| d|¡\}}| ||d¡S)zXGet the ACLs for a mailbox. (typ, [data]) = .getacl(mailbox) rZACLrÄ©rWr¸r¨r©r?r?r@Úgetacl(óz IMAP4.getaclcCs"| d|||¡\}}| ||d¡S)za(typ, [data]) = .getannotation(mailbox, entry, attribute) Retrieve ANNOTATIONs.r Ú ANNOTATIONrÄ)rWr¸ÚentryZ attributer¨r©r?r?r@Ú getannotation1szIMAP4.getannotationcCrÚ)zªGet the quota root's resource usage and limits. Part of the IMAP4 QUOTA extension defined in rfc2087. (typ, [data]) = .getquota(root) r!ÚQUOTArÄ)rWÚrootr¨r©r?r?r@Úgetquota9szIMAP4.getquotacCs@| d|¡\}}| ||d¡\}}| ||d¡\}}|||gfS)zœGet the list of quota roots for the named mailbox. (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = .getquotaroot(mailbox) r"ráZ QUOTAROOTrÄ)rWr¸r¨r©ZquotaZ quotarootr?r?r@Ú getquotarootDs zIMAP4.getquotarootú""Ú*cCrØ)z«List mailbox names in directory matching pattern. (typ, [data]) = .list(directory='""', pattern='*') 'data' is list of LIST responses. r$rÄ©rWZ directoryÚpatternr§r¨r©r?r?r@ÚlistOóz IMAP4.listcCs<| d|| |¡¡\}}|dkr| |d¡‚d|_||fS)z”Identify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. r%rkr£r)r·Ú_quoterArH)rWÚuserÚpasswordr¨r©r?r?r@Úlogin[s z IMAP4.logincCs|||_|_| d|j¡S)zr Force use of CRAM-MD5 authentication. (typ, [data]) = .login_cram_md5(user, password) zCRAM-MD5)rìrírÂÚ_CRAM_MD5_AUTH)rWrìrír?r?r@Úlogin_cram_md5iszIMAP4.login_cram_md5cCsBddl}t|jtƒr|j d¡n|j}|jd| ||d¡ ¡S)z1 Authobject to use with CRAM-MD5 authentication. rNrgú Zmd5)ÚhmacÚ isinstanceríÚstrÚencoderìZHMACZ hexdigest)rWZ challengeròÚpwdr?r?r@rïrs ÿzIMAP4._CRAM_MD5_AUTHcCs$d|_| d¡\}}| ¡||fS)z|Shutdown connection to server. (typ, [data]) = .logout() Returns server 'BYE' response. r)rHr·rTrÊr?r?r@rƒzsz IMAP4.logoutcCrØ)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çr?r?r@Úlsub‡rêz IMAP4.lsubcCs| d|¡\}}| ||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Ûr?r?r@Úmyrights’rÝzIMAP4.myrightscCrÃ)zb Returns IMAP namespaces ala rfc2342 (typ, [data, ...]) = .namespace() r'rÄr¦r?r?r@Ú namespacešszIMAP4.namespacecCs" |jdkr | |j¡| d¡S)zFSend NOOP command. (typ, [data]) = .noop() Trlr()rGÚ_dump_urrKr·rfr?r?r@r¥¤s   z IMAP4.noopcCs(d}| |||||¡\}}| ||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)rrÄ)rWZ message_numZ message_partÚstartZlengthr§r¨r©r?r?r@Úpartial¯sz IMAP4.partialcCsd}| d|¡S)z³Assume authentication as "user". Allows an authorised administrator to proxy into any user's mailbox. (typ, [data]) = .proxyauth(user) r*rÆ)rWrìr§r?r?r@Ú proxyauth»s zIMAP4.proxyauthcCrË)zkRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) r+rÆ)rWZ oldmailboxZ newmailboxr?r?r@ÚrenameÈrÎz IMAP4.renamecGsXd}|r|jr t d¡‚|j|d|g|¢RŽ\}}n |j|g|¢RŽ\}}| |||¡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)r]rrAr·r¤)rWÚcharsetZcriteriar§r¨r©r?r?r@ÚsearchÐs z IMAP4.searchr®FcCsŽi|_||_|r d}nd}| ||¡\}}|dkr d|_||fSd|_d|jvr=|s= |jdkr6| |j¡| d |¡‚||j d 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-rkrrú READ-ONLYTrjz%s is not writableÚEXISTSN)rKrMr·rHrGrúrDÚget)rWr¸rDr§r¨r©r?r?r@Úselectâs$  ÿ  z IMAP4.selectcCs| d|||¡S)zZSet a mailbox acl. (typ, [data]) = .setacl(mailbox, who, what) r.rÆ)rWr¸rÔZwhatr?r?r@Úsetaclsz IMAP4.setaclcGs$|jdg|¢RŽ\}}| ||d¡S)z_(typ, [data]) = .setannotation(mailbox[, entry, attribute]+) Set ANNOTATIONs.r/rÞrÄ)rWr„r¨r©r?r?r@Ú setannotation szIMAP4.setannotationcCs | d||¡\}}| ||d¡S)ziSet the quota root's resource limits. (typ, [data]) = .setquota(root, limits) r0rárÄ)rWrâZlimitsr¨r©r?r?r@ÚsetquotaszIMAP4.setquotacGsHd}|d|dfdkrd|}|j|||g|¢RŽ\}}| |||¡S)zIMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) r1rr£r¯r²rÄ)rWZ sort_criteriarÚsearch_criteriar§r¨r©r?r?r@Úsorts z IMAP4.sortcCs¦d}ts | d¡‚|jr| d¡‚||jvr| d¡‚|dur#t ¡}| |¡\}}|dkrG|j|j |j d|_ |j   d¡|_ d|_|  ¡n| d ¡‚| |||¡S) Nr2zSSL support missingzTLS session already establishedzTLS not supported by serverrk©Zserver_hostnamer‹TzCouldn't establish TLS session)ÚHAVE_SSLrArOrCrwÚsslÚ_create_stdlib_contextr·Ú wrap_socketrŒrXrrŽrvr¤)rWÚ ssl_contextr§r¨r©r?r?r@Ústarttls)s&    ÿ  zIMAP4.starttlscCrØ)zpRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) r3rÄ)rWr¸Únamesr§r¨r©r?r?r@Ústatus@sz IMAP4.statuscCs>|d|dfdkrd|}| d|||¡\}}| ||d¡S)zAlters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) rr£r¯r²r4rrÄ)rWrÌÚcommandr¹r¨r©r?r?r@ÚstoreLsz IMAP4.storecCrÏ)zYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) r5rÆrÐr?r?r@Ú subscribeWrÒzIMAP4.subscribecGs,d}|j|||g|¢RŽ\}}| |||¡S)z‹IMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) r6rÄ)rWZthreading_algorithmrr r§r¨r©r?r?r@Úthread_sz IMAP4.threadc Gsˆ| ¡}|tvr| d|¡‚|jt|vr&| d||jd t|¡f¡‚d}|j||g|¢RŽ\}}|dvr;|}nd}| |||¡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: %sú9command %s illegal in state %s, only allowed in states %sú, r7)r,r1r6r)r«r{rArHÚjoinr·r¤)rWrr„r§r¨r©r?r?r@Úuidis ÿþz IMAP4.uidcCrÏ)z_Unsubscribe from old mailbox. (typ, [data]) = .unsubscribe(mailbox) r8rÆrÐr?r?r@Ú unsubscribe‚rÒzIMAP4.unsubscribecCrÈ)aMFree server's resources associated with the selected mailbox and returns the server to the authenticated state. This command performs the same actions as CLOSE, except that no messages are permanently removed from the currently selected mailbox. (typ, [data]) = .unselect() r9rrÉ)rWr¨rr?r?r@ÚunselectŠs  ÿzIMAP4.unselectcGs.| ¡}|tvr|jft|<|j|g|¢RŽ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«r{rHr·©rWr§r„r?r?r@Úxatomšs  z IMAP4.xatomc Csf|durd}|j} |jdkr| d|t| |d¡ƒ|f¡||vr,|| |¡dS|g||<dS)NóTéz#untagged_responses[%s] %s += ["%r"]rE)rKrGrsr˜rr¼)rWr¨r©Zurr?r?r@Ú_append_untagged°s ÿzIMAP4._append_untaggedcCs,|j d¡}|r| |d |jd¡¡‚dS)NÚBYEr£r½)rKrrCrÀr^)rWÚbyer?r?r@Ú _check_bye¾s ÿzIMAP4._check_byec Gs|jt|vrd|_| d||jd t|¡f¡‚dD] }||jvr'|j|=qd|jvr5|js5| d¡‚| ¡}t ||j ƒ}|d|}|D]}|durNqGt |t ƒrYt ||j ƒ}|d|}qG|j}|dur„d|_t |ƒt |jƒurv|}nd}|t dt|ƒ|j ƒ} |jd kr’| d |¡n| d |¡z | |t¡Wntyµ} z| d | ¡‚d} ~ ww|dur¼|S | ¡rÌ|j|rÈ|S| ¡sÁ|rÓ||jƒ} |jd krâ| d t|ƒ¡z | |¡| t¡Wnty} z| d | ¡‚d} ~ ww|s |Sq½)Nrr©rkÚNOÚBADrz#mailbox status changed to READ-ONLYó z {%s}Téz> %rzsocket error: %srjzwrite literal size %s)rHr{rIrArrKrMrDÚ_new_tagÚbytesr^rórôÚtypeÚ_commandr˜rGrsÚ_logržr¶rUrCrurJrL) rWr§r„r¨ÚtagrÚargrIZ literatorÚvalr?r?r@r.Äs~ ÿþ € ÿ       €ÿ þ   €ÿçzIMAP4._commandc Cs²|dk}|s | ¡z |j||d\}}Wn+|jy+}z | d||f¡‚d}~w|jy@}z | d||f¡‚d}~ww|sG| ¡|dkrU| d|||f¡‚||fS)Nr)Ú expect_byezcommand: %s => %sr(z%s command error: %s %s)r%Ú_get_tagged_responserCrA)rWr§r0rƒr¨rr2r?r?r@Ú_command_completes"€€ÿzIMAP4._command_completecCsJ| ¡\}}|dgkr| d¡‚t|d|jƒ}| ¡}t| ¡ƒ|_dS)Nz"no CAPABILITY response from serverr£)rÅrArôr^r«ÚtupleÚsplitrwrÊr?r?r@rv#s   zIMAP4._get_capabilitiescCsî| ¡}| |j|¡r8|j d¡}||jvr| d|¡‚|j d¡}t||jƒ}|j d¡}||gf|j|<nŠd}| t |¡sM| |j |¡rM|j d¡}|jdurh| t |¡ra|j d¡|_ dS| d|¡‚|j d¡}t||jƒ}|j d¡}|dur€d}|rˆ|d|}| |j |¡r¼t|j d ¡ƒ} |jd kr¤| d |¡| |¡}| |||f¡| ¡}| |j |¡s| ||¡|d vrâ| t|¡râ|j d¡}t||jƒ}| ||j d¡¡ |jdkrõ|dvrõ| d||f¡|S)Nr0zunexpected tagged response: %rr-rZdata2zunexpected response: %rr r)r“Tr*zread literal size %sr&rj)r'r(r#z%s response: %r)Ú _get_lineÚ_matchroÚmoÚgrouprJrCrôr^ÚUntagged_responsereÚ ContinuationrLrcÚintrGrsr‘r"Ú Response_code)rWÚrespr0r¨r©Zdat2r“rr?r?r@ru,sR               ð   zIMAP4._get_responsec CsŽ |j|}|dur|j|=|S|r#d}|j |d¡}|dur#||fS| ¡z| ¡Wn|jyE}z |jdkr@| ¡‚d}~wwq)Nrjr#)rJrKÚpopr%rurCrGÚ print_log)rWr0r3Úresultr¨r$r2r?r?r@r4|s*   €üèzIMAP4._get_tagged_responsecCsj| ¡}|s | d¡‚| d¡s| d|¡‚|dd…} |jdkr,| d|¡|S| d|¡|S)Nzsocket error: EOFr z#socket error: unterminated line: %réþÿÿÿTr*z< %r)r–rCÚendswithrGrsr/r™r?r?r@r8s    ÿzIMAP4._get_linecCsF| |¡|_ |jdur|jdkr| d|j|j ¡f¡|jduS)NTr!z matched %r => %r)Úmatchr:rGrsrèÚgroups)rWZcreÚsr?r?r@r9°s  z IMAP4._matchcCs2|jtt|jƒ|jƒ}|jd|_d|j|<|S)Nrj)rnr,rôrNr^rJ)rWr0r?r?r@r+¼s  zIMAP4._new_tagcCs$| dd¡}| dd¡}d|dS)Nú\z\\ú"z\")r½)rWr1r?r?r@rëÄs   z IMAP4._quotecGs| ||j|g|¢RŽ¡Sr)r5r.rr?r?r@r·ÌszIMAP4._simple_commandcCsV|dkr||fS||jvr|dgfS|j |¡} |jdkr'| d||f¡||fS)Nr'Tr!zuntagged_responses[%s] => %s)rKrArGrs)rWr¨r©r§rr?r?r@r¤Ñs    zIMAP4._untagged_responseTcCsN|durt ¡}t dt |¡¡}tj d||dd|f¡tj ¡dS)Nz%M:%Sz %s.%02d %s éd)ÚtimeÚstrftimeÚ localtimer‡ÚstderrÚwriteÚflush)rWrHZsecsZtmr?r?r@rsßs z IMAP4._mesgcCs2|sdSdd„| ¡Dƒ}| dd |¡¡dS)Ncss"|] \}}|›d|›VqdS)z: Nr?)Ú.0ÚkeyÚvaluer?r?r@Ú és€ÿz!IMAP4._dump_ur..zuntagged responses dump:z )Úitemsrsr)rWZuntagged_resp_dictrVr?r?r@rúæs ÿzIMAP4._dump_urcCs<|t ¡f|j|j<|jd7_|j|jkrd|_dSdS)Nrjr)rLrrrqrpr™r?r?r@r/ís   ÿz IMAP4._logcCsn| dt|jƒ¡|j|j}}|r5z |j|j|ŽWnY|d7}||jkr-d}|d8}|sdSdS)Nzlast %d IMAP4 interactions:rjr)rsr˜rrrqrp)rWÚiÚnr?r?r@rBôs  øzIMAP4.print_log)råræ)r®Fr)F)Ur<r=r>Ú__doc__rSrArCrDÚ IMAP4_PORTr[rPrhrRr€r‚r…rŠrQr‘r–ržrTr‰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þrrrrrr rrrrrrrrrr"r%r.r5rvrur4r8r9r+rër·r¤rsrúr/rBr?r?r?r@r‡s¤/*                      M P!   rc@s>eZdZdZdeddddfdd„Zdd„Zdedfdd „ZdS) Ú IMAP4_SSLaäIMAP4 client class over SSL connection Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile[, ssl_context[, timeout=None]]]]]]) 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. timeout - socket timeout (default: None) If timeout is not given or is None, the global default socket timeout is used for more documentation see the docstring of the parent class IMAP4. rENcCs’|dur |dur tdƒ‚|dur|durtdƒ‚|dus |dur+ddl}| dtd¡||_||_|durrYÚIMAP4_SSL_PORTr[rŠrQr?r?r?r@r[s ÿr[c@sBeZdZdZdd„Zddd„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||_t |¡dSr)rrr[)rWrr?r?r@r[IszIMAP4_stream.__init__NcCsNd|_d|_d|_d|_tj|jttjtjddd|_ |j j |_ |j j |_ dS)z…Setup a stream connection. This connection will be used by the routines: read, readline, send, shutdown. NT)ÚbufsizeÚstdinÚstdoutÚshellZ close_fds)rXrYrŒrŽÚ subprocessÚPopenrrÚPIPEr¿rdÚ writefilereÚreadfilerVr?r?r@rQNsý zIMAP4_stream.opencCrr)rkr‘r’r?r?r@r‘^r”zIMAP4_stream.readcCs |j ¡S)r•)rkr–rfr?r?r@r–cs zIMAP4_stream.readlinecCs|j |¡|j ¡dS)r›N)rjrPrQrœr?r?r@ržhs zIMAP4_stream.sendcCs"|j ¡|j ¡|j ¡dS)rŸN)rkr rjr¿Úwaitrfr?r?r@rTns  zIMAP4_stream.shutdown)NNN) r<r=r>rYr[rQr‘r–ržrTr?r?r?r@r=s  rc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) r¾zcPrivate class to provide en/decoding for base64-based authentication conversation. cCs ||_dSr)rÁ)rWZmechinstr?r?r@r[|s z_Authenticator.__init__cCs&| | |¡¡}|durdS| |¡S)Nó*)rÁrÀrõ)rWrZretr?r?r@r¿s z_Authenticator.processcCspd}t|tƒr | d¡}|r6t|ƒdkr!|dd…}|dd…}n|}d}t |¡}|r4||dd…}|s|S)Nr rgé0r£)rórôrõr˜ÚbinasciiZ b2a_base64)rWÚinpZoupÚtÚer?r?r@rõ…s     ÷ z_Authenticator.encodecCs|sdSt |¡S)Nr )roZ a2b_base64)rWrpr?r?r@rÀs z_Authenticator.decodeN)r<r=r>rYr[r¿rõrÀr?r?r?r@r¾vs  r¾z0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrñcCsi|] \}}| ¡|d“qS)rj)rõ)rRrXrHr?r?r@Ú £srsrjc CsØt |¡}|s dSt| d¡}| d¡}t| d¡ƒ}t| d¡ƒ}t| d¡ƒ}t| d¡ƒ}t| d¡ƒ}t| d ¡ƒ} t| d ¡ƒ} | d | d } |d krU| } ||||||d d d f } t | ¡| } t | ¡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£) Ú InternalDaterFÚMon2numr;r>ÚcalendarZtimegmrLrN)r@r:rtrurvrwrxryrzr{r|ZzoneZttÚutcr?r?r@r¥s$   rcCsBd}d}tt|ƒƒ}|rt|dƒ\}}|||d…|}|s |S)z-Convert integer to A-P string representation.r sABCDEFGHIJKLMNOPérj)r>ÚabsÚdivmod)Znumr2ZAPÚmodr?r?r@r Ès þr cCs$t |¡}|s dSt| d¡ ¡ƒS)z-Convert IMAP4 flags response to python tuple.r?r¹)ÚFlagsrFr6r;r7)r@r:r?r?r@r Õs r cCst|ttfƒrt |tj¡ ¡}npt|tƒr[z|j }Wn,t yGt j rA|d}|dkr7t   t  |¡¡d}t jt jf| }nt j }Ynwt|d}t|dd…dt|ƒiŽ}n&t|tƒrl|jduritdƒ‚|}nt|tƒr}|d|dfd kr}|Std ƒ‚d  t|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 awarer)rJrJzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z")rór>ÚfloatrZ fromtimestamprr‚Z astimezoner6Ú tm_gmtoffr~rLÚdaylightrNÚmktimeÚaltzonerrŠr†rôÚformatÚMonthsZmonthrM)rºZdtZgmtoffZdstZdeltaZfmtr?r?r@r às: ÿÿ   €ù    r Ú__main__zd:s:)r?r?z-dz-s)rEzIMAP password for %s on %s: Z localhostzJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)sÚ )rìZlfrî)rÑ)ú /tmp/xxx 1)rþ)r”z/tmp/yyy)r©ú /tmp/yyz 2r¼r–)ré)z/tmpzyy*)rr•)r)NZSUBJECTÚtest)rÙ)Ú1z(FLAGS INTERNALDATE RFC822))r)r˜ÚFLAGSz (\Deleted))rùr?)r×r?)rªr?)r r?)rr?)r­)Z UIDVALIDITY)r)r,ZALL)r­)r)rƒr?cCsLt d||f¡tt|ƒ|Ž\}}t d|||f¡|dkr$|d‚|S)Nz%s %sz %s => %s %sr'r)ÚMrsr|)Úcmdr„r¨r©r?r?r@ÚrunAs rœrzPROTOCOL_VERSION = %szCAPABILITIES = %rré)z/tmp/zyy%z .*"([^"]+)"$r£rÓrz%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 )UrYrtror¡rmr_r‰rgr‡rLrrrrÚiorr r Ú ImportErrorÚ__all__r¶rFrZrbrxr—r{r`r=r‡rrbrcr´r?r<rerardrr[r¼rr¾r7r‘Ú enumerater€rr r r r<ZgetoptZgetpassÚargvZoptlistr„rAr2Zstream_commandÚoptr>rXZgetuserZUSERZPASSWDZ test_mesgZ test_seq1Z test_seq2rœršrHrsryrwr›ZmlrFr:r;Úpathr©rÚprintr?r?r?r@ÚsžH  ÿ þýüûúùø ÷ ö õ ô óòñðïîíìëêéèçæåäãâá à!ß"Þ#Ý$Õ 0    ÿ 69 ,#  )€ÿ     €  òù            ÿý˜