Qf?4dZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl Zddl Z ddl Z ddl mZ ddlZgdZej$j'dZGddZGdd eZGd d eZGd d eZGddeZGddeZGddeZGddeZGddej8j:ZGddeZGddeZGddeZ GddeZ!Gd d!eZ"Gd"d#eZ#Gd$d%Z$Gd&d'e$Z%d8d(Z&d)Z'd*Z(d+Z)d,Z*d-Z+Gd.d/e,Z-Gd0d1e-Z.Gd2d3e-Z/Gd4d5e-Z0Gd6d7e-Z1y#e$rdZYAwxYw)9zDRead/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.N) GenericAlias)MailboxMaildirmboxMHBabylMMDFMessageMaildirMessage mboxMessage MHMessage BabylMessage MMDFMessageErrorNoSuchMailboxError NotEmptyErrorExternalClashError FormatErrorasciiceZdZdZd#dZdZdZdZdZdZ d$d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZd$dZdZd$dZdZdZdZdZ d Z!d!Z"d%d"Z#e$e%Z&y)&rz*A group of messages in a particular place.Nctjjtjj||_||_y)zInitialize a Mailbox instance.N)ospathabspath expanduser_path_factoryselfrfactorycreates ./opt/alt/python312/lib64/python3.12/mailbox.py__init__zMailbox.__init__%s,WW__RWW%7%7%=>  ctd)$Add message and return assigned key.&Method must be implemented by subclassNotImplementedErrorrmessages r"addz Mailbox.add*!"JKKr$ctd)=Remove the keyed message; raise KeyError if it doesn't exist.r'r(rkeys r"removezMailbox.remove.r-r$c&|j|yN)r2r0s r" __delitem__zMailbox.__delitem__2s Cr$cF |j|y#t$rYywxYwz'If the keyed message exists, remove it.N)r2KeyErrorr0s r"discardzMailbox.discard5s%  KK    s   ctd)>Replace the keyed message; raise KeyError if it doesn't exist.r'r(rr1r+s r" __setitem__zMailbox.__setitem__<r-r$cH |j|S#t$r|cYSwxYw)z9Return the keyed message, or default if it doesn't exist.) __getitem__r8)rr1defaults r"getz Mailbox.get@s, ##C( ( N s  !!c|js|j|Stj|j |5}|j|cdddS#1swYyxYw)z=Return the keyed message; raise KeyError if it doesn't exist.N)r get_message contextlibclosingget_file)rr1files r"r?zMailbox.__getitem__GsP}}##C( (##DMM#$674}}T* + +77s AA&ctd)4Return a Message representation or raise a KeyError.r'r(r0s r"rCzMailbox.get_messageOr-r$cftj|j|jS)zReturn a string representation or raise a KeyError. Uses email.message.Message to create a 7bit clean string representation of the message.emailmessage_from_bytes get_bytes as_stringr0s r" get_stringzMailbox.get_stringSs' ''s(;<FFHHr$ctd)z8Return a byte string representation or raise a KeyError.r'r(r0s r"rNzMailbox.get_bytesZr-r$ctd)6Return a file-like representation or raise a KeyError.r'r(r0s r"rFzMailbox.get_file^r-r$ctd)Return an iterator over keys.r'r(rs r"iterkeyszMailbox.iterkeysbr-r$c4t|jS)zReturn a list of keys.)listrWrVs r"keysz Mailbox.keysfsDMMO$$r$c#hK|jD] } ||}|y#t$rYwxYww)z%Return an iterator over all messages.NrWr8rr1values r" itervalueszMailbox.itervaluesjs>==?C S K #  s2#2 /2/2c"|jSr4)r_rVs r"__iter__zMailbox.__iter__ss  r$c4t|jS)z,Return a list of messages. Memory intensive.)rYr_rVs r"valueszMailbox.valuesvsDOO%&&r$c#lK|jD]} ||}||fy#t$rYwxYww)z.Return an iterator over (key, message) tuples.Nr\r]s r" iteritemszMailbox.iteritemszsC==?C S ,  #  s4% 4 1414c4t|jS)z9Return a list of (key, message) tuples. Memory intensive.)rYrerVs r"itemsz Mailbox.itemssDNN$%%r$ctd)9Return True if the keyed message exists, False otherwise.r'r(r0s r" __contains__zMailbox.__contains__r-r$ctd)*Return a count of messages in the mailbox.r'r(rVs r"__len__zMailbox.__len__r-r$cP|jD]}|j|y)zDelete all messages.N)rZr9r0s r"clearz Mailbox.clears99;C LL r$cV ||}|j||S#t$r|cYSwxYw)z3Delete the keyed message and return it, or default.)r8r9)rr1r@results r"popz Mailbox.pops9 #YF S  N s  ((cj|jD]}||j|fcStd)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailbox)rWrrr8r0s r"popitemzMailbox.popitems3==?C#' '#34 4r$ct|dr|j}nt|dr|j}n|}d}|D] \}} |||< |r tdy#t$rd}Y)wxYw)z4Change the messages that correspond to certain keys.rergFTzNo message with key(s)N)hasattrrergr8)rargsourcebad_keyr1r+s r"updatezMailbox.updates~ 3 $]]_F S' "YY[FF"LC #S # 34 4   sA A+*A+ctd)&Write any pending changes to the disk.r'r(rVs r"flushz Mailbox.flushr-r$ctd)Lock the mailbox.r'r(rVs r"lockz Mailbox.lockr-r$ctd)#Unlock the mailbox if it is locked.r'r(rVs r"unlockzMailbox.unlockr-r$ctd)Flush and close the mailbox.r'r(rVs r"closez Mailbox.closer-r$cV |jdS#t$r tdwxYw)Nrz?String input must be ASCII-only; use bytes or a Message instead)encode UnicodeError ValueErrorr*s r"_string_to_byteszMailbox._string_to_bytess7 2>>'* * 212 2 2s(Fct|tjjrt j }tj j||d}|j||jd|j}|jdt}|j||jr,|jts|jty y y t|t t"tj$frt|tj$r+t'j(dt*d|j-}t|t r|j/|}|r|jdd}|jdt}|j||jr,|jts|jty y y t1|drt1|dr't'j(d t*d|j2}d } |j5}|jd r |d d dz}n|jd r|d ddz}|snE|r|j7drd|dd z}|jdt}|j||}|jr/|r,|jts|jty y y y t9dt;|z)z%Dump message contents to target file.r 8Use of StringIO input is deprecated, use BytesIO insteads From s >From readbufferDUse of text mode files is deprecated, use a binary mode file insteadN  From s>From Invalid message type: %s) isinstancerLr+r ioBytesIO generatorBytesGeneratorflattenseekrreplacelinesepwrite_append_newlineendswithstrbytesStringIOwarningswarnDeprecationWarninggetvaluerrvrreadline startswith TypeErrortype) rr+target mangle_from_rgendatalastlinelines r" _dump_messagezMailbox._dump_messagesv gu}}44 5ZZ\F//00qIC KK KKN;;=D<<w/D LL ##DMM',B W%-C##ubkk!: ;'2;;/ *+=qB!**,'3'//8!//*kBooeW5G LL !##G,<, g~ . HHX]]gg&&x}}5w7G7G7IJ L  ) t, (--( G  NN  IIhmm $  0#O4 / (--.  /  IIhmm $ww%,,&()O+/*011  sBF G>H:G/H HHH I+A I&&I+ctjtjj|j|j |yr/N)rr2rrr_lookupr0s r"r2zMaildir.removeNs* "'',,tzz4<<+<=>r$cR |j|y#ttf$rYywxYwr7)r2r8FileNotFoundErrorr0s r"r9zMaildir.discardRs+  KK +,   s &&c|j|}|j|}|j|}t|tr|}n|}tj j |}|j|vr,|j|j|jdz}nd}|j|tj j|j|} tj j|j|||z} t|trCt j| tj j| |jft j| | y)r;rrN)rr,rr rrrrrr9rrrrrr) rr1r+ old_subpathtemp_key temp_subpathdominant_subpathrrtmp_pathnew_paths r"r=zMaildir.__setitem__Zsll3' 88G$||H- g~ .+  + !12 ::) )ZZ"2"8"8"DR"HHFF S77<< L977<< FC&LA g~ . HHXgg&&x0'2B2B2DE G (H%r$c|j|}ttjj |j |d5}|j r|j |}n t|}dddtjj|\}}j||j|vr-|j|j|jd|jtjjtjj |j ||S#1swYxYw)rIrbNr)ropenrrrrrr r set_subdirrset_infoset_dategetmtime)rr1subpathfmsgrrs r"rCzMaildir.get_messageus,,s# "'',,tzz73T :a}}mmA&$Q' ; ww}}W-  v ::  LLDJJ/3 4 RWW%%bggll4::w&GHI ; :s *D>>Ecttjj|j|j |d5}|j jtdcdddS#1swYyxYw)2Return a bytes representation or raise a KeyError.rrN) rrrrrrrrrrr1rs r"rNzMaildir.get_bytessQ "'',,tzz4<<+<=t D668##GU3 4 4 D Ds $A22A;cttjj|j|j |d}t |S)rSr)rrrrrr _ProxyFilers r"rFzMaildir.get_files4 djj$,,s*;|j||jvSri)r rr0s r"rjzMaildir.__contains__s diir$cL|jt|jSrl)r lenrrVs r"rmzMaildir.__len__s 499~r$cy)"Write any pending changes to disk.NrrVs r"r}z Maildir.flushs r$cy)rNrrVs r"rz Maildir.lockr$cy)rNrrVs r"rzMaildir.unlockrr$cyrNrrVs r"rz Maildir.closerr$c:g}tj|jD]v}t|dkDs|ddk(stjj tjj |j|sc|j|ddx|S)Return a list of folder names.r.N)rlistdirrrrisdirrappendrrqentrys r" list_folderszMaildir.list_folderssoZZ +E5zA~%(c/ww}}RWW\\$**e<= eABi(, r$cttjj|jd|z|j dS)z/Return a Maildir instance for the named folder.rFr r!)rrrrrrrfolders r" get_folderzMaildir.get_folders2rww||DJJf =#}}#% %r$ctjj|jd|z}t ||j }tjj|d}tjj |sItjtj|tjtjzd|S)z>Create a folder and return a Maildir instance representing it.rr maildirfolder) rrrrrrrrrO_CREATO_WRONLY)rr#rrqmaildirfolder_paths r" add_folderzMaildir.add_foldersww||DJJf 5t}}5WW\\$@ww~~01 HHRWW/bkk1I  r$ctjj|jd|z}tjtjj|dtjtjj|dzD]&}t |dks |ddk7st d|ztj|D]b}|dk7s |dk7s|dk7stjjtjj||sSt d|d |tj|d D]z\}}}|D]5}tjtjj||7|D]5}tjtjj||7|tj|y ) -Delete the named folder, which must be empty.rrrrrzFolder contains message(s): %srzFolder contains subdirectory 'z': F)topdownN) rrrrrrrrwalkr2rmdir)rr#rrrootdirsfiless r" remove_folderzMaildir.remove_foldersYww||DJJf 5ZZ T5 9:ZZ T5 9:;E5zA~qS#$Dv$MNN;ZZ%E~%5.Ue^ww}}RWW\\$67#%+U%455& "$u!= D$ "'',,tU34dE23"> r$c|tj}tjtjj |j dD]h}tjj |j d|}|tjj |z dkDsTtj|jy)zDelete old files in "tmp".ri@N)timerrrrrrr2)rnowrrs r"cleanz Maildir.cleansuiikZZ TZZ ?@E77<< E59DRWW%%d++f4 $Ar$rc btj}tj}d|vr|jdd}d|vr|jdd}t |dt |dzdzdt j d tjd | }t jj|jd |} t j|t!d |z#t$r9txjdz c_ t|cYS#t$rYnwxYwYOwxYw) z=Create a file in the tmp subdirectory and open and return it./z\057rz\072z.Mrg.APQrrz&Name clash prevented file creation: %s)r7socket gethostnamerintrgetpidr_countrrrstatr_create_carefullyFileExistsErrorr)rr8hostnamerrs r"rzMaildir._create_tmpsiik%%' (?''W5H (?''W5H$'Hc#'C-.@"))+$+NNH>ww||DJJt4  GGDM!!I!%"&' '!  NNa N (.."    s6 C,,"D. DD. D(%D.'D((D.-D.ctj|jz d|jzkDred}|jD]Q}tj j |j|}||j|kDrd}||j|<S|syi|_|jD]}|j|}t j|D]}tj j||}tj j|rC|j|jd}tj j|||j|<tj|_y)z!Update table of contents mapping.FTNr)r7rrrrrrrrrrrrr)rrefreshrmtimerrprs r"r zMaildir._refreshs) 99; (1t/?/?+? ?G**((V)<=4++F33"G+0  ( +  &&F;;v&DD)GGLLu-77==#{{4::.q1"$'',,vu"= $ *'))+r$cb tjjtjj|j|j |r|j |S |j |j |S#t $rY+wxYw#t $rt d|zdwxYw)z=Use TOC to return subpath for given key, or raise a KeyError.No message with key: %sN)rrrrrrr8r r0s r"rzMaildir._lookup&s ww~~bggll4::tyy~FGyy~%H  F99S> !      F4s:; E FsA"B7B BBB.ct|ds|j|_ |t|jS#t$rYyt $rY/wxYw)z0Return the next message in a one-time iteration. _onetime_keysN)rvrWrOnext StopIterationr8rVs r"rPz Maildir.next4sUt_-!%D  D!3!3455    s< AAAr)rrrrrr#r,r2r9r=rCrNrFrWrjrmr}rrrrr$r,r5r9rBrr rrPrr$r"rr s( E((T?&6 4     % & F'0"&H F r$rcteZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdZdZddZdZy)_singlefileMailboxzA single-file mailbox.Nctj|||| t|jd}||_ d|_ d|_ d|_ d|_d|_d|_y#t$r}|j t j k(r.|rt|jd}nYt|j|j t jt jfvrt|jd}nYd}~d}~wwxYw)z!Initialize a single-file mailbox.rb+zwb+rNrF)rr#rrrrENOENTrEACCESEROFS_filer _next_key_pending _pending_sync_locked _file_length)rrr r!rrs r"r#z_singlefileMailbox.__init__DstWf5 TZZ'A   "  ! ww%,,&TZZ/A,TZZ88U\\5;;77T* sA"" D+BC??Dc|j|j||j|j<|xjdz c_d|_|jdz S)r&rT)r_append_messagerrZr\r*s r"r,z_singlefileMailbox.add[sO $($8$8$A $..! !"~~!!r$cN|j||j|=d|_y)r/TN)rrr[r0s r"r2z_singlefileMailbox.removees  S IIcN r$cp|j||j||j|<d|_y)r;TN)rr`rr[r<s r"r=z_singlefileMailbox.__setitem__ks- S--g6 # r$c#tK|j|jjEd{y7wr)rrrZrVs r"rWz_singlefileMailbox.iterkeysqs# 99>>###s .868c>|j||jvSr )rrr0s r"rjz_singlefileMailbox.__contains__vs diir$cL|jt|jSr )rrrrVs r"rmz_singlefileMailbox.__len__{s 499~r$cV|jst|jd|_yy)rTN)r] _lock_filerYrVs r"rz_singlefileMailbox.locks!|| tzz "DLr$cV|jrt|jd|_yyrFN)r] _unlock_filerYrVs r"rz_singlefileMailbox.unlocks! <<  $ DL r$c 2|js)|jrt|jd|_y|jJ|jj dd|jj }||jk7rtd|j|fzt|j} i}|j|t|jjD]}|j|\}}|jj ||j||j } |jjt!d||jj z }|sn|j#|U||j f||<|j%||j |_t/||jj't)j0|j} t)j2|j,| j4 t)j6|j,| j8| j: t)j@|j,|jtE|jd|_||_d|_d|_|jFrtI|jdyy#|j't)j*|j,xYw#t<t>f$rYwxYw#tB$rLt)j*|jt)j@|j,|jYwxYw) rFNrrHz4Size of mailbox file changed (expected %i, found %i)rU)dotlock)%r[r\ _sync_flushrYrrtellr^r_create_temporaryr_pre_mailbox_hooksortedrZ_pre_message_hookrminr_post_message_hookrrr2rrrCchmodst_modechownst_uidst_gidrrrrErr]rg) rcur_lennew_filenew_tocr1startstop new_startrinfos r"r}z_singlefileMailbox.flushs}}!!DJJ'%*"  yy$$$ 1**//# d'' '$&?&*&7&7%A&BC C%TZZ0 G  " "8 ,diinn./"iin t &&&x0$MMO !ZZ__S15 8I1I.KLF!NN6*  !*8==?; ''10!) D  H wwtzz"  -  HHX]]DKK = 1 IIhmmTZZ 0$**e,   " << tzz5 1 /  NN  IIhmm $ (    1 IIdjj ! IIhmmTZZ 0 1s29DK75L,8*M72L),L>=L>ANNcy),Called before writing the mailbox to file f.Nrrrs r"rqz$_singlefileMailbox._pre_mailbox_hookrr$cy)-Called before writing each message to file f.Nrrs r"rsz$_singlefileMailbox._pre_message_hookrr$cy,Called after writing each message to file f.Nrrs r"ruz%_singlefileMailbox._post_message_hookrr$c |j |jr|j|jj y#|jj wxYw# |jr|j|jj w#|jj wxYwxYwr)r}r]rrYrrVs r"rz_singlefileMailbox.closes| # JJL #<<KKM   "   "  #<<KKM   "   "s.A)A A&)C+B"C"B>>Cc|j|j| |j|Sy#t$rtd|zdwxYw)z'Return (start, stop) or raise KeyError.NrM)r _generate_tocr8r0s r"rz_singlefileMailbox._lookups\ 99     ? Jyy~%  J83>?TI Js 0A cD|jjdd|jj}t|jdk(r'|j s|j |j |j|j|j|}|j|j|jj|jj|_ |S#t$r|jj|wxYw)z;Append message to mailbox and return (start, stop) offsets.rrH)rYrrorrr[rqrs_install_messagerurtruncater}r^)rr+beforeoffsetss r"r`z"_singlefileMailbox._append_messages 1" tyy>Q t}}  " "4:: .   " "4:: .++G4G  # #DJJ /  JJOO-   JJ   '  s 7AC99&Drr4)rrrrr#r,r2r=rWrjrmrrr}rqrsrurrr`rr$r"rSrSAsX !."  $    ! B2H #Jr$rSc8eZdZdZdZdZd dZd dZd dZdZ y) _mboxMMDFzAn mbox or MMDF mailbox.Tc|j|\}}|jj||jjj t dj d}|jj||jjz }|j|j t d}|j||j|dd|S)rIr$rrrN) rrYrrrrdecoderro_message_factory set_unixfromset_from)rr1r~r from_linestringrs r"rCz_mboxMMDF.get_message sll3' t JJ'')11'3?FFwO  (9!9:##FNN7E$BC # Yqr]# r$cltj|j||j|S)3Return a string representation or raise a KeyError.)unixfromrK)rr1from_s r"rPz_mboxMMDF.get_strings0'' NN3 &((1 5 (A Br$c0|j|\}}|jj||s|jj|jj ||jj z }|j tdS)rr)rrYrrrrorr)rr1rr~rrs r"rNz_mboxMMDF.get_bytessjll3' t  JJ   ! (9!9:~~gu--r$c|j|\}}|jj||s|jjt |j|jj |S)rS)rrYrr _PartialFilero)rr1rr~rs r"rFz_mboxMMDF.get_file&sUll3' t  JJ   !DJJ (94@@r$cJd}t|tr|j|}t|tr:|j dr)|j d}|dk7r|d|}||dzd}n|}d}n|t|t r%|jjd}d|z}nGt|tjjr#|j}||jd}|8dtjtjjz}|j j#}|j j%|t&z|j)||j |j*|j j#}||fS) z1Format a message and blindly write to self._file.Nrrrrr$rsFrom MAILER-DAEMON )rrrrrfind_mboxMMDFMessageget_fromrrLr+r get_unixfromr7asctimegmtimerYrorrr _mangle_from_)rr+rnewlineauthorr~rs r"rz_mboxMMDF._install_message.s^ gs #++G4G gu %'*<*G$i!mG77<< CL9 h ' ||1  $ &&w2gy1((':<< OA!%||$QN!FIIh'<< O As71E C%"D,>E %AD))D,,EE EcHtjj|jt |} t |d}|j tj|y#t$r1}|jtjk(rtd|zd}~wwxYw)r/rUrMN) rrrrrrrr2rrrVr8)rr1rrrs r"r2z MH.removes{ww||DJJC1 T5!A GGI IIdO ww%,,&83>??  s A'' B!0,BB!ctjj|jt |} t |d} |jr t| tjtj |tjtjz|j||t!|t"r|j%|||jr t'| t)|y#t $r1}|jtjk(rtd|zd}~wwxYw#|jr t'|wwxYw#t)|wxYw)r;rUrMN)rrrrrrrrrVr8r]rgrr*O_TRUNCrrr rrjr)rr1r+rrrs r"r=zMH.__setitem__sww||DJJC1 T5!A ||1  $r{{RZZ'?@A""7A.gy1((#6<< O N# ww%,,&83>??  << O  Ns< C:EAttjj |j t |d}n=ttjj |j t |d}|5|jr t| t|}|jr t| ddd|jjD]\}}||vs j!|S#t$r1}|jtjk(rtd|zd}~wwxYw#|jr t|wwxYw#1swYxYw)rIrUrrMN)r]rrrrrrrrrVr8rgr rj get_sequencesrg add_sequence)rr1rrrrkey_lists r"rCzMH.get_messages ||djj#c(;UCdjj#c(;TB ||1  $l<< O#00288:ND(h  &; ! ww%,,&83>??  << O Qs<BD E'$ E /E' E,EE E$$E''E0c |jr>ttjj |j t |d}n=ttjj |j t |d}|5|jr t| |jjtd|jr t|cdddS#t$r1}|jtjk(rtd|zd}~wwxYw#|jr t|wwxYw#1swYyxYw)rrUrrMNr)r]rrrrrrrrrVr8rgrrrrjrr1rrs r"rNz MH.get_bytess ||djj#c(;UCdjj#c(;TB ||1  $vvx''7<< O $ $  ww%,,&83>??  << O Qs<BC( E$#D%E( D"1,DD"%D??EE c ttjj|jt |d}t|S#t $r1}|jtjk(rtd|zd}~wwxYw)rSrrMN) rrrrrrrrrVr8rrs r"rFz MH.get_file1sl RWW\\$**c#h7>A !}  ww%,,&83>??  s=A B,A??Bcrttdtj|jDS)rUc3RK|]}|jr t|!ywr4)isdigitr@).0rs r" zMH.iterkeys..>s%:3I%).u:3Is%')iterrrrrrrVs r"rWz MH.iterkeys<s/F:2::djj3I::; ;r$ctjjtjj|jt |Sr )rrrrrrr0s r"rjzMH.__contains__As,ww~~bggll4::s3x@AAr$cFtt|jSr )rrYrWrVs r"rmz MH.__len__Es4 ())r$c|jsVttjj |j dd|_t|j d|_yy)rrrUTN)r]rrrrrrYrgrVs r"rzMH.lockIsB||bggll4::GODJ tzz "DLr$c|jr4t|jt|j|`d|_yyri)r]rjrYrrVs r"rz MH.unlockPs2 <<  $  #  DL r$cy)r|NrrVs r"r}zMH.flushXrr$c>|jr|jyyr)r]rrVs r"rzMH.close\s << KKM r$cg}tj|jD][}tjj tjj |j|sK|j |]|S)r)rrrrrrrrs r"rzMH.list_foldersasTZZ +Eww}}RWW\\$**e<= e$, r$cttjj|j||j dS)z+Return an MH instance for the named folder.Fr!rrrrrrr"s r"r$z MH.get_folderis-"'',,tzz62--7 7r$cttjj|j||j S)z:Create a folder and return an MH instance representing it.r&rr"s r"r,z MH.add_folderns+"'',,tzz62--) )r$c\tjj|j|}tj|}|dgk(r4tj tjj|dn|gk(rnt d|jztj|y)r.rzFolder not empty: %sN)rrrrrr2rr1)rr#rentriess r"r5zMH.remove_folderssxww||DJJ/**T" ' ' IIbggll49 : ]  6 CD D r$c i}ttjj|jddd5}t |j }|D]} |jd\}}t }|jD]f}|jr|jt|.d|jdD\} } |jt| | dzht|D cgc]} | |vr|  c} ||<t||d k(r||= d d d |Scc} w#t$rt!d |j#zwxYw#1swY|SxYw) z=Return a name-to-key-list dictionary to define each sequence.rrASCIIencodingrc32K|]}t|ywr4)r@)rxs r"rz#MH.get_sequences..s*K?a3q6?s-rrz"Invalid sequence specification: %sN)rrrrrsetrZrrr,r@rzrangerrrrrrstrip) rresultsrall_keysrrcontentsrZspecr~rr1s r"rzMH.get_sequencessK "'',,tzz?;S7 SWX499;'H5%)ZZ_ND(5D ( 0<<> HHSY/*K4::c?*KKE4 KKeTAX(>? !1 5;4L%=LS,/8O&)L%=GDM74=)Q.#DMT&%="5%&J&*kkm'4555!T&s6EB$D6= D1 D6$E1D66&EEE)cttjj|jddd} tj tj|j tjtjz|jD]\}}t|dk(r|j|dzd}d}tt|D]Q}|d z |k(r|sCd }|jd n/|rd}|j|d |n|jd |z|}S|r|jt|dz|jd t|y#t|wxYw)z:Set sequences using the given name-to-key-list dictionary.rzr+rrrrNFrTr z %s )rrrrrrrr*rrgrrrrrrr)r sequencesrrrZprev completingr1s r" set_sequenceszMH.set_sequencess" djj/:D7 S  HHRWWQVVR[[2::%=> ?'oo/ dt9>s #" !#d),CQw$))-JGGCL#%* 4 56 ,D-GGCI,-GGDM)0, NKNs D*E// E<c  |j}d}g}|jD]}|dz |k7r|j||dzf tjtj j |jt|tj j |jt|dztjtj j |jt||dz }|dz|_ t|dk(ry|jD](\}}|D]\}}||vs |||j!|< *|j#|y#ttf$r~tjtj j |jt|tj j |jt|dzYwxYw)z?Re-name messages to eliminate numbering gaps. Invalidates keys.rrN)rrWrrrrrrrunlinkrrrrZrrgindexr) rrrchangesr1rroldrs r"packzMH.packs&&( ==?CQw$TAX/BGGBGGLLSX>GGLLS]CE IIbggll4::s3x@A AID# w<1  'oo/ND(#S(?47HX^^C01$0 9%'8GIIbggll4::s3x@ ggll4::s4!8}EGGsA;E55B HHc|j}|j}|jD]2\}}||vr|j|||vs!||j|=4|D] }||vs|g||<|j |y)z;Inspect a new MHMessage and update sequences appropriately.N)rrgrrr)rr+r1pending_sequences all_sequencesrrsequences r"rzMH._dump_sequencess#113**, +113ND((($X^^C01 4 *H},+.% h'* =)r$r)rrrrr#r,r2r=rCrNrFrWrjrmrrr}rrr$r,r5rrrrrr$r"rrsu  D 02$* ; B* ! 7 ) 0:&4 *r$rcteZdZdZehdZddZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZy)rzAn Rmail-style Babyl mailbox.>filededitedresentunseendeletedanswered forwardedNcBtj||||i|_y)zInitialize a Babyl mailbox.N)rSr#_labelsrs r"r#zBabyl.__init__s##D$@ r$ctj||}t|tr|j |j |<|S)r&)rSr,rr get_labelsr)rr+r1s r"r,z Babyl.adds: $$T73 g| , ' 2 2 4DLL  r$chtj||||jvr|j|=yyr)rSr2rr0s r"r2z Babyl.removes/!!$, $,,  S! r$ctj|||t|tr|j |j |<yy)r;N)rSr=rrrrr<s r"r=zBabyl.__setitem__s:&&tS': g| , ' 2 2 4DLL  -r$c|j|\}}|jj||jjt j } |jj}|dt zk(s|sn&|j|jt dOt j } |jj}|t k(s|sn&|j|jt dL||jjz }|dk\sJ|jj|}|jt d}t|j|z} | j|j||jvr| j|j|| S)rI *** EOOH ***rr)rrYrrrrrrrrorrr set_visibler set_labels) rr1r~roriginal_headersrvisible_headersnbodyrs r"rCzBabyl.get_messagesill3' t  ::<::&&(D00  " "4<<#? @  **,::&&(Dwd  ! !$,,w"> ?  4::??$ $Av vzzq!||GU++446=> 0023 $,,  NN4<<, - r$c|j|\}}|jj||jjt j } |jj}|dt zk(s|sn&|j|jt dO |jj}|t k(s|sn'|j}||jjz }|dk\sJ|jj|}|jt d}||zS)rrrr) rrYrrrrrrrrror) rr1r~rrrheadersrrs r"rNzBabyl.get_bytess ll3' t  ::<::&&(D00  " "4<<#? @  ::&&(Dwd#++- 4::??$ $Av vzzq!||GU+~r$crtj|j|jdtS)rSr)rrrNrrr0s r"rFzBabyl.get_file-s'zz$..-55eWEFFr$c|jt}|jjD]}|j ||j |j t|S)z4Return a list of user-defined labels in the mailbox.)rrrrcrzdifference_update_special_labelsrY)rlabels label_lists r"rzBabyl.get_labels1sS ,,--/J MM* %0  !5!56F|r$c@gg}}|jjdd}g} |}|jj}|jj}|dtzk(rt |t |kr!|j |t tz |j ||jjddjdDcgc]"}|jr|j$}}|j |nn|dk(s |dtzk(r9t |t |krF|j |t tz n$|s"|j |t tz ndttt|||_ tt||_ t |j|_|jjdd|jj|_ycc}w)rrs rN,rH)rYrrrorrrrstriprrrrrrZr^) rrrr label_listsrrlabelr"s r"rzBabyl._generate_toc:sB  H::&&(Dzz(H{W,,u:F +LLCL!89 h'+/::+>+>+@+D+J+J4+P:+P-2+0;;= ++-+P:""6*DGg,=$=u:F +LLCL!89 XG 45#$3vu#567 Ik23 TYY 1 JJOO-:s'Hcdtz}|dtzz }|j}d|D}|ddj|ztzz }|dz }|j|y)rsBABYL OPTIONS:s Version: 5c3<K|]}|jywr4)r)rr)s r"rz*Babyl._pre_mailbox_hook..]s5fU%,,.fssLabels:r%r&N)rrrr)rrbabylr"s r"rqzBabyl._pre_mailbox_hookXsc!G+ (("5f5 dii//'99  r$c4|jdtzy)r Nrrs r"rszBabyl._pre_message_hookbs '!"r$c4|jtdzy)rr&Nrrs r"ruzBabyl._post_message_hookfs '!"r$c|jj}t|tr g}g}|j D]3}||j vr|j |#|j |5|jjd|D].}|jjd|jz0|jjd|D]1}|jjd|jzdz3|jjtn"|jjdtzt|tjjrtj}tjj!|dd}|j#||j%d |j'}|jj|j)d t|d k(s|snH|jjd tzt|trtj} tjj!| dd} | j#|j+ | j'}|jj|j)d t|d k(s|sn[H|j%d |j'}|jj|j)d t|d k(s|snH |j-d } | sn|jj| j)d tEt|t.t0tj2frt|tj2r+t5j6d t8d|j;}t|t0r|j=|}|j?ddz} | dz dk7r|jj|d| j)d t|jjd tz|jj|d| j)d t|jj|| dj)d tn|jjd tztz|jj|j)d tntA|drtA|dr't5j6dt8d|jB}|j} d } |j'}|jEdr |ddd z}n|jEdr|ddd z}|jj|j)d t|d k(s|s9|r6d}|jjd tz|j%| nn |j'}|sn|jEdr |ddtz}n;|jEdr |ddtz}n|jEd r |ddtz}|jj|tGdtI|z|jj}||fS)z0Write message contents and return (start, stop).1s, s,, r%s1,,FrTrrrlrrs rHrNrrrrrrr)%rYrorrrr!rrrrrLr+r rrrrrrrr get_visiblerrrrrrrrrrrvrrrr)rr+r~special_labelsr"r) orig_bufferorig_generatorr vis_buffer vis_generatorr body_start original_pos first_passrs r"rzBabyl._install_messagejs ! g| ,NF ++-D000"))%0MM%( . JJ  T "'   !78( JJ  U #    !6!=> JJ  W % JJ  Vg- . gu}}44 5**,K"__;;KPQRN  " "7 +   Q "++-   eW!=>5=  JJ  _w6 7'<0ZZ\ % > >z5RS T %%g&9&9&;<%..0DJJ$$T\\%%ABu}D    #&//1DJJ$$T\\%%ABu}D  $))$/   w!?@  %bkk!: ;'2;;/ *+=qB!**,'3'//8 g.2JA~#   *!5!=!=eW!MN   7!:;   *!5!=!=eW!MN   !5!=!=eW!MN   7!:W!DE   !@A Wj )w) 56H!M!.."<<>LJ'')==)9u,D]]5)9u,D   eW!=>5=!%*  ((7)BC \2'')==)9w.D]]5)9w.D]]5)9w.D   &6gFG Gzz t}r$r)rrrr frozensetr!r#r,r2r=rCrNrFrrrqrsrurrr$r"rrsY'!BCO " 5 8,G.<##ir$rc$eZdZdZddZdZdZy)r z0Message with mailbox-format-specific properties.Nct|tjjrG|j t j |t|tr|j|yyt|tr%|j tj|yt|tr%|j tj|yt|tjr%|j tj|yt|dr%|j tj |y|*tjjj#|yt%dt'|z)zInitialize a Message instance.rNr)rrLr+r _become_messagecopydeepcopy _explain_torrMrmessage_from_stringr TextIOWrappermessage_from_filervmessage_from_binary_filer#rrr*s r"r#zMessage.__init__s gu}}44 5  w!7 8'7+##D),  '  !9!9'!B C  %  !:!:7!C D !1!1 2  !8!8!A B Wf %  !?!?!H I _ MM ! ! * *4 06gFG Gr$ct|dg}|jD]#}||vs|j||j|<%y)z0Assume the non-format-specific state of message._type_specific_attributesN)getattr__dict__)rr+ type_specificrs r"r?zMessage._become_messagesB)DbI $$D=(&-&6&6t&< d#%r$c:t|trytd)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rr rr*s r"rBzMessage._explain_tos gw ' >? ?r$r4)rrrrr#r?rBrr$r"r r s:H&=@r$r cbeZdZdZgdZddZdZdZdZdZ d Z d Z d Z d Z d ZdZdZy)r z)Message with Maildir-specific properties.)_subdir_info_dateNc~d|_d|_tj|_tj ||y)z%Initialize a MaildirMessage instance.rrN)rNrOr7rPr r#r*s r"r#zMaildirMessage.__init__s-  YY[ w'r$c|jS)zReturn 'new' or 'cur'.)rNrVs r"rzMaildirMessage.get_subdirs ||r$cB|dk(s|dk(r||_ytd|z)zSet subdir to 'new' or 'cur'.rrz!subdir must be 'new' or 'cur': %sN)rNr)rrs r"rzMaildirMessage.set_subdir s' U?fo!DL@6IJ Jr$cX|jjdr|jddSy)*Return as a string the flags that are set.2,rHNr)rOrrVs r" get_flagszMaildirMessage.get_flagss' ::  &::ab> !r$cHddjt|z|_y))Set the given flags and unset all others.rVrN)rrrrO)rflagss r" set_flagszMaildirMessage.set_flagssBGGF5M22 r$c|jdjt|jt|zyz.Set the given flag(s) without changing others.rNr[rrrWrflags r"add_flagzMaildirMessage.add_flag, rwws4>>#34s4y@ABr$c|jrD|jdjt|jt|z yy)7Unset the given string flag(s) without changing others.rN)rWr[rrr_s r" remove_flagzMaildirMessage.remove_flag!s; >>  NN2773t~~'7#83t9#DE F r$c|jS)zSet "From " line, formatting and appending time_ if specified.NTr)r7rrr{)rrtime_s r"rz_mboxMMDFMessage.set_fromzs9  }  S4<<.. .E r$cL|jdd|jddzS)rUStatusrX-Status)rArVs r"rWz_mboxMMDFMessage.get_flagss#xx"%R(@@@r$ct|}d\}}dD]}||vs||z }|j|dD]}||vs||z }|j||djt|z } |j d| |j d|y#t $r|j d|Y1wxYw#t $r|j d|YywxYw)rY)rr)rorp)rrrsrtrrrN)rr2rrrreplace_headerr8 add_header)rrZ status_flags xstatus_flagsr`s r"r[z_mboxMMDFMessage.set_flagssE &,# mDu}$  T"$Du}%  T"$ //  4   , 7 7    M : 4 OOHl 3 4 7 OOJ 6 7s$3BB:B76B7:CCc|jdjt|jt|zyr]r^r_s r"raz_mboxMMDFMessage.add_flagrbr$cd|vsd|vrD|jdjt|jt|z yy)rdrrrNr^r_s r"rez_mboxMMDFMessage.remove_flags@ t zT1 NN2773t~~'7#83t9#DE F 2r$ct|trt|j}d|vr|j dd|vr|j dd|vr|j dd|vr|j dd|vr|j d|d =|d =d j |jjd d } |jtjtj|dy t|t r?|j#|j|j%|jy t|t&r_t|j}d|vr|j)dd|vr|j)dd|vr|j)d|d =|d =y t|t*r_t|j}d|vr|j-dd|vr|j-dd|vr|j-d|d =|d =y t|t.ry t1dt3|z#ttf$rYy wxYw)zACopy mbox- or MMDF-specific state to message insofar as possible.rprrsrtrornrrrqstatuszx-statusrNz%a %b %d %H:%M:%S %Yr rvrwr r rx)rr rrWrrarrrrcalendartimegmr7strptimer OverflowErrorrr[rr rrryr rr)rr+rZ maybe_dates r"rBz_mboxMMDFMessage._explain_tos9 g~ .()Ee|""5)e|  %e|  %e|  %e|  %! #$--/"7"7"9"#">?J   z6L2N"OP!1 2   dnn. /   T]]_ -  +()E%$$X.e|$$Y/e|$$Y/! #  .()E%!!(+e|!!),e|!!*-! #  ) B M*+ +9 .  s 8II*)I*r4) rrrrrHr#rrrWr[rarerBrr$r"rrhs89!( (A7,CG 1+r$rceZdZdZy)r z&Message with mbox-specific properties.Nrrrrrr$r"r r 0r$r c<eZdZdZdgZd dZdZdZdZdZ d Z y) r z$Message with MH-specific properties. _sequencesNc>g|_tj||y)z!Initialize an MHMessage instance.N)rr r#r*s r"r#zMHMessage.__init__sw'r$c |jddS)z4Return a list of sequences that include the message.N)rrVs r"rzMHMessage.get_sequencessq!!r$c$t||_y)z3Set the list of sequences that include the message.N)rYr)rrs r"rzMHMessage.set_sequencess y/r$ct|tr+||jvr|jj|yyt dt |z)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rrrrrrrrs r"rzMHMessage.add_sequencesF h $t.&&x0/;d8nLM Mr$cZ |jj|y#t$rYywxYw)zARemove sequence from the list of sequences including the message.N)rr2rrs r"remove_sequencezMHMessage.remove_sequences+  OO " "8 ,     **c|t|tr}t|j}d|vr|j dn"|j d|j dd|vr|j dd|vr|j dy y t|t rlt|j}d|vr|j dn|j d d|vr|j dd|vr|j d y y t|tr'|jD]}|j|y t|trEt|j}d|vr|jdd|vr|jd y y t|try td t|z)z6Copy MH-specific state to message insofar as possible.r rrnrwrsrvroROrprtr rxN)rr rrrrarr rrryr rr)rr+rrs r"rBzMHMessage._explain_tos g~ .D..01I9$""5)""5)  %I%  %I%  %& !1 2D..01Iy(  &  %I%  %I%  %&  + ..0$$X.1  .D..01I9$!!(+I%!!*-&  ) B M*+ +r$r4) rrrrrHr#rrrrrBrr$r"r r s,.!-( "*N$+r$r cPeZdZdZddgZddZdZdZdZd Z d Z d Z d Z d Z y)rz'Message with Babyl-specific properties.r_visibleNc\g|_t|_tj||y)z#Initialize a BabylMessage instance.N)rr rr#r*s r"r#zBabylMessage.__init__*s"   w'r$c |jddS)z'Return a list of labels on the message.N)rrVs r"rzBabylMessage.get_labels0s||Ar$c$t||_y)z&Set the list of labels on the message.N)rYr)rr"s r"rzBabylMessage.set_labels4s F| r$ct|tr+||jvr|jj|yyt dt |z)z+Add label to list of labels on the message.zlabel must be a string: %sN)rrrrrrrr)s r"ryzBabylMessage.add_label8sF eS !DLL( ##E*)84;FG Gr$cZ |jj|y#t$rYywxYw)z4Remove label from the list of labels on the message.N)rr2rrs r" remove_labelzBabylMessage.remove_label@s+  LL   &   rc,t|jS)z3Return a Message representation of visible headers.r rrVs r"r3zBabylMessage.get_visibleGst}}%%r$c$t||_y)z2Set the Message representation of visible headers.Nr)rvisibles r"rzBabylMessage.set_visibleKs( r$c|jjD]3}||vr |jj|||'|j|=5dD](}||vs||jvs|||j|<*y)z9Update and/or sensibly generate a set of visible headers.)DateFromzReply-ToToCCSubjectN)rrZr)rheaders r"update_visiblezBabylMessage.update_visibleOsvmm((*F~ ,,VT&\BMM&) + JF~& "=(,V  f%Jr$ct|trt|j}d|vr|j dn"|j d|j dd|vsd|vr|j dd|vr|j dd |vr|j d yyt|t rlt|j}d|vr|j d n|j d d |vr|j d d|vr|j dyyt|trEt|j}d|vr|jdd|vr|jdyyt|trF|j|j|jD]}|j|yt|trytdt|z)z9Copy Babyl-specific state to message insofar as possible.r rrnr r r<r ror rqrrprrrtrvrxN)rr rrrrarr rrrr3ryr rr)rr+r"r)s r"rBzBabylMessage._explain_toZs g~ .*+F6!""5)""5)  %f$F(:  %V#  %F"  %# !1 2*+Fv%  &  %F"  %V#  %$  +*+F6!$$X.V#$$Y/$  .    0 0 2 3*!!%(+  ) B M*+ +r$r4)rrrrrHr#rrryrr3rrrBrr$r"rr%s>1!*J 7( $H&) 5'+r$rceZdZdZy)rz&Message with MMDF-specific properties.Nrrr$r"rrrr$rceZdZdZddZddZddZddZddZdZ d Z dd Z d Z d Z d ZdZdZdZdZdZedZeeZy)rzA read-only wrapper of a file.NcP||_||j|_y||_y)zInitialize a _ProxyFile.N)rYro_pos)rrposs r"r#z_ProxyFile.__init__s" ;DIDIr$cN|j||jjSz Read bytes.)_readrYrrsizes r"rz_ProxyFile.readszz$ 00r$cN|j||jjSr)rrYread1rs r"rz_ProxyFile.read1szz$ 0 011r$cN|j||jjS)z Read a line.)rrYrrs r"rz_ProxyFile.readlineszz$ 3 344r$clg}|D],}|j|||t|z}|dks+|S|S)zRead multiple lines.r)rr)rsizehintrqrs r" readlinesz_ProxyFile.readlinessGD MM$ #CI%q=   r$c#`K|jx}r||jx}ryyw)zIterate over lines.N)r)rrs r"raz_ProxyFile.__iter__s/mmo%d%Jmmo%d%s)..c|jS)zReturn the position.)rrVs r"roz_ProxyFile.tells yyr$c|dk(r%|jj|j|jj|||jj|_y)zChange position.rNrYrrroroffsetwhences r"rz_ProxyFile.seeksA Q; JJOODII & 'JJOO% r$ct|dr4 t|jdr|jj|`yy#|`wxYw)zClose the file.rYrN)rvrYrrVs r"rz_ProxyFile.closesB 4 ! 4::w/JJ$$&J " Js 0AAc|d}|jj|j||}|jj|_|S)z"Read size bytes using read_method.rr)rr read_methodrqs r"rz_ProxyFile._readsA <D  "T"JJOO%  r$c|S)z$Context management protocol support.rrVs r" __enter__z_ProxyFile.__enter__s r$c$|jyr4)r)rexcs r"__exit__z_ProxyFile.__exit__s  r$c6|jjSr4)rYreadablerVs r"rz_ProxyFile.readablezz""$$r$c6|jjSr4)rYwritablerVs r"rz_ProxyFile.writablerr$c6|jjSr4)rYseekablerVs r"rz_ProxyFile.seekablerr$c6|jjSr4)rYr}rVs r"r}z_ProxyFile.flushszz!!r$cvt|dsyt|jdsy|jjS)NrYTrF)rvrYrrVs r"rz_ProxyFile.closeds0tW%tzz8,zz   r$r4r)rrrrr#rrrrrarorrrrrrrrr}propertyrrrrrr$r"rrsv(125  &%%%"!!$L1r$rc2eZdZdZddZdZd dZdZdZy) rz&A read-only wrapper of part of a file.NcNtj|||||_||_y)zInitialize a _PartialFile.N)rr#_start_stop)rrr~rs r"r#z_PartialFile.__init__s"D!U+  r$cFtj||jz S)z*Return the position with respect to start.)rrorrVs r"roz_PartialFile.tellst$t{{22r$c|dk(r|j|_d}n|dk(r|j|_d}tj |||y)z8Change position, possibly with respect to start or stop.rrrHN)rrrrrrs r"rz_PartialFile.seeks@ Q; DIF q[ DIFff-r$c|j|jz }|dkry| |dks||kDr|}tj|||S)z;Read size bytes using read_method, honoring start and stop.rr$)rrrr)rrr remainings r"rz_PartialFile._readsJJJ* > <4!8ti'7DdK88r$c"t|dr|`yy)NrY)rvrYrVs r"rz_PartialFile.close s 4 !  "r$)NNr) rrrrr#rorrrrr$r"rrs0 3.9r$rcd} tr6 tj|tjtjz|r{ t|jdz}|j tj|j|jdzd}tj|jyyy#t$rY}|j t j t jt jfvrtd|jzd}~wwxYw#t$r7}|j t jt jfvrYd}~yd}~wwxYw#t t"f$r2tj$|j|jdzd}YwxYw#t&$r8tj(|jtd|jzwxYw#tr$tj|tj*|r"tj(|jdzxYw)z(Lock file f using lockf and dot locking.Fzlockf: lock unavailable: %sN.lockTzdot lock unavailable: %s)fcntllockfLOCK_EXLOCK_NBrrEAGAINrWrXrrrprrrrrrrrEr2LOCK_UN)rrm dotlock_donerpre_locks r"rgrgsL%   Au}}u}}<=  ,QVVg-=> 1-GGHMM166G+;<#'L IIhmm,!   77u||U\\5;;GG,-J-.VV.455   77u||U[[99  '8(IIhmmQVVg-=>#'L( # 1 (--(()C)**011 1  KK5== )  IIaffw& ' sG.5B>G.(D#-/E&F*> D ADD  G.# E#,,EG.EE##G.&>F'$F*&F''F**AG++G..AH?ctr$tj|tjtjj |j dzr#tj|j dzyy)z*Unlock file f using lockf and dot locking.rN)rrrrrrrr2rs r"rjrj;sJ  Au}}% ww~~affw&' !&&7"#(r$ctj|tjtjztjzd} t|dtj |S#tj |wxYw)zCCreate a file if it doesn't exist and open for reading and writing.r(rU)rrr)rO_RDWRr)rfds r"rDrDBsP rzzBII- 95 ABD%    s A**Bc t|dttjdtjdt j S)zBCreate a temp file based on path and open for reading and writing.r)rDr@r7r>r?rrA)rs r"rprpJs8 dC 4D.4.@.@.B.0iik; <The specified mailbox is not empty and deletion was requested.Nrrr$r"rrbsHr$rceZdZdZy)rz)Another process caused an action to fail.Nrrr$r"rre3r$rceZdZdZy)rz)A file appears to have an invalid format.Nrrr$r"rrhrr$r)T)2rrr7rr>rr@rrL email.messageemail.generatorrrDtypesrr ImportError__all__rrrrrSrrr rrr+r r rr r rrrrrgrjrDrprnr Exceptionrrrrrrr$r"r sJ     A **  G $f2f2Rsgsl CCN@"@F1.91.h*.9*.Zn*n*b v vr"@emm##"@Jj+Wj+Zn+wn+b1"1E+E+P\+7\+~1"1_2_2D$:$N(T$<   -I-EEIEI444%4aB EsE55F?F