QfddZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZ ddlZdZgdZd ZdZd Zd Zd Zd Ziddddddddddddddddddddddddddd dd!dd"dd#did$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4dddddddddd5Zej6d6Zej6d7Zej6d8Zej6d9ej>Z ej6d:Z!ej6d;Z"ej6d<Z#ej6d=ej>Z$d9Z%d=Z&Gd>d?Z'erGd@dAe'Z(ejSdAGdBdCe'Z*GdDdEZ+dFjYdGZ-e.e-dHdDcic]\}}|j_|dHzc}}Z0dIZ1dJZ2dKZ3dLZ4e5dMk(rddl6Z6ddl7Z7 e6jlejpdHddN\Z9Z:dZ=e9D]!\Z>ZdPk(r e?e<Ze>dQk(se\ZMZ:eGeMe:ZSeMe:fdkk7reSdujYZTeTs-eGdwddxeTduzdyf@eUdzyy#e$rdZYwxYwcc}}w#e6jv$rZ.*))?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.*))?ceZdZdZGddeZGddeZGddeZded fd Z d Z d Z d Z dZ dZdZdZded fdZdZdZdZdZdZdZdZdZdZdZdZdZdZd Zd!Z d"Z!d#Z"d$Z#d%Z$d&Z%d'Z&d(Z'd)Z(dRd*Z)d+Z*d,Z+d-Z,d.Z-dRd/Z.d0Z/d1Z0d2Z1d3Z2d4Z3d5Z4d6Z5dSd7Z6d8Z7d9Z8d:Z9d;Z:dTd<Z;d=ZZ=d?Z>d@Z?dAZ@dBZAdCZBdDZCdEZDdFZEdGZFdHZGdIZHdJZIdUdKZJdLZKdMZLdNZMdOZNdPZOdQZPy )VraIMAP4 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 lowercase). 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 eZdZy) IMAP4.errorN__name__ __module__ __qualname__./opt/alt/python312/lib64/python3.12/imaplib.pyerrorr?rErGc eZdZy) IMAP4.abortNr@rDrErFabortrJrHrErKc eZdZy)IMAP4.readonlyNr@rDrErFreadonlyrMrHrErNNcNt|_d|_d|_i|_i|_d|_d|_d|_d|_ |j|j||| |jy#t$r" |j#t$rYwxYwwxYw)NrrOFr)Debugdebugstateliteraltagged_commandsuntagged_responsescontinuation_response is_readonlytagnum_tls_established _mode_asciiopen_connect ExceptionshutdownOSErrorselfhostporttimeouts rF__init__zIMAP4.__init__s   !"$%'"  %  $g&  MMO        s0(A99 B$BB$ B B$B  B$cd|_d|_tjttj |_tjttj |_y)NFascii) utf8_enabled _encodingrecompile_LiteralASCIILiteral_Untagged_statusUntagged_statusrbs rFr[zIMAP4._mode_asciis?! zz(BHH5 !zz*:BHHErEcd|_d|_tjt|_tjt |_y)NTutf-8)rirjrkrlrmrorprqrrs rF _mode_utf8zIMAP4._mode_utf8s3  zz(+ !zz*:;rEcttjdd|_t j d|jzdztj |_ |j|_d|j vrd|_n1d|j vrd|_n|j%|j|j' t*D]}||j(vr||_y|j%d ) Niis(?Ps"\d+) (?P[A-Z]+) (?P.*)PREAUTHrOKrzserver not IMAP4 compliant)r randomrandinttagprerkrlrntagre _cmd_log_len _cmd_log_idx_cmd_logrR_mesg __version__ _get_responsewelcomerVrSrG_get_capabilities capabilitiesAllowedVersionsPROTOCOL_VERSION)rbversions rFr]zIMAP4._connectsV^^D%89 ZZ ++!&@!ABD((L  ))+ // /DJ T,, ,"DJ**T\\* *  'Gd///$+D !  ' jj566rEcb|tvrt||jStd|z)NzUnknown IMAP4 command: '%s')CommandsgetattrlowerAttributeError)rbattrs rF __getattr__zIMAP4.__getattr__ s. 8 4. .:TABBrEc|SNrDrrs rF __enter__zIMAP4.__enter__s rEcd|jdk(ry |jy#t$rYywxYw)Nr)rSlogoutr`)rbargss rF__exit__zIMAP4.__exit__s1 :: !   KKM   s # //c"| |s td|jsdn |j}tjd||j|j||jf}|t j ||St j |S)Nz0Non-blocking socket (timeout=0) is not supportedz imaplib.open) ValueErrorrcsysauditrdsocketcreate_connection)rbrercaddresss rF_create_socketzIMAP4._create_socket#s{  wOP P99t$)) .$ 499=#  ++GW= =''00rEc||_||_|j||_|jj d|_y)zSetup 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)rcrdrsockmakefilefileras rFr\z IMAP4.open0s:   ''0 II&&t, rEc8|jj|SzRead 'size' bytes from remote.)rreadrbsizes rFrz IMAP4.read<syy~~d##rEc|jjtdz}t|tkDr|j dtz|S)Read line from remote.zgot more than %d bytes)rreadline_MAXLINElenrGrblines rFrzIMAP4.readlineAs@yy!!(Q,/ t9x **5@A A rEchtjd|||jj|y)Send data to remote.z imaplib.sendN)rrrsendallrbdatas rFsendz IMAP4.sendIs$ .$- $rEc|jj |jjtj |jjy#t $r8}|jtjk7rt|dddk7rYd}~Wd}~wwxYw#|jjwxYw) Close I/O established in "open".winerrorri&'N) rcloserr_r SHUT_RDWRr`errnoENOTCONNr)rbexcs rFr_zIMAP4.shutdownOs   II  v// 0 IIOO   U^^+3 A.%7   IIOO s))A B!).BB$B!!B$$Cc|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )rrrs rFrz IMAP4.socket_s yyrEcd}|jddg|\}}|dr||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. RECENTrxN)_untagged_responsenooprbnametypdats rFrecentz IMAP4.recentksW**4$>S r78O99;S&&sC66rEcF|j|dg|jS)zReturn data for response 'code' if received, or None. Old value for response 'code' is cleared. (code, [data]) = .response(code) N)rupper)rbcodes rFresponsezIMAP4.response|s!&&tdVTZZ\BBrEcd}|sd}|r|d|dfdk7rd|z}nd}|r t|}nd}tjt|}|jrd|zd z}||_|j ||||S) zAppend message to named mailbox. (typ, [data]) = .append(mailbox, flags, date_time, message) All args except `message' can be None. rINBOXrr()(%s)NsUTF8 ())r MapCRLFsubCRLFrirT_simple_command)rbmailboxflags date_timemessagerrTs rFappendz IMAP4.appendsG ar#y0E ))4II++dG,   ')D0G ##D'5)DDrEc|j}t|j|_|j d|\}}|dk7r$|j |dj ddd|_||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. rrxrrtreplacer)r_AuthenticatorprocessrTrrGdecoderS)rb mechanism authobjectmechrrs rF authenticatezIMAP4.authenticateso   &j199 ''=S $;**SW^^GY?@ @ CxrEcTd}|j|\}}|j|||S)zT(typ, [data]) = .capability() Fetch capabilities list from server.rrrrs rF capabilityzIMAP4.capabilitys2''-S&&sC66rEc$|jdS)zRCheckpoint mailbox on server. (typ, [data]) = .check() rrrrs rFcheckz IMAP4.checks ##G,,rEcZ |jd\}}d|_||fS#d|_wxYw)zClose currently selected mailbox. Deleted messages are removed from writable mailbox. This is the recommended command before 'LOGOUT'. (typ, [data]) = .close() rrrrSrbrrs rFrz IMAP4.closes6 ++G4HCDJCx DJ! *c(|jd||S)zCopy 'message_set' messages onto end of 'new_mailbox'. (typ, [data]) = .copy(message_set, new_mailbox) rr)rb message_set new_mailboxs rFcopyz IMAP4.copys ##FKEErEc&|jd|S)zPCreate new mailbox. (typ, [data]) = .create(mailbox) rrrbrs rFcreatez IMAP4.create ##Hg66rEc&|jd|S)zPDelete old mailbox. (typ, [data]) = .delete(mailbox) rrrs rFdeletez IMAP4.deleterrEc(|jd||S)zDelete the ACLs (remove any rights) set for who on mailbox. (typ, [data]) = .deleteacl(mailbox, who) rr)rbrwhos rF deleteaclzIMAP4.deleteacls ##K#>>rEcd|jvrtjd|jd|\}}|dk(r"d|j vr|j ||fS)zlSend an RFC5161 enable string to the server. (typ, [data]) = .enable(capability) rzServer does not support ENABLErxz UTF8=ACCEPT)rrrGrrru)rbrrrs rFenablez IMAP4.enablesc 4,, ,++>? ?((:> T $;=J,<,<,>> OO DyrEcTd}|j|\}}|j|||S)zPermanently 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. rrrs rFexpungez IMAP4.expunge s2''-S&&sC66rEcXd}|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)rbr message_partsrrrs rFfetchz IMAP4.fetchs6''k=IS&&sC66rEcR|jd|\}}|j||dS)zXGet the ACLs for a mailbox. (typ, [data]) = .getacl(mailbox) r!ACLrrbrrrs rFgetaclz IMAP4.getacl(s/ ''':S&&sC77rEcV|jd|||\}}|j||dS)za(typ, [data]) = .getannotation(mailbox, entry, attribute) Retrieve ANNOTATIONs.r" ANNOTATIONr)rbrentry attributerrs rF getannotationzIMAP4.getannotation1s3''%SS&&sC>>rEcR|jd|\}}|j||dS)zGet the quota root's resource usage and limits. Part of the IMAP4 QUOTA extension defined in rfc2087. (typ, [data]) = .getquota(root) r#QUOTAr)rbrootrrs rFgetquotazIMAP4.getquota9s/'' D9S&&sC99rEc|jd|\}}|j||d\}}|j||d\}}|||gfS)zGet the list of quota roots for the named mailbox. (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = .getquotaroot(mailbox) r$r QUOTAROOTr)rbrrrquota quotaroots rF getquotarootzIMAP4.getquotarootDsZ ''@S,,S#w? U00c;GYY&&&rEcXd}|j|||\}}|j|||S)zList mailbox names in directory matching pattern. (typ, [data]) = .list(directory='""', pattern='*') 'data' is list of LIST responses. r&rrb directorypatternrrrs rFlistz IMAP4.listO6''iAS&&sC66rEc|jd||j|\}}|dk7r|j|dd|_||fS)zIdentify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. r'rxrr)r_quoterGrS)rbuserpasswordrrs rFloginz IMAP4.login[sO''t{{87LMS $;**SW% % CxrEcX||c|_|_|jd|jS)zr Force use of CRAM-MD5 authentication. (typ, [data]) = .login_cram_md5(user, password) zCRAM-MD5)rr r_CRAM_MD5_AUTH)rbrr s rFlogin_cram_md5zIMAP4.login_cram_md5is- $(  4=  T-@-@AArEcddl}t|jtr|jj dn |j}|j dz|j ||djzS)z1 Authobject to use with CRAM-MD5 authentication. rNrt md5)hmac isinstancer strencoderHMAC hexdigest)rb challenger(pwds rFr#zIMAP4._CRAM_MD5_AUTHrsY0:4==#0Nt}}##G,26-- yy33 5!A!K!K!MMMrEc`d|_|jd\}}|j||fS)z|Shutdown connection to server. (typ, [data]) = .logout() Returns server 'BYE' response. r)rSrr_rs rFrz IMAP4.logoutzs1 ''1S CxrEcXd}|j|||\}}|j|||S)zList 'subscribed' mailbox names in directory matching pattern. (typ, [data, ...]) = .lsub(directory='""', pattern='*') 'data' are tuples of message part envelope and data. r(rrs rFlsubz IMAP4.lsubrrEcR|jd|\}}|j||dS)zShow my ACLs for a mailbox (i.e. the rights that I have on mailbox). (typ, [data]) = .myrights(mailbox) r%rrs rFmyrightszIMAP4.myrightss/ &&z7;C&&sC<.namespace() r*rrs rF namespacezIMAP4.namespaces2 ''-S&&sC66rEc& |jdS)zFSend NOOP command. (typ, [data]) = .noop() r+)rR_dump_urrVrrrs rFrz IMAP4.noops ##F++rEc\d}|j|||||\}}|j||dS)zFetch 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)rb message_num message_partstartlengthrrrs rFpartialz IMAP4.partials;''k<PVWS&&sC99rEc*d}|jd|S)zAssume authentication as "user". Allows an authorised administrator to proxy into any user's mailbox. (typ, [data]) = .proxyauth(user) r-r)rbrrs rF proxyauthzIMAP4.proxyauths##K66rEc(|jd||S)zkRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) r.r)rb oldmailbox newmailboxs rFrenamez IMAP4.renames ##Hj*EErEcd}|r:|jrtjd|j|d|g|\}}n|j|g|\}}|j |||S)zSearch 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 modeCHARSET)rirrGrr)rbcharsetcriteriarrrs rFsearchz IMAP4.searchst   kk"KLL+t++D)WPxPHC+t++D<8.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. rr0rxrr READ-ONLYz%s is not writableEXISTSN)rVrXrrSrRr8rNget)rbrrNrrrs rFselectz IMAP4.selects#%# DD''g6S $;DJ8O $11 1 -- 4w >? ?D++//4&AAArEc*|jd|||S)zZSet a mailbox acl. (typ, [data]) = .setacl(mailbox, who, what) r1r)rbrrwhats rFsetaclz IMAP4.setacls ##HgsDAArEcT|jdg|\}}|j||dS)z_(typ, [data]) = .setannotation(mailbox[, entry, attribute]+) Set ANNOTATIONs.r2r r)rbrrrs rF setannotationzIMAP4.setannotation s4(4''?$?S&&sC>>rEcT|jd||\}}|j||dS)ziSet the quota root's resource limits. (typ, [data]) = .setquota(root, limits) r3rr)rbrlimitsrrs rFsetquotazIMAP4.setquotas1 '' D&AS&&sC99rEcd}|d|dfdk7rd|z}|j|||g|\}}|j|||S)zIMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) r4rrrrr)rb sort_criteriarGsearch_criteriarrrs rFsortz IMAP4.sorts`  ! ]2. /9 <"]2M'4''mWWWS&&sC66rEcd}ts|jd|jr|jd||jvr|jd|t j }|j|\}}|dk(rd|j|j|j|_ |jjd|_ d|_|jn|jd |j|||S) Nr5zSSL support missingzTLS session already establishedzTLS not supported by serverrxserver_hostnamerTzCouldn't establish TLS session)HAVE_SSLrGrZrKrssl_create_stdlib_contextr wrap_socketrrcrrrr)rb ssl_contextrrrs rFstarttlszIMAP4.starttls)s**23 3  **>? ? t(( (**:; ;  446K''-S $;#// @D 0KDI **40DI$(D !  " " $**=> >&&sC66rEcXd}|j|||\}}|j|||S)zpRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) r6r)rbrnamesrrrs rFstatusz IMAP4.status@s8 ''gu=S&&sC66rEcz|d|dfdk7rd|z}|jd|||\}}|j||dS)zAlters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) rrrrr7r r)rbrcommandrrrs rFstorez IMAP4.storeLsQ !HU2Y 9 ,UNE''guMS&&sC99rEc&|jd|S)zYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) r8rrs rF subscribezIMAP4.subscribeWs ##K99rEc\d}|j|||g|\}}|j|||S)zIMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) r9r)rbthreading_algorithmrGrYrrrs rFthreadz IMAP4.thread_s> '4''.A7]_]S&&sC66rEc b|j}|tvr|jd|z|jt|vr:|jd|d|jddj t|d}|j ||g|\}}|dvr|}nd}|j |||S) zExecute "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: %scommand  illegal in state , only allowed in states , r:)r/r4r9r )rrrGrSjoinrr)rbrhrrrrs rFuidz IMAP4.uidis--/("**.unsubscribe(mailbox) r;rrs rF unsubscribezIMAP4.unsubscribes ##M7;;rEcZ |jd\}}d|_||fS#d|_wxYw)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() r<rr)rbrrs rFunselectzIMAP4.unselects7 ,,Z8ICDJDy DJrc|j}|tvr|jft|<|j|g|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'. )rrrSrrbrrs rFxatomz IMAP4.xatoms@zz|x"jj]HTN#t##D0400rEcd|d}|j} ||vr||j |y|g||<yNrE)rVrRrrrMr)rbrrurs rF_append_untaggedzIMAP4._append_untaggeds> ;C  $ $  "9 sGNN3 eBsGrEc|jjd}|r.|j|dj|jdy)NBYErr)rVrMrKrrj)rbbyes rF _check_byezIMAP4._check_byesB%%))%0 **SW^^DNNIFG G rEc |jt|vrAd|_|jd|d|jddj t|dD]}||j vs|j |= d|j vr|j s|jd|j}t||j}|dz|z}|D]3}|t|trt||j}|dz|z}5|j}|Qd|_t|t|jur|}n'd}|td t|z|jz} |j'|t(z||S |j/r"|j0|r|S|j/r"r||j2} |j'||j't(|s |St#t*$r} |j-d | zd} ~ wwxYw#t*$r} |j-d | zd} ~ wwxYw) NrprqrrrsrxNOBADrKz#mailbox status changed to READ-ONLY z {%s}zsocket error: %s)rSrrTrGrtrVrXrN_new_tagbytesrjr)r*type_commandrrRr_logrrr`rKrrUrW) rbrrrtagrargrT literatorvals rFrzIMAP4._commands9 ::Xd^ +DL**"DJJ"ii79: : 'Cd---++C0' $11 1  -- EF FmmoT4>>*TzD C{H#s#C0$;$D  ,,  DLG}T]] 33#  eGc'l$:DNNKK   7 IIdTk " ?J$$&'',J$$& #D$>$>? ; '" $ 3  7**/#56 6 72 ;jj!3c!9:: ;s0,G=&H"= HHH" I+H??Ict|dk(}|s|j |j||\}}|s|j|dk(r|j|d|d|||fS#|j$r}|jd|d|d}~w|j$r}|jd|d|d}~wwxYw)Nr) expect_byez command:  => rz command error: r&)r_get_tagged_responserKrG)rbrrrrrrs rF_command_completezIMAP4._command_completes(" OO  @11#&1IIC  OO  %<**$TJK KDyzz @**D#>? ?zz @**D#>? ? @s#A##B72B  B7B22B7c|j\}}|dgk(r|jdt|d|j}|j }t |j |_y)Nz"no CAPABILITY response from serverr)rrGr*rjrtuplesplitrrs rFrzIMAP4._get_capabilities#s]??$S 4&=**AB B#b'4>>*iik!#))+.rEc|j}|j|j|r|jj d}||j vr|j d|z|jj d}t||j}|jj d}||gf|j |<nd}|jt|s7|j|j|r|jj d}|jK|jt|r!|jj d|_ y|j d|z|jj d}t||j}|jj d}|d}|r|dz|z}|j|j|rwt|jj d } |j#|}|j%|||f|j}|j|j|rw|j%|||d vrr|jt&|r\|jj d}t||j}|j%||jj d |S) Nrzunexpected tagged response: %rrrdata2zunexpected response: %rrErrr) _get_line_matchr|mogrouprUrKr*rjUntagged_responserq ContinuationrWrointrRrrr Response_code)rbresprrrdat2rrs rFrzIMAP4._get_response,s\~~ ;;tzz4 (''--&C$...jj!AD!HII''--'Cc4>>*C''--'C),se D  %D;;0$7;;t33T:77==1Dww;;|T215v1FD.jj!:T!ABB''--'Cc4>>*C''--'C{#C3:,S++dllC0477==01yy%%cC;7nn&!++dllC0$  ! !#s + % %$++mS*I''--'Cc4>>*C  ! !#tww}}V'< =  rEc |j|}||j|=|S|r$d}|jj|d}|||fS|j |j h#|j $r} d}~wwxYw)Nr)rUrVpoprrrKrR print_log)rbrrresultrrrs rFrzIMAP4._get_tagged_response|s))#.F!((- --11#t<?:% OO  ""$/0::   sA**B9A;;Bc|j}|s|jd|jds|jd|z|dd} |S)Nzsocket error: EOFr z#socket error: unterminated line: %r)rrKendswithrRrrrs rFrzIMAP4._get_linesX}}**01 1}}W%**BTIJ JCRy   rEcL|j||_ |jduSr)matchrrRrrgroups)rbcress rFrz IMAP4._matchs' ))A, wwd""rEc|jtt|j|jz}|jdz|_d|j |<|S)Nr)r{rr*rYrjrU)rbrs rFrzIMAP4._new_tagsHkkE#dkk"2DNNCCkkAo $(S! rEcZ|jdd}|jdd}d|zdzS)N\z\\"z\")r)rbrs rFrz IMAP4._quotes0kk$'kk#u%Sy3rEcH|j||j|g|Sr)rrr{s rFrzIMAP4._simple_commands%%%dMDMM$,F,FGGrEcz|dk(r||fS||jvr|dgfS|jj|} ||fS)Nr)rVrrRr)rbrrrrs rFrzIMAP4._untagged_responsesQ $;8Ot...; &&**40 DyrE)z""*)rFr)F)UrArBrC__doc__r^rGrKrN IMAP4_PORTrfr[rur]rrrrr\rrrr_rrrrrrrrrrrrrrrrr rrrr!r$r#rr2r4r6rr>r@rDrIrNrQrSrVrZrcrfrirkrnrurwryr|rrrrrrrrrrrrrrr8rrrDrErFrrs-^!  5Z2F<'7TC  1T -$   7"CE4:7- F77?  7 78?:' 7 BN  7=7, : 7F7$B@B?: 77. 7::772<  1, H JZ$/M`B& #H rErc8eZdZdZdefddddZdZdedfdZy) IMAP4_SSLaIMAP4 client class over SSL connection Instantiate with: IMAP4_SSL([host[, port[, ssl_context[, timeout=None]]]]) host - host's name (default: localhost); port - port number (default: standard IMAP4 SSL port); ssl_context - a SSLContext object that contains your certificate chain and private key (default: None) 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. rON)rbrecn|tj}||_tj ||||yr)r_r`rbrrf)rbrcrdrbres rFrfzIMAP4_SSL.__init__s0"!88: *D  NN4tW 5rEc|tj||}|jj||jS)Nr\)rrrbrarc)rbrers rFrzIMAP4_SSL._create_sockets=''g6D##//@D 0K KrEc4tj||||y)zSetup 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)rr\ras rFr\zIMAP4_SSL.open!s JJtT4 1rE)rArBrCrIMAP4_SSL_PORTrfrr\rDrErFrrs1 !# 6$($ 6 K ^T 2rErc6eZdZdZdZd dZdZdZdZdZ y) rzIMAP4 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. c<||_tj|yr)rhrrf)rbrhs rFrfzIMAP4_stream.__init__8s  trENc<d|_d|_d|_d|_t j |j ttjtjdd|_ |jj|_ |jj|_ y)zSetup a stream connection. This connection will be used by the routines: read, readline, send, shutdown. NT)bufsizestdinstdoutshell close_fds)rcrdrr subprocessPopenrhrPIPErr writefilerreadfileras rFr\zIMAP4_stream.open=sq     !'' '//*//$( ++ ++ rEc8|jj|Sr)rrrs rFrzIMAP4_stream.readMs}}!!$''rEc6|jjS)r)rrrrs rFrzIMAP4_stream.readlineRs}}%%''rEcn|jj||jjy)rN)rwriteflushrs rFrzIMAP4_stream.sendWs$ T" rEc|jj|jj|jj y)rN)rrrrwaitrrs rFr_zIMAP4_stream.shutdown]s2   rE)NNN) rArBrCrrfr\rrrr_rDrErFrr,s% , ( (  rErc(eZdZdZdZdZdZdZy)rzcPrivate class to provide en/decoding for base64-based authentication conversation. c||_yr)r)rbmechinsts rFrfz_Authenticator.__init__ks  rEcj|j|j|}|y|j|S)N*)rrr+)rbrrets rFrz_Authenticator.processns0ii D)* ;{{3rEcd}t|tr|jd}|r?t|dkDr |dd}|dd}n|}d}t j |}|r||ddz}|r?|S)NrErt0r)r)r*r+rbinascii b2a_base64)rbinpouptes rFr+z_Authenticator.encodets} c3 **W%C3x"}H"#h##A&AAcrFl rEc2|sytj|Sr~)r a2b_base64)rbrs rFrz_Authenticator.decodes""3''rEN)rArBrCrrfrr+rrDrErFrres 0(rErz0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Decr&rc tj|}|syt|jd}|jd}t |jd}t |jd}t |jd}t |jd}t |jd}t |jd } t |jd } | d z| zd z} |d k(r| } ||||||d d d f } t j | | z } tj| S)zParse 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. Nmonzonendayyearhourminseczonehzonem<-r) InternalDaterMon2numrrcalendartimegmtime localtime)rrrrrrrrrrrzonettutcs rFr r s   D !B  "((5/ "C HHW E bhhuo C rxx D rxx D bhhuo C bhhuo C ! "E ! "E "Hu b D }u S$S"b" 5B //"  $C >># rEctd}d}tt|}|rt|d\}}|||dz|z}|r|S)z-Convert integer to A-P string representation.rEsABCDEFGHIJKLMNOPr)rabsdivmod)numrAPmods rFr r sM C'r c#h-C #r?SSUmc!  JrEctj|}|syt|jdj S)z-Convert IMAP4 flags response to python tuple.rDr)Flagsrrrr)rrs rFr r s5 T B  '"((* ++rEc:t|ttfr3tj|t j j}nt|tr1 |j}t!|}t|dddt |i}nTt|tr|j" t%d|}n*t|t&r|d|dfd k(r|St%d d j)t*|j,}|j/|S#t$rtjrZ|d}|dk(r+tjtj|d}tj tjf| }ntj }Y2wxYw) aConvert 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)secondsNtzinfozdate_time must be awarer)rrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z")r)rfloatr fromtimestamprr astimezoner tm_gmtoffrrdaylightrmktimealtzonerrrr*formatMonthsmonthstrftime)rdtgmtoffdstdeltafmts rFr r s])c5\*  # #I$,LL22<*, Iu % (((F&) y!} =Xe_ = Ix (    #67 7  Is #1im(D (Q899 " ) )&*: ;C ;;s ' (}}l"9..Y)?@CC==$,,7<<-- (s DBFF__main__zd:s:)rDrDz-dz-s)rOzIMAP password for z on localhostz: zJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)s )rlfr!)r) /tmp/xxx 1)rD)rz/tmp/yyy)r /tmp/yyz 2rr)r)z/tmpzyy*)rNr)rI)NSUBJECTtest)r)1z(FLAGS INTERNALDATE RFC822))ri)r"FLAGSz (\Deleted))r6rD)rrD)rrD)rrD)rNrD)r) UIDVALIDITY)ru)r/ALL)r)rL)rrDctj|d|tt||\}}tj|d|d||dk(r|d|S)Nr&rrr)Mrr)cmdrrrs rFrunr)0sP 3%&"71c?D)S c3/0 $;c!f  rErzPROTOCOL_VERSION = %szCAPABILITIES = r)z/tmp/zyy%z .*"([^"]+)"$rrruz%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 )Vrrrrryrkrrrrrrrriorr_r^ ImportError__all__rrQrrrrrrlrrrrnrorrrrqrmrprrrrrrr enumerater+rr r r r rAgetoptgetpassargvoptlistrrGrstream_commandoptrrcgetuserUSERPASSWD test_mesg test_seq1 test_seq2r)r'rSrrrr(mlrrrpathrruprint)nrs00rFr>sf , KKKKK22"H 8    (  , ,,   ,  A ,  ,  ,   ,  ,,  ,,  ,,   ,  ,,   ,   ,  ,, ,!, " ,#, $ ,%, & ,', ( ,), *  +, , A-, . ,/, 0  1, 2 ,3, 4 A5, 6  7, 8  9, : ,;, <  =, > ,?, @ ,A, B ,C, D ,E, F  G, H%,%,%%,%W, `rzz01  45rzz "**+RXX 6 "**^ $ DE BJJGH"**;RXXG "Jxxv# #2E#2J NN;555r*(*(X < A A# F&/qr &; <&;da188:ac>&; <F ,%R z % chhqrlF; NC $;HE D[ N 1   7D 7?? D W__tTEX[EXY ZF\gkrv_wwI tVn* dD)45)3,I$! dD),-I) ^,Ad A 77f !!" I '!*<*<<= q~~78!HC TN"f./B/2.B"((1+4B$ 4' " 0 "HCc4.CDz77b'--/C BPR S"  {q.Hd+ =` << j     hhqk  s<O O"#O(?DP OO(P7PP %P/