Ñò §ÚêLc @s~dZddklZedddƒ[dZdZdZd Zdd kZdd kZdd k Z dd k Z dd k Z dd k Z dd k l Z d d ddgZd efd„ƒYZd fd„ƒYZe idƒZd„Zdfd„ƒYZde ifd„ƒYZdefd„ƒYZdfd„ƒYZdd„Zdd„Zd„Zedjo eƒnd S(sŸ MH interface -- purely object-oriented (well, almost) Executive summary: import mhlib mh = mhlib.MH() # use default mailbox directory and profile mh = mhlib.MH(mailbox) # override mailbox location (default from profile) mh = mhlib.MH(mailbox, profile) # override mailbox and profile mh.error(format, ...) # print error message -- can be overridden s = mh.getprofile(key) # profile entry (None if not set) path = mh.getpath() # mailbox pathname name = mh.getcontext() # name of current folder mh.setcontext(name) # set name of current folder list = mh.listfolders() # names of top-level folders list = mh.listallfolders() # names of all folders, including subfolders list = mh.listsubfolders(name) # direct subfolders of given folder list = mh.listallsubfolders(name) # all subfolders of given folder mh.makefolder(name) # create new folder mh.deletefolder(name) # delete folder -- must have no subfolders f = mh.openfolder(name) # new open folder object f.error(format, ...) # same as mh.error(format, ...) path = f.getfullname() # folder's full pathname path = f.getsequencesfilename() # full pathname of folder's sequences file path = f.getmessagefilename(n) # full pathname of message n in folder list = f.listmessages() # list of messages in folder (as numbers) n = f.getcurrent() # get current message f.setcurrent(n) # set current message list = f.parsesequence(seq) # parse msgs syntax into list of messages n = f.getlast() # get last message (0 if no messagse) f.setlast(n) # set last message (internal use only) dict = f.getsequences() # dictionary of sequences in folder {name: list} f.putsequences(dict) # write sequences back to folder f.createmessage(n, fp) # add message from file f as number n f.removemessages(list) # remove messages in list from folder f.refilemessages(list, tofolder) # move messages in list to other folder f.movemessage(n, tofolder, ton) # move one message to a given destination f.copymessage(n, tofolder, ton) # copy one message to a given destination m = f.openmessage(n) # new open message object (costs a file descriptor) m is a derived class of mimetools.Message(rfc822.Message), with: s = m.getheadertext() # text of message's headers s = m.getheadertext(pred) # text of message's headers, filtered by pred s = m.getbodytext() # text of message's body, decoded s = m.getbodytext(0) # text of message's body, not decoded iÿÿÿÿ(twarnpy3ksOthe mhlib module has been removed in Python 3.0; use the mailbox module insteadt stacklevelis ~/.mh_profiles~/Mails .mh_sequencesiÀN(tbisecttMHtErrortFoldertMessagecBseZRS((t__name__t __module__(((s/usr/lib64/python2.6/mhlib.pyR[scBs’eZdZddd„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„ZRS(s<Class representing a particular collection of folders. Optional constructor arguments are the pathname for the directory containing the collection, and the MH profile to use. If either is omitted or empty a default is used; the default directory is taken from the MH profile if it is specified there.cCsÚ|djo t}ntii|ƒ|_|djo|idƒ}n|p t}ntii|ƒ o*|ddjotii d|ƒ}ntii|ƒ}tii |ƒp t d‚n||_dS(s Constructor.tPathit~sMH() path not foundN( tNonet MH_PROFILEtostpatht expandusertprofilet getprofiletPATHtisabstjointisdirR(tselfRR((s/usr/lib64/python2.6/mhlib.pyt__init__fs   % cCsd|i|ifS(sString representation.s MH(%r, %r)(RR(R((s/usr/lib64/python2.6/mhlib.pyt__repr__rscGstiid||ƒdS(sARoutine to print an error. May be overridden by a derived class.s MH error: %s N(tsyststderrtwrite(Rtmsgtargs((s/usr/lib64/python2.6/mhlib.pyterrorvscCst|i|ƒS(s*Return a profile entry, None if not found.(tpicklineR(Rtkey((s/usr/lib64/python2.6/mhlib.pyRzscCs|iS(s9Return the path (the name of the collection's directory).(R(R((s/usr/lib64/python2.6/mhlib.pytgetpath~scCs9ttii|iƒdƒdƒ}|p d}n|S(s&Return the name of the current folder.tcontextsCurrent-Foldertinbox(RR RRR!(RR"((s/usr/lib64/python2.6/mhlib.pyt getcontext‚s   cCsItii|iƒdƒ}t|dƒ}|id|ƒ|iƒdS(s#Set the name of the current folder.R"twsCurrent-Folder: %s N(R RRR!topenRtclose(RR"tfntf((s/usr/lib64/python2.6/mhlib.pyt setcontext‰scCssg}|iƒ}xPti|ƒD]?}tii||ƒ}tii|ƒo|i|ƒq"q"W|iƒ|S(s*Return the names of the top-level folders.(R!R tlistdirRRRtappendtsort(RtfoldersRtnametfullname((s/usr/lib64/python2.6/mhlib.pyt listfolderss  c CsÚtii|i|ƒ}ti|ƒi}|djogSg}ti|ƒ}xx|D]p}tii||ƒ}tii|ƒoBtii||ƒ}|i|ƒ|d}|djoPqÈqXqXW|iƒ|S(scReturn the names of the subfolders in a given folder (prefixed with the given folder name).ii( R RRtstattst_nlinkR+RR,R-( RR/R0tnlinkst subfolderstsubnamestsubnamet fullsubnamet name_subname((s/usr/lib64/python2.6/mhlib.pytlistsubfolders›s"      cCs |idƒS(s<Return the names of all folders and subfolders, recursively.t(tlistallsubfolders(R((s/usr/lib64/python2.6/mhlib.pytlistallfolders³sc Cs/tii|i|ƒ}ti|ƒi}|djogSg}ti|ƒ}xÍ|D]Å}|ddjp t|ƒoqXntii||ƒ}tii|ƒortii||ƒ}|i|ƒtii |ƒp|i |ƒ} || }n|d}|djoPqqXqXW|i ƒ|S(s>Return the names of subfolders in a given folder, recursively.iit,i( R RRR2R3R+t isnumericRR,tislinkR<R-( RR/R0R4R5R6R7R8R9t subsubfolders((s/usr/lib64/python2.6/mhlib.pyR<·s.       cCs t||ƒS(s0Return a new Folder object for the named folder.(R(RR/((s/usr/lib64/python2.6/mhlib.pyt openfolderÓscCsht|idƒ}|o t|ƒot|dƒ}nt}titii|i ƒ|ƒ|ƒdS(s@Create a new folder (or raise os.error if it cannot be created).sFolder-ProtectiN( RRR?tinttFOLDER_PROTECTR tmkdirRRR!(RR/tprotecttmode((s/usr/lib64/python2.6/mhlib.pyt makefolder×s cCs–tii|iƒ|ƒ}xgti|ƒD]V}tii||ƒ}yti|ƒWq+tij o|id|ƒq+Xq+Wti|ƒdS(s‡Delete a folder. This removes files in the folder but not subdirectories. Raise os.error if deleting the folder itself fails.s%s not deleted, continuing...N(R RRR!R+tunlinkRtrmdir(RR/R0R7R8((s/usr/lib64/python2.6/mhlib.pyt deletefolderàs N(RRt__doc__R RRRRR!R$R*R1R:R=R<RBRHRK(((s/usr/lib64/python2.6/mhlib.pyR_s           s ^[1-9][0-9]*$cCsti|ƒdj S(N(t numericprogtmatchR (tstr((s/usr/lib64/python2.6/mhlib.pyR?ïscBsòeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zdd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s'Class representing a particular folder.cCs@||_||_tii|iƒƒptd|‚ndS(s Constructor.s no folder %sN(tmhR/R RRt getfullnameR(RRPR/((s/usr/lib64/python2.6/mhlib.pyRõs  cCsd|i|ifS(sString representation.sFolder(%r, %r)(RPR/(R((s/usr/lib64/python2.6/mhlib.pyRüscGs|ii|ŒdS(sError message handler.N(RPR(RR((s/usr/lib64/python2.6/mhlib.pyRscCstii|ii|iƒS(s'Return the full pathname of the folder.(R RRRPR/(R((s/usr/lib64/python2.6/mhlib.pyRQscCstii|iƒtƒS(s8Return the full pathname of the folder's sequences file.(R RRRQt MH_SEQUENCES(R((s/usr/lib64/python2.6/mhlib.pytgetsequencesfilenamescCstii|iƒt|ƒƒS(s4Return the full pathname of a message in the folder.(R RRRQRO(Rtn((s/usr/lib64/python2.6/mhlib.pytgetmessagefilename scCs|ii|iƒS(s!Return list of direct subfolders.(RPR:R/(R((s/usr/lib64/python2.6/mhlib.pyR:scCs|ii|iƒS(sReturn list of all subfolders.(RPR<R/(R((s/usr/lib64/python2.6/mhlib.pyR<scCs‘g}ti}|i}x8ti|iƒƒD]!}||ƒo||ƒq.q.Wtt|ƒ}|iƒ|o|d|_ n d|_ |S(s€Return the list of messages currently present in the folder. As a side effect, set self.last to the last message (or 0).iÿÿÿÿi( RMRNR,R R+RQtmapRCR-tlast(RtmessagesRNR,R/((s/usr/lib64/python2.6/mhlib.pyt listmessagess     cCsÚh}|iƒ}yt|dƒ}Wntj o|SXx—|iƒ}|pPn|idƒ}t|ƒdjo!|id||iƒfƒn|diƒ}t|diƒdƒi ƒ}|||iismultiple errors:N( RUROR RIRtrenameR,tremovefromallsequencesR`(RtlistterrorstdeletedRTRt commapathR((s/usr/lib64/python2.6/mhlib.pytremovemessagesÑs*ic Cs’g}h}xü|D]ô}|iƒd}|i|ƒ}|i|ƒ} yti|| ƒWn’tij oƒy!ti|| ƒti|ƒWqðttifj oC} |i | ƒyti| ƒWqtij oqXqqðXnX|i |ƒ|||RxcCs7g|_||_||_|o|i|ƒndS(N(tpairstseptrngt fromstring(RtdataRãRä((s/usr/lib64/python2.6/mhlib.pyRs    cCs g|_dS(N(Râ(R((s/usr/lib64/python2.6/mhlib.pytreset scCst|i|iƒS(N(tcmpRâ(Rtother((s/usr/lib64/python2.6/mhlib.pyt__cmp__#scCs t|iƒS(N(thashRâ(R((s/usr/lib64/python2.6/mhlib.pyt__hash__&scCsd|iƒ|i|ifS(NsIntSet(%r, %r, %r)(RkRãRä(R((s/usr/lib64/python2.6/mhlib.pyR)scCs¨|iiƒd}xŽ|t|iƒjow|i|d\}}|i|\}}||djo.|t||ƒfg|i|d|d+q|d}qWdS(Ni(RâR-R`Rp(RR~talotahitblotbhi((s/usr/lib64/python2.6/mhlib.pyt normalize,s .cCs€d}xs|iD]h\}}||jot|ƒ}nt|ƒ|it|ƒ}|o||i|}q|}qW|S(NR;(RâR»RäRã(RRmtlothitt((s/usr/lib64/python2.6/mhlib.pyRk7s   cCsAg}x4|iD])\}}t||dƒ}||}qW|S(Ni(Râtrange(RtlRòRótm((s/usr/lib64/python2.6/mhlib.pyRc@s  cCs"x|D]}|i|ƒqWdS(N(R,(RR‘R~((s/usr/lib64/python2.6/mhlib.pyRjGscCstƒ}|i|_|S(N(RbRâ(RR©((s/usr/lib64/python2.6/mhlib.pytcloneKs  cCs|iddS(Ni(Râ(R((s/usr/lib64/python2.6/mhlib.pytminPscCs|iddS(Niÿÿÿÿ(Râ(R((s/usr/lib64/python2.6/mhlib.pyRpSscCsAx:|iD]/\}}||jo |jnotSq WtS(N(RâtTruetFalse(RtxRòRó((s/usr/lib64/python2.6/mhlib.pytcontainsVs   cCs~xtt|iƒƒD]ê}|i|\}}||jo²|d|jo||f|i|/dev/nulls<-- picksf.listmessages()(sfirstslastscurR‰sprevsnextsfirst:3slast:3scur:3scur:-3sprev:3snext:3s1:3s1:-3s100:3s100:-3s10000:3s10000:-3sall(R tsystemRRPRBR)RhRbRcRntreversedR$RtpopenR¯RVRCR_( Rt testfoldersRôRsR"RlRtstuffR‘((s/usr/lib64/python2.6/mhlib.pyttestÂsV                    t__main__(RLtwarningsRR RRRRDR RRR¹RÔR—Rt__all__t ExceptionRRRRMR?RRR×RbRRuRR(((s/usr/lib64/python2.6/mhlib.pyt6s<         ÿ¦M‰  " *