fc&@sdZdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z ddlmZyddlZeZWnek reZYnXdddd d d gZd ZdZd ZdZddfZdZi'ddfd6dfd6ddddfd6dfd6dfd6dfd6ddfd6ddfd6ddfd6ddfd6dfd6dfd 6ddfd!6ddfd"6ddfd#6ddfd$6ddfd%6ddfd&6dfd'6ddddfd6ddfd(6ddfd)6ddddfd*6dfd+6dfd,6ddfd-6dfd.6ddfd/6ddfd06ddfd16ddfd26dfd36dfd46ddfd56dfd66ddfd76dfd86dfd96ddfd:6Zejd;Zejd<Zejd=Z ejd>ej!Z"ejd?Z#ejd@Z$ejdAZ%ejdBej!Z&GdCddZ'erGdDdEdEe'Z(ej)dEnGdFdde'Z*GdGdHdHZ+dIj,dJZ-dKdLe.e-dMdDZ/dNdZ0dOd Z1dPd Z2dQd Z3e4dRkrddl5Z5ddl6Z6y)e5j5ej7dMddS\Z8Z9Wn:e5j:k rZ;zfff\Z8Z9WYddZ;[;XnXe<Z=xWe8D]O\Z>Z;e>dTkr e?e;Zn(e>dUkr1e;Z=e9 r.e=fZ9nnqWe9 rHdVfZ9ne9dZ@e6jAZBe6j6dWeBe@psdXfZCdYieBdZ6d[d\6ZDd]eBeCffd^d_ffd`d_daffddbffdcdbe<e<eDffdddedfffdgdbffdhe<didjffdkdldmffdndldodpffdqffdrffdsffdtfffZEdgffdudvffdwd.dxffdudyffdce<e<e<eDffdsffdzfffZFd{d|ZGye=re*e=ZHn e'e@ZHeHjIdkreEdMdZEneHjJd}eHjKeHjJd~eHjLfx!eED]\ZMZ9eGeMe9q9WxheGddddfD]QZNejOdeNZPePrePjQdMZRneNj,dM ZReGdeRfqlWxeFD]|\ZMZ9eGeMe9ZSeMe9fdwd.dxffkrqneSdM j,ZTeT r%qneGdwd deTdM dfqWeUdWn4eUde reUdej7dnYnXndS(uIMAP4 client. Based on RFC 2060. Public class: IMAP4 Public variable: Debug Public functions: Internaldate2tuple Int2AP ParseFlags Time2Internaldate u2.58iN(udatetimeutimezoneu timedelta(uDEFAULT_BUFFER_SIZEuIMAP4u IMAP4_streamuInternaldate2tupleuInt2APu ParseFlagsuTime2Internaldates iiu IMAP4REV1i'uAUTHuSELECTEDuAPPENDuNONAUTHu AUTHENTICATEuLOGOUTu CAPABILITYuCHECKuCLOSEuCOPYuCREATEuDELETEu DELETEACLuEXAMINEuEXPUNGEuFETCHuGETACLu GETANNOTATIONuGETQUOTAu GETQUOTAROOTuMYRIGHTSuLISTuLOGINuLSUBu NAMESPACEuNOOPuPARTIALu PROXYAUTHuRENAMEuSEARCHuSELECTuSETACLu SETANNOTATIONuSETQUOTAuSORTuSTARTTLSuSTATUSuSTOREu SUBSCRIBEuTHREADuUIDu 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.*))?cBs|EeZdZdZGdddeZGdddeZGdddeZded d Z d d Z d dZ ddZ deddZ ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Z d9d:Z!d;d<Z"d=d>Z#d?d@dAdBZ$dCdDZ%dEdFZ&dGdHZ'dIdJZ(d?d@dKdLZ)dMdNZ*dOdPZ+dQdRZ,dSdTZ-dUdVZ.dWdXZ/dYdZZ0d[dd\d]Z2d^d_Z3d`daZ4dbdcZ5dddeZ6ddfdgZ8dhdiZ9djdkZ:dldmZ;dndoZ<dpdqZ=drdsZ>dtduZ?dvdwZ@dxdyZAdzd{ZBd|d}ZCd~dZDddZEddZFddZGddZHddZIddZJddZKddZLdS(uIMAP4uIMAP4 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. cBs|EeZdZdS(u IMAP4.errorN(u__name__u __module__u __qualname__(u __locals__((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuerrorsuerrorcBs|EeZdZdS(u IMAP4.abortN(u__name__u __module__u __qualname__(u __locals__((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuabortsuabortcBs|EeZdZdS(uIMAP4.readonlyN(u__name__u __module__u __qualname__(u __locals__((u,/opt/alt/python33/lib64/python3.3/imaplib.pyureadonlysureadonlyucCst|_d|_d|_i|_i|_d|_d|_ d|_ d|_ |j ||y|j Wn;tk ry|jWntjk rYnXYnXdS(NuLOGOUTuiF(uDebugudebugustateuNoneuliteralutagged_commandsuuntagged_responsesucontinuation_responseuFalseu is_readonlyutagnumu_tls_establisheduopenu_connectu Exceptionushutdownusocketuerror(uselfuhostuport((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu__init__s$          uIMAP4.__init__cCsttjdd|_tjd|jdtj|_|j|_ d|j krhd|_ n-d|j krd|_ n|j |j |j x-tD]%}||jkrqn||_dSW|j d dS( Niis(?Ps"\d+) (?P[A-Z]+) (?P.*)uPREAUTHuAUTHuOKuNONAUTHuserver not IMAP4 compliant(uInt2APurandomurandintutagpreureucompileuASCIIutagreu _get_responseuwelcomeuuntagged_responsesustateuerroru_get_capabilitiesuAllowedVersionsu capabilitiesuPROTOCOL_VERSION(uselfuversion((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu_connects       uIMAP4._connectcCs3|tkrt||jStd|dS(NuUnknown IMAP4 command: '%s'(uCommandsugetattruloweruAttributeError(uselfuattr((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu __getattr__s uIMAP4.__getattr__cCstj|j|jfS(N(usocketucreate_connectionuhostuport(uself((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu_create_socketsuIMAP4._create_socketcCs:||_||_|j|_|jjd|_dS(uSetup connection to remote server on "host:port" (default: localhost:standard IMAP4 port). This connection will be used by the routines: read, readline, send, shutdown. urbN(uhostuportu_create_socketusockumakefileufile(uselfuhostuport((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuopens  u IMAP4.opencCs|jj|S(uRead 'size' bytes from remote.(ufileuread(uselfusize((u,/opt/alt/python33/lib64/python3.3/imaplib.pyureadsu IMAP4.readcCsB|jjtd}t|tkr>|jdtn|S(uRead line from remote.iugot more than %d bytes(ufileureadlineu_MAXLINEulenuerror(uselfuline((u,/opt/alt/python33/lib64/python3.3/imaplib.pyureadline suIMAP4.readlinecCs|jj|dS(uSend data to remote.N(usockusendall(uselfudata((u,/opt/alt/python33/lib64/python3.3/imaplib.pyusendsu IMAP4.sendcCs|jjz^y|jjtjWn@tjk ri}z|jtjkrWnWYdd}~XnXWd|jjXdS(u Close I/O established in "open".N( ufileucloseusockushutdownusocketu SHUT_RDWRuerroruerrnouENOTCONN(uselfue((u,/opt/alt/python33/lib64/python3.3/imaplib.pyushutdowns uIMAP4.shutdowncCs|jS(ufReturn socket instance used to connect to IMAP4 server. socket = .socket() (usock(uself((u,/opt/alt/python33/lib64/python3.3/imaplib.pyusocket$su IMAP4.socketcCs]d}|jddg|\}}|dr8||fS|j\}}|j|||S(uReturn 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. uRECENTuOKiNi(u_untagged_responseuNoneunoop(uselfunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyurecent0s   u IMAP4.recentcCs|j|dg|jS(uReturn data for response 'code' if received, or None. Old value for response 'code' is cleared. (code, [data]) = .response(code) N(u_untagged_responseuNoneuupper(uselfucode((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuresponseAsuIMAP4.responsecCsd}|sd}n|rE|d|dfd krKd|}qKnd }|r`t|}nd }tjt||_|j||||S( uAppend message to named mailbox. (typ, [data]) = .append(mailbox, flags, date_time, message) All args except `message' can be None. uAPPENDuINBOXiiu(u)u(%s)i(u(u)N(uNoneuTime2InternaldateuMapCRLFusubuCRLFuliteralu_simple_command(uselfumailboxuflagsu date_timeumessageuname((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuappendOs u IMAP4.appendcCsk|j}t|j|_|jd|\}}|dkrX|j|dnd|_||fS(usAuthenticate 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. u AUTHENTICATEuOKiuAUTHi(uupperu_Authenticatoruprocessuliteralu_simple_commanduerrorustate(uselfu mechanismu authobjectumechutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu authenticatefs   uIMAP4.authenticatecCs.d}|j|\}}|j|||S(uT(typ, [data]) = .capability() Fetch capabilities list from server.u CAPABILITY(u_simple_commandu_untagged_response(uselfunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu capabilitysuIMAP4.capabilitycCs |jdS(uRCheckpoint mailbox on server. (typ, [data]) = .check() uCHECK(u_simple_command(uself((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuchecksu IMAP4.checkc Cs0z|jd\}}Wdd|_X||fS(uClose currently selected mailbox. Deleted messages are removed from writable mailbox. This is the recommended command before 'LOGOUT'. (typ, [data]) = .close() uCLOSENuAUTH(u_simple_commandustate(uselfutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyucloses u IMAP4.closecCs|jd||S(uCopy 'message_set' messages onto end of 'new_mailbox'. (typ, [data]) = .copy(message_set, new_mailbox) uCOPY(u_simple_command(uselfu message_setu new_mailbox((u,/opt/alt/python33/lib64/python3.3/imaplib.pyucopysu IMAP4.copycCs|jd|S(uPCreate new mailbox. (typ, [data]) = .create(mailbox) uCREATE(u_simple_command(uselfumailbox((u,/opt/alt/python33/lib64/python3.3/imaplib.pyucreatesu IMAP4.createcCs|jd|S(uPDelete old mailbox. (typ, [data]) = .delete(mailbox) uDELETE(u_simple_command(uselfumailbox((u,/opt/alt/python33/lib64/python3.3/imaplib.pyudeletesu IMAP4.deletecCs|jd||S(uDelete the ACLs (remove any rights) set for who on mailbox. (typ, [data]) = .deleteacl(mailbox, who) u DELETEACL(u_simple_command(uselfumailboxuwho((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu deleteaclsuIMAP4.deleteaclcCs.d}|j|\}}|j|||S(uPermanently 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. uEXPUNGE(u_simple_commandu_untagged_response(uselfunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuexpunges u IMAP4.expungecCs4d}|j|||\}}|j|||S(u#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. uFETCH(u_simple_commandu_untagged_response(uselfu message_setu message_partsunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyufetchs u IMAP4.fetchcCs+|jd|\}}|j||dS(uXGet the ACLs for a mailbox. (typ, [data]) = .getacl(mailbox) uGETACLuACL(u_simple_commandu_untagged_response(uselfumailboxutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyugetaclsu IMAP4.getaclcCs1|jd|||\}}|j||dS(ua(typ, [data]) = .getannotation(mailbox, entry, attribute) Retrieve ANNOTATIONs.u GETANNOTATIONu ANNOTATION(u_simple_commandu_untagged_response(uselfumailboxuentryu attributeutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu getannotationsuIMAP4.getannotationcCs+|jd|\}}|j||dS(uGet the quota root's resource usage and limits. Part of the IMAP4 QUOTA extension defined in rfc2087. (typ, [data]) = .getquota(root) uGETQUOTAuQUOTA(u_simple_commandu_untagged_response(uselfurootutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyugetquotasuIMAP4.getquotacCs^|jd|\}}|j||d\}}|j||d\}}|||gfS(uGet the list of quota roots for the named mailbox. (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = .getquotaroot(mailbox) u GETQUOTAROOTuQUOTAu QUOTAROOT(u_simple_commandu_untagged_response(uselfumailboxutypudatuquotau quotaroot((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu getquotarootsuIMAP4.getquotarootu""u*cCs4d}|j|||\}}|j|||S(uList mailbox names in directory matching pattern. (typ, [data]) = .list(directory='""', pattern='*') 'data' is list of LIST responses. uLIST(u_simple_commandu_untagged_response(uselfu directoryupatternunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyulistsu IMAP4.listcCsY|jd||j|\}}|dkrF|j|dnd|_||fS(uIdentify client using plaintext password. (typ, [data]) = .login(user, password) NB: 'password' will be quoted. uLOGINuOKiuAUTHi(u_simple_commandu_quoteuerrorustate(uselfuuserupasswordutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyulogins $  u IMAP4.logincCs&|||_|_|jd|jS(ur Force use of CRAM-MD5 authentication. (typ, [data]) = .login_cram_md5(user, password) uCRAM-MD5(uuserupasswordu authenticateu_CRAM_MD5_AUTH(uselfuuserupassword((u,/opt/alt/python33/lib64/python3.3/imaplib.pyulogin_cram_md5suIMAP4.login_cram_md5cCsZddl}t|jtr0|jjdn|j}|jd|j||jS(u1 Authobject to use with CRAM-MD5 authentication. iNuASCIIu (uhmacu isinstanceupasswordustruencodeuuseruHMACu hexdigest(uselfu challengeuhmacupwd((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu_CRAM_MD5_AUTH(s $ uIMAP4._CRAM_MD5_AUTHc Csd|_y|jd\}}Wn,ddtjddg}}YnX|jd|jkr{d|jdfS||fS(u|Shutdown connection to server. (typ, [data]) = .logout() Returns server 'BYE' response. uLOGOUTuNOu%s: %sNiuBYE(ustateu_simple_commandusysuexc_infoushutdownuuntagged_responses(uselfutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyulogout0s ) u IMAP4.logoutcCs4d}|j|||\}}|j|||S(uList 'subscribed' mailbox names in directory matching pattern. (typ, [data, ...]) = .lsub(directory='""', pattern='*') 'data' are tuples of message part envelope and data. uLSUB(u_simple_commandu_untagged_response(uselfu directoryupatternunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyulsub@su IMAP4.lsubcCs+|jd|\}}|j||dS(uShow my ACLs for a mailbox (i.e. the rights that I have on mailbox). (typ, [data]) = .myrights(mailbox) uMYRIGHTS(u_simple_commandu_untagged_response(uselfumailboxutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyumyrightsKsuIMAP4.myrightscCs.d}|j|\}}|j|||S(ub Returns IMAP namespaces ala rfc2342 (typ, [data, ...]) = .namespace() u NAMESPACE(u_simple_commandu_untagged_response(uselfunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu namespaceSsuIMAP4.namespacecCs |jdS(uFSend NOOP command. (typ, [data]) = .noop() uNOOP(u_simple_command(uself((u,/opt/alt/python33/lib64/python3.3/imaplib.pyunoop]su IMAP4.noopcCs:d}|j|||||\}}|j||dS(uFetch truncated part of a message. (typ, [data, ...]) = .partial(message_num, message_part, start, length) 'data' is tuple of message part envelope and data. uPARTIALuFETCH(u_simple_commandu_untagged_response(uselfu message_numu message_partustartulengthunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyupartialhs!u IMAP4.partialcCsd}|jd|S(uAssume authentication as "user". Allows an authorised administrator to proxy into any user's mailbox. (typ, [data]) = .proxyauth(user) u PROXYAUTH(u_simple_command(uselfuuseruname((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu proxyauthts uIMAP4.proxyauthcCs|jd||S(ukRename old mailbox name to new. (typ, [data]) = .rename(oldmailbox, newmailbox) uRENAME(u_simple_command(uselfu oldmailboxu newmailbox((u,/opt/alt/python33/lib64/python3.3/imaplib.pyurenamesu IMAP4.renamecGsXd}|r-|j|d||\}}n|j||\}}|j|||S(uSearch mailbox for matching messages. (typ, [data]) = .search(charset, criterion, ...) 'data' is space separated list of matching message numbers. uSEARCHuCHARSET(u_simple_commandu_untagged_response(uselfucharsetucriteriaunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyusearchs !u IMAP4.searchuINBOXcCsi|_||_|r!d}nd}|j||\}}|dkr^d|_||fSd|_d|jkr| r|jd|n||jjdd gfS( utSelect 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. uEXAMINEuSELECTuOKuAUTHuSELECTEDu READ-ONLYu%s is not writableuEXISTSN(uuntagged_responsesu is_readonlyu_simple_commandustateureadonlyugetuNone(uselfumailboxureadonlyunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuselects       u IMAP4.selectcCs|jd|||S(uZSet a mailbox acl. (typ, [data]) = .setacl(mailbox, who, what) uSETACL(u_simple_command(uselfumailboxuwhouwhat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyusetaclsu IMAP4.setaclcGs+|jd|\}}|j||dS(u_(typ, [data]) = .setannotation(mailbox[, entry, attribute]+) Set ANNOTATIONs.u SETANNOTATIONu ANNOTATION(u_simple_commandu_untagged_response(uselfuargsutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu setannotationsuIMAP4.setannotationcCs.|jd||\}}|j||dS(uiSet the quota root's resource limits. (typ, [data]) = .setquota(root, limits) uSETQUOTAuQUOTA(u_simple_commandu_untagged_response(uselfurootulimitsutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyusetquotasuIMAP4.setquotacGs^d}|d|dfdkr-d|}n|j||||\}}|j|||S( uIMAP4rev1 extension SORT command. (typ, [data]) = .sort(sort_criteria, charset, search_criteria, ...) uSORTiiu(u)u(%s)i(u(u)(u_simple_commandu_untagged_response(uselfu sort_criteriaucharsetusearch_criteriaunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyusorts  u IMAP4.sortcCsd}ts|jdn|jr9|jdn||jkrZ|jdn|dkrtjtj}|j tj O_ n|j |\}}|dkr|j |j |_ |j jd|_d|_|jn|jd|j|||S( NuSTARTTLSuSSL support missinguTLS session already establisheduTLS not supported by serveruOKurbuCouldn't establish TLS sessionT(uHAVE_SSLuerroru_tls_establisheduabortu capabilitiesuNoneusslu SSLContextuPROTOCOL_SSLv23uoptionsu OP_NO_SSLv2u_simple_commandu wrap_socketusockumakefileufileuTrueu_get_capabilitiesu_untagged_response(uselfu ssl_contextunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyustarttlss$     uIMAP4.starttlscCs4d}|j|||\}}|j|||S(upRequest named status conditions for mailbox. (typ, [data]) = .status(mailbox, names) uSTATUS(u_simple_commandu_untagged_response(uselfumailboxunamesunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyustatussu IMAP4.statuscCsX|d|dfd kr'd|}n|jd|||\}}|j||dS( uAlters flag dispositions for messages in mailbox. (typ, [data]) = .store(message_set, command, flags) iiu(u)u(%s)uSTOREuFETCHi(u(u)(u_simple_commandu_untagged_response(uselfu message_setucommanduflagsutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyustores u IMAP4.storecCs|jd|S(uYSubscribe to new mailbox. (typ, [data]) = .subscribe(mailbox) u SUBSCRIBE(u_simple_command(uselfumailbox((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu subscribesuIMAP4.subscribecGs7d}|j||||\}}|j|||S(uIMAPrev1 extension THREAD command. (type, [data]) = .thread(threading_algorithm, charset, search_criteria, ...) uTHREAD(u_simple_commandu_untagged_response(uselfuthreading_algorithmucharsetusearch_criteriaunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuthreadsu IMAP4.threadcGs|j}|tkr.|jd|n|jt|krp|jd||jdjt|fnd}|j|||\}}|d kr|}nd}|j|||S( uExecute "command arg ..." with messages identified by UID, rather than message number. (typ, [data]) = .uid(command, arg1, arg2, ...) Returns response appropriate to 'command'. uUnknown IMAP4 UID command: %su9command %s illegal in state %s, only allowed in states %su, uUIDuSEARCHuSORTuTHREADuFETCH(uSEARCHuSORTuTHREAD(uupperuCommandsuerrorustateujoinu_simple_commandu_untagged_response(uselfucommanduargsunameutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuuid s      u IMAP4.uidcCs|jd|S(u_Unsubscribe from old mailbox. (typ, [data]) = .unsubscribe(mailbox) u UNSUBSCRIBE(u_simple_command(uselfumailbox((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu unsubscribe9suIMAP4.unsubscribecGs;|j}|tkr+|jft|.xatom(name, arg, ...) Returns response appropriate to extension command `name'. (uupperuCommandsustateu_simple_command(uselfunameuargs((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuxatomAs  u IMAP4.xatomcCsO|dkrd}n|j}||kr>||j|n |g|||jjd}|r:|j|djddndS(NuBYEiuasciiureplacei(uuntagged_responsesugetuabortudecode(uselfubye((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu _check_byeesuIMAP4._check_byec Gs|jt|krKd|_|jd||jdjt|fnx*d D]"}||jkrR|j|=qRqRWd|jkr|j r|jdn|j }t |d}|d |}xO|D]G}|dkrqnt |t r t |d}n|d |}qW|j}|dk rd|_t |t |jkr`|}qd}|t d t|d}ny|j|tWnAtjtfk r} z|jd | WYdd} ~ XnX|dkr|Sxx!|jr|j|r|SqW|r.||j}ny|j||jtWnAtjtfk r} z|jd | WYdd} ~ XnX|sPqq|S( Nu9command %s illegal in state %s, only allowed in states %su, uOKuNOuBADu READ-ONLYu#mailbox status changed to READ-ONLYuASCIIs u {%s}usocket error: %s(uOKuNOuBAD(ustateuCommandsuNoneuliteraluerrorujoinuuntagged_responsesu is_readonlyureadonlyu_new_tagubytesu isinstanceustrutypeu_commandulenusenduCRLFusocketuOSErroruabortu _get_responseutagged_commandsucontinuation_response( uselfunameuargsutyputagudatauarguliteralu literatoruval((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu_commandks^             &   &uIMAP4._commandcCs|dkr|jny|j|\}}Wn|jk ru}z|jd||fWYdd}~XnA|jk r}z|jd||fWYdd}~XnX|dkr|jn|dkr|jd|||fn||fS(NuLOGOUTucommand: %s => %suBADu%s command error: %s %s(u _check_byeu_get_tagged_responseuabortuerror(uselfunameutagutypudatauval((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu_command_completes  +,   uIMAP4._command_completecCsk|j\}}|dgkr3|jdnt|dd}|j}t|j|_dS(Nu"no CAPABILITY response from serveriuASCIIi(u capabilityuNoneuerrorustruupperutupleusplitu capabilities(uselfutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu_get_capabilitiess  uIMAP4._get_capabilitiescCsi|j}|j|j|r|jjd}||jkrX|jd|n|jjd}t|d}|jjd}||gf|j|=s u ic Cs7tj|}|sd St|jd}|jd}t|jd}t|jd}t|jd}t|jd}t|jd}t|jd} t|jd } | d | d } |d kr| } n||||||dddf } tj| | } tj | S(uParse 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. umonuzonenudayuyearuhouruminusecuzonehuzonemi<s-iNiii( u InternalDateumatchuNoneuMon2numugroupuintucalendarutimegmutimeu localtime(urespumoumonuzonenudayuyearuhouruminusecuzonehuzonemuzoneuttuutc((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuInternaldate2tuple?s$  !cCs\d}d}tt|}x7|rWt|d\}}|||d|}q!W|S(u-Convert integer to A-P string representation.ssABCDEFGHIJKLMNOPii(uintuabsudivmod(unumuvaluAPumod((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuInt2APbs cCs2tj|}|sfSt|jdjS(u-Convert IMAP4 flags response to python tuple.uflags(uFlagsumatchutupleugroupusplit(urespumo((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu ParseFlagsoscCst|ttfr3tj|tjj}n6t|try |j }Wntt k rt j r|d}|d krt j t j|d}nt jt jf| }n t j }YnXtd|}tdt||dd}not|tr0|jdkr'tdn|}n9t|tr]|d|d fdkr]|Std d jt|j}|j|S(uConvert 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. iiusecondsutzinfoNiudate_time must be awareiu"udate_time not of a known typeu"%d-{}-%Y %H:%M:%S %z"ii(u"u"(u isinstanceuintufloatudatetimeu fromtimestamputimezoneuutcu astimezoneutupleu tm_gmtoffuAttributeErrorutimeudaylightu localtimeumktimeualtzoneu timedeltautzinfouNoneu ValueErrorustruformatuMonthsumonthustrftime(u date_timeudtugmtoffudstudeltaufmt((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuTime2Internaldatezs0       % ) u__main__ud:s:u-du-suuIMAP password for %s on %s: u localhostuJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)suuseru ulfuloginucreateu /tmp/xxx 1urenameu/tmp/yyyu /tmp/yyz 2uappendulistu/tmpuyy*uselectusearchuSUBJECTutestufetchu1u(FLAGS INTERNALDATE RFC822)ustoreuFLAGSu (\Deleted)u namespaceuexpungeurecentucloseuresponseu UIDVALIDITYuuiduALLuEXISTSulogoutcCsitjd||ftt||\}}tjd|||f|dkre|dn|S(Nu%s %su %s => %s %suNOi(uMu_mesgugetattr(ucmduargsutypudat((u,/opt/alt/python33/lib64/python3.3/imaplib.pyuruns  urunuPROTOCOL_VERSION = %suCAPABILITIES = %ru/tmp/uyy%u .*"([^"]+)"$udeleteu%su:(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)u All tests OK.u Tests failed.u8 If you would like to see debugging output, try: %s -d5 (Vu__doc__u __version__ubinasciiuerrnourandomureusocketu subprocessusysutimeucalendarudatetimeutimezoneu timedeltauiouDEFAULT_BUFFER_SIZEussluTrueuHAVE_SSLu ImportErroruFalseu__all__uCRLFuDebugu IMAP4_PORTuIMAP4_SSL_PORTuAllowedVersionsu_MAXLINEuCommandsucompileu ContinuationuFlagsu InternalDateuASCIIuLiteraluMapCRLFu Response_codeuUntagged_responseuUntagged_statusuIMAP4u IMAP4_SSLuappendu IMAP4_streamu_AuthenticatorusplituMonthsu enumerateuMon2numuInternaldate2tupleuInt2APu ParseFlagsuTime2Internaldateu__name__ugetoptugetpassuargvuoptlistuargsuerroruvaluNoneustream_commanduoptuintuhostugetuseruUSERuPASSWDu test_mesgu test_seq1u test_seq2urunuMustateu_mesguPROTOCOL_VERSIONu capabilitiesucmdumlumatchumougroupupathudatuuiduprint(((u,/opt/alt/python33/lib64/python3.3/imaplib.pyu s8 l                                         1/9,# # ) )%