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
 lŽŒY×ËãY@sbdZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZyddlZdZWnek rÔdZYnXdd d d d d gZdZdZdZdZddfZdZdddfddfdddddfddfddfddfdddfdddfdddfd dfd!ddfd"dfd#dfd$ddfd%ddfd&ddfd'ddfd(ddfd)ddfd*dfdddddfd+ddfd,ddfd-ddddfd.dfd/dfd0ddfd1dfd2ddfd3ddfd4ddfd5ddfd6dfd7dfd8ddfd9dfd:ddfd;dfd<dfd=ddfi(Zejd>ƒZejd?ƒZejd@ƒZejdAejƒZ ejdBƒZ!ejdCƒZ"ejdDƒZ#ejdEejƒZ$dAZ%dEZ&GdFd„dƒZ'er«GdGdH„dHe'ƒZ(ej)dHƒGdId „d e'ƒZ*GdJdK„dKƒZ+dLj,dMƒZ-dNdO„e.e-dPd…ƒDƒZ/dQd „Z0dRd „Z1dSd „Z2dTd „Z3e4dUkr^ddl5Z5ddl6Z6y)e5j5ej7dPd…dVƒ\Z8Z9Wn:e5j:k r¿Z;zfff\Z8Z9WYddZ;[;XnXdZ<xQe8D]I\Z=Z;e=dWkrôe>e;ƒZn"e=dXkre;Z<e9 re<fZ9qÍWe9 r*dYfZ9e9dZ?e6j@ƒZAe6j6dZeAe?pUd[fƒZBd\d]eAd^d_iZCd`eAeBffdadbffdcdbddffddeffdfdeddeCffdgdhdiffdjdeffdkddldmffdndodpffdqdodrdsffdtffduffdvffdwfffZDdjffdxdyffdzd1d{ffdxd|ffdfdddeCffdvffd}fffZEd~d„ZFy‰e<r¹e*e<ƒZGn e'e?ƒZGeGjHdkräeDdPd…ZDeGjId€eGjJƒeGjId�eGjKfƒx!eDD]\ZLZ9eFeLe9ƒqWxheFdgd‚dƒfƒD]QZMejNd„eMƒZOeOryeOjPdPƒZQneMj,ƒdP ZQeFd…eQfƒqIWx~eED]v\ZLZ9eFeLe9ƒZReLe9fdzd1d{ffkráq¥eRdP j,ƒZSeS rüq¥eFdzd#d†eSdP d‡fƒq¥WeTdˆƒWn1eTd‰ƒe rVeTdŠej7dƒ‚YnXdS)‹zöIMAP4 client. Based on RFC 2060. Public class: IMAP4 Public variable: Debug Public functions: Internaldate2tuple Int2AP ParseFlags Time2Internaldate z2.58éN)ÚdatetimeÚtimezoneÚ timedelta)ÚDEFAULT_BUFFER_SIZETFÚIMAP4Ú IMAP4_streamÚInternaldate2tupleÚInt2APÚ ParseFlagsÚTime2Internaldates é�iáZ IMAP4REV1i@BÚAPPENDÚAUTHÚSELECTEDÚ AUTHENTICATEÚNONAUTHÚ CAPABILITYÚLOGOUTÚCHECKÚCLOSEÚCOPYÚCREATEÚDELETEÚ DELETEACLÚENABLEÚEXAMINEÚEXPUNGEÚFETCHÚGETACLÚ GETANNOTATIONÚGETQUOTAÚ GETQUOTAROOTÚMYRIGHTSÚLISTÚLOGINÚLSUBÚ NAMESPACEÚNOOPÚPARTIALÚ PROXYAUTHÚRENAMEÚSEARCHÚSELECTÚSETACLÚ SETANNOTATIONÚSETQUOTAÚSORTÚSTARTTLSÚSTATUSÚSTOREÚ SUBSCRIBEÚTHREADÚUIDÚ UNSUBSCRIBEs\+( (?P.*))?s.*FLAGS \((?P[^\)]*)\)sÕ.*INTERNALDATE "(?P[ 0123][0-9])-(?P[A-Z][a-z][a-z])-(?P[0-9][0-9][0-9][0-9]) (?P[0-9][0-9]):(?P[0-9][0-9]):(?P[0-9][0-9]) (?P[-+])(?P[0-9][0-9])(?P[0-9][0-9])"s.*{(?P\d+)}$s \r\n|\r|\ns)\[(?P[A-Z-]+)( (?P[^\]]*))?\]s$\* (?P[A-Z-]+)( (?P.*))?s3\* (?P\d+) (?P[A-Z-]+)( (?P.*))?c@seZdZdZGdd„deƒZGdd„deƒZGdd„deƒZded d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„Zdd„Zdedd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Z d9d:„Z!d;d<„Z"d=d>„Z#d?d@„Z$dAdB„Z%dCdD„Z&dEdF„Z'dGdH„Z(dIdJdKdL„Z)dMdN„Z*dOdP„Z+dQdR„Z,dSdT„Z-dIdJdUdV„Z.dWdX„Z/dYdZ„Z0d[d\„Z1d]d^„Z2d_d`„Z3dadb„Z4dcdd„Z5dedfdgdh„Z6didj„Z7dkdl„Z8dmdn„Z9dodp„Z:dqdrds„Z;dtdu„Z<dvdw„Z=dxdy„Z>dzd{„Z?d|d}„Z@d~d„ZAd€d�„ZBd‚dƒ„ZCd„d…„ZDd†d‡„ZEdˆd‰„ZFdŠd‹„ZGdŒd�„ZHdŽd�„ZId�d‘„ZJd’d“„ZKd”d•„ZLd–d—„ZMd˜d™„ZNdšd›„ZOdqdœd�„ZPdždŸ„ZQd d¡„ZRd¢d£„ZSdqS)¤raëIMAP4 client class. Instantiate with: IMAP4([host[, port]]) host - host's name (default: localhost); port - port number (default: standard IMAP4 port). All IMAP4rev1 commands are supported by methods of the same name (in lower-case). All arguments to commands are converted to strings, except for AUTHENTICATE, and the last argument to APPEND which is passed as an IMAP4 literal. If necessary (the string contains any non-printing characters or white-space and isn't enclosed with either parentheses or double quotes) each string is quoted. However, the 'password' argument to the LOGIN command is always quoted. If you want to avoid having an argument string quoted (eg: the 'flags' argument to STORE) then enclose the string in parentheses (eg: "(\Deleted)"). Each command returns a tuple: (type, [data, ...]) where 'type' is usually 'OK' or 'NO', and 'data' is either the text from the tagged response, or untagged results from command. Each 'data' is either a string, or a tuple. If a tuple, then the first part is the header of the response, and the second part contains the data (ie: 'literal' value). Errors raise the exception class .error(""). IMAP4 server errors raise .abort(""), which is a sub-class of 'error'. Mailbox status changes from READ-WRITE to READ-ONLY raise the exception class .readonly(""), which is a sub-class of 'abort'. "error" exceptions imply a program error. "abort" exceptions imply the connection should be reset, and the command re-tried. "readonly" exceptions imply the command should be re-tried. Note: to use this module, you must read the RFCs pertaining to the IMAP4 protocol, as the semantics of the arguments to each IMAP4 command are left to the invoker, not to mention the results. Also, most IMAP servers implement a sub-set of the commands available here. c@seZdZdS)z IMAP4.errorN)Ú__name__Ú __module__Ú __qualname__©r;r;ú&/opt/python35/lib/python3.5/imaplib.pyÚerror«s r=c@seZdZdS)z IMAP4.abortN)r8r9r:r;r;r;r<Úabort¬s r>c@seZdZdS)zIMAP4.readonlyN)r8r9r:r;r;r;r<Úreadonly­s r?ÚcCs¸t|_d|_d|_i|_i|_d|_d|_d|_d|_ |j ƒ|j ||ƒy|j ƒWn8t k r³y|jƒWntk r«YnX‚YnXdS)Nrr@Fr)ÚDebugÚdebugÚstateÚliteralÚtagged_commandsÚuntagged_responsesÚcontinuation_responseÚ is_readonlyÚtagnumÚ_tls_establishedÚ _mode_asciiÚopenÚ_connectÚ ExceptionÚshutdownÚOSError)ÚselfÚhostÚportr;r;r<Ú__init__¯s&            zIMAP4.__init__cCsFd|_d|_tjttjƒ|_tjttjƒ|_dS)NFÚascii) Ú utf8_enabledÚ _encodingÚreÚcompileÚ_LiteralÚASCIIÚLiteralÚ_Untagged_statusÚUntagged_status)rQr;r;r<rKÈs  zIMAP4._mode_asciicCs:d|_d|_tjtƒ|_tjtƒ|_dS)NTzutf-8)rVrWrXrYrZr\r]r^)rQr;r;r<Ú _mode_utf8Ïs  zIMAP4._mode_utf8cCsTttjddƒƒ|_tjd|jdtjƒ|_d|_d|_ i|_ |j dkr�|j dt ƒ|j d |jƒ|jƒ|_d |jkr·d |_n-d |jkrÒd |_n|j|jƒ‚|jƒ|j dkr|j d|jfƒx*tD]"}||jkr3q||_dSW|jdƒ‚dS)Niiÿÿs(?Ps"\d+) (?P[A-Z]+) (?P.*)é rézimaplib version %sznew IMAP4 connection, tag=%sZPREAUTHrÚOKrézCAPABILITIES: %rzserver not IMAP4 compliant)r ÚrandomÚrandintÚtagprerXrYr[ÚtagreÚ _cmd_log_lenÚ _cmd_log_idxÚ_cmd_logrBÚ_mesgÚ __version__Ú _get_responseZwelcomerFrCr=Ú_get_capabilitiesÚ capabilitiesÚAllowedVersionsÚPROTOCOL_VERSION)rQÚversionr;r;r<rMÖs0        zIMAP4._connectcCs3|tkrt||jƒƒStd|ƒ‚dS)NzUnknown IMAP4 command: '%s')ÚCommandsÚgetattrÚlowerÚAttributeError)rQÚattrr;r;r<Ú __getattr__s zIMAP4.__getattr__cCs|S)Nr;)rQr;r;r<Ú __enter__szIMAP4.__enter__c Gs'y|jƒWntk r"YnXdS)N)ÚlogoutrP)rQÚargsr;r;r<Ú__exit__ s zIMAP4.__exit__cCstj|j|jfƒS)N)ÚsocketÚcreate_connectionrRrS)rQr;r;r<Ú_create_socketszIMAP4._create_socketcCs:||_||_|jƒ|_|jjdƒ|_dS)zÑSetup connection to remote server on "host:port" (default: localhost:standard IMAP4 port). This connection will be used by the routines: read, readline, send, shutdown. ÚrbN)rRrSrÚsockÚmakefileÚfile)rQrRrSr;r;r<rLs  z IMAP4.opencCs|jj|ƒS)zRead 'size' bytes from remote.)rƒÚread)rQÚsizer;r;r<r„"sz IMAP4.readcCs?|jjtdƒ}t|ƒtkr;|jdtƒ‚|S)zRead line from remote.razgot more than %d bytes)rƒÚreadlineÚ_MAXLINEÚlenr=)rQÚliner;r;r<r†'szIMAP4.readlinecCs|jj|ƒdS)zSend data to remote.N)r�Úsendall)rQÚdatar;r;r<Úsend/sz IMAP4.sendcCs’|jjƒzpy|jjtjƒWnRtk r{}z2|jtjkrit |ddƒdkri‚WYdd}~XnXWd|jjƒXdS)z Close I/O established in "open".Úwinerrorri&'N) rƒÚcloser�rOr}Ú SHUT_RDWRrPÚerrnoZENOTCONNrt)rQÚexcr;r;r<rO4s zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server. socket = .socket() )r�)rQr;r;r<r}Dsz IMAP4.socketcCs]d}|jddg|ƒ\}}|dr8||fS|jƒ\}}|j|||ƒS)aReturn most recent 'RECENT' responses if any exist, else prompt server for an update using the 'NOOP' command. (typ, [data]) = .recent() 'data' is None if no new messages, else list of RECENT responses, most recent last. ZRECENTrbNraéÿÿÿÿ)Ú_untagged_responseÚnoop)rQÚnameÚtypÚdatr;r;r<ÚrecentPs   z IMAP4.recentcCs|j|dg|jƒƒS)z¥Return data for response 'code' if received, or None. Old value for response 'code' is cleared. (code, [data]) = .response(code) N)r“Úupper)rQÚcoder;r;r<ÚresponseaszIMAP4.responsecCs¨d}|sd}|r?|d|d fd krEd|}nd}|rZt|ƒ}nd}tjt|ƒ}|jr‰d |d }||_|j||||ƒS) z°Append message to named mailbox. (typ, [data]) = .append(mailbox, flags, date_time, message) All args except `message' can be None. r ÚINBOXrraú(ú)z(%s)NsUTF8 (ó)r’)r�rž)r ÚMapCRLFÚsubÚCRLFrVrDÚ_simple_command)rQÚmailboxÚflagsÚ date_timeÚmessager•rDr;r;r<Úappendos   z IMAP4.appendcCst|jƒ}t|ƒj|_|jd|ƒ\}}|dkra|j|djddƒƒ‚d|_||fS)asAuthenticate command - requires response processing. 'mechanism' specifies which authentication mechanism is to be used - it must appear in .capabilities in the form AUTH=. 'authobject' must be a callable object: data = authobject(response) It will be called to process server continuation responses; the response argument it is passed will be a bytes. It should return bytes data that will be base64 encoded and sent to the server. It should return None if the client abort response '*' should be sent instead. rrbrazutf-8Úreplacerr’)r™Ú_AuthenticatorÚprocessrDr£r=ÚdecoderC)rQZ mechanismZ authobjectÚmechr–r—r;r;r<Ú authenticate‰s   zIMAP4.authenticatecCs.d}|j|ƒ\}}|j|||ƒS)zT(typ, [data]) = .capability() Fetch capabilities list from server.r)r£r“)rQr•r–r—r;r;r<Ú capability¦szIMAP4.capabilitycCs |jdƒS)zRCheckpoint mailbox on server. (typ, [data]) = .check() r)r£)rQr;r;r<Úcheck¯sz IMAP4.checkc Cs0z|jdƒ\}}Wdd|_X||fS)zÌClose currently selected mailbox. Deleted messages are removed from writable mailbox. This is the recommended command before 'LOGOUT'. (typ, [data]) = .close() rNr)r£rC)rQr–r—r;r;r<rŽ·s z IMAP4.closecCs|jd||ƒS)z‚Copy 'message_set' messages onto end of 'new_mailbox'. (typ, [data]) = .copy(message_set, new_mailbox) r)r£)rQÚ message_setZ new_mailboxr;r;r<ÚcopyÆsz IMAP4.copycCs|jd|ƒS)zPCreate new mailbox. (typ, [data]) = .create(mailbox) r)r£)rQr¤r;r;r<ÚcreateÎsz IMAP4.createcCs|jd|ƒS)zPDelete old mailbox. (typ, [data]) = .delete(mailbox) r)r£)rQr¤r;r;r<ÚdeleteÖsz IMAP4.deletecCs|jd||ƒS)z€Delete the ACLs (remove any rights) set for who on mailbox. (typ, [data]) = .deleteacl(mailbox, who) r)r£)rQr¤Úwhor;r;r<Ú deleteaclÝszIMAP4.deleteaclcCshd|jkrtjdƒ‚|jd|ƒ\}}|dkr^d|jƒkr^|jƒ||fS)zkSend an RFC5161 enable string to the server. (typ, [data]) = .enable(capability) rzServer does not support ENABLErbz UTF8=ACCEPT)rorr=r£r™r_)rQr¯r–r‹r;r;r<Úenableäs  z IMAP4.enablecCs.d}|j|ƒ\}}|j|||ƒS)z÷Permanently remove deleted items from selected mailbox. Generates 'EXPUNGE' response for each deleted message. (typ, [data]) = .expunge() 'data' is list of 'EXPUNGE'd message numbers in order received. r)r£r“)rQr•r–r—r;r;r<Úexpungeðs z IMAP4.expungecCs4d}|j|||ƒ\}}|j|||ƒS)a#Fetch (parts of) messages. (typ, [data, ...]) = .fetch(message_set, message_parts) 'message_parts' should be a string of selected parts enclosed in parentheses, eg: "(UID BODY[TEXT])". 'data' are tuples of message part envelope and data. r)r£r“)rQr±Z message_partsr•r–r—r;r;r<Úfetchþs z IMAP4.fetchcCs+|jd|ƒ\}}|j||dƒS)zXGet the ACLs for a mailbox. (typ, [data]) = .getacl(mailbox) rZACL)r£r“)rQr¤r–r—r;r;r<Úgetacl sz IMAP4.getaclcCs1|jd|||ƒ\}}|j||dƒS)za(typ, [data]) = .getannotation(mailbox, entry, attribute) Retrieve ANNOTATIONs.rÚ ANNOTATION)r£r“)rQr¤ÚentryZ attributer–r—r;r;r<Ú getannotationszIMAP4.getannotationcCs+|jd|ƒ\}}|j||dƒS)zªGet the quota root's resource usage and limits. Part of the IMAP4 QUOTA extension defined in rfc2087. (typ, [data]) = .getquota(root) r ÚQUOTA)r£r“)rQÚrootr–r—r;r;r<ÚgetquotaszIMAP4.getquotacCs^|jd|ƒ\}}|j||dƒ\}}|j||dƒ\}}|||gfS)zœGet the list of quota roots for the named mailbox. (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = .getquotaroot(mailbox) r!r¾Z QUOTAROOT)r£r“)rQr¤r–r—ZquotaZ quotarootr;r;r<Ú getquotaroot)szIMAP4.getquotarootz""Ú*cCs4d}|j|||ƒ\}}|j|||ƒS)z«List mailbox names in directory matching pattern. (typ, [data]) = .list(directory='""', pattern='*') 'data' is list of LIST responses. r#)r£r“)rQÚ directoryÚpatternr•r–r—r;r;r<Úlist4sz IMAP4.listcCsV|jd||j|ƒƒ\}}|dkrC|j|dƒ‚d|_||fS)z”Identify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. r$rbrarr’)r£Ú_quoter=rC)rQÚuserÚpasswordr–r—r;r;r<Úlogin@s $  z IMAP4.logincCs&|||_|_|jd|jƒS)zr Force use of CRAM-MD5 authentication. (typ, [data]) = .login_cram_md5(user, password) zCRAM-MD5)rÇrÈr®Ú_CRAM_MD5_AUTH)rQrÇrÈr;r;r<Úlogin_cram_md5NszIMAP4.login_cram_md5cCs]ddl}t|jtƒr0|jjdƒn|j}|jd|j||dƒjƒS)z1 Authobject to use with CRAM-MD5 authentication. rNzutf-8ú Úmd5)ÚhmacÚ isinstancerÈÚstrÚencoderÇZHMACÚ hexdigest)rQZ challengerÎÚpwdr;r;r<rÊWs $ zIMAP4._CRAM_MD5_AUTHc Cs…d|_y|jdƒ\}}Wn,ddtjƒdd…g}}YnX|jƒd|jkr{d|jdfS||fS)z|Shutdown connection to server. (typ, [data]) = .logout() Returns server 'BYE' response. rÚNOz%s: %sNéÚBYE)rCr£ÚsysÚexc_inforOrF)rQr–r—r;r;r<rz_s ) z IMAP4.logoutcCs4d}|j|||ƒ\}}|j|||ƒS)zÐList 'subscribed' mailbox names in directory matching pattern. (typ, [data, ...]) = .lsub(directory='""', pattern='*') 'data' are tuples of message part envelope and data. r%)r£r“)rQrÃrÄr•r–r—r;r;r<Úlsubosz IMAP4.lsubcCs+|jd|ƒ\}}|j||dƒS)zƒShow my ACLs for a mailbox (i.e. the rights that I have on mailbox). (typ, [data]) = .myrights(mailbox) r")r£r“)rQr¤r–r—r;r;r<ÚmyrightszszIMAP4.myrightscCs.d}|j|ƒ\}}|j|||ƒS)zb Returns IMAP namespaces ala rfc2342 (typ, [data, ...]) = .namespace() r&)r£r“)rQr•r–r—r;r;r<Ú namespace‚szIMAP4.namespacecCs,|jdkr|j|jƒ|jdƒS)zFSend NOOP command. (typ, [data]) = .noop() rcr')rBÚ_dump_urrFr£)rQr;r;r<r”Œsz IMAP4.noopcCs:d}|j|||||ƒ\}}|j||dƒS)zÂFetch truncated part of a message. (typ, [data, ...]) = .partial(message_num, message_part, start, length) 'data' is tuple of message part envelope and data. r(r)r£r“)rQZ message_numZ message_partÚstartÚlengthr•r–r—r;r;r<Úpartial—s!z IMAP4.partialcCsd}|jd|ƒS)z³Assume authentication as "user". Allows an authorised administrator to proxy into any user's mailbox. (typ, [data]) = .proxyauth(user) r))r£)rQrÇr•r;r;r<Ú proxyauth£s zIMAP4.proxyauthcCs|jd||ƒS)zkRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) r*)r£)rQZ oldmailboxZ newmailboxr;r;r<Úrename°sz IMAP4.renamecGspd}|rE|jr$tjdƒ‚|j|d||Œ\}}n|j||Œ\}}|j|||ƒS)zéSearch mailbox for matching messages. (typ, [data]) = .search(charset, criterion, ...) 'data' is space separated list of matching message numbers. If UTF8 is enabled, charset MUST be None. r+z'Non-None charset not valid in UTF8 modeÚCHARSET)rVrr=r£r“)rQÚcharsetZcriteriar•r–r—r;r;r<Úsearch¸s !z IMAP4.searchrœFcCsËi|_||_|r!d}nd}|j||ƒ\}}|dkr^d|_||fSd|_d|jkr¯| r¯|jdkrœ|j|jƒ|jd|ƒ‚||jjd d gƒfS) atSelect a mailbox. Flush all untagged responses. (typ, [data]) = .select(mailbox='INBOX', readonly=False) 'data' is count of messages in mailbox ('EXISTS' response). Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so other responses should be obtained via .response('FLAGS') etc. rr,rbrrz READ-ONLYraz%s is not writableÚEXISTSN)rFrHr£rCrBrÜr?Úget)rQr¤r?r•r–r—r;r;r<ÚselectÊs       z IMAP4.selectcCs|jd|||ƒS)zZSet a mailbox acl. (typ, [data]) = .setacl(mailbox, who, what) r-)r£)rQr¤rµZwhatr;r;r<Úsetaclêsz IMAP4.setaclcGs+|jd|Œ\}}|j||dƒS)z_(typ, [data]) = .setannotation(mailbox[, entry, attribute]+) Set ANNOTATIONs.r.r»)r£r“)rQr{r–r—r;r;r<Ú setannotationòszIMAP4.setannotationcCs.|jd||ƒ\}}|j||dƒS)ziSet the quota root's resource limits. (typ, [data]) = .setquota(root, limits) r/r¾)r£r“)rQr¿Zlimitsr–r—r;r;r<ÚsetquotaúszIMAP4.setquotacGs[d}|d|dfdkr*d|}|j||||Œ\}}|j|||ƒS) z�IMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) r0rrar�ržz(%s)r’)r�rž)r£r“)rQZ sort_criteriarãÚsearch_criteriar•r–r—r;r;r<Úsorts  z IMAP4.sortNcCsõd}ts|jdƒ‚|jr3|jdƒ‚||jkrQ|jdƒ‚|dkritjƒ}|j|ƒ\}}|dkrÓ|j|j d|j ƒ|_ |j j dƒ|_ d|_|j ƒn|jd ƒ‚|j|||ƒS) Nr1zSSL support missingzTLS session already establishedzTLS not supported by serverrbÚserver_hostnamer€TzCouldn't establish TLS session)ÚHAVE_SSLr=rJr>roÚsslÚ_create_stdlib_contextr£Ú wrap_socketr�rRr‚rƒrnr“)rQÚ ssl_contextr•r–r—r;r;r<Ústarttlss$      zIMAP4.starttlscCs4d}|j|||ƒ\}}|j|||ƒS)zpRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) r2)r£r“)rQr¤Únamesr•r–r—r;r;r<Ústatus(sz IMAP4.statuscCsU|d|dfd kr$d|}|jd|||ƒ\}}|j||dƒS) z�Alters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) rrar�ržz(%s)r3rr’)r�rž)r£r“)rQr±Úcommandr¥r–r—r;r;r<Ústore4s z IMAP4.storecCs|jd|ƒS)zYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) r4)r£)rQr¤r;r;r<Ú subscribe?szIMAP4.subscribecGs7d}|j||||Œ\}}|j|||ƒS)z‹IMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) r5)r£r“)rQZthreading_algorithmrãrër•r–r—r;r;r<ÚthreadGsz IMAP4.threadcGs¹|jƒ}|tkr+|jd|ƒ‚|jt|krj|jd||jdjt|ƒfƒ‚d}|j|||Œ\}}|d kr |}nd}|j|||ƒS) zåExecute "command arg ..." with messages identified by UID, rather than message number. (typ, [data]) = .uid(command, arg1, arg2, ...) Returns response appropriate to 'command'. zUnknown IMAP4 UID command: %sz9command %s illegal in state %s, only allowed in states %sz, r6r+r0r5r)r+r0r5)r™rsr=rCÚjoinr£r“)rQrör{r•r–r—r;r;r<ÚuidQs      z IMAP4.uidcCs|jd|ƒS)z_Unsubscribe from old mailbox. (typ, [data]) = .unsubscribe(mailbox) r7)r£)rQr¤r;r;r<Ú unsubscribejszIMAP4.unsubscribecGs8|jƒ}|tkr(|jft|<|j||ŒS)aAllow simple extension commands notified by server in CAPABILITY response. Assumes command is legal in current state. (typ, [data]) = .xatom(name, arg, ...) Returns response appropriate to extension command `name'. )r™rsrCr£)rQr•r{r;r;r<Úxatomrs  z IMAP4.xatomcCs‡|dkrd}|j}|jdkrV|jd|t|j|dƒƒ|fƒ||krv||j|ƒn |g|||jjdƒ}|r:|j|dj|jdƒƒ‚dS)NrÖrar©r’)rFrær>r¬rW)rQZbyer;r;r<Ú _check_bye–szIMAP4._check_byec GsÛ|jt|krHd|_|jd||jdjt|ƒfƒ‚x'dD]}||jkrO|j|=qOWd|jkrš|j rš|jdƒ‚|jƒ}t ||j ƒ}|d|}xL|D]D}|dkrâqÍt |t ƒrt ||j ƒ}|d|}qÍW|j}|dk r}d|_t |ƒt |jƒkrW|}n&d}|t d t|ƒ|j ƒ}|jd kr |jd |ƒn|jd |ƒy|j|tƒWn8tk r} z|jd | ƒ‚WYdd} ~ XnX|dkr|SxÃx!|jƒr7|j|r|SqW|rM||jƒ}|jd krs|jd t|ƒƒy|j|ƒ|jtƒWn8tk rË} z|jd | ƒ‚WYdd} ~ XnX|sPqW|S)Nz9command %s illegal in state %s, only allowed in states %sz, rbrÔÚBADz READ-ONLYz#mailbox status changed to READ-ONLYó z {%s}éz> %rzsocket error: %szwrite literal size %s)rbrÔr)rCrsrDr=rúrFrHr?Ú_new_tagÚbytesrWrÏrÐÚtypeÚ_commandrˆrBrkÚ_logrŒr¢rPr>rmrErG) rQr•r{r–Útagr‹ÚargrDZ literatorÚvalr;r;r<r œsh             &   &zIMAP4._commandcCsû|dkr|jƒy|j|ƒ\}}Wn�|jk rr}z|jd||fƒ‚WYdd}~XnA|jk r²}z|jd||fƒ‚WYdd}~XnX|dkrÉ|jƒ|dkrñ|jd|||fƒ‚||fS)Nrzcommand: %s => %srz%s command error: %s %s)rÚ_get_tagged_responser>r=)rQr•r r–r‹r r;r;r<Ú_command_completeés  +,   zIMAP4._command_completecCsk|jƒ\}}|dgkr0|jdƒ‚t|d|jƒ}|jƒ}t|jƒƒ|_dS)Nz"no CAPABILITY response from serverrar’)r¯r=rÐrWr™ÚtupleÚsplitro)rQr–r—r;r;r<rnús  zIMAP4._get_capabilitiescCsµ|jƒ}|j|j|ƒr¤|jjdƒ}||jkrU|jd|ƒ‚|jjdƒ}t||jƒ}|jjdƒ}||gf|j|rÐrWÚUntagged_responser^Ú ContinuationrGr\ÚintrBrkr„rÚ Response_code)rQÚrespr r–r—Zdat2r…r‹r;r;r<rmsP  zIMAP4._get_responsecCs‘xŠ|j|}|dk r*|j|=|S|jƒy|jƒWq|jk rˆ}z!|jdkrs|jƒ‚WYdd}~XqXqWdS)Nra)rErrmr>rBÚ print_log)rQr Úresultr r;r;r<rSs     zIMAP4._get_tagged_responsecCs‹|jƒ}|s!|jdƒ‚|jdƒsC|jd|ƒ‚|dd…}|jdkrv|jd|ƒn|jd|ƒ|S)Nzsocket error: EOFs z#socket error: unterminated line: %rrÕrz< %réþÿÿÿ)r†r>ÚendswithrBrkr )rQr‰r;r;r<rns zIMAP4._get_linecCs`|j|ƒ|_|jdk rS|jdkrS|jd|j|jjƒfƒ|jdk S)Nrÿz matched r'%r' => %r)ÚmatchrrBrkrÄÚgroups)rQZcreÚsr;r;r<r�s#z IMAP4._matchcCsC|jtt|jƒ|jƒ}|jd|_d|j|<|S)Nra)rfrrÐrIrWrE)rQr r;r;r<r�s" zIMAP4._new_tagcCs0|jddƒ}|jddƒ}d|dS)Nú\z\\ú"z\")r©)rQr r;r;r<rÆ•sz IMAP4._quotecGs|j||j||ŒƒS)N)rr )rQr•r{r;r;r<r£�szIMAP4._simple_commandcCst|dkr||fS||jkr2|dgfS|jj|ƒ}|jdkrj|jd||fƒ||fS)NrÔrÿzuntagged_responses[%s] => %s)rFÚpoprBrk)rQr–r—r•r‹r;r;r<r“¢s   zIMAP4._untagged_responsecCsi|dkrtjƒ}tjdtj|ƒƒ}tjjd||dd|fƒtjjƒdS)Nz%M:%Sz %s.%02d %s éd)ÚtimeÚstrftimeÚ localtimer×ÚstderrÚwriteÚflush)rQr!ZsecsZtmr;r;r<rk°s   %z IMAP4._mesgcCsU|jƒ}|sdSd}tdd„|ƒ}|jd||j|ƒfƒdS)Nz cSs3d|d|ddr+dj|dƒp.dfS)Nz%s: "%s"rraz" "r@)rú)Úxr;r;r<Ú¼sz IMAP4._dump_ur..zuntagged responses dump:%s%s)ÚitemsÚmaprkrú)rQÚdictÚlÚtr;r;r<rÜ·s  zIMAP4._dump_urcCsJ|tjƒf|j|j<|jd7_|j|jkrFd|_dS)Nrar)r&rjrirh)rQr‰r;r;r<r ¿sz IMAP4._logc CsŠ|jdt|jƒƒ|j|j}}xV|r…y|j|j|ŒWnYnX|d7}||jkrxd}|d8}q0WdS)Nzlast %d IMAP4 interactions:rar)rkrˆrjrirh)rQÚiÚnr;r;r<rÆs  zIMAP4.print_log)Tr8r9r:Ú__doc__rNr=r>r?Ú IMAP4_PORTrTrKr_rMrxryr|rrLr„r†rŒrOr}r˜r›r¨r®r¯r°rŽr²r³r´r¶r·r¸r¹rºr½rÀrÁrÅrÉrËrÊrzrÙrÚrÛr”rßràrárärçrèrérêrìrórõr÷rørùrûrürýrrr rrnrmrrrrrÆr£r“rkrÜr rr;r;r;r<r}sž ,   *                                     M  P        c@sOeZdZdZdeddddd„Zdd„Zdedd „ZdS) Ú IMAP4_SSLa3IMAP4 client class over SSL connection Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile[, ssl_context]]]]]) host - host's name (default: localhost); port - port number (default: standard IMAP4 SSL port); keyfile - PEM formatted file that contains your private key (default: None); certfile - PEM formatted certificate chain file (default: None); ssl_context - a SSLContext object that contains your certificate chain and private key (default: None) Note: if ssl_context is provided, then parameters keyfile or certfile should not be set otherwise ValueError is raised. for more documentation see the docstring of the parent class IMAP4. r@NcCsž|dk r$|dk r$tdƒ‚|dk rH|dk rHtdƒ‚||_||_|dkr~tjd|d|ƒ}||_tj|||ƒdS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusiveÚcertfileÚkeyfile)Ú ValueErrorr9r8rïrðròrrT)rQrRrSr9r8ròr;r;r<rTés       zIMAP4_SSL.__init__cCs(tj|ƒ}|jj|d|jƒS)Nrí)rrròrñrR)rQr�r;r;r<rúszIMAP4_SSL._create_socketcCstj|||ƒdS)zæSetup connection to remote server on "host:port". (default: localhost:standard IMAP4 SSL port). This connection will be used by the routines: read, readline, send, shutdown. N)rrL)rQrRrSr;r;r<rLÿszIMAP4_SSL.open)r8r9r:r5ÚIMAP4_SSL_PORTrTrrLr;r;r;r<r7Ös   r7c@sdeZdZdZdd„Zdddd„Zdd„Zd d „Zd d „Zd d„Z dS)rzæIMAP4 client class over a stream Instantiate with: IMAP4_stream(command) "command" - a string that can be passed to subprocess.Popen() for more documentation see the docstring of the parent class IMAP4. cCs||_tj|ƒdS)N)rörrT)rQrör;r;r<rTs zIMAP4_stream.__init__Nc Csd|_d|_d|_d|_tj|jdtdtjdtjddddƒ|_ |j j |_ |j j |_ dS)z…Setup a stream connection. This connection will be used by the routines: read, readline, send, shutdown. NÚbufsizeÚstdinÚstdoutÚshellTÚ close_fds)rRrSr�rƒÚ subprocessÚPopenrörÚPIPEr«r=Ú writefiler>Úreadfile)rQrRrSr;r;r<rLs    zIMAP4_stream.opencCs|jj|ƒS)zRead 'size' bytes from remote.)rEr„)rQr…r;r;r<r„+szIMAP4_stream.readcCs |jjƒS)zRead line from remote.)rEr†)rQr;r;r<r†0szIMAP4_stream.readlinecCs!|jj|ƒ|jjƒdS)zSend data to remote.N)rDr*r+)rQr‹r;r;r<rŒ5szIMAP4_stream.sendcCs+|jjƒ|jjƒ|jjƒdS)z Close I/O established in "open".N)rErŽrDr«Úwait)rQr;r;r<rO;s  zIMAP4_stream.shutdown) r8r9r:r5rTrLr„r†rŒrOr;r;r;r<r s     c@sFeZdZdZdd„Zdd„Zdd„Zdd „Zd S) rªzcPrivate class to provide en/decoding for base64-based authentication conversation. cCs ||_dS)N)r­)rQZmechinstr;r;r<rTIsz_Authenticator.__init__cCs5|j|j|ƒƒ}|dkr(dS|j|ƒS)Nó*)r­r¬rÑ)rQr‹Úretr;r;r<r«Ls z_Authenticator.processcCsŸd}t|tƒr$|jdƒ}xt|ršt|ƒdkrb|dd…}|dd…}n |}d}tj|ƒ}|r'||dd…}q'W|S)Nrþzutf-8é0rar’)rÏrÐrÑrˆÚbinasciiZ b2a_base64)rQÚinpZoupr2Úer;r;r<rÑRs  z_Authenticator.encodecCs|s dStj|ƒS)Nrþ)rJZ a2b_base64)rQrKr;r;r<r¬jsz_Authenticator.decodeN)r8r9r:r5rTr«rÑr¬r;r;r;r<rªCs    rªz0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrÌcCs)i|]\}}|d|jƒ“qS)ra)rÑ)Ú.0r4r!r;r;r<ú ps rNrac Cs4tj|ƒ}|sdSt|jdƒ}|jdƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jdƒƒ}t|jd ƒƒ} t|jd ƒƒ} | d | d } |d kró| } ||||||dddf } tj| ƒ| } tj| ƒS)z¨Parse an IMAP4 INTERNALDATE string. Return corresponding local time. The return value is a time.struct_time tuple or None if the string has wrong format. NÚmonÚzonenÚdayÚyearÚhourÚminÚsecÚzonehÚzonemé<ó-rar’r’r’) Ú InternalDaterÚMon2numrrÚcalendarZtimegmr&r()rrrOrPrQrRrSrTrUrVrWZzoneÚttÚutcr;r;r<rrs$ !cCs\d}d}tt|ƒƒ}x7|rWt|dƒ\}}|||d…|}q!W|S)z-Convert integer to A-P string representation.rþsABCDEFGHIJKLMNOPéra)rÚabsÚdivmod)Únumr ZAPÚmodr;r;r<r •s cCs2tj|ƒ}|sfSt|jdƒjƒƒS)z-Convert IMAP4 flags response to python tuple.r¥)ÚFlagsrrrr)rrr;r;r<r ¢sc Cs†t|ttfƒr3tj|tjƒjƒ}n0t|tƒr÷y |j }Wnqt k rÂt j r´|d}|d kršt j t j|ƒƒd}t jt jf| }n t j }YnXtd|ƒ}t|dd…dt|ƒŒ}nlt|tƒr*|jdkr!tdƒ‚|}n9t|tƒrW|d|d fdkrW|Std ƒ‚d jt|jƒ}|j|ƒS)aèConvert date_time to IMAP4 INTERNALDATE representation. Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The date_time argument can be a number (int or float) representing seconds since epoch (as returned by time.time()), a 9-tuple representing local time, an instance of time.struct_time (as returned by time.localtime()), an aware datetime instance or a double-quoted string. In the last case, it is assumed to already be in the correct format. éraZsecondsNéÚtzinfozdate_time must be awarerr#zdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"r’r’)r#r#)rÏrÚfloatrZ fromtimestamprr^Z astimezonerÚ tm_gmtoffrvr&Údaylightr(ÚmktimeÚaltzonerrgr:rÐÚformatÚMonthsZmonthr')r¦ZdtZgmtoffÚdstZdeltaÚfmtr;r;r<r ­s0       %  ) Ú__main__zd:s:z-dz-sr@zIMAP password for %s on %s: Ú localhostzJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)srÇZlfÚ rÉr³z /tmp/xxx 1ráz/tmp/yyyz /tmp/yyz 2r¨rÅz/tmpzyy*rçräZSUBJECTZtestr¹Ú1z(FLAGS INTERNALDATE RFC822)r÷ÚFLAGSz (\Deleted)rÛr¸r˜rŽr›Z UIDVALIDITYrûZALLrårzcCsftjd||fƒtt|ƒ|Œ\}}tjd|||fƒ|dkrb|d‚|S)Nz%s %sz %s => %s %srÔr)ÚMrkrt)Úcmdr{r–r—r;r;r<Úruns  rxzPROTOCOL_VERSION = %szCAPABILITIES = %rz/tmp/zyy%z .*"([^"]+)"$r´z%sz:(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)z All tests OK.z Tests failed.z8 If you would like to see debugging output, try: %s -d5 )Ur5rlrJr�rdrXr}rAr×r&r\rrrÚiorrïrîÚ ImportErrorÚ__all__r¢rAr6r;rpr‡rsrYrrdrZr[r\r rrr^rZr]rr7r¨rrªrrnÚ enumerater[rr r r r8ZgetoptZgetpassÚargvZoptlistr{r=r Zstream_commandÚoptrrRZgetuserZUSERZPASSWDZ test_mesgZ test_seq1Z test_seq2rxrvrCrkrqrorwÚmlrrrÚpathr—rûÚprintr;r;r;r<Ú s< l                                          ÿÿÿÿ[1 9,# # ) )%