\dQldZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZ ddlZdZn #e$rdZYnwxYwgdZd ZdZd Zd Zd Zd Ziddddddddddddddddddddddddddd dd!dd"dd#did$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4dddddddddd5Zejd6Zejd7Zejd8Zejd9ejZ ejd:Z!ejd;Z"ejd<Z#ejd=ejZ$d9Z%d=Z&Gd>d?Z'er#Gd@dAe'Z(e)dAGdBdCe'Z*GdDdEZ+dF,dGZ-dHe.e-dIdDZ/dJZ0dKZ1dLZ2dMZ3e4dNkr?ddl5Z5ddl6Z6 e5j5ej7dIddO\Z8Z9n#e5j:$rZ;dP\Z8Z9YdZ;[;ndZ;[;wwxYwdZe;Ze=dRkre;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.*))?cLeZdZdZGddeZGddeZGddeZded 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(d[d,Z)d-Z*d.Z+d/Z,d0Z-d[d1Z.d2Z/d3Z0d4Z1d5Z2d6Z3d7Z4d8Z5d\d;Z6d<Z7d=Z8d>Z9d?Z:d]d@Z;dAZdDZ?dEZ@dFZAdGZBdHZCdIZDdJZEdKZFdLZGdMZHdNZId^dOZJdPZKdQZLdRZMdSZNdTZOdUZP d]dWZQdXZRdYZSdZZTd S)_raIMAP4 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. ceZdZdS) IMAP4.errorN__name__ __module__ __qualname__..\python\lib\imaplib.pyerrorr?rErGceZdZdS) IMAP4.abortNr@rDrErFabortrJrHrErKceZdZdS)IMAP4.readonlyNr@rDrErFreadonlyrMrHrErNNcxt|_d|_d|_i|_i|_d|_d|_d|_d|_ | | ||| | dS#t$r( |n#t$rYnwxYwwxYw)NrrOFr)Debugdebugstateliteraltagged_commandsuntagged_responsescontinuation_response is_readonlytagnum_tls_established _mode_asciiopen_connect ExceptionshutdownOSErrorselfhostporttimeouts rF__init__zIMAP4.__init__s   !"$%'"  %  $g&&&  MMOOOOO            s01B B9B'&B9' B41B93B44B9cd|_d|_tjttj|_tjttj|_dS)NFascii) utf8_enabled _encodingrecompile_LiteralASCIILiteral_Untagged_statusUntagged_statusrbs rFr[zIMAP4._mode_asciisC! z(BH55 !z*:BHEErEcd|_d|_tjt|_tjt |_dS)NTutf-8)rirjrkrlrmrorprqrrs rF _mode_utf8zIMAP4._mode_utf8s;  z(++ !z*:;;rEcttjdd|_t jd|jzdztj|_ d|_d|_ i|_ |j dkr:| d tz| d |jz||_d |jvrd |_n+d |jvrd|_n||j| |j dkr| d|jt*D]}||jvr ||_dS|d)Niis(?Ps"\d+) (?P[A-Z]+) (?P.*)T rzimaplib version %sznew IMAP4 connection, tag=%sPREAUTHrOKrzCAPABILITIES: zserver 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%8899 Z +!&@!ABD(LL  I "D  !D DMzQ /+=>>> 9DKGHHH))++ / / /DJJ T, , ,"DJJ**T\** *     FzQ 1B1BDEEE&  Gd///$+D ! FFjj5666rEc||tvr"t||Std|z)NzUnknown IMAP4 command: '%s')CommandsgetattrlowerAttributeError)rbattrs rF __getattr__zIMAP4.__getattr__ s9 8  4.. .:TABBBrEc|SNrDrrs rF __enter__zIMAP4.__enter__s rEcl|jdkrdS |dS#t$rYdSwxYw)Nr)rSlogoutr`)rbargss rF__exit__zIMAP4.__exit__sL : ! ! F  KKMMMMM    DD s % 33c||std|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  w OPP P93tt$) .$ 49===#  +GW== ='000rEc||_||_|||_|jd|_dS)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.open0sB   ''00 I&&t,, rEc6|j|SzRead 'size' bytes from remote.)rreadrbsizes rFrz IMAP4.read<sy~~d###rEc|jtdz}t|tkr|dtz|S)Read line from remote.rxzgot more than %d bytes)rreadline_MAXLINElenrGrblines rFrzIMAP4.readlineAsIy!!(Q,// t99x  **5@AA A rEcftjd|||j|dS)Send data to remote.z imaplib.sendN)rrrsendallrbdatas rFsendz IMAP4.sendIs2 .$--- $rEcv|j |jtjnB#t $r5}|jtjkrt|dddkrYd}~nd}~wwxYw|jdS#|jwxYw) Close I/O established in "open".winerrorri&'N) rcloserr_r SHUT_RDWRr`errnoENOTCONNr)rbexcs rFr_zIMAP4.shutdownOs   I  v/ 0 0 0 0    U^++3 A..%77   IOO     DIOO    s.$AB A? +A:5B:A??BB8c|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )rrrs rFrz IMAP4.socket_s yrEcd}|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. RECENTrzN)_untagged_responsenooprbnametypdats rFrecentz IMAP4.recentksd**4$>>S r7 8O99;;S&&sC666rEcV||dg|S)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\\BBBrEcd}|sd}|r|d|dfdkrd|z}nd}|rt|}nd}tt|}|jrd|zd z}||_|||||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.appends G  ar#y00E  ))44III++dG,,   1')D0G ##D'5)DDDrEc|}t|j|_|d|\}}|dkr/||dddd|_||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. rrzrrtreplacer)r_AuthenticatorprocessrTrrGdecoderS)rb mechanism authobjectmechrrs rF authenticatezIMAP4.authenticates}    &j119 ''==S $;;**SW^^GY??@@ @ CxrEcdd}||\}}||||S)zT(typ, [data]) = .capability() Fetch capabilities list from server.rrrrs rF capabilityzIMAP4.capabilitys8''--S&&sC666rEc,|dS)zRCheckpoint mailbox on server. (typ, [data]) = .check() rrrrs rFcheckz IMAP4.checks ##G,,,rEcd |d\}}d|_n #d|_wxYw||fS)zClose currently selected mailbox. Deleted messages are removed from writable mailbox. This is the recommended command before 'LOGOUT'. (typ, [data]) = .close() rrrrSrbrrs rFrz IMAP4.closesC ++G44HCDJJDJ    Cx" +c0|d||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 ##FKEEErEc.|d|S)zPCreate new mailbox. (typ, [data]) = .create(mailbox) rrrbrs rFcreatez IMAP4.create ##Hg666rEc.|d|S)zPDelete old mailbox. (typ, [data]) = .delete(mailbox) rrrs rFdeletez IMAP4.deleterrEc0|d||S)zDelete the ACLs (remove any rights) set for who on mailbox. (typ, [data]) = .deleteacl(mailbox, who) rr)rbrwhos rF deleteaclzIMAP4.deleteacls ##K#>>>rEcd|jvrtd|d|\}}|dkr*d|vr|||fS)zlSend an RFC5161 enable string to the server. (typ, [data]) = .enable(capability) rzServer does not support ENABLErzz UTF8=ACCEPT)rrrGrrru)rbrrrs rFenablez IMAP4.enablesw 4, , ,++>?? ?((:>> T $;;=J,<,<,>,>>> OO   DyrEcdd}||\}}||||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 s8''--S&&sC666rEchd}||||\}}||||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.fetchs<''k=IIS&&sC666rEcb|d|\}}|||dS)zXGet the ACLs for a mailbox. (typ, [data]) = .getacl(mailbox) r!ACLrrbrrrs rFgetaclz IMAP4.getacl(s5 '''::S&&sC777rEcf|d|||\}}|||dS)za(typ, [data]) = .getannotation(mailbox, entry, attribute) Retrieve ANNOTATIONs.r" ANNOTATIONr)rbrentry attributerrs rF getannotationzIMAP4.getannotation1s9''%SSS&&sC>>>rEcb|d|\}}|||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.getquota9s5'' D99S&&sC999rEc|d|\}}|||d\}}|||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.getquotarootDsc ''@@S,,S#w?? U00c;GGYY&&&rE""*chd}||||\}}||||S)zList mailbox names in directory matching pattern. (typ, [data]) = .list(directory='""', pattern='*') 'data' is list of LIST responses. r&rrb directorypatternrrrs rFlistz IMAP4.listO<''iAAS&&sC666rEc|d|||\}}|dkr||dd|_||fS)zIdentify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. r'rzrr)r_quoterGrS)rbuserpasswordrrs rFloginz IMAP4.login[sZ''t{{87L7LMMS $;;**SW%% % CxrEcV||c|_|_|d|jS)zr Force use of CRAM-MD5 authentication. (typ, [data]) = .login_cram_md5(user, password) zCRAM-MD5)r#r$r_CRAM_MD5_AUTH)rbr#r$s rFlogin_cram_md5zIMAP4.login_cram_md5is- $(  4=  T-@AAArEcddl}t|jtr|jdn|j}|jdz|||dzS)z1 Authobject to use with CRAM-MD5 authentication. rNrt md5)hmac isinstancer$strencoder#HMAC hexdigest)rb challenger,pwds rFr'zIMAP4._CRAM_MD5_AUTHrsl 0:4=#0N0N@t}##G,,,26- y33 5!A!A!K!K!M!MMMrEcpd|_|d\}}|||fS)z|Shutdown connection to server. (typ, [data]) = .logout() Returns server 'BYE' response. r)rSrr_rs rFrz IMAP4.logoutzs8 ''11S CxrEchd}||||\}}||||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.lsubr rEcb|d|\}}|||dS)zShow my ACLs for a mailbox (i.e. the rights that I have on mailbox). (typ, [data]) = .myrights(mailbox) r%rr s rFmyrightszIMAP4.myrightss5 &&z7;;C&&sC<<.namespace() r*rrs rF namespacezIMAP4.namespaces8 ''--S&&sC666rEcx |jdkr||j|dS)zFSend NOOP command. (typ, [data]) = .noop() Tr{r+)rR_dump_urrVrrrs rFrz IMAP4.noops;  7zQ d5666##F+++rEcld}||||||\}}|||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.partialsA''k<PVWWS&&sC999rEc2d}|d|S)zAssume authentication as "user". Allows an authorised administrator to proxy into any user's mailbox. (typ, [data]) = .proxyauth(user) r-r)rbr#rs rF proxyauthzIMAP4.proxyauths##K666rEc0|d||S)zkRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) r.r)rb oldmailbox newmailboxs rFrenamez IMAP4.renames ##Hj*EEErEcd}|r5|jrtd|j|d|g|R\}}n|j|g|R\}}||||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.searchs  =  Mkk"KLLL+t+D)WPxPPPHC+t+D<8<< |jdkr||j|d |z||jd d gfS) 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. rr0rzrr READ-ONLYTrxz%s is not writableEXISTSN)rVrXrrSrRr<rNget)rbrrNrrrs rFselectz IMAP4.selects#%#  DDD''g66S $;;DJ8O $1 1 1  2 ;:??MM$"9:::-- 4w >?? ?D+//4&AAAArEc2|d|||S)zZSet a mailbox acl. (typ, [data]) = .setacl(mailbox, who, what) r1r)rbrrwhats rFsetaclz IMAP4.setacls ##HgsDAAArEcR|jdg|R\}}|||dS)z_(typ, [data]) = .setannotation(mailbox[, entry, attribute]+) Set ANNOTATIONs.r2r r)rbrrrs rF setannotationzIMAP4.setannotation s:(4'?$???S&&sC>>>rEcd|d||\}}|||dS)ziSet the quota root's resource limits. (typ, [data]) = .setquota(root, limits) r3rr)rbrlimitsrrs rFsetquotazIMAP4.setquotas7 '' D&AAS&&sC999rEcd}|d|dfdkrd|z}|j|||g|R\}}||||S)zIMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) r4rrrrr)rb sort_criteriarKsearch_criteriarrrs rFsortz IMAP4.sortsi  ! ]2. /9 < <"]2M'4'mWWWWWS&&sC666rEc2d}ts|d|jr|d||jvr|d|t j}||\}}|dkra||j |j |_ |j d|_ d|_| n|d ||||S) Nr5zSSL support missingzTLS session already establishedzTLS not supported by serverrzserver_hostnamerTzCouldn't establish TLS session)HAVE_SSLrGrZrKrssl_create_stdlib_contextr wrap_socketrrcrrrr)rb ssl_contextrrrs rFstarttlszIMAP4.starttls)s 4**233 3   @**>?? ? t( ( (**:;; ;  466K''--S $;;#// @D 0KKDI **400DI$(D !  " " $ $ $ $**=>> >&&sC666rEchd}||||\}}||||S)zpRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) r6r)rbrnamesrrrs rFstatusz IMAP4.status@s> ''gu==S&&sC666rEc|d|dfdkrd|z}|d|||\}}|||dS)zAlters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) rrrrr7r r)rbrcommandrrrs rFstorez IMAP4.storeLsZ !HU2Y 9 , ,UNE''guMMS&&sC999rEc.|d|S)zYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) r8rrs rF subscribezIMAP4.subscribeWs ##K999rEcZd}|j|||g|R\}}||||S)zIMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) r9r)rbthreading_algorithmrKr]rrrs rFthreadz IMAP4.thread_sD '4'.A7]_]]]S&&sC666rEc ~|}|tvr|d|z|jt|vrA|d|d|jddt|d}|j||g|R\}}|dvr|}nd}||||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)rbrlrrrrs rFuidz IMAP4.uidis--//(""**.unsubscribe(mailbox) r;rrs rF unsubscribezIMAP4.unsubscribes ##M7;;;rEcd |d\}}d|_n #d|_wxYw||fS)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.unselectsD ,,Z88ICDJJDJ    Dyrcx|}|tvr|jft|<|j|g|RS)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.xatomsFzz||x"j]HTN#t#D040000rEc |d}|j} |jdkr@|d|dt||dd|d||vr|||dS|g||<dS) NrETuntagged_responses[z] rOz += ["z"])rVrRrrrQr)rbrrurs rF_append_untaggedzIMAP4._append_untaggeds ;C  $ 9zQ c"&&R..11113338999 "99 sGNN3     eBsGGGrEc|jd}|r4||d|jddS)NBYErr)rVrQrKrrj)rbbyes rF _check_byezIMAP4._check_byesS%))%00  H**SW^^DNIFFGG G H HrEc |jt|vrHd|_|d|d|jddt|dD]}||jvr|j|=d|jvr|js|d|}t||j }|dz|z}|D]7}|t|trt||j }|dz|z}8|j}|Wd|_t|t|jur|}n*d}|td t|z|j z} |jd kr|d |zn|d |z ||t(zn*#t*$r} |d | zd} ~ wwxYw||S |r#|j|r|S|#|r||j} |jd kr%|dt|z |||t(n*#t*$r} |d | zd} ~ wwxYw|sn|S)NrtrurvrwrzNOBADrOz#mailbox status changed to READ-ONLY z {%s}Tz> %rzsocket error: %srxzwrite literal size %s)rSrrTrGrxrVrXrN_new_tagbytesrjr-r.type_commandrrRr_logrrr`rKrrUrW) rbrrrtagrargrT literatorvals rFrzIMAP4._commands. :Xd^ + +DL***"ddDJJJ"ii7779:: : ' 1 1Cd---+C0 $1 1 1  2-- EFF FmmooT4>**TzD  % %C{H#s## 1C00$;$DD,  DLG}}T] 3 333#  eGc'll$:DNKKK )zQ 6D=)))) &4-((( 7 IIdTk " " " " 7 7 7**/#566 6 7 ?J $$&& ',J$$&&   @#)D$>?? G:??JJ6WEFFF ; '""" $ ; ; ;jj!3c!9::: ; / 2 s0!F?? G& G!!G&)/J K#J;;Kc|dk}|s| |||\}}nU#|j$r }|d|d|d}~w|j$r }|d|d|d}~wwxYw|s||dkr||d|d|||fS)Nr) expect_byez command:  => rz command error: r*)r_get_tagged_responserKrG)rbrrrrrrs rF_command_completezIMAP4._command_completes("  OO    @11#&1IIICz @ @ @***DDD##>?? ?z @ @ @***DDD##>?? ? @  OO    %<<**$$$TTJKK KDys!9 B A B +BB c|\}}|dgkr|dt|d|j}|}t ||_dS)Nz"no CAPABILITY response from serverr)rrGr.rjrtuplesplitrrs rFrzIMAP4._get_capabilities#ss??$$S 4&==**ABB B#b'4>**iikk!#))++..rEc|}||j|r|jd}||jvr|d|z|jd}t||j}|jd}||gf|j|<nd}|t|s5||j |r|jd}|jT|t|r!|jd|_ dS|d|z|jd}t||j}|jd}|d}|r|dz|z}||j |rt|jd } |jd kr|d |z||}||||f|}||j |||||d vrx|t&|r]|jd}t||j}|||jd |jdkr|dvr||d||S)Nrzunexpected tagged response: %rrrdata2zunexpected response: %rrErrTrzread literal size %srrx)rrrz response: ) _get_line_matchrmogrouprUrKr.rjUntagged_responserq ContinuationrWrointrRrrr Response_code)rbresprrrdat2rrs rFrzIMAP4._get_response,s~~ ;;tz4 ( (5 ,'--&&C$...jj!AD!HIII'--''Cc4>**C'--''C),se D  % %D;;0$77 2;;t3T::27==11Dw;;|T22 15v1F1FD.4jj!:T!ABBB'--''Cc4>**C'--''C{#C ,3:,S++dlC00 '47==0011BzQ #9D#@AAAyy%%cC;777nn&&!++dlC00 '$  ! !#s + + + % % %$++mS*I*I %'--''Cc4>**C  ! !#tw}}V'<'< = = = ;zQ3*>#>#> SS9::: rEc< |j|}| |j|=|S|r#d}|j|d}|||fS| |n3#|j$r&} |jdkr|d}~wwxYw)Nrxr)rUrVpoprrrKrR print_log)rbrrresultrrrs rFrzIMAP4._get_tagged_response|s )#.F!(-  &-11#t<<?:% OO    ""$$$$:   )zQ(((  1 sA** B4!BBcD|}|s|d|ds|d|z|dd} |jdkr|d|zn|d|z|S)Nzsocket error: EOFr z#socket error: unterminated line: %rTrz< %r)rrKendswithrRrrrs rFrzIMAP4._get_lines}} 2**011 1}}W%% K**BTIJJ JCRCy )zQ 6D=)))) &4-((( rEc|||_ |jB|jdkr7|d|jd|j|jduS)NTrz matched r)matchrrRrrgroups)rbcress rFrz IMAP4._matchsh ))A,, Sw"tzQ 3;;;@P@P@PQRRRwd""rEc|jtt|j|jz}|jdz|_d|j|<|S)Nrx)r~rr.rYrjrU)rbrs rFrzIMAP4._new_tagsCkE#dk"2"2DNCCCkAo $(S! rEcj|dd}|dd}d|zdzS)N\z\\"z\")r)rbrs rFr"z IMAP4._quotes6kk$''kk#u%%Sy3rEcF|||j|g|RSr)rrrs rFrzIMAP4._simple_commands,%%dMDM$,F,F,F,FGGGrEc|dkr||fS||jvr|dgfS|j|} |jdkr|d|d|||fS)NrTrrz] => )rVrrRr)rbrrrrs rFrzIMAP4._untagged_responses~ $;;8Ot...; &**400 JzQ TTT44HIIIDyrETc|tj}tjdtj|}tjd||dzdz|fztjdS)Nz%M:%Sz %s.%02d %s d)timestrftime localtimerstderrwriteflush)rbrsecstms rFrz IMAP4._mesgsr|y{{wt(<(<==B J  -d3h^Q0GG H H H J       rEc|sdSd|D}|dd|zdS)Nc3*K|]\}}|d|VdS): NrD).0keyvalues rF z!IMAP4._dump_ur..sPBB"U((u((BBBBBBrEzuntagged responses dump:z )itemsrrx)rbuntagged_resp_dictrs rFr<zIMAP4._dump_ursh% BB&8&>&>&@&@BBBE JJ1HMM%4H4HH I I I I IrEc|tjf|j|j<|xjdz c_|j|jkr d|_dSdS)Nrxr)rrrrrs rFrz IMAP4._logsW04dikk/BDM$+ ,    "   D$555$%!!!65rEc|dt|jz|j|j}}|r9 |j|j|n#YnxYw|dz }||jkrd}|dz}|7dSdS)Nzlast %d IMAP4 interactions:rxr)rrrrr)rbins rFrzIMAP4.print_logs JJ4s4=7I7II J J J$d&7qA DJ a 0111DQ)))AQ     s AA)rr)rFr)F)UrArBrC__doc__r^rGrKrN IMAP4_PORTrfr[rur]rrrrr\rrrr_rrrrrrrrrrrrrrrr rrrrr%r(r'rr6r8r:rrBrDrHrMrRrUrWrZr^rgrjrmrorrryr{r}rrrrrrrrrrrr"rrrr<rrrDrErFrrsS--^!       5Z2FFF<<<'7'7'7TCCC  1 1 1T - - - -$$$       777"CCCEEE4:777---   FFF777777???    7 7 7 7 7 7888???:::''' 7 7 7 7   BBBNNN    7 7 7 7===777,,, : : : 7 7 7FFF777$BBBB@BBB???::: 7 7 77777. 7 7 7::::::7777772<<<    111,   HHH JJJZ$///MMM`B& # # #HHH   "     J J J & & &     rErc:eZdZdZdeddddfdZdZdedfdZdS) IMAP4_SSLaIMAP4 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. rONc.||td||td|| ddl}|dtd||_||_|t j||}||_t ||||dS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusiverzEkeyfile and certfile are deprecated, use a custom ssl_context instead)certfilekeyfile) rwarningswarnDeprecationWarningrrrcrdrfrrf)rbrcrdrrrfrers rFrfzIMAP4_SSL.__init__s&7+> "-...&8+? "-..."h&: ;rs* < < #  rEcd}d}tt|}|r%t|d\}}|||dz|z}|%|S)z-Convert integer to A-P string representation.rEsABCDEFGHIJKLMNOPrx)rabsdivmod)numrAPmods rFr r s_ C'r c#hh--C "#r??SSUmc! " JrEct|}|sdSt|dS)z-Convert IMAP4 flags response to python tuple.rDr)Flagsrrrr)rrs rFr r sH T  B r '""((** + ++rEct|ttfr3tj|t j}n;t|tr |j }n#t$rvtj rZ|d}|dkr,tj tj|d}tjtjf| }n tj }YnwxYwt!|}t|dddt |i}nht|tr|jt%d|}n:t|t&r|d|dfd kr|St%d d t*|j}||S) 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_gmtoffrrdaylightrmktimealtzonerr(rr.formatMonthsmonthr)rdtgmtoffdstdeltafmts rFr r s)c5\**:  #I$,L222<*,,  Iu % %: ((FF ( ( (} (l"99.Y)?)?@@CC=$,7<<- (&))) y!} =Xe__ = = Ix ( (:   #677 7  Is # #:1im(D (Q(Q8999 " ) )&*: ; ;C ;;s  s&A..A=C.-C.__main__zd:s:)rDrDz-dz-s)rOzIMAP password for z on localhostrzJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)s )r#lfr%)r) /tmp/xxx 1)rH)r<z/tmp/yyy)r /tmp/yyz 2rr>)r)z/tmpzyy*)rRr=)rM)NSUBJECTtest)r)1z(FLAGS INTERNALDATE RFC822))rm)rAFLAGSz (\Deleted))r:rD)rrD)rrD)rrD)rRrD)r) UIDVALIDITY)ry)r/ALL)r)rP)rrDct|d|tt||\}}t|d|d||dkr|d|S)Nr*rrr)Mrr)cmdrrrs rFrunrHAsp 333%&&&"71c??D)S ccc33/000 $;;c!f  rErzPROTOCOL_VERSION = %szCAPABILITIES = r)z/tmp/zyy%z .*"([^"]+)"$rrryz%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 )Urrrrr|rkrrrrrrrriorrcrb ImportError__all__rrQrrrrrrlrr#rrnrorrrrqrmrprrrrrrr1 enumeraterr r r r rAgetoptgetpassargvoptlistrrGrstream_commandoptrrcgetuserUSERPASSWD test_mesg test_seq1 test_seq2rHrFrSrrrrGmlrrrpathrryprintrDrErFr\s  , KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK2222222222""""""JJJHHHHH 8 8 8    (  , ,,   ,  A ,  ,  ,   ,  ,,  ,,  ,,   ,  ,,   ,   ,  ,, ,!, " ,#, $ ,%, , & ,', ( ,), *  +, , A-, . ,/, 0  1, 2 ,3, 4 A5, 6  7, 8  9, : ,;, <  =, > ,?, @ ,A, B ,C, D ,E, F  G, , H%,%,%%,%W, , , `rz011  455rz "*+RX 6 6 "*^ $ $ DEE BJGHH"*;RXGG "Jxxxxxxxxv# 8 4242424242E424242l NN;555555555r*(*(*(*(*(*(*(*(X < A A# F F < !H H9*H44H9D8P)P1