B Ƣg0X@sNddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl Z ddl Z y ddl Z Wne k rdZ YnXdddddddd d d d d dddddgZejdZGdddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddejjZGdd d eZGd d!d!eZGd"d d eZGd#d d eZGd$d d eZGd%d d eZ Gd&d'd'Z!Gd(d)d)e!Z"dZ d?Z!dFd@dAZ"dS)GrNTcCs tjtj||_||_dS)N)ospathabspath expanduser_path_factory)selfrfactorycreater*/opt/alt/python37/lib/python3.7/mailbox.py__init__$szMailbox.__init__cCs tddS)Nz&Method must be implemented by subclass)NotImplementedError)rmessagerrradd)sz Mailbox.addcCs tddS)Nz&Method must be implemented by subclass)r )rkeyrrrremove-szMailbox.removecCs||dS)N)r$)rr#rrr __delitem__1szMailbox.__delitem__cCs(y||Wntk r"YnXdS)N)r$KeyError)rr#rrrdiscard4szMailbox.discardcCs tddS)Nz&Method must be implemented by subclass)r )rr#r!rrr __setitem__;szMailbox.__setitem__cCs$y ||Stk r|SXdS)N) __getitem__r&)rr#defaultrrrget?s z Mailbox.getc Cs6|js||St|| }||SQRXdS)N)r get_message contextlibclosingget_file)rr#filerrrr)Fs zMailbox.__getitem__cCs tddS)Nz&Method must be implemented by subclass)r )rr#rrrr,NszMailbox.get_messagecCst||S)N)emailmessage_from_bytes get_bytes as_string)rr#rrr get_stringRszMailbox.get_stringcCs tddS)Nz&Method must be implemented by subclass)r )rr#rrrr3YszMailbox.get_bytescCs tddS)Nz&Method must be implemented by subclass)r )rr#rrrr/]szMailbox.get_filecCs tddS)Nz&Method must be implemented by subclass)r )rrrriterkeysaszMailbox.iterkeyscCs t|S)N)listr6)rrrrkeysesz Mailbox.keysc cs@x:|D].}y ||}Wntk r0w YnX|Vq WdS)N)r6r&)rr#valuerrr itervaluesis  zMailbox.itervaluescCs|S)N)r:)rrrr__iter__rszMailbox.__iter__cCs t|S)N)r7r:)rrrrvaluesuszMailbox.valuesc csDx>|D]2}y ||}Wntk r0w YnX||fVq WdS)N)r6r&)rr#r9rrr iteritemsys  zMailbox.iteritemscCs t|S)N)r7r=)rrrritemssz Mailbox.itemscCs tddS)Nz&Method must be implemented by subclass)r )rr#rrr __contains__szMailbox.__contains__cCs tddS)Nz&Method must be implemented by subclass)r )rrrr__len__szMailbox.__len__cCs x|D]}||q WdS)N)r8r')rr#rrrclearsz Mailbox.clearcCs0y ||}Wntk r |SX|||S)N)r&r')rr#r*resultrrrpops   z Mailbox.popcCs*x$|D]}|||fSWtddS)NzNo messages in mailbox)r6rCr&)rr#rrrpopitemszMailbox.popitemc Csxt|dr|}nt|dr(|}n|}d}x6|D].\}}y |||<Wq6tk rbd}Yq6Xq6W|rttddS)Nr=r>FTzNo message with key(s))hasattrr=r>r&)rargsourceZbad_keyr#r!rrrupdates     zMailbox.updatecCs tddS)Nz&Method must be implemented by subclass)r )rrrrflushsz Mailbox.flushcCs tddS)Nz&Method must be implemented by subclass)r )rrrrlocksz Mailbox.lockcCs tddS)Nz&Method must be implemented by subclass)r )rrrrunlockszMailbox.unlockcCs tddS)Nz&Method must be implemented by subclass)r )rrrrclosesz Mailbox.closecCs,y |dStk r&tdYnXdS)Nrz?String input must be ASCII-only; use bytes or a Message instead)encode UnicodeError ValueError)rr!rrr_string_to_bytess zMailbox._string_to_bytesFc Cst|tjjrvt}tj||d}||| d| }| dt }| ||jrr|t sr| t nt|tttjfrt|tjrtdtd|}t|tr||}|r| dd}| dt }| ||jr|t s| t nt|drt|dr2td td|j}d}x|}|d r^|dd d}n|d rz|dd d}|sP|r|drd|dd}| dt }| ||}q8W|jr|r|t s| t ntdt|dS)Nr z8Use of StringIO input is deprecated, use BytesIO insteads From s >From readbufferzDUse of text mode files is deprecated, use a binary mode file insteads  sFrom s>From zInvalid message type: %s) isinstancer1r!rioBytesIO generatorBytesGeneratorflattenseekrSreplacelinesepwrite_append_newlineendswithstrbytesStringIOwarningswarnDeprecationWarninggetvaluerPrErTreadline startswith TypeErrortype) rr!targetZ mangle_from_rTgendataZlastlinelinerrr _dump_messagesZ                   zMailbox._dump_message)NT)N)N)N)F)#__name__ __module__ __qualname__rr"r$r%r'r(r+r)r,r5r3r/r6r8r:r;r<r=r>r?r@rArCrDrHrIrJrKrLrPrcrtrrrrr!s@       c@seZdZdZd5ddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,Zd-d.Zd/d0Zd1d2Zd3d4ZdS)6r:NTcCst||||tj|jdtj|jdtj|jdd|_tj|js|rt|jdx*|j D]}t|dqnWn t |ji|_ ddd|_ d|_ d|_dS) Ntmpnewcur)ryrzr{ir)r{rzg?)rrrrjoinr_pathsexistsmkdirr<r_toc _toc_mtimes _last_read _skewfactor)rdirnamerrrrrrr s  zMaildir.__init__c Cs~|}y|||Wn*tk rB|t|jYnXt|t|t r|| }|j | }||j krd}nd}d}tj |j|j d}tj |j|||}t|t rt|jtj |j|fyLyt|j|Wn(ttfk rt|j|YnXt|jWnNtk rx}z.t|j|jtjkrftd|nWdd}~XYnX|S)Nrzrz$Name clash with existing message: %s) _create_tmprt BaseExceptionrLrr$name _sync_closerYr get_subdircolonget_inforbasenamesplitr|rutimegetatimeget_datelinkAttributeErrorPermissionErrorrenameOSErrorerrnoZEEXISTr)rr!Ztmp_filesubdirsuffixuniqdesterrrr"!sB      z Maildir.addcCs ttj|j||dS)N)rr$rr|r_lookup)rr#rrrr$KszMaildir.removec Cs,y||Wnttfk r&YnXdS)N)r$r&FileNotFoundError)rr#rrrr'OszMaildir.discardc Cs||}||}||}t|tr.|}n|}tj|}|j|kr`|j||jd}nd}| |tj |j |} tj |j |||} t|trt | tj | |ft| | dS)NrWr)rr"rYr rrrrrr'r|rrrrr) rr#r!Z old_subpathZtemp_keyZ temp_subpathZdominant_subpathrrZtmp_pathnew_pathrrrr(Ws"        zMaildir.__setitem__c Cs||}ttj|j|d }|jr4||}nt|}WdQRXtj|\}}| ||j |kr| ||j d| tj tj|j||S)NrbrW)ropenrrr|rrr r set_subdirrset_infoset_dategetmtime)rr#Zsubpathfmsgrrrrrr,rs    zMaildir.get_messagec Cs8ttj|j||d}|tdSQRXdS)NrrQ) rrrr|rrrSr`ra)rr#rrrrr3szMaildir.get_bytescCs$ttj|j||d}t|S)Nr)rrrr|rr _ProxyFile)rr#rrrrr/szMaildir.get_filec csH|x:|jD]0}y||Wntk r8wYnX|VqWdS)N)_refreshrrr&)rr#rrrr6s zMaildir.iterkeyscCs|||jkS)N)rr)rr#rrrr?szMaildir.__contains__cCs|t|jS)N)rlenr)rrrrr@szMaildir.__len__cCsdS)Nr)rrrrrIsz Maildir.flushcCsdS)Nr)rrrrrJsz Maildir.lockcCsdS)Nr)rrrrrKszMaildir.unlockcCsdS)Nr)rrrrrLsz Maildir.closecCs`g}xVt|jD]F}t|dkr|ddkrtjtj|j|r||ddqW|S)Nr.)rlistdirrrrisdirr|append)rrBentryrrr list_folderss zMaildir.list_folderscCs ttj|jd||jddS)NrF)rr)rrrr|rr)rfolderrrr get_folderszMaildir.get_foldercCs\tj|jd|}t||jd}tj|d}tj|sXtt|tj tj Bd|S)Nr)rZ maildirfolderi) rrr|rrrr~rLrO_CREATO_WRONLY)rrrrBZmaildirfolder_pathrrr add_folders zMaildir.add_foldercCs,tj|jd|}xTttj|dttj|dD](}t|dksZ|ddkr>td|q>WxPt|D]B}|dkrv|dkrv|dkrvtjtj||rvtd||fqvWx`tj|d d D]N\}}}x |D]}t tj||qWx |D]}t tj||qWqWt |dS) Nrrzr{rrzFolder contains message(s): %sryz%Folder contains subdirectory '%s': %sF)topdown) rrr|rrrrrwalkr$rmdir)rrrrrootdirsfilesrrr remove_folders   zMaildir.remove_foldercCs\t}xNttj|jdD]4}tj|jd|}|tj|dkr t|q WdS)Nryi@)timerrrr|rrr$)rnowrrrrrcleans z Maildir.cleanrc Cst}t}d|kr$|dd}d|kr8|dd}dt|t|ddttj|f}tj |j d|}yt |Wn@t k rtjd7_yt|Stk rYnXYnXtd |dS) N/z\057rxz\072z%s.M%sP%sQ%s.%srg.Aryz&Name clash prevented file creation: %s)rsocket gethostnamer`intrgetpidr_countrr|rstatr_create_carefullyFileExistsErrorr)rrZhostnamerrrrrrs&    zMaildir._create_tmpcCst|jd|jkrbd}x<|jD]2}tj|j|}||j|krLd}||j|<q$W|sbdSi|_xl|jD]b}|j|}xRt |D]D}tj ||}tj |rq| |j d}tj |||j|<qWqpWt|_dS)NFTr)rrrrrrrr}rrr|rrr)rZrefreshrmtimerrprrrrrs&    zMaildir._refreshcCs|y,tjtj|j|j|r*|j|SWntk r@YnX|y |j|Stk rvtd|dYnXdS)NzNo message with key: %s)rrr~r|rrr&r)rr#rrrr#s zMaildir._lookupcCsVt|ds||_xs   @ rc@s>eZdZdZddZdddZdddZdd d Zd d Zd S) _mboxMMDFTcCsp||\}}|j||jtd}|j||j}||td}| |dd d|S)NrQrXr) rrr_rlr`rarSr_message_factoryset_fromdecode)rr#rr from_linestringrrrrr,s z_mboxMMDF.get_messageFcCst||j|dS)N)unixfrom)r1r2r3r4)rr#from_rrrr5sz_mboxMMDF.get_stringcCsJ||\}}|j||s(|j|j||j}|tdS)NrQ)rrr_rlrSrr`ra)rr#rrrrrrrr3s   z_mboxMMDF.get_bytescCs<||\}}|j||s(|jt|j|j|S)N)rrr_rl _PartialFiler)rr#rrrrrrr/s   z_mboxMMDF.get_filecCs d}t|tr||}t|trf|drf|d}|dkr\|d|}||dd}q|}d}nJt|tr|d}d|}n(t|t j j r| }|dk r|d}|dkrdt t }|j}|j|t|||j|j|j}||fS)NsFrom rQrWrrrsFrom MAILER-DAEMON )rYrerPrfrmfind_mboxMMDFMessageget_fromrMr1r!r get_unixfromrasctimegmtimerrrbrart _mangle_from_)rr!rnewlineZauthorrrrrrr&s0         z_mboxMMDF._install_messageN)F)F)F) rurvrwrr,r5r3r/rrrrrrs   rc@s.eZdZdZdZd ddZddZddZdS) rTNcCst|_t||||dS)N)r rrr)rrrrrrrrLsz mbox.__init__cCs|tdS)N)rbra)rrrrrrQszmbox._post_message_hookcCsgg}}d}|jdx|j}|j}|dr|t|t|krl|rb||ttn ||||d}q|s|r||ttn ||Pq|tkrd}qd}qWtt t |||_ t|j |_ |j|_ dS)NFrsFrom T)rr_rrlrmrrradict enumerateziprrr)rstartsstopsZlast_was_emptyline_posrsrrrrUs0         zmbox._generate_toc)NT)rurvrwrrcrrrrrrrrCs  c@s.eZdZd ddZddZddZd d ZdS) rNTcCst|_t||||dS)N)r rrr)rrrrrrrrzsz MMDF.__init__cCs|dtdS)Ns)rbra)rrrrrrszMMDF._pre_message_hookcCs|tdtdS)Ns)rbra)rrrrrrszMMDF._post_message_hookcCsgg}}|jdd}x|}|j}|j}|dtr||xV|}|j}|j}|dtkr||ttPqN|sN||PqNWq|sPqWtt t |||_ t|j |_ |jdd|j|_ dS)Nrsr)rr_rlrrmrarrrrrrrr)rrrnext_posrrsrrrrs2          zMMDF._generate_toc)NT)rurvrwrrrrrrrrrws c@seZdZd/ddZddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.ZdS)0rNTcCstt||||tj|jsj|r`t|jdtttj |jdtj tj Btj Bdn t |jd|_dS)Niz .mh_sequencesiF)rrrrr~rrrLrr|rO_EXCLrrr)rrrrrrrrs z MH.__init__cCs|}t|dkrd}n t|d}tj|jt|}t|}d}z|j rVt |zfy| ||Wn:t k r|j rt |t|d}t|YnXt|tr|||Wd|j rt |XWd|st|X|S)NrrFT)r8rmaxrrr|rrerrrrtrrrr$rYr _dump_sequences)rr!r8Znew_keyrrclosedrrrr"s6     zMH.addc Csxtj|jt|}yt|d}Wn>tk r`}z |jtjkrNt d|nWdd}~XYnX| t |dS)Nzrb+zNo message with key: %s) rrr|rrerrrrr&rLr$)rr#rrrrrrr$s z MH.removec Cstj|jt|}yt|d}Wn>tk r`}z |jtjkrNt d|nWdd}~XYnXzd|j rrt |z@t t|tj tjB|||t|tr|||Wd|j rt|XWdt|XdS)Nzrb+zNo message with key: %s)rrr|rrerrrrr&rrrLrO_TRUNCrtrYr r rr)rr#r!rrrrrrr(s$   zMH.__setitem__c Csy@|jr$ttj|jt|d}nttj|jt|d}Wn>tk r~}z |jtj krlt d|nWdd}~XYnX|2|jrt |z t |}Wd|jrt |XWdQRXx*|D]\}}||kr||qW|S)Nzrb+rzNo message with key: %s)rrrrr|rrerrrr&rr r get_sequencesr> add_sequence)rr#rrrrkey_listrrrr,s&  zMH.get_messagec Csy@|jr$ttj|jt|d}nttj|jt|d}Wn>tk r~}z |jtj krlt d|nWdd}~XYnX|6|jrt |z| tdS|jrt|XWdQRXdS)Nzrb+rzNo message with key: %srQ)rrrrr|rrerrrr&rrSr`rar)rr#rrrrrr3s z MH.get_bytesc Csfyttj|jt|d}Wn>tk r\}z |jtjkrJt d|nWdd}~XYnXt |S)NrzNo message with key: %s) rrrr|rrerrrr&r)rr#rrrrrr/)s z MH.get_filecCsttddt|jDS)Ncss|]}|rt|VqdS)N)isdigitr).0rrrr 6szMH.iterkeys..)iterrrrr)rrrrr64sz MH.iterkeyscCstjtj|jt|S)N)rrr~r|rre)rr#rrrr?9szMH.__contains__cCstt|S)N)rr7r6)rrrrr@=sz MH.__len__cCs2|js.ttj|jdd|_t|jd|_dS)Nz .mh_sequenceszrb+T)rrrrr|rrr)rrrrrJAs zMH.lockcCs(|jr$t|jt|j|`d|_dS)NF)rrrr)rrrrrKHs   z MH.unlockcCsdS)Nr)rrrrrIPszMH.flushcCs|jr|dS)N)rrK)rrrrrLTszMH.closecCs@g}x6t|jD]&}tjtj|j|r||qW|S)N)rrrrrr|r)rrBrrrrrYs zMH.list_folderscCsttj|j||jddS)NF)rr)rrrr|rr)rrrrrrasz MH.get_foldercCsttj|j||jdS)N)r)rrrr|rr)rrrrrrfsz MH.add_foldercCs`tj|j|}t|}|dgkr:ttj|dn|gkrDntd|jt|dS)Nz .mh_sequenceszFolder not empty: %s)rrr|rrr$rr)rrrentriesrrrrks  zMH.remove_folderc s i}ttj|jdddd}t|x|D]}y|d\}}t}xT|D]H}|rr| t |qVdd|dD\}} | t || d qVWfd d t |D||<t||d kr||=Wq2tk rtd |Yq2Xq2WWdQRX|S)Nz .mh_sequencesrASCII)encodingrxcss|]}t|VqdS)N)r)rxrrrrsz#MH.get_sequences..-rcsg|]}|kr|qSrr)rr#)all_keysrr sz$MH.get_sequences..rz"Invalid sequence specification: %s)rrrr|rsetr8rrr"rrHrangerrrOrrstrip) rresultsrrsrcontentsr8specrrr)rrr ws&    zMH.get_sequencescCs ttj|jdddd}ztt|jtjtjBx| D]\}}t |dkrXqB| |dd}d}xbt t |D]R}|d|kr|sd }| d n*|rd}| d ||fn| d ||}q|W|r| t|d qB| d qBWWdt|XdS)Nz .mh_sequenceszr+r)rrrxFrTrz%s %sz %s )rrrr|rrLrrr r>rrbrrrer)r sequencesrrr8prevZ completingr#rrr set_sequencess.   zMH.set_sequencesc CsL|}d}g}x|D]}|d|kr|||dfy4ttj|jt|tj|jt|dWnHt t fk rt tj|jt|tj|jt|dYnXt tj|jt||d7}qW|d|_ t|dkrdSxB|D]6\}}x*|D]"\}}||kr||||<qWqW||dS)Nrr)r r6rrrrr|rrerrrunlinkrrr>indexr$) rr"r#Zchangesr#rroldrzrrrpacks,      zMH.packcCs||}|}x<|D]0\}}||kr6||q||kr|||=qWx|D]}||krT|g||<qTW||dS)N)r r>rr&r$)rr!r#Zpending_sequencesZ all_sequencesrrsequencerrrr s  zMH._dump_sequences)NT)rurvrwrr"r$r(r,r3r/r6r?r@rJrKrIrLrrrrr r$r(r rrrrrs, "  c@seZdZedddddddhZd$d d Zd d ZddZddZddZ ddZ ddZ ddZ ddZ ddZddZd d!Zd"d#ZdS)%runseendeletedZfiledanswered forwardedZeditedresentNTcCst||||i|_dS)N)rr_labels)rrrrrrrrszBabyl.__init__cCs(t||}t|tr$||j|<|S)N)rr"rYr get_labelsr/)rr!r#rrrr"s  z Babyl.addcCs"t||||jkr|j|=dS)N)rr$r/)rr#rrrr$s  z Babyl.removecCs*t|||t|tr&||j|<dS)N)rr(rYr r0r/)rr#r!rrrr(s zBabyl.__setitem__c Cs||\}}|j||jt}x2|j}|dtksH|sJP||tdq.Wt}x.|j}|tks|sP||tdqjW||j }|j |}|td}t | |} | | ||jkr| |j|| S)Ns *** EOOH ***rQ)rrr_rlrZr[rarbr`rrSr rk set_visibler/ set_labels) rr#rroriginal_headersrsZvisible_headersnZbodyrrrrr,s.        zBabyl.get_messagec Cs||\}}|j||jt}x2|j}|dtksH|sJP||tdq.Wx|j}|tksx|sbPqbW| }||j }|j |}|td}||S)Ns *** EOOH ***rQ) rrr_rlrZr[rarbr`rkrrS) rr#rrr3rsZheadersr4rrrrrr3s$       zBabyl.get_bytescCst||dtS)NrQ)rZr[r3r`ra)rr#rrrr/%szBabyl.get_filecCs@|t}x|jD]}||qW||jt|S)N)rrr/r<rHdifference_update_special_labelsr7)rlabelsZ label_listrrrr0)s  zBabyl.get_labelscCs>gg}}|jdd}g}x|}|j}|j}|dtkrt|t|krf||tt||dd|jdddD}||q |dks|dtkrt|t|kr||ttq |s ||ttPq Wtt t |||_ tt ||_ t|j |_ |jdd|j|_dS) Nrs cSsg|]}|r|qSr)strip)rlabelrrrr@sz'Babyl._generate_toc..r,r)rr_rlrrarrrrrrrr/rr)rrrrZ label_listsrrsr7rrrr2s4        zBabyl._generate_toccCsVdt}|dt7}|}dd|D}|dd|t7}|d7}||dS)NsBABYL OPTIONS:s Version: 5css|]}|VqdS)N)rM)rr9rrrrUsz*Babyl._pre_mailbox_hook..sLabels:r:r;)rar0r|rb)rrZbabylr7rrrrPs zBabyl._pre_mailbox_hookcCs|dtdS)N )rbra)rrrrrrZszBabyl._pre_message_hookcCs|tddS)Nr;)rbra)rrrrrr^szBabyl._post_message_hookcCs|j}t|trg}g}x0|D]$}||jkr@||q&||q&W|jdx |D]}|jd|q`W|jdx$|D]}|jd|dqW|jt n|jdt t|t j j r*t }t j|dd}|||dx4|}|j|d t |d ks6|s Pq W|jd t t|trt } t j| dd} | |xv| }|j|d t |d ks|sPqWn@|dx4|}|j|d t |d ks|sPqWx,|d } | s P|j| d t qWnXt|ttt jfr&t|t jrbtd td |}t|trx||}|dd} | ddkr|j|d| d t |jd t |j|d| d t |j|| dd t n(|jd t t |j|d t n\t |drrt |drRtdtd |j!}|} d}x|}|"dr|ddd }n|"dr|ddd }|j|d t |d ks|s`|rd}|jd t || nPq`Wx|}|sP|"dr$|ddt }n:|"drB|ddt }n|"d r^|ddt }|j|qWnt#dt$||j}||fS)N1s, s,, r:s1,,FrrQs *** EOOH ***iz8Use of StringIO input is deprecated, use BytesIO insteadrRs rrWrlrTzDUse of text mode files is deprecated, use a binary mode file insteadTs rUrVzInvalid message type: %s)%rrrYr r0r6rrbrMrar1r!rrZr[r\r]r^r_rlr` get_visiblerSrfrergrhrirjrkrPrrErTrdrnro)rr!rZspecial_labelsr7r9Z orig_bufferZorig_generatorrsZ vis_bufferZ vis_generatorrTZ body_startZ original_posZ first_passrrrrrbs                         zBabyl._install_message)NT)rurvrw frozensetr6rr"r$r(r,r3r/r0rrrrrrrrrrs     c@s&eZdZdddZddZddZdS) rNcCst|tjjr4|t|t|tr||nt|trP|t |n~t|t rl|t |nbt|t j r|t|nDt|dr|t|n(|dkrtjj|ntdt|dS)NrSzInvalid message type: %s)rYr1r!r_become_messagecopyZdeepcopy _explain_torfr2reZmessage_from_stringrZ TextIOWrapperZmessage_from_filerEZmessage_from_binary_filerrnro)rr!rrrrs      zMessage.__init__cCs8t|dg}x&|jD]}||kr|j||j|<qWdS)N_type_specific_attributes)getattr__dict__)rr!Z type_specificrrrrrAs  zMessage._become_messagecCst|trdStddS)Nz Cannot convert to specified type)rYrrn)rr!rrrrCs zMessage._explain_to)N)rurvrwrrArCrrrrrs c@sxeZdZdddgZdddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZddZdS)r _subdir_info_dateNcCs&d|_d|_t|_t||dS)Nrzr)rHrIrrJrr)rr!rrrrs zMaildirMessage.__init__cCs|jS)N)rH)rrrrrszMaildirMessage.get_subdircCs(|dks|dkr||_n td|dS)Nrzr{z!subdir must be 'new' or 'cur': %s)rHrO)rrrrrrszMaildirMessage.set_subdircCs"|jdr|jddSdSdS)Nz2,rr)rIrm)rrrr get_flags s zMaildirMessage.get_flagscCsddt||_dS)Nz2,r)r|rrI)rflagsrrr set_flagsszMaildirMessage.set_flagscCs$|dt|t|BdS)Nr)rMr|rrK)rflagrrradd_flagszMaildirMessage.add_flagcCs,|r(|dt|t|dS)Nr)rKrMr|r)rrNrrr remove_flagszMaildirMessage.remove_flagcCs|jS)N)rJ)rrrrrszMaildirMessage.get_datecCs6yt||_Wn"tk r0td|dYnXdS)Nzcan't convert to float: %s)floatrJrOrn)rZdaterrrr"szMaildirMessage.set_datecCs|jS)N)rI)rrrrr)szMaildirMessage.get_infocCs&t|tr||_ntdt|dS)Nzinfo must be a string: %s)rYrerIrnro)rinforrrr-s zMaildirMessage.set_infocCst|tr8||||||nht|trt |}d|kr`| d|dkrv| dd|kr| dd|kr| dd|kr| d| d t |nt|trt |}d|kr|d d|kr|d d|kr|d nt|trt |}d|krD|d d|krX|d d|krl|dd|kr|dnt|trntdt|dS)NSRr{OTDFAz MAILER-DAEMONr*repliedflaggedr+r,Pr-z$Cannot convert to specified type: %s)rYr rMrKrrrrrrrOrrrr r r add_labelrrnro)rr!rLrrrrC4sN                           zMaildirMessage._explain_to)N)rurvrwrErrrrKrMrOrPrrrrrCrrrrr s  c@sVeZdZdgZdddZddZdddZd d Zd d Zd dZ ddZ ddZ dS)r_fromNcCsV|ddt|tjjrF|}|dk rF|drF||ddt||dS)Nz MAILER-DAEMONTzFrom rX)rrYr1r!rrrmr)rr!rrrrres  z_mboxMMDFMessage.__init__cCs|jS)N)r^)rrrrrnsz_mboxMMDFMessage.get_fromcCs4|dk r*|dkrt}|dt|7}||_dS)NT )rrrr^)rrZtime_rrrrrs z_mboxMMDFMessage.set_fromcCs|dd|ddS)NStatusrzX-Status)r+)rrrrrKzsz_mboxMMDFMessage.get_flagscCst|}d\}}x&dD]}||kr||7}||qWx&dD]}||kr>||7}||q>W|dt|7}y|d|Wn tk r|d|YnXy|d|Wn tk r|d|YnXdS)N)rr)rTrU)rWrXrYrr`zX-Status)rr$r|rreplace_headerr&Z add_header)rrLZ status_flagsZ xstatus_flagsrNrrrrM~s&  z_mboxMMDFMessage.set_flagscCs$|dt|t|BdS)Nr)rMr|rrK)rrNrrrrOsz_mboxMMDFMessage.add_flagcCs4d|ksd|kr0|dt|t|dS)Nr`zX-Statusr)rMr|rrK)rrNrrrrPsz_mboxMMDFMessage.remove_flagc Cst|trt|}d|kr(|dd|kr:|dd|krL|dd|kr^|dd|krp|d|d =|d =d |d d}y| t t |d Wnttfk rYnXn t|tr||||nt|trZt|}d|kr$|dd|kr8|dd|krL|d|d =|d =nt|trt|}d|kr|dd|kr|dd|kr|d|d =|d =nt|trntdt|dS)NrUr{rXrYrTrSrWrVstatuszx-statusr_z%a %b %d %H:%M:%S %Yr*rZr[r+r,z$Cannot convert to specified type: %s)rYr rrKrrOr|rrrcalendarZtimegmrZstrptimerO OverflowErrorrrMrr r r r]rrnro)rr!rLZ maybe_daterrrrCs^                          z_mboxMMDFMessage._explain_to)N)N) rurvrwrErrrrKrMrOrPrCrrrrr`s  rc@s eZdZdS)r N)rurvrwrrrrr sc@sDeZdZdgZdddZddZddZd d Zd d Zd dZ dS)r _sequencesNcCsg|_t||dS)N)rfrr)rr!rrrrszMHMessage.__init__cCs|jddS)N)rf)rrrrr szMHMessage.get_sequencescCst||_dS)N)r7rf)rr"rrrr$szMHMessage.set_sequencescCs6t|tr"||jkr2|j|ntdt|dS)Nzsequence type must be str: %s)rYrerfrrnro)rr)rrrr s  zMHMessage.add_sequencecCs*y|j|Wntk r$YnXdS)N)rfr$rO)rr)rrrremove_sequenceszMHMessage.remove_sequencecCsJt|trdt|}d|kr*|dn|d|dd|krP|dd|krb|dnt|trt|}d|kr|dn |d d|kr|dd|kr|d nt|trx||D]}||qWn`t|t r(t|}d|kr| dd|krF| d nt|t r6nt d t |dS) Nr*r{rSr[rXrZrTROrUrYr,z$Cannot convert to specified type: %s)rYr rr rrOrr r r r]rrnro)rr!r"r)rrrrCs@                     zMHMessage._explain_to)N) rurvrwrErr r$r rgrCrrrrr s c@s^eZdZddgZdddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ dS)r r/_visibleNcCsg|_t|_t||dS)N)r/rrir)rr!rrrr"szBabylMessage.__init__cCs|jddS)N)r/)rrrrr0(szBabylMessage.get_labelscCst||_dS)N)r7r/)rr7rrrr2,szBabylMessage.set_labelscCs6t|tr"||jkr2|j|ntdt|dS)Nzlabel must be a string: %s)rYrer/rrnro)rr9rrrr]0s  zBabylMessage.add_labelcCs*y|j|Wntk r$YnXdS)N)r/r$rO)rr9rrr remove_label8szBabylMessage.remove_labelcCs t|jS)N)rri)rrrrr??szBabylMessage.get_visiblecCst||_dS)N)rri)rZvisiblerrrr1CszBabylMessage.set_visiblecCsjx6|jD](}||kr,|j|||q |j|=q Wx,dD]$}||kr>||jkr>|||j|<q>WdS)N)ZDateZFromzReply-ToZToZCCZSubject)rir8ra)rheaderrrrupdate_visibleGs  zBabylMessage.update_visiblecCsvt|tr~t|}d|kr*|dn|d|dd|ksNd|krX|dd|krj|dd |kr||d nt|trt|}d|kr|d n |d d |kr|d d|kr|dnt|trt|}d|kr|dd|krr|dnXt|t rT| | x<|D]}| |q>Wnt|t rbntdt|dS)Nr*r{rSr-r.r\r,rTr+rVrhrUrWrYrZz$Cannot convert to specified type: %s)rYr rr0rrOrr r r r1r?r]rrnro)rr!r7r9rrrrCRsF                      zBabylMessage._explain_to)N) rurvrwrErr0r2r]rjr?r1rlrCrrrrr s  c@s eZdZdS)r N)rurvrwrrrrr |sc@seZdZd%ddZd&ddZd'ddZd(dd Zd)d d Zd d ZddZ d*ddZ ddZ ddZ ddZ ddZddZddZdd Zd!d"Zed#d$ZdS)+rNcCs$||_|dkr||_n||_dS)N)rr_pos)rrposrrrrs z_ProxyFile.__init__cCs|||jjS)N)_readrrS)rsizerrrrSsz_ProxyFile.readcCs|||jjS)N)rorread1)rrprrrrqsz_ProxyFile.read1cCs|||jjS)N)rorrl)rrprrrrlsz_ProxyFile.readlinecCs>g}x4|D],}|||dk r |t|8}|dkr Pq W|S)Nr)rr)rsizehintrBrsrrr readliness   z_ProxyFile.readlinesccs x|}|sdS|VqWdS)N)rl)rrsrrrr;s z_ProxyFile.__iter__cCs|jS)N)rm)rrrrrsz_ProxyFile.tellrcCs4|dkr|j|j|j|||j|_dS)Nr)rr_rmr)roffsetwhencerrrr_sz_ProxyFile.seekcCs0t|dr,zt|jdr"|jWd|`XdS)NrrL)rErrL)rrrrrLs   z_ProxyFile.closecCs2|dkr d}|j|j||}|j|_|S)NrW)rr_rmr)rrp read_methodrBrrrros  z_ProxyFile._readcCs|S)Nr)rrrr __enter__sz_ProxyFile.__enter__cGs |dS)N)rL)rexcrrr__exit__sz_ProxyFile.__exit__cCs |jS)N)rreadable)rrrrrzsz_ProxyFile.readablecCs |jS)N)rwritable)rrrrr{sz_ProxyFile.writablecCs |jS)N)rseekable)rrrrr|sz_ProxyFile.seekablecCs |jS)N)rrI)rrrrrIsz_ProxyFile.flushcCs&t|dsdSt|jdsdS|jjS)NrTr F)rErr )rrrrr s   z_ProxyFile.closed)N)N)N)N)N)r)rurvrwrrSrqrlrsr;rr_rLrorwryrzr{r|rIpropertyr rrrrrs"        rc@s8eZdZd ddZddZdddZd d Zd d ZdS)rNcCst|||||_||_dS)N)rr_start_stop)rrrrrrrrsz_PartialFile.__init__cCst||jS)N)rrr~)rrrrrsz_PartialFile.tellrcCs<|dkr|j|_d}n|dkr*|j|_d}t|||dS)Nrrr)r~rmrrr_)rrtrurrrr_sz_PartialFile.seekcCsB|j|j}|dkrdS|dks0|dks0||kr4|}t|||S)Nrr)rrmrro)rrprvZ remainingrrrros  z_PartialFile._readcCst|dr|`dS)Nr)rEr)rrrrrLs z_PartialFile.close)NN)r)rurvrwrrr_rorLrrrrrs    rTc Csd}yZtrpyt|tjtjBWnJtk rn}z,|jtjtjtjfkr\t d|j nWdd}~XYnX|r^yt |j d}| Wn:tk r}z|jtjtjfkrdSWdd}~XYnXy`yt |j |j dd}Wn2ttfk rt |j |j dd}YnXt |j Wn0tk r\t |j t d|j YnXWn8tr|t|tj|rt |j dYnXdS)NFzlockf: lock unavailable: %sz.lockTzdot lock unavailable: %s)fcntllockfZLOCK_EXZLOCK_NBrrZEAGAINrrrrrrLrrrrrr%rr$LOCK_UN)rrZ dotlock_donerZpre_lockrrrr sH    rcCs8trt|tjtj|jdr4t|jddS)Nz.lock)rrrrrr~rr$)rrrrr4src Cs8t|tjtjBtjBd}z t|dSt|XdS)Nizrb+)rrrrO_RDWRrL)rfdrrrr;s rcCs$td|ttttfS)Nz %s.%s.%s.%s)rrrrrrr)rrrrrCsrcCs$|ttdr t|dS)Nfsync)rIrErrfileno)rrrrrIs rcCst||dS)N)rrL)rrrrrOsrc@s eZdZdS)rN)rurvrwrrrrrUsc@s eZdZdS)rN)rurvrwrrrrrXsc@s eZdZdS)rN)rurvrwrrrrr[sc@s eZdZdS)rN)rurvrwrrrrr^sc@s eZdZdS)rN)rurvrwrrrrras)T)/rrrdrrrBrhr1Z email.messageZemail.generatorrZr-r ImportError__all__rarMrrrrrrrrr!rr rr r r r rrrrrrrr Exceptionrrrrrrrrr sn     h8DB4-3z%mqH_c' *