Pc@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl Zddl Z y(ej dkre nddlZWne k reZnXddlZej0ejrejddenddlZWdQXdddd d d d d dddddddddgZdfdYZdefdYZdefdYZdefdYZdefdYZd efdYZd efdYZd efd YZd ejj fd!YZ d e fd"YZ!d#e fd$YZ"de"fd%YZ#de fd&YZ$de fd'YZ%de"fd(YZ&d)fd*YZ'd+e'fd,YZ(e)d-Z*d.Z+d/Z,d0Z-d1Z.d2Z/d3fd4YZ0de0fd5YZ1de1fd6YZ2de0fd7YZ3dfd8YZ4de0fd9YZ5d:e6fd;YZ7d<e7fd=YZ8d>e7fd?YZ9d@e7fdAYZ:dBe7fdCYZ;dS(DsDRead/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.iNtos2emxtignores.*rfc822 has been removedtMailboxtMaildirtmboxtMHtBabyltMMDFtMessagetMaildirMessaget mboxMessaget MHMessaget BabylMessaget MMDFMessaget UnixMailboxtPortableUnixMailboxt MmdfMailboxt MHMailboxt BabylMailboxcBs.eZdZdedZdZdZdZdZ dZ ddZ dZ d Z d Zd Zd Zd ZdZdZdZdZdZdZdZdZdZddZdZddZdZdZdZ dZ!e"dZ#RS( s*A group of messages in a particular place.cCs.tjjtjj||_||_dS(sInitialize a Mailbox instance.N(tostpathtabspatht expandusert_patht_factory(tselfRtfactorytcreate((s..\python\lib\mailbox.pyt__init__-s!cCstddS(s$Add message and return assigned key.s&Method must be implemented by subclassN(tNotImplementedError(Rtmessage((s..\python\lib\mailbox.pytadd2scCstddS(s=Remove the keyed message; raise KeyError if it doesn't exist.s&Method must be implemented by subclassN(R(Rtkey((s..\python\lib\mailbox.pytremove6scCs|j|dS(N(R!(RR ((s..\python\lib\mailbox.pyt __delitem__:scCs)y|j|Wntk r$nXdS(s'If the keyed message exists, remove it.N(R!tKeyError(RR ((s..\python\lib\mailbox.pytdiscard=s cCstddS(s>Replace the keyed message; raise KeyError if it doesn't exist.s&Method must be implemented by subclassN(R(RR R((s..\python\lib\mailbox.pyt __setitem__DscCs*y|j|SWntk r%|SXdS(s9Return the keyed message, or default if it doesn't exist.N(t __getitem__R#(RR tdefault((s..\python\lib\mailbox.pytgetHs cCs0|js|j|S|j|j|SdS(s=Return the keyed message; raise KeyError if it doesn't exist.N(Rt get_messagetget_file(RR ((s..\python\lib\mailbox.pyR&Os  cCstddS(s4Return a Message representation or raise a KeyError.s&Method must be implemented by subclassN(R(RR ((s..\python\lib\mailbox.pyR)VscCstddS(s3Return a string representation or raise a KeyError.s&Method must be implemented by subclassN(R(RR ((s..\python\lib\mailbox.pyt get_stringZscCstddS(s6Return a file-like representation or raise a KeyError.s&Method must be implemented by subclassN(R(RR ((s..\python\lib\mailbox.pyR*^scCstddS(sReturn an iterator over keys.s&Method must be implemented by subclassN(R(R((s..\python\lib\mailbox.pytiterkeysbscCst|jS(sReturn a list of keys.(tlistR,(R((s..\python\lib\mailbox.pytkeysfsccsEx>|jD]0}y||}Wntk r7q nX|Vq WdS(s%Return an iterator over all messages.N(R,R#(RR tvalue((s..\python\lib\mailbox.pyt itervaluesjs  cCs |jS(N(R0(R((s..\python\lib\mailbox.pyt__iter__sscCst|jS(s,Return a list of messages. Memory intensive.(R-R0(R((s..\python\lib\mailbox.pytvaluesvsccsKxD|jD]6}y||}Wntk r7q nX||fVq WdS(s.Return an iterator over (key, message) tuples.N(R,R#(RR R/((s..\python\lib\mailbox.pyt iteritemszs  cCst|jS(s9Return a list of (key, message) tuples. Memory intensive.(R-R3(R((s..\python\lib\mailbox.pytitemsscCstddS(s9Return True if the keyed message exists, False otherwise.s&Method must be implemented by subclassN(R(RR ((s..\python\lib\mailbox.pythas_keyscCs |j|S(N(R5(RR ((s..\python\lib\mailbox.pyt __contains__scCstddS(s*Return a count of messages in the mailbox.s&Method must be implemented by subclassN(R(R((s..\python\lib\mailbox.pyt__len__scCs(x!|jD]}|j|q WdS(sDelete all messages.N(R,R$(RR ((s..\python\lib\mailbox.pytclearscCs4y||}Wntk r"|SX|j||S(s3Delete the keyed message and return it, or default.(R#R$(RR R'tresult((s..\python\lib\mailbox.pytpops   cCs7x0|jD]}||j|fSWtddS(s6Delete an arbitrary (key, message) pair and return it.sNo messages in mailboxN(R,R:R#(RR ((s..\python\lib\mailbox.pytpopitemscCst|dr|j}n$t|dr<|j}n|}t}x<|D]4\}}y|||From treadtsFrom s>From isInvalid message type: %sN(t isinstancetemailRRtStringIOt generatort GeneratortflattentseektwriteRGtreplaceRtlineseptstrR<R>treadlinet startswitht TypeErrorttype(RRttargett mangle_from_tbuffertgentline((s..\python\lib\mailbox.pyt _dump_messages*   %   N($t__name__t __module__t__doc__tNoneR>RRR!R"R$R%R(R&R)R+R*R,R.R0R1R2R3R4R5R6R7R8R:R;RBRCRDRERFR=R](((s..\python\lib\mailbox.pyR*s>                         cBseZdZdZejedZdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZRS(sA qmail-style Maildir mailbox.t:cCstj||||tjj|js|rtj|jdtjtjj|jddtjtjj|jddtjtjj|jddqt|jni|_ d|_ dS(sInitialize a Maildir instance.ittmptnewtcurN( RRRRtexistsRtmkdirtjointNoSuchMailboxErrort_tocRat _last_read(RtdirnameRR((s..\python\lib\mailbox.pyRs""% cCs|j}z|j||Wdt|Xt|trw|j}|j|j}||jkrd}qn d}d}tj j |j j |jd}tj j |j|||}yLttdrtj|j |tj|j ntj|j |WnKtk r`}tj|j |jtjkrZtd|qanXt|trtj|tj j||jfnd|_|S(s$Add message and return assigned key.NRHRditlinks$Name clash with existing message: %s(t _create_tmpR]t _sync_closeRIR t get_subdirtcolontget_infoRRtbasenametnametsplitRhRR<RmR!trenametOSErrorterrnotEEXISTtExternalClashErrortutimetgetatimetget_dateRaRk(RRttmp_filetsubdirtsuffixtuniqtdestte((s..\python\lib\mailbox.pyRs8    % + cCs5tjtjj|j|j|d|_dS(s=Remove the keyed message; raise KeyError if it doesn't exist.N(RR!RRhRt_lookupRaRk(RR ((s..\python\lib\mailbox.pyR!s(cCsSy|j|Wn;tk r$n+tk rN}|jtjkrOqOnXdS(s'If the keyed message exists, remove it.N(R!R#RwRxtENOENT(RR R((s..\python\lib\mailbox.pyR$%s c Cs'|j|}|j|}|j|}t|trE|}n|}tjj|}|j|kr|j|j|jd}nd}|j |tjj |j |||} tj tjj |j || t|trtj | tjj| |jfnd|_dS(s>Replace the keyed message; raise KeyError if it doesn't exist.iRHN(RRRIR RRRlRqRuR$RhRRvR{R|R}RaRk( RR Rt old_subpathttemp_keyt temp_subpathtdominant_subpathRRtnew_path((s..\python\lib\mailbox.pyR%0s"   "cCs|j|}ttjj|j|d}z+|jrN|j|}n t|}Wd|jXtjj |\}}|j ||j |kr|j |j |j dn|j tjjtjj|j||S(s4Return a Message representation or raise a KeyError.trNi(RtopenRRRhRRR RFRut set_subdirRqtset_infotset_datetgetmtime(RR tsubpathtftmsgRRt((s..\python\lib\mailbox.pyR)Is!    +cCsJttjj|j|j|d}z|jSWd|jXdS(s3Return a string representation or raise a KeyError.RN(RRRRhRRRGRF(RR R((s..\python\lib\mailbox.pyR+[s*cCs4ttjj|j|j|d}t|S(s6Return a file-like representation or raise a KeyError.trb(RRRRhRRt _ProxyFile(RR R((s..\python\lib\mailbox.pyR*cs*ccsO|jx>|jD]3}y|j|Wntk rAqnX|VqWdS(sReturn an iterator over keys.N(t_refreshRjRR#(RR ((s..\python\lib\mailbox.pyR,hs  cCs|j||jkS(s9Return True if the keyed message exists, False otherwise.(RRj(RR ((s..\python\lib\mailbox.pyR5rs cCs|jt|jS(s*Return a count of messages in the mailbox.(RtlenRj(R((s..\python\lib\mailbox.pyR7ws cCs d|_dS(s"Write any pending changes to disk.N(RaRk(R((s..\python\lib\mailbox.pyRC|scCsdS(sLock the mailbox.N((R((s..\python\lib\mailbox.pyRDscCsdS(s#Unlock the mailbox if it is locked.N((R((s..\python\lib\mailbox.pyREscCsdS(sFlush and close the mailbox.N((R((s..\python\lib\mailbox.pyRFscCsg}xttj|jD]`}t|dkr|ddkrtjjtjj|j|r|j|dqqW|S(sReturn a list of folder names.iit.(RtlistdirRRRtisdirRhtappend(RR9tentry((s..\python\lib\mailbox.pyt list_folderss "$cCs/ttjj|jd|d|jdtS(s/Return a Maildir instance for the named folder.RRR(RRRRhRRR=(Rtfolder((s..\python\lib\mailbox.pyt get_folders cCstjj|jd|}t|d|j}tjj|d}tjj|stjtj|tj tj Bdn|S(s>Create a folder and return a Maildir instance representing it.RRt maildirfolderi( RRRhRRRRfRFRtO_CREATtO_WRONLY(RRRR9tmaildirfolder_path((s..\python\lib\mailbox.pyt add_folders cCstjj|jd|}xwtjtjj|dtjtjj|dD];}t|dks|ddkrWtd|qWqWWxutj|D]d}|dkr|dkr|dkrtjjtjj||rtd||fqqWxtj|d t D]i\}}}x*|D]"}tj tjj||q:Wx*|D]"}tj tjj||qgWq$Wtj |d S( s-Delete the named folder, which must be empty.RRdReiisFolder contains message(s): %sRcs%Folder contains subdirectory '%s': %sttopdownN( RRRhRRRt NotEmptyErrorRtwalkR=R!trmdir(RRRRtroottdirstfiles((s..\python\lib\mailbox.pyt remove_folders #"$!%   $cCstj}xptjtjj|jdD]M}tjj|jd|}|tjj|dkr.tj|q.q.WdS(sDelete old files in "tmp".Rci@N(ttimeRRRRhRR|R!(RtnowRR((s..\python\lib\mailbox.pytcleans  (icCsItj}tj}d|kr9|jdd}nd|krZ|jdd}ndt|t|ddtjtj|f}tj j |j d|}ytj |Wnvt k r4}|jtjkr.tjd7_yt|SWq1t k r*}|jtjkr+q+q1Xq5nXtd |d S( s=Create a file in the tmp subdirectory and open and return it.t/s\057Rbs\072s%s.M%sP%sQ%s.%sig.ARcs&Name clash prevented file creation: %sN(Rtsockett gethostnameRQtintRtgetpidRt_countRRhRtstatRwRxRt_create_carefullyRyRz(RRthostnameRRR((s..\python\lib\mailbox.pyRns,    & csjdk r^xLdD]=}tjjtjjj|}|jkrPqqWdSntjd}i_fd}|d|d|_dS(s!Update table of contents mapping.RdReNicstjjj|}xvtj|D]e}tjj||}tjj|r[q(n|jjd}tjj||j|tnextt StopIterationRaR#(R((s..\python\lib\mailbox.pyRs   ( R^R_R`Rqtrfc822RR>RRR!R$R%R)R+R*R,R5R7RCRDRERFRRRRRRRnRRR(((s..\python\lib\mailbox.pyRs6 $                ! t_singlefileMailboxcBseZdZdedZdZdZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZddZdZRS(sA single-file mailbox.cCstj||||yt|jd}Wn|tk r}|jtjkr}|rkt|jd}qt|jq|jtjkrt|jd}qnX||_ d|_ d|_ t |_t |_d|_dS(s!Initialize a single-file mailbox.srb+swb+RiN(RRRRtIOErrorRxRRitEACCESt_fileRaRjt _next_keyR=t_pendingt_lockedt _file_length(RRRRRR((s..\python\lib\mailbox.pyRs"     cCsF|j|j||j|j<|jd7_t|_|jdS(s$Add message and return assigned key.i(Rt_append_messageRjRR>R(RR((s..\python\lib\mailbox.pyR5s   cCs$|j||j|=t|_dS(s=Remove the keyed message; raise KeyError if it doesn't exist.N(RRjR>R(RR ((s..\python\lib\mailbox.pyR!=s  cCs0|j||j||j|Replace the keyed message; raise KeyError if it doesn't exist.N(RRRjR>R(RR R((s..\python\lib\mailbox.pyR%Cs ccs-|jx|jjD] }|VqWdS(sReturn an iterator over keys.N(RRjR.(RR ((s..\python\lib\mailbox.pyR,Is cCs|j||jkS(s9Return True if the keyed message exists, False otherwise.(RRj(RR ((s..\python\lib\mailbox.pyR5Os cCs|jt|jS(s*Return a count of messages in the mailbox.(RRRj(R((s..\python\lib\mailbox.pyR7Ts cCs&|js"t|jt|_ndS(sLock the mailbox.N(Rt _lock_fileRR>(R((s..\python\lib\mailbox.pyRDYs  cCs&|jr"t|jt|_ndS(s#Unlock the mailbox if it is locked.N(Rt _unlock_fileRR=(R((s..\python\lib\mailbox.pyRE_s  c Cs}|js dS|jdk s"t|jjdd|jj}||jkrotd|j|fnt |j }yi}|j |xt |jj D]}|j|\}}|jj||j||j}xOtr=|jjtd||jj}|dkr-Pn|j|qW||jf||<|j|qWWn$|jtj|jnXt||jjytj|j|j Wnrtk r2} | jtjkstjdkr,| jtjkr,tj|j tj|j|j q3nXt|j d|_||_t|_|j ryt!|jd tndS( s"Write any pending changes to disk.Niis4Size of mailbox file changed (expected %i, found %i)iRHtos2srb+tdotlock("RRjRatAssertionErrorRROttellRRzt_create_temporaryRt_pre_mailbox_hooktsortedR.t_pre_message_hookR>RGtminRPt_post_message_hookRFRR!RtRoRvRwRxRyRRR=RR( Rtcur_lentnew_filetnew_tocR tstarttstopt new_startRZR((s..\python\lib\mailbox.pyRCesX         !   cCsdS(s,Called before writing the mailbox to file f.N((RR((s..\python\lib\mailbox.pyRscCsdS(s-Called before writing each message to file f.N((RR((s..\python\lib\mailbox.pyRscCsdS(s,Called after writing each message to file f.N((RR((s..\python\lib\mailbox.pyRscCs1|j|jr |jn|jjdS(sFlush and close the mailbox.N(RCRRERRF(R((s..\python\lib\mailbox.pyRFs   cCsb|jdkr|jn|dk r^y|j|SWq^tk rZtd|q^XndS(s'Return (start, stop) or raise KeyError.sNo message with key: %sN(RjRat _generate_tocR#(RR ((s..\python\lib\mailbox.pyRs   cCse|jjdd|j|j|j|}|j|j|jj|jj|_|S(s;Append message to mailbox and return (start, stop) offsets.ii(RRORt_install_messageRRCRR(RRtoffsets((s..\python\lib\mailbox.pyRs N(R^R_R`RaR>RRR!R%R,R5R7RDRERCRRRRFRR(((s..\python\lib\mailbox.pyRs"         :     t _mboxMMDFcBs>eZdZeZdZedZedZdZ RS(sAn mbox or MMDF mailbox.cCs|j|\}}|jj||jjjtjd}|jj||jj}|j |jtjd}|j |d|S(s4Return a Message representation or raise a KeyError.RHs i( RRRORTRQRRRRGRt_message_factorytset_from(RR RRt from_linetstringR((s..\python\lib\mailbox.pyR)scCsm|j|\}}|jj||s;|jjn|jj||jj}|jtjdS(s3Return a string representation or raise a KeyError.s ( RRRORTRGRRQRRR(RR tfrom_RRR((s..\python\lib\mailbox.pyR+s cCsW|j|\}}|jj||s;|jjnt|j|jj|S(s6Return a file-like representation or raise a KeyError.(RRRORTt _PartialFileR(RR RRR((s..\python\lib\mailbox.pyR*s cCs/d}t|tri|jdri|jd}|dkrZ|| }||d}q|}d}nFt|trd|j}n$t|tjj r|j }n|dkrdt j t j }n|jj}|jj|tj|j||j|j|jj}||fS(s1Format a message and blindly write to self._file.sFrom s iiRHsFrom MAILER-DAEMON %sN(RaRIRSRUtfindt_mboxMMDFMessagetget_fromRJRRt get_unixfromRtasctimetgmtimeRRRPRRRR]t _mangle_from_(RRRtnewlineRR((s..\python\lib\mailbox.pyRs&    ( R^R_R`R>RR)R=R+R*R(((s..\python\lib\mailbox.pyRs  cBs5eZdZeZdedZdZdZRS(sA classic mbox mailbox.cCs#t|_tj||||dS(sInitialize an mbox mailbox.N(R RRR(RRRR((s..\python\lib\mailbox.pyRs cCs)|jdkr%|jtjndS(s-Called before writing each message to file f.iN(RRPRRR(RR((s..\python\lib\mailbox.pyR scCsgg}}|jjdxtr|jj}|jj}|jdrt|t|kr|j|ttj n|j|q |dkr |j|Pq q Wt t t |||_ t|j |_|jj|_dS(s0Generate key-to-(start, stop) table of contents.isFrom RHN(RROR>RRTRURRRRRtdictt enumeratetzipRjRR(Rtstartststopstline_posR\((s..\python\lib\mailbox.pyRs    N( R^R_R`R>RRaRRR(((s..\python\lib\mailbox.pyRs  cBs8eZdZdedZdZdZdZRS(sAn MMDF mailbox.cCs#t|_tj||||dS(sInitialize an MMDF mailbox.N(R RRR(RRRR((s..\python\lib\mailbox.pyR%s cCs|jdtjdS(s-Called before writing each message to file f.sN(RPRRR(RR((s..\python\lib\mailbox.pyR*scCs|jtjdtjdS(s,Called after writing each message to file f.sN(RPRRR(RR((s..\python\lib\mailbox.pyR.scCsbgg}}|jjdd}xtr|}|jj}|jj}|jdtjr|j|xtr|}|jj}|jj}|dtjkr|j|t tjPqv|dkrv|j|PqvqvWq&|dkr&Pq&q&Wt t t |||_ t |j |_|jjdd|jj|_dS(s0Generate key-to-(start, stop) table of contents.isRHiN(RROR>RTRRURRRRRRRRRjRR(RRRtnext_posRR\((s..\python\lib\mailbox.pyR2s2        N( R^R_R`RaR>RRRR(((s..\python\lib\mailbox.pyR"s   cBseZdZdedZdZdZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZdZdZdZdZdZdZRS(sAn MH mailbox.cCstj||||tjj|js|rtj|jdtjtjtjj |jdtj tj Btj Bdqt |jnt|_dS(sInitialize an MH instance.is .mh_sequencesiN(RRRRRfRRgRFRRhRtO_EXCLRRiR=R(RRRR((s..\python\lib\mailbox.pyRRs!!cCs|j}t|dkr'd}nt|d}tjj|jt|}t|}zj|j rzt |nz6|j ||t |t r|j||nWd|j rt|nXWdt|X|S(s$Add message and return assigned key.iiN(R.RtmaxRRRhRRSRRRR]RIR t_dump_sequencesRRo(RRR.tnew_keyRR((s..\python\lib\mailbox.pyR^s"       cCstjj|jt|}yt|d}Wn;tk rn}|jtjkrht d|qnX|j tj |dS(s=Remove the keyed message; raise KeyError if it doesn't exist.srb+sNo message with key: %sN( RRRhRRSRRRxRR#RFR!(RR RRR((s..\python\lib\mailbox.pyR!us cCstjj|jt|}yt|d}Wn;tk rn}|jtjkrht d|qonXz|j rt |nzYtj tj|tj tjB|j||t|tr|j||nWd|j rt|nXWdt|XdS(s>Replace the keyed message; raise KeyError if it doesn't exist.srb+sNo message with key: %sN(RRRhRRSRRRxRR#RRRFRtO_TRUNCR]RIR RRRo(RR RRRR((s..\python\lib\mailbox.pyR%s$  # cCs1y^|jr6ttjj|jt|d}n'ttjj|jt|d}Wn;tk r}|jtj krt d|qnXzD|jrt |nzt |}Wd|jrt |nXWd|jXx<|jjD](\}}||kr|j|qqW|S(s4Return a Message representation or raise a KeyError.sr+RsNo message with key: %sN(RRRRRhRRSRRxRR#RR RRFt get_sequencesR3t add_sequence(RR RRRRttkey_list((s..\python\lib\mailbox.pyR)s( *+     cCsy^|jr6ttjj|jt|d}n'ttjj|jt|d}Wn;tk r}|jtj krt d|qnXzB|jrt |nz|j SWd|jrt |nXWd|jXdS(s3Return a string representation or raise a KeyError.sr+RsNo message with key: %sN(RRRRRhRRSRRxRR#RRGRRF(RR RR((s..\python\lib\mailbox.pyR+s  *+   cCssy+ttjj|jt|d}Wn;tk rh}|jtjkrbt d|qinXt |S(s6Return a file-like representation or raise a KeyError.RsNo message with key: %s( RRRRhRRSRRxRR#R(RR RR((s..\python\lib\mailbox.pyR*s+cCs&ttdtj|jDS(sReturn an iterator over keys.css'|]}|jrt|VqdS(N(tisdigitR(t.0R((s..\python\lib\mailbox.pys s(titerRRRR(R((s..\python\lib\mailbox.pyR,scCs(tjjtjj|jt|S(s9Return True if the keyed message exists, False otherwise.(RRRfRhRRS(RR ((s..\python\lib\mailbox.pyR5scCstt|jS(s*Return a count of messages in the mailbox.(RR-R,(R((s..\python\lib\mailbox.pyR7scCsJ|jsFttjj|jdd|_t|jt|_ndS(sLock the mailbox.s .mh_sequencessrb+N( RRRRRhRRRR>(R((s..\python\lib\mailbox.pyRDs $ cCs9|jr5t|jt|j|`t|_ndS(s#Unlock the mailbox if it is locked.N(RRRRoR=(R((s..\python\lib\mailbox.pyREs    cCsdS(s&Write any pending changes to the disk.N((R((s..\python\lib\mailbox.pyRCscCs|jr|jndS(sFlush and close the mailbox.N(RRE(R((s..\python\lib\mailbox.pyRFs cCs[g}xNtj|jD]:}tjjtjj|j|r|j|qqW|S(sReturn a list of folder names.(RRRRRRhR(RR9R((s..\python\lib\mailbox.pyRs $cCs+ttjj|j|d|jdtS(s+Return an MH instance for the named folder.RR(RRRRhRRR=(RR((s..\python\lib\mailbox.pyRscCs%ttjj|j|d|jS(s:Create a folder and return an MH instance representing it.R(RRRRhRR(RR((s..\python\lib\mailbox.pyR scCstjj|j|}tj|}|dgkrUtjtjj|dn"|gkrdntd|jtj|dS(s-Delete the named folder, which must be empty.s .mh_sequencessFolder not empty: %sN(RRRhRRR!RR(RRRtentries((s..\python\lib\mailbox.pyRs c Csmi}ttjj|jdd}z4t|j}x|D]}y|jd\}}t}xo|jD]a}|jr|j t |qwd|jdD\} } |j t | | dqwWgt |D]} | |kr| ^q||)st-iis"Invalid sequence specification: %sN(RRRRhRtsetR.RuRRRRBtrangeRRt ValueErrort FormatErrortrstripRF( RtresultsRtall_keysR\RttcontentsR.tspecRRR ((s..\python\lib\mailbox.pyRs,!     cCsettjj|jdd}z2tjtj|jtjtjBx|j D]\}}t |dkr{qWn|j d|d }t }xtt|D]r}|d|kr|st}|j dqn7|rt }|j d||fn|j d||}qW|rA|j t|d qW|j d qWWWd t|Xd S( s:Set sequences using the given name-to-key-list dictionary.s .mh_sequencessr+is%s:iRs%s %ss %ss N(RRRRhRRFRtRRR3RRPRaR=RRR>RSRo(Rt sequencesRRtR.tprevt completingR ((s..\python\lib\mailbox.pyt set_sequences6s.!& c Cs|j}d}g}x|jD]}|d|kr|j||dfttdrtjtjj|jt |tjj|jt |dtj tjj|jt |qtj tjj|jt |tjj|jt |dn|d7}q%W|d|_ t |dkrEdSxS|jD]E\}}x6|D].\}}||kre|||j|RRR!R%R)R+R*R,R5R7RDRERCRFRRRRRRRR(((s..\python\lib\mailbox.pyROs.                  cBseZdZedZdedZd Zd Z d Z d Z d Z dZ dZdZdZdZdZdZRS(sAn Rmail-style Babyl mailbox.tunseentdeletedtfiledtansweredt forwardedteditedtresentcCs#tj||||i|_dS(sInitialize a Babyl mailbox.N(RRt_labels(RRRR((s..\python\lib\mailbox.pyRscCs;tj||}t|tr7|j|j|Replace the keyed message; raise KeyError if it doesn't exist.N(RR%RIR RR(RR R((s..\python\lib\mailbox.pyR%sc Cs}|j|\}}|jj||jjtj}xXtr|jj}|dtjksu|dkryPn|j|j tjdqAWtj}xTtr|jj}|tjks|dkrPn|j|j tjdqW|jj ||jj j tjd}t |j |}|j|j ||jkry|j|j|n|S(s4Return a Message representation or raise a KeyError.s *** EOOH ***RHs (RRRORTRKR>RRRRPRQRGRR tgetvaluet set_visibleRt set_labels( RR RRtoriginal_headersR\tvisible_headerstbodyR((s..\python\lib\mailbox.pyR)s,       % cCs |j|\}}|jj||jjtj}xXtr|jj}|dtjksu|dkryPn|j|j tjdqAWx8tr|jj}|tjks|dkrPqqW|j |jj ||jj j tjdS(s3Return a string representation or raise a KeyError.s *** EOOH ***RHs ( RRRORTRKR>RRRRPRQR RGR(RR RRR#R\((s..\python\lib\mailbox.pyR+s       %cCs%tj|j|jdtjS(s6Return a file-like representation or raise a KeyError.s (RKR+RQRRR(RR ((s..\python\lib\mailbox.pyR*scCsT|jt}x$|jjD]}|j|q#W|j|jt|S(s4Return a list of user-defined labels in the mailbox.(RRRR2RBtdifference_updatet_special_labelsR-(Rtlabelst label_list((s..\python\lib\mailbox.pyRs   c Csgg}}|jjdd}g}x[tr|}|jj}|jj}|dtjkrt|t|kr|j|ttjn|j|g|jjdj dD]$}|j dkr|j ^q}|j|q,|dks!|dtjkrYt|t|kr|j|ttjqq,|dkr,|j|ttjPq,q,Wt t t |||_t t ||_t|j|_|jjdd|jj|_dS( s0Generate key-to-(start, stop) table of contents.is it,RHsiN(RROR>RTRRRRRRRutstripRRRRjRRR( RRRRt label_listsRR\tlabelR(((s..\python\lib\mailbox.pyRs6    $  cCs9|jdtjtjdj|jtjfdS(s,Called before writing the mailbox to file f.s(BABYL OPTIONS:%sVersion: 5%sLabels:%s%sR*N(RPRRRRhR(RR((s..\python\lib\mailbox.pyRs cCs|jdtjdS(s-Called before writing each message to file f.s N(RPRRR(RR((s..\python\lib\mailbox.pyRscCs|jtjddS(s,Called after writing each message to file f.sN(RPRRR(RR((s..\python\lib\mailbox.pyRscCs,|jj}t|trg}g}x@|jD]2}||jkr\|j|q7|j|q7W|jjdx"|D]}|jjd|qW|jjdx&|D]}|jjd|dqW|jjtj n|jjdtj t|t j j rt j }t jj|td}|j||jdxQtr|j}|jj|jdtj |dks|d kr^Pq^q^W|jjd tj t|trct j } t jj| td} | j|jxtr_| j}|jj|jdtj |dksX|d krPqqWna|jdxQtr|j}|jj|jdtj |dks|d krsPqsqsWxLtr|jd } | d krPn|jj| jdtj qWnt|tr|jd d } | d dkr|jj|| jdtj |jjd tj |jj|| jdtj |jj|| jdtj q|jjd tj tj |jj|jdtj n t|dr|j} t}xtr|j}|jj|jdtj |dkst|d kr+|jjd tj |rt}|j| qPq+q+Wxatr|jd } | d krPn|jj| jdtj qWntdt||jj}||fS(s0Write message contents and return (start, stop).t1s, s,,t R*s1,,is RHs *** EOOH ***is iiRTsInvalid message type: %s(RRRIR RR'RRPRRRRJRRRKRLRMR=RNROR>RTRQt get_visibleRGRSRR<RVRW(RRRtspecial_labelsR(R-t orig_buffertorig_generatorR\t vis_buffert vis_generatorRZt body_startt original_post first_passR((s..\python\lib\mailbox.pyRs                &  "     &(RRRRRRRN(R^R_R`t frozensetR'RaR>RRR!R%R)R+R*RRRRRR(((s..\python\lib\mailbox.pyR{s            cBs,eZdZddZdZdZRS(s0Message with mailbox-format-specific properties.cCst|tjjrM|jtj|t|tr|j|qnt|tru|jtj |n`t |dr|jtj |n8|dkrtjjj |ntdt|dS(sInitialize a Message instance.RGsInvalid message type: %sN(RIRJRRt_become_messagetcopytdeepcopyt _explain_toRStmessage_from_stringR<tmessage_from_fileRaRRVRW(RR((s..\python\lib\mailbox.pyR[s cCs)x"d D]}|j||j|ntdt|dS(s;Copy Maildir-specific state to message insofar as possible.tStRRetOtTtDtFtAs MAILER-DAEMONRtrepliedtflaggedRRtPRs$Cannot convert to specified type: %sN(RIR RNRLRRpRR}RRRPRRRR RR t add_labelRRVRW(RRRM((s..\python\lib\mailbox.pyR=sN    "       N(R^R_R`RaRRpRRLRNRPRQR}RRrRR=(((s..\python\lib\mailbox.pyR xs           RcBs\eZdZd dZdZd dZdZdZdZ dZ dZ RS( s/Message with mbox- or MMDF-specific properties.cCsw|jdtt|tjjrc|j}|dk rc|jdrc|j|dqcntj ||dS(s'Initialize an mboxMMDFMessage instance.s MAILER-DAEMONsFrom iN( RR>RIRJRRRRaRUR(RRtunixfrom((s..\python\lib\mailbox.pyRs  cCs|jS(s Return contents of "From " line.(t_from(R((s..\python\lib\mailbox.pyRscCsN|dk rA|tkr'tj}n|dtj|7}n||_dS(s>Set "From " line, formatting and appending time_ if specified.R/N(RaR>RRRRa(RRttime_((s..\python\lib\mailbox.pyRs   cCs |jdd|jddS(s*Return as a string the flags that are set.tStatusRHsX-Status(R((R((s..\python\lib\mailbox.pyRLscCst|}d \}}x4d D],}||kr||7}|j|qqWx4d D],}||krV||7}|j|qVqVW|djt|7}y|jd|Wn!tk r|jd|nXy|jd|Wn!tk r|jd|nXd S( s)Set the given flags and unset all others.RHRVRWRYRZR[RcsX-StatusN(RHRH(RVRW(RYRZR[(RR!RhRtreplace_headerR#t add_header(RRMt status_flagst xstatus_flagsRO((s..\python\lib\mailbox.pyRNs&          cCs0|jdjt|jt|BdS(s.Set the given flag(s) without changing others.RHN(RNRhRRL(RRO((s..\python\lib\mailbox.pyRPscCsKd|ksd|krG|jdjt|jt|ndS(s7Unset the given string flag(s) without changing others.RcsX-StatusRHN(RNRhRRL(RRO((s..\python\lib\mailbox.pyRQscCst|trt|j}d|kr=|jdnd|krY|jdnd|kru|jdnd|kr|jdnd|kr|jdn|d =|d =d j|jjd }y&|j t j t j |d Wqttfk rqXnlt|trU|j|j|j|jn4t|trt|j}d|kr|jdnd|kr|jdnd|kr|jdn|d =|d =nt|trat|j}d|kr|jdnd|kr4|jdnd|krP|jdn|d =|d =n(t|trsntdt|dS(sACopy mbox- or MMDF-specific state to message insofar as possible.RWReRZR[RVRURYRXtstatussx-statusR/is%a %b %d %H:%M:%S %YRR\R]RRs$Cannot convert to specified type: %sN(RIR RRLRRPRhRRuRtcalendarttimegmRtstrptimeRt OverflowErrorRRNRR RR R_RRVRW(RRRMt maybe_date((s..\python\lib\mailbox.pyR=s^             N( R^R_R`RaRRRRLRNRPRQR=(((s..\python\lib\mailbox.pyRs      cBseZdZRS(s&Message with mbox-specific properties.(R^R_R`(((s..\python\lib\mailbox.pyR RscBsGeZdZddZdZdZdZdZdZ RS(s$Message with MH-specific properties.cCsg|_tj||dS(s!Initialize an MHMessage instance.N(t _sequencesRR(RR((s..\python\lib\mailbox.pyRYs cCs|jS(s4Return a list of sequences that include the message.(Rn(R((s..\python\lib\mailbox.pyR^scCst||_dS(s3Set the list of sequences that include the message.N(R-Rn(RR ((s..\python\lib\mailbox.pyRbscCsNt|tr4||jkrJ|jj|qJntdt|dS(s8Add sequence to list of sequences including the message.ssequence must be a string: %sN(RIRSRnRRVRW(RR((s..\python\lib\mailbox.pyRfscCs,y|jj|Wntk r'nXdS(sARemove sequence from the list of sequences including the message.N(RnR!R(RR((s..\python\lib\mailbox.pytremove_sequencens cCst|trt|j}d|kr=|jdn|jd|jdd|krs|jdnd|kr|jdqn?t|trt|j}d|kr|jdn |jd d|kr|jdnd|kr|jd qnt|trMx|jD]}|j|q3Wnt|t rt|j}d|kr|j dnd|kr|j d qn(t|t rnt d t |d S(s6Copy MH-specific state to message insofar as possible.RReRUR]RZR\RVtRORWR[Rs$Cannot convert to specified type: %sN(RIR RRRRPRR RR R_RRVRW(RRR R((s..\python\lib\mailbox.pyR=us@           N( R^R_R`RaRRRRRoR=(((s..\python\lib\mailbox.pyR Vs     cBsbeZdZd dZdZdZdZdZdZ dZ dZ d Z RS( s'Message with Babyl-specific properties.cCs)g|_t|_tj||dS(s$Initialize an BabylMessage instance.N(RRt_visibleR(RR((s..\python\lib\mailbox.pyRs  cCs|jS(s'Return a list of labels on the message.(R(R((s..\python\lib\mailbox.pyRscCst||_dS(s&Set the list of labels on the message.N(R-R(RR(((s..\python\lib\mailbox.pyR"scCsNt|tr4||jkrJ|jj|qJntdt|dS(s+Add label to list of labels on the message.slabel must be a string: %sN(RIRSRRRVRW(RR-((s..\python\lib\mailbox.pyR_scCs,y|jj|Wntk r'nXdS(s4Remove label from the list of labels on the message.N(RR!R(RR-((s..\python\lib\mailbox.pyt remove_labels cCs t|jS(s3Return a Message representation of visible headers.(RRq(R((s..\python\lib\mailbox.pyR0scCst||_dS(s2Set the Message representation of visible headers.N(RRq(Rtvisible((s..\python\lib\mailbox.pyR!scCsxG|jjD]6}||kr<|jj|||q|j|=qWx=dD]5}||krQ||jkrQ|||j|RRvRwRyR!tLOCK_UN(RRt dotlock_doneRtpre_lock((s..\python\lib\mailbox.pyRYsL  !cCsPtrtj|tjntjj|jdrLtj|jdndS(s*Unlock file f using lockf and dot locking.s.lockN(RRRRRRfRtR!(R((s..\python\lib\mailbox.pyRscCsLtj|tjtjBtjBd}zt|dSWdtj|XdS(sCCreate a file if it doesn't exist and open for reading and writing.isrb+N(RRRRtO_RDWRRF(Rtfd((s..\python\lib\mailbox.pyRs&cCs2td|ttjtjtjfS(sBCreate a temp file based on path and open for reading and writing.s %s.%s.%s.%s(RRRRRRR(R((s..\python\lib\mailbox.pyRs cCs3|jttdr/tj|jndS(s0Ensure changes to file f are physically on disk.tfsyncN(RCR<RRtfileno(R((s..\python\lib\mailbox.pyt _sync_flushs cCst||jdS(s:Close file f, ensuring all changes are physically on disk.N(RRF(R((s..\python\lib\mailbox.pyRos t_MailboxcBs)eZejdZdZdZRS(cCs||_d|_||_dS(Ni(tfptseekpR(RRR((s..\python\lib\mailbox.pyRs  cCst|jdS(N(RRRa(R((s..\python\lib\mailbox.pyR1scCsx|jj|jy|jWn$tk rJ|jj|_dSX|jj}|j|jj|_}||krPqq|jt |j||S(N( RRORt _search_starttEOFErrorRRat _search_endRR(RRR((s..\python\lib\mailbox.pyRs   (R^R_RRRR1R(((s..\python\lib\mailbox.pyRs cBs>eZdZdZdZdZdZdZeZ RS(cCsjxc|jj}|jj}|s0tn|d dkr|j|r|jj|dSqdS(NisFrom (RRRTRt_isrealfromlineRO(RR|R\((s..\python\lib\mailbox.pyRs cCsr|jjx^|jj}|jj}|s8dS|d dkr|j|r|jj|dSqdS(NisFrom (RRTRRRO(RR|R\((s..\python\lib\mailbox.pyRs saFrom \s*[^\s]+\s+\w\w\w\s+\w\w\w\s+\d?\d\s+\d?\d:\d\d(:\d\d)?(\s+[^\s]+)?\s+\d\d\d\d\s*[^\s]*\s*$cCs=|js-ddl}|j|j|_n|jj|S(Ni(t_regexptretcompilet_fromlinepatterntmatch(RR\R((s..\python\lib\mailbox.pyt_strict_isrealfromlines  cCstS(N(R>(RR\((s..\python\lib\mailbox.pyt_portable_isrealfromlinesN( R^R_RRRRaRRRR(((s..\python\lib\mailbox.pyRs $  cBseZejZRS((R^R_RRR(((s..\python\lib\mailbox.pyRscBseZdZdZRS(cCs<x5|jj}|s!tn|d dkrdSqdS(Nis (RRTR(RR\((s..\python\lib\mailbox.pyR s  cCsRxK|jj}|jj}|s+dS|dkr|jj|dSqdS(Ns (RRRTRO(RR|R\((s..\python\lib\mailbox.pyRs (R^R_RR(((s..\python\lib\mailbox.pyR s cBs)eZejdZdZdZRS(cCsddl}|jd}||_tj|j}t|j|}tt|}|j tt ||_ |j j ||_ dS(Nis ^[1-9][0-9]*$(RRRlRRtfilterRtmaptlongtsortRStboxestreverseR(RRlRRtpatR-((s..\python\lib\mailbox.pyR"s    cCst|jdS(N(RRRa(R((s..\python\lib\mailbox.pyR12scCst|js dS|jj}ttjj|j|}|j|}y ||_ Wnt t fk ronX|S(N( RRaR:RRRRhRlRt _mh_msgnotAttributeErrorRV(RtfnRR((s..\python\lib\mailbox.pyR5s  (R^R_RRRR1R(((s..\python\lib\mailbox.pyR s cBseZdZdZRS(cCs8x1|jj}|s!tn|dkrdSqdS(Ns *** EOOH *** (RRTR(RR\((s..\python\lib\mailbox.pyRDs   cCs^xW|jj}|jj}|s+dS|dksC|dkr|jj|dSqdS(Ns s(RRRTRO(RR|R\((s..\python\lib\mailbox.pyRLs(R^R_RR(((s..\python\lib\mailbox.pyRBs tErrorcBseZdZRS(s"Raised for module-specific errors.(R^R_R`(((s..\python\lib\mailbox.pyRYsRicBseZdZRS(s:The specified mailbox does not exist and won't be created.(R^R_R`(((s..\python\lib\mailbox.pyRi\sRcBseZdZRS(s>The specified mailbox is not empty and deletion was requested.(R^R_R`(((s..\python\lib\mailbox.pyR_sRzcBseZdZRS(s)Another process caused an action to fail.(R^R_R`(((s..\python\lib\mailbox.pyRzbsRcBseZdZRS(s)A file appears to have an invalid format.(R^R_R`(((s..\python\lib\mailbox.pyRes(<R`tsysRRRiRRxR;RJt email.messagetemail.generatorRKtplatformt ImportErrorRRatwarningstcatch_warningst py3kwarningtfilterwarningstDeprecationWarningRt__all__RRRRRRRRRRR RR R R R RRR>RRRRRRoRRRRRRt ExceptionRRiRRzR(((s..\python\lib\mailbox.pyts~                     88"-- koF];! -     B"