Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
3 N”ªjÔÐã2@sÖdZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZyddlZdZWnek r˜dZYnXdd d d d d gZdZdZdZdZdhZdZdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dd€d�d‚dƒd„d…d†d‡dˆd‰dŠd‹dŒd�dŽd�d�d‘dœ)ZejdƒZejdƒZejdƒZejdejƒZ ejdƒZ!ejdƒZ"ejdƒZ#ejdejƒZ$dZ%dZ&ejd ƒZ'Gd!d„dƒZ(e�r²Gd"d#„d#e(ƒZ)ej*d#ƒGd$d „d e(ƒZ+Gd%d&„d&ƒZ,d'j-d(ƒZ.d)d*„e/e.d+d…ƒDƒZ0d,d „Z1d-d „Z2d.d „Z3d/d „Z4e5d0k�rÒddl6Z6ddl7Z7ye6j6ej8d+d…d1ƒ\Z9Z:Wn0e6j;k �r|Z<zffZ9Z:WYddZ<[Zd2k�r¤e?e<ƒZne>d3k�rˆe.*))?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.*))?s[ ]c@sŒeZdZdZGdd„deƒZGdd„deƒZGdd„deƒZdefd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„Zdd„Zdefdd„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(dœdKdL„Z)dMdN„Z*dOdP„Z+dQdR„Z,dSdT„Z-d�dUdV„Z.dWdX„Z/dYdZ„Z0d[d\„Z1d]d^„Z2d_d`„Z3dadb„Z4dcdd„Z5dždgdh„Z6didj„Z7dkdl„Z8dmdn„Z9dodp„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�d‘„ZJd’d“„ZKd”d•„ZLd–d—„ZMd˜d™„ZNdšd›„ZOdqS) raëIMAP4 client class. Instantiate with: IMAP4([host[, port]]) host - host's name (default: localhost); port - port number (default: standard IMAP4 port). All IMAP4rev1 commands are supported by methods of the same name (in lower-case). All arguments to commands are converted to strings, except for AUTHENTICATE, and the last argument to APPEND which is passed as an IMAP4 literal. If necessary (the string contains any non-printing characters or white-space and isn't enclosed with either parentheses or double quotes) each string is quoted. However, the 'password' argument to the LOGIN command is always quoted. If you want to avoid having an argument string quoted (eg: the 'flags' argument to STORE) then enclose the string in parentheses (eg: "(\Deleted)"). Each command returns a tuple: (type, [data, ...]) where 'type' is usually 'OK' or 'NO', and 'data' is either the text from the tagged response, or untagged results from command. Each 'data' is either a string, or a tuple. If a tuple, then the first part is the header of the response, and the second part contains the data (ie: 'literal' value). Errors raise the exception class .error(""). IMAP4 server errors raise .abort(""), which is a sub-class of 'error'. Mailbox status changes from READ-WRITE to READ-ONLY raise the exception class .readonly(""), which is a sub-class of 'abort'. "error" exceptions imply a program error. "abort" exceptions imply the connection should be reset, and the command re-tried. "readonly" exceptions imply the command should be re-tried. Note: to use this module, you must read the RFCs pertaining to the IMAP4 protocol, as the semantics of the arguments to each IMAP4 command are left to the invoker, not to mention the results. Also, most IMAP servers implement a sub-set of the commands available here. c@s eZdZdS)z IMAP4.errorN)Ú__name__Ú __module__Ú __qualname__©r<r<ú/usr/lib64/python3.6/imaplib.pyÚerrorµsr>c@s eZdZdS)z IMAP4.abortN)r9r:r;r<r<r<r=Úabort¶sr?c@s eZdZdS)zIMAP4.readonlyN)r9r:r;r<r<r<r=Úreadonly·sr@ÚcCs”t|_d|_d|_i|_i|_d|_d|_d|_d|_ |j ƒ|j ||ƒy |j ƒWn8t k rŽy |jƒWntk r†YnX‚YnXdS)NrrAFr)Ú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__cCs0d|_d|_tjttjƒ|_tjttjƒ|_dS)NFÚascii) Ú utf8_enabledÚ _encodingÚreÚcompileÚ_LiteralÚASCIIÚLiteralÚ_Untagged_statusÚUntagged_status)rRr<r<r=rLÒszIMAP4._mode_asciicCs(d|_d|_tjtƒ|_tjtƒ|_dS)NTzutf-8)rWrXrYrZr[r]r^r_)rRr<r<r=Ú _mode_utf8Ùs zIMAP4._mode_utf8cCsžttjddƒƒ|_tjd|jdtjƒ|_|jƒ|_ d|j krHd|_ nd|j krZd|_ n |j |j ƒ‚|j ƒx tD]}||jkr„qt||_dSW|j d ƒ‚dS) Niiÿÿs(?Ps"\d+) (?P[A-Z]+) (?P.*)ZPREAUTHrÚOKrzserver not IMAP4 compliant)r ÚrandomZrandintÚtagprerYrZr\ÚtagreÚ _get_responseZwelcomerGrDr>Ú_get_capabilitiesÚAllowedVersionsÚ capabilitiesÚPROTOCOL_VERSION)rRÚversionr<r<r=rNàs       zIMAP4._connectcCs&|tkrt||jƒƒStd|ƒ‚dS)NzUnknown IMAP4 command: '%s')ÚCommandsÚgetattrÚlowerÚAttributeError)rRÚattrr<r<r=Ú __getattr__ szIMAP4.__getattr__cCs|S)Nr<)rRr<r<r=Ú __enter__szIMAP4.__enter__c Gs&y |jƒWntk r YnXdS)N)ÚlogoutrQ)rRÚargsr<r<r=Ú__exit__s zIMAP4.__exit__cCs |js dn|j}tj||jfƒS)N)rSÚsocketZcreate_connectionrT)rRrSr<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)rSrTrvÚsockÚmakefileÚfile)rRrSrTr<r<r=rM$s z IMAP4.opencCs |jj|ƒS)zRead 'size' bytes from remote.)rzÚread)rRÚsizer<r<r=r{0sz IMAP4.readcCs.|jjtdƒ}t|ƒtkr*|jdtƒ‚|S)zRead line from remote.ézgot more than %d bytes)rzÚreadlineÚ_MAXLINEÚlenr>)rRÚliner<r<r=r~5s zIMAP4.readlinecCs|jj|ƒdS)zSend data to remote.N)rxZsendall)rRÚdatar<r<r=Úsend=sz IMAP4.sendcCst|jjƒzXy|jjtjƒWn@tk r^}z$|jtjkrNt |ddƒdkrN‚WYdd}~XnXWd|jjƒXdS)z Close I/O established in "open".Zwinerrorri&'N) rzÚcloserxrPruZ SHUT_RDWRrQÚerrnoZENOTCONNrl)rRÚexcr<r<r=rPBs  zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )rx)rRr<r<r=ruRsz IMAP4.socketcCsBd}|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. ZRECENTraNr}éÿÿÿÿ)Ú_untagged_responseÚnoop)rRÚnameÚtypÚdatr<r<r=Úrecent^s  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)rRÚcoder<r<r=ÚresponseoszIMAP4.responsecCsxd}|s d}|r.|d|d fd kr2d|}nd}|r@t|ƒ}nd}tjt|ƒ}|jrbd |d }||_|j||||ƒS) z°Append message to named mailbox. (typ, [data]) = .append(mailbox, flags, date_time, message) All args except `message' can be None. rÚINBOXrr}ú(ú)z(%s)NsUTF8 (ó)r‡)r’r“)r ÚMapCRLFÚsubÚCRLFrWrEÚ_simple_command)rRÚmailboxÚflagsÚ date_timeÚmessagerŠrEr<r<r=Úappend}s    z IMAP4.appendcCsP|jƒ}t|ƒj|_|jd|ƒ\}}|dkrB|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. rrar}zutf-8Úreplacerr‡)rŽÚ_AuthenticatorÚprocessrEr˜r>ÚdecoderD)rRZ 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ˆ)rRrŠr‹rŒr<r<r=Ú capability´szIMAP4.capabilitycCs |jdƒS)zRCheckpoint mailbox on server. (typ, [data]) = .check() r)r˜)rRr<r<r=Úcheck½sz IMAP4.checkc Cs$z|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˜rD)rRr‹rŒr<r<r=r„Åsz IMAP4.closecCs|jd||ƒS)z‚Copy 'message_set' messages onto end of 'new_mailbox'. (typ, [data]) = .copy(message_set, new_mailbox) r)r˜)rRÚ message_setZ new_mailboxr<r<r=ÚcopyÔsz IMAP4.copycCs |jd|ƒS)zPCreate new mailbox. (typ, [data]) = .create(mailbox) r)r˜)rRr™r<r<r=ÚcreateÜsz IMAP4.createcCs |jd|ƒS)zPDelete old mailbox. (typ, [data]) = .delete(mailbox) r)r˜)rRr™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˜)rRr™Ú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 ENABLEraz UTF8=ACCEPT)rhrr>r˜rŽr`)rRr¤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ˆ)rRrŠr‹rŒr<r<r=Úexpungeþs z IMAP4.expungecCs$d}|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ˆ)rRr¦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ˆ)rRr™r‹rŒr<r<r=Úgetaclsz IMAP4.getaclcCs"|jd|||ƒ\}}|j||dƒS)za(typ, [data]) = .getannotation(mailbox, entry, attribute) Retrieve ANNOTATIONs.r Ú ANNOTATION)r˜rˆ)rRr™ÚentryZ attributer‹rŒr<r<r=Ú getannotation$szIMAP4.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ˆ)rRÚrootr‹rŒr<r<r=Úgetquota,szIMAP4.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ˆ)rRr™r‹rŒZquotaZ quotarootr<r<r=Ú getquotaroot7szIMAP4.getquotarootú""Ú*cCs$d}|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ˆ)rRÚ directoryÚpatternrŠr‹rŒr<r<r=ÚlistBsz IMAP4.listcCs<|jd||j|ƒƒ\}}|dkr.|j|dƒ‚d|_||fS)z”Identify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. r%rar}rr‡)r˜Ú_quoter>rD)rRÚuserÚpasswordr‹rŒr<r<r=ÚloginNs 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)rRr½r¾r<r<r=Úlogin_cram_md5\szIMAP4.login_cram_md5cCsBddl}t|jtƒr |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)rRZ challengerÃÚpwdr<r<r=rÀeszIMAP4._CRAM_MD5_AUTHc Csjd|_y|jdƒ\}}Wn(ddtjƒdd…g}}YnX|jƒd|jkrbd|jdfS||fS)z|Shutdown connection to server. (typ, [data]) = .logout() Returns server 'BYE' response. rÚNOz%s: %sNéÚBYE)rDr˜ÚsysÚexc_inforPrG)rRr‹rŒr<r<r=rrms" z IMAP4.logoutcCs$d}|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ˆ)rRr¹rºrŠr‹rŒr<r<r=Úlsub}sz 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ˆ)rRr™r‹rŒr<r<r=ÚmyrightsˆszIMAP4.myrightscCs d}|j|ƒ\}}|j|||ƒS)zb Returns IMAP namespaces ala rfc2342 (typ, [data, ...]) = .namespace() r')r˜rˆ)rRrŠr‹rŒr<r<r=Ú namespace�szIMAP4.namespacecCs |jdƒS)zFSend NOOP command. (typ, [data]) = .noop() r()r˜)rRr<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ˆ)rRZ message_numZ message_partÚstartZlengthrŠr‹rŒr<r<r=Úpartial¥sz 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˜)rRr½rŠr<r<r=Ú proxyauth±s zIMAP4.proxyauthcCs|jd||ƒS)zkRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) r+)r˜)rRZ oldmailboxZ newmailboxr<r<r=Úrename¾sz IMAP4.renamecGsTd}|r2|jrtjdƒ‚|j|d|f|žŽ\}}n|j|f|žŽ\}}|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)rWrr>r˜rˆ)rRÚcharsetZcriteriarŠr‹rŒr<r<r=ÚsearchÆs z IMAP4.searchr‘FcCsxi|_||_|rd}nd}|j||ƒ\}}|dkr@d|_||fSd|_d|jkrd| rd|jd|ƒ‚||jjdd gƒfS) atSelect a mailbox. Flush all untagged responses. (typ, [data]) = .select(mailbox='INBOX', readonly=False) 'data' is count of messages in mailbox ('EXISTS' response). Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so other responses should be obtained via .response('FLAGS') etc. rr-rarrz READ-ONLYz%s is not writableÚEXISTSN)rGrIr˜rDr@Úget)rRr™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˜)rRr™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˜rˆ)rRrsr‹rŒr<r<r=Ú setannotationszIMAP4.setannotationcCs |jd||ƒ\}}|j||dƒS)ziSet the quota root's resource limits. (typ, [data]) = .setquota(root, limits) r0r³)r˜rˆ)rRr´Zlimitsr‹rŒr<r<r=ÚsetquotaszIMAP4.setquotacGsFd}|d|dfdkr d|}|j|||f|žŽ\}}|j|||ƒS) z�IMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) r1rr}r’r“z(%s)r‡)r’r“)r˜rˆ)rRZ sort_criteriarÕÚsearch_criteriarŠr‹rŒr<r<r=Úsorts z IMAP4.sortNcCs¦d}ts|jdƒ‚|jr"|jdƒ‚||jkr6|jdƒ‚|dkrFtjƒ}|j|ƒ\}}|dkrŽ|j|j |j d�|_ |j j dƒ|_ d|_|j ƒn |jd ƒ‚|j|||ƒS) Nr2zSSL support missingzTLS session already establishedzTLS not supported by serverra)Úserver_hostnamerwTzCouldn't establish TLS session)ÚHAVE_SSLr>rKr?rhÚsslÚ_create_stdlib_contextr˜Ú wrap_socketrxrSryrzrfrˆ)rRÚ ssl_contextrŠr‹rŒr<r<r=Ústarttlss$       zIMAP4.starttlscCs$d}|j|||ƒ\}}|j|||ƒS)zpRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) r3)r˜rˆ)rRr™ÚnamesrŠr‹rŒr<r<r=Ústatus6sz IMAP4.statuscCs>|d|dfd krd|}|jd|||ƒ\}}|j||dƒS) z�Alters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) rr}r’r“z(%s)r4rr‡)r’r“)r˜rˆ)rRr¦Úcommandršr‹rŒr<r<r=ÚstoreBsz IMAP4.storecCs |jd|ƒS)zYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) r5)r˜)rRr™r<r<r=Ú subscribeMszIMAP4.subscribecGs*d}|j|||f|žŽ\}}|j|||ƒS)z‹IMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) r6)r˜rˆ)rRZthreading_algorithmrÕrÝrŠr‹rŒr<r<r=ÚthreadUsz IMAP4.threadcGs†|jƒ}|tkr|jd|ƒ‚|jt|krL|jd||jdjt|ƒfƒ‚d}|j||f|žŽ\}}|d krt|}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, r7r,r1r6r)r,r1r6)rŽrkr>rDÚjoinr˜rˆ)rRrèrsrŠr‹rŒr<r<r=Úuid_sz IMAP4.uidcCs |jd|ƒS)z_Unsubscribe from old mailbox. (typ, [data]) = .unsubscribe(mailbox) r8)r˜)rRr™r<r<r=Ú unsubscribexszIMAP4.unsubscribecGs,|jƒ}|tkr|jft|<|j|f|žŽ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ŽrkrDr˜)rRrŠrsr<r<r=Úxatom€s  z IMAP4.xatomcCs8|dkr d}|j}||kr*||j|ƒn |g||<dS)Nó)rGr�)rRr‹rŒZurr<r<r=Ú_append_untagged–s zIMAP4._append_untaggedcCs,|jjdƒ}|r(|j|dj|jdƒƒ‚dS)NrÊr}ržr‡)rGrØr?r¡rX)rRZbyer<r<r=Ú _check_bye¤s zIMAP4._check_byec Gs|jt|kr4d|_|jd||jdjt|ƒfƒ‚xd D]}||jkr:|j|=q:Wd|jkrp|j rp|jdƒ‚|jƒ}t ||j ƒ}|d|}xJ|D]B}|dkr¤q–t |t ƒrºt ||j ƒ}t j|ƒrÌtd ƒ‚|d|}q–W|j}|dk �r(d|_t|ƒt|jƒk�r |}nd}|t d t|ƒ|j ƒ}y|j|tƒWn2tk �rl} z|jd | ƒ‚WYdd} ~ XnX|dk�r||SxŒx |jƒ�rž|j|�r€|S�q€W|�r°||jƒ}y|j|ƒ|jtƒWn2tk �rú} z|jd | ƒ‚WYdd} ~ XnX|�s~P�q~W|S) Nz9command %s illegal in state %s, only allowed in states %sz, rarÈÚBADz READ-ONLYz#mailbox status changed to READ-ONLYó z*Control characters not allowed in commandsz {%s}zsocket error: %s)rarÈró)rDrkrEr>rìrGrIr@Ú_new_tagÚbytesrXrÄrÅÚ_control_charsrÖÚ ValueErrorÚtypeÚ_commandr€rƒr—rQr?rerFrH) rRrŠrsr‹Útagr‚ÚargrEZ literatorÚvalr<r<r=rúªsb                    zIMAP4._commandcCsÂ|dkr|jƒy|j|ƒ\}}Wnj|jk rX}z|jd||fƒ‚WYdd}~Xn6|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>)rRrŠrûr‹r‚rýr<r<r=Ú_command_completeùs"$zIMAP4._command_completecCsJ|jƒ\}}|dgkr |jdƒ‚t|d|jƒ}|jƒ}t|jƒƒ|_dS)Nz"no CAPABILITY response from serverr}r‡)r¤r>rÅrXrŽÚtupleÚsplitrh)rRr‹rŒr<r<r=rf s    zIMAP4._get_capabilitiescCs²|jƒ}|j|j|ƒrp|jjdƒ}||jkr:|jd|ƒ‚|jjdƒ}t||jƒ}|jjdƒ}||gf|j|<núd}|jt |ƒsš|j|j |ƒrš|jjdƒ}|jdkrÐ|jt |ƒrÂ|jjdƒ|_ dS|jd|ƒ‚|jjdƒ}t||jƒ}|jjdƒ}|dk�rd}|�r|d|}xH|j|j |ƒ�r\t|jjd ƒƒ}|j|ƒ}|j|||fƒ|jƒ}�qW|j||ƒ|d k�r®|jt|ƒ�r®|jjdƒ}t||jƒ}|j||jjdƒƒ|S)Nrûzunexpected tagged response: %rrùr‚Zdata2zunexpected response: %rrðrôr|rarÈró)rarÈró)Ú _get_lineÚ_matchrdÚmoÚgrouprFr?rÅrXÚUntagged_responser_Ú ContinuationrHr]Úintr{rñÚ Response_code)rRÚresprûr‹rŒZdat2r|r‚r<r<r=resH                  zIMAP4._get_responsecCsdx^|j|}|dk r |j|=|S|jƒy |jƒWq|jk rZ}z‚WYdd}~XqXqWdS)N)rFròrer?)rRrûÚresultrýr<r<r=rþcs  zIMAP4._get_tagged_responsecCs>|jƒ}|s|jdƒ‚|jdƒs.|jd|ƒ‚|dd…}|S)Nzsocket error: EOFs z#socket error: unterminated line: %rrÉéþÿÿÿ)r~r?Úendswith)rRr�r<r<r=r~s   zIMAP4._get_linecCs|j|ƒ|_|jdk S)N)Úmatchr)rRZcreÚsr<r<r=r‘s z IMAP4._matchcCs2|jtt|jƒ|jƒ}|jd|_d|j|<|S)Nr})rcrörÅrJrXrF)rRrûr<r<r=rõ�s  zIMAP4._new_tagcCs$|jddƒ}|jddƒ}d|dS)Nú\z\\ú"z\")rž)rRrür<r<r=r¼¥s  z IMAP4._quotecGs|j||j|f|žŽƒS)N)rÿrú)rRrŠrsr<r<r=r˜­szIMAP4._simple_commandcCs8|dkr||fS||jkr$|dgfS|jj|ƒ}||fS)NrÈ)rGÚpop)rRr‹rŒrŠr‚r<r<r=rˆ²s    zIMAP4._untagged_response)r·r¸)r·r¸)r‘F)N)Pr9r:r;Ú__doc__rOr>r?r@Ú IMAP4_PORTrUrLr`rNrprqrtrvrMr{r~rƒrPrur�r�r�r£r¤r¥r„r§r¨r©r«r¬r­r®r¯r²rµr¶r»r¿rÁrÀrrrÍrÎrÏr‰rÑrÒrÓrÖrÙrÚrÛrÜrÞrårçrérêrërírîrïrñròrúrÿrfrerþrrrõr¼r˜rˆr<r<r<r=r‡s˜,*                    O P  c@s:eZdZdZdedddfdd„Zdd„Zdefdd „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. rANcCs�|dk r|dk rtdƒ‚|dk r0|dk r0tdƒ‚|dk s@|dk rVddl}|jdtdƒ||_||_|dkrxtj||d�}||_t j |||ƒ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 insteadrÉ)ÚcertfileÚkeyfile) røÚwarningsÚwarnÚDeprecationWarningrrrárârärrU)rRrSrTrrrärr<r<r=rUùszIMAP4_SSL.__init__cCstj|ƒ}|jj||jd�S)N)rß)rrvrärãrS)rRrxr<r<r=rv s zIMAP4_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)rrM)rRrSrTr<r<r=rMszIMAP4_SSL.open)r9r:r;rÚIMAP4_SSL_PORTrUrvrMr<r<r<r=ræs rc@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||_tj|ƒdS)N)rèrrU)rRrèr<r<r=rU)szIMAP4_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)rSrTrxrzÚ subprocessÚPopenrèrÚPIPEr rÚ writefilerÚreadfile)rRrSrTr<r<r=rM.s  zIMAP4_stream.opencCs |jj|ƒS)zRead 'size' bytes from remote.)r$r{)rRr|r<r<r=r{>szIMAP4_stream.readcCs |jjƒS)zRead line from remote.)r$r~)rRr<r<r=r~CszIMAP4_stream.readlinecCs|jj|ƒ|jjƒdS)zSend data to remote.N)r#ÚwriteÚflush)rRr‚r<r<r=rƒHs zIMAP4_stream.sendcCs"|jjƒ|jjƒ|jjƒdS)z Close I/O established in "open".N)r$r„r#r Úwait)rRr<r<r=rPNs  zIMAP4_stream.shutdown)NN) r9r:r;rrUrMr{r~rƒrPr<r<r<r=rs  c@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) rŸzcPrivate class to provide en/decoding for base64-based authentication conversation. cCs ||_dS)N)r¢)rRZmechinstr<r<r=rU\sz_Authenticator.__init__cCs&|j|j|ƒƒ}|dkrdS|j|ƒS)Nó*)r¢r¡rÆ)rRr‚Zretr<r<r=r _sz_Authenticator.processcCsrd}t|tƒr|jdƒ}xT|rlt|ƒdkrD|dd…}|dd…}n|}d}tj|ƒ}|r||dd…}qW|S)Nrðzutf-8é0r}r‡)rÄrÅrÆr€ÚbinasciiZ b2a_base64)rRÚinpZoupÚtÚer<r<r=rÆes      z_Authenticator.encodecCs|sdStj|ƒS)Nrð)r*Z a2b_base64)rRr+r<r<r=r¡}sz_Authenticator.decodeN)r9r:r;rrUr rÆr¡r<r<r<r=rŸVs rŸz0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrÂcCsi|]\}}|d|jƒ“qS)r})rÆ)Ú.0Únrr<r<r=ú ƒsr0r}c CsØtj|ƒ}|sdSt|jdƒ}|jdƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jd ƒƒ} t|jd ƒƒ} | d | d } |d krª| } ||||||dddf } tj| ƒ| } tj| ƒS)z¨Parse an IMAP4 INTERNALDATE string. Return corresponding local time. The return value is a time.struct_time tuple or None if the string has wrong format. NÚmonÚzonenÚdayÚyearÚhourÚminÚsecÚzonehÚzonemé<ó-r}r‡r‡r‡) Ú InternalDaterÚMon2numrrÚcalendarZtimegmÚtimeÚ localtime)r rr1r2r3r4r5r6r7r8r9ZzoneZttÚutcr<r<r=r…s$  cCsDd}d}tt|ƒƒ}x*|r>t|dƒ\}}|||d…|}qW|S)z-Convert integer to A-P string representation.rðsABCDEFGHIJKLMNOPér})rÚabsÚdivmod)ZnumrýZAPÚmodr<r<r=r ¨s cCs$tj|ƒ}|sfSt|jdƒjƒƒS)z-Convert IMAP4 flags response to python tuple.rš)ÚFlagsrrrr)r rr<r<r=r µs c Cs t|ttfƒr"tj|tjƒjƒ}nät|tƒr¸y |j }WnZt k r�t j r„|d}|d krpt j t j|ƒƒd}t jt jf| }nt j }YnXt|d�}t|dd…dt|ƒiŽ}nNt|tƒrÚ|jdkrÔtdƒ‚|}n,t|tƒoö|d|d fdk�rþ|Std ƒ‚d jt|jƒ}|j|ƒS)aèConvert date_time to IMAP4 INTERNALDATE representation. Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The date_time argument can be a number (int or float) representing seconds since epoch (as returned by time.time()), a 9-tuple representing local time, an instance of time.struct_time (as returned by time.localtime()), an aware datetime instance or a double-quoted string. In the last case, it is assumed to already be in the correct format. ér})ZsecondsNéÚtzinfozdate_time must be awarerrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"r‡r‡)rr)rÄrÚfloatrZ fromtimestamprrAZ astimezonerZ tm_gmtoffrnr?Zdaylightr@ZmktimeZaltzonerrIrørÅÚformatÚMonthsZmonthZstrftime)r›ZdtZgmtoffÚdstZdeltaZfmtr<r<r=r Às0       Ú__main__zd:s:z-dz-srAzIMAP 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 1rÓú/tmp/yyyrú /tmp/yyz 2r�r»ú/tmpúyy*rÙrÖÚSUBJECTÚtestr®Ú1ú(FLAGS INTERNALDATE RFC822)réÚFLAGSú (\Deleted)rÏr­r�r„r�Ú UIDVALIDITYrír,ÚALLr×rrcCsLtjd||fƒtt|ƒ|Ž\}}tjd|||fƒ|dkrH|d‚|S)Nz%s %sz %s => %s %srÈr)ÚMÚ_mesgrl)Úcmdrsr‹rŒr<r<r=Úrun!s r`zPROTOCOL_VERSION = %szCAPABILITIES = %rú/tmp/úyy%z .*"([^"]+)"$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 )r r)rr)r)rrrr)r)r)r)rr)rr)rr)r)rr)r)r)rr)rr)rr)rr)rr)rr)r)rrrr)rr)r)rr)rrrr)r)r)rr)r)rr)rr)rr)rr)r)r)rr)r)rr)r)r)rr)rA©rP)r¨rc©rPrQ)rÓrd©rR)rre©rSrT)r»rf©rR)rÙrg©NrUrV)rÖrh©rWrX)r®ri©rWrYrZ)rérj©r[)r�rk©r,r\)rírl©r×)r�rm)rarbr‡©r,r\)rírnr‡r‡)VrÚ __version__r*r…rbrYrur rËr?r>rrrÚiorráràÚ ImportErrorÚ__all__r—rBrrrgrrkrZrrFr<r\r]r•r rr_r[r^r÷rrr�rrŸrrLÚ enumerater=rr r r r9ZgetoptZgetpassÚargvZoptlistrsr>rýZstream_commandÚoptrrSZgetuserZUSERZPASSWDZ test_mesgZ test_seq1Z test_seq2r`r]rDr^rirhr_ZmlrrrÚpathrŒríÚprintr<r<r<r=Ú sH H           e4 9, #  )