grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ”qcR2ã@s0dZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl Zddl Z ddl Z yddl Z Wnek rÀdZ YnXddddddd d d d d dg ZejjdƒZGdd„dƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd „d ejjƒZGdd „d eƒZGdd„deƒZGdd „d eƒZGdd „d eƒZGd d „d eƒZ Gd!d„deƒZ!Gd"d#„d#ƒZ"Gd$d%„d%e"ƒZ#d&d'd(„Z$d)d*„Z%d+d,„Z&d-d.„Z'd/d0„Z(d1d2„Z)Gd3d4„d4e*ƒZ+Gd5d6„d6e+ƒZ,Gd7d8„d8e+ƒZ-Gd9d:„d:e+ƒZ.Gd;d<„d<e+ƒZ/dS)=zDRead/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.éNÚMailboxÚMaildirÚmboxÚMHÚBabylÚMMDFÚMessageÚMaildirMessageÚ mboxMessageÚ MHMessageÚ BabylMessageÚ MMDFMessageÚasciic@s¢eZdZdZdddd„Zdd„Zdd „Zd d „Zd d „Zdd„Z ddd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zdd0d1„Zd2d3„Zdd4d5„Zd6d7„Zd8d9„Zd:d;„Zd<d=„Z d>d?„Z!d@Z"d@dAdB„Z#dS)Crz*A group of messages in a particular place.NTcCs.tjjtjj|ƒƒ|_||_dS)zInitialize a Mailbox instance.N)ÚosÚpathÚabspathÚ expanduserÚ_pathÚ_factory)ÚselfrÚfactoryÚcreate©rú,/opt/alt/python35/lib64/python3.5/mailbox.pyÚ__init__#s!zMailbox.__init__cCstdƒ‚dS)z$Add message and return assigned key.z&Method must be implemented by subclassN)ÚNotImplementedError)rÚmessagerrrÚadd(sz Mailbox.addcCstdƒ‚dS)z=Remove the keyed message; raise KeyError if it doesn't exist.z&Method must be implemented by subclassN)r)rÚkeyrrrÚremove,szMailbox.removecCs|j|ƒdS)N)r)rrrrrÚ __delitem__0szMailbox.__delitem__c Cs*y|j|ƒWntk r%YnXdS)z'If the keyed message exists, remove it.N)rÚKeyError)rrrrrÚdiscard3s zMailbox.discardcCstdƒ‚dS)z>Replace the keyed message; raise KeyError if it doesn't exist.z&Method must be implemented by subclassN)r)rrrrrrÚ __setitem__:szMailbox.__setitem__c Cs.y|j|ƒSWntk r)|SYnXdS)z9Return the keyed message, or default if it doesn't exist.N)Ú __getitem__r!)rrÚdefaultrrrÚget>s z Mailbox.getc CsI|js|j|ƒStj|j|ƒƒ�}|j|ƒSWdQRXdS)z=Return the keyed message; raise KeyError if it doesn't exist.N)rÚ get_messageÚ contextlibÚclosingÚget_file)rrÚfilerrrr$Es  zMailbox.__getitem__cCstdƒ‚dS)z4Return a Message representation or raise a KeyError.z&Method must be implemented by subclassN)r)rrrrrr'MszMailbox.get_messagecCstj|j|ƒƒjƒS)zœReturn a string representation or raise a KeyError. Uses email.message.Message to create a 7bit clean string representation of the message.)ÚemailÚmessage_from_bytesÚ get_bytesÚ as_string)rrrrrÚ get_stringQszMailbox.get_stringcCstdƒ‚dS)z8Return a byte string representation or raise a KeyError.z&Method must be implemented by subclassN)r)rrrrrr.XszMailbox.get_bytescCstdƒ‚dS)z6Return a file-like representation or raise a KeyError.z&Method must be implemented by subclassN)r)rrrrrr*\szMailbox.get_filecCstdƒ‚dS)zReturn an iterator over keys.z&Method must be implemented by subclassN)r)rrrrÚiterkeys`szMailbox.iterkeyscCst|jƒƒS)zReturn a list of keys.)Úlistr1)rrrrÚkeysdsz Mailbox.keysc csFx?|jƒD]1}y||}Wntk r8w YnX|Vq WdS)z%Return an iterator over all messages.N)r1r!)rrÚvaluerrrÚ itervalueshs  zMailbox.itervaluescCs |jƒS)N)r5)rrrrÚ__iter__qszMailbox.__iter__cCst|jƒƒS)z,Return a list of messages. Memory intensive.)r2r5)rrrrÚvaluestszMailbox.valuesc csLxE|jƒD]7}y||}Wntk r8w YnX||fVq WdS)z.Return an iterator over (key, message) tuples.N)r1r!)rrr4rrrÚ iteritemsxs  zMailbox.iteritemscCst|jƒƒS)z9Return a list of (key, message) tuples. Memory intensive.)r2r8)rrrrÚitems�sz Mailbox.itemscCstdƒ‚dS)z9Return True if the keyed message exists, False otherwise.z&Method must be implemented by subclassN)r)rrrrrÚ __contains__…szMailbox.__contains__cCstdƒ‚dS)z*Return a count of messages in the mailbox.z&Method must be implemented by subclassN)r)rrrrÚ__len__‰szMailbox.__len__cCs(x!|jƒD]}|j|ƒq WdS)zDelete all messages.N)r3r")rrrrrÚclear�sz Mailbox.clearc Cs8y||}Wntk r&|SYnX|j|ƒ|S)z3Delete the keyed message and return it, or default.)r!r")rrr%ÚresultrrrÚpop’s    z Mailbox.popcCs7x0|jƒD]}||j|ƒfSWtdƒ‚dS)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailboxN)r1r>r!)rrrrrÚpopitem›szMailbox.popitemc Csžt|dƒr|jƒ}n$t|dƒr<|jƒ}n|}d}x=|D]5\}}y|||From ÚreadÚbufferzDUse of text mode files is deprecated, use a binary mode file insteadNs és ésFrom s>From ézInvalid message type: %séþÿÿÿéÿÿÿÿ)Ú isinstancer,rrÚioÚBytesIOÚ generatorÚBytesGeneratorÚflattenÚseekrMÚreplaceÚlinesepÚwriteÚ_append_newlineÚendswithÚstrÚbytesÚStringIOÚwarningsÚwarnÚDeprecationWarningÚgetvaluerKr@rNÚreadlineÚ startswithÚ TypeErrorÚtype) rrÚtargetZ mangle_from_rNÚgenÚdataZlastlineÚlinerrrÚ _dump_messageÐsZ               zMailbox._dump_message)$Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr r"r#r&r$r'r0r.r*r1r3r5r6r7r8r9r:r;r<r>r?rCrDrErFrGrKr^rorrrrr sB                         c@sHeZdZdZdZdddd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-Zd.d/„Zd0d1„Zd2d3„Zd4d5„ZdS)6rzA qmail-style Maildir mailbox.ú:NTcCstj||||ƒdtjj|jdƒdtjj|jdƒdtjj|jdƒi|_tjj|jƒsÑ|rÂtj|jdƒx9|jj ƒD]}tj|dƒq¥Wnt |jƒ‚i|_ ddddi|_ d|_ d|_dS)zInitialize a Maildir instance.ÚtmpÚnewÚcuriÀrgš™™™™™¹?N)rrrrÚjoinrÚ_pathsÚexistsÚmkdirr7ÚNoSuchMailboxErrorÚ_tocÚ _toc_mtimesÚ _last_readÚ _skewfactor)rÚdirnamerrrrrrr s!  zMaildir.__init__cCsß|jƒ}y|j||ƒWn/tk rQ|jƒtj|jƒ‚YnXt|ƒt|t ƒr¢|j ƒ}|j |j ƒ}||j kr®d}n d}d}tj j|jƒj|j ƒd}tj j|j|||ƒ}t|t ƒr/tj|jtj j|jƒ|jƒfƒyLttdƒrgtj|j|ƒtj|jƒntj|j|ƒWn]tk rÚ}z=tj|jƒ|jtjkrÅtd|ƒ‚n‚WYdd}~XnX|S)z$Add message and return assigned key.ÚrvrÚlinkz$Name clash with existing message: %sN)Ú _create_tmproÚ BaseExceptionrGrrÚnameÚ _sync_closerTr Ú get_subdirÚcolonÚget_inforÚbasenameÚsplitrxrÚutimeÚgetatimeÚget_dater@rƒÚrenameÚOSErrorÚerrnoZEEXISTÚExternalClashError)rrZtmp_fileÚsubdirÚsuffixÚuniqÚdestÚerrrr s@      % " z Maildir.addcCs,tjtjj|j|j|ƒƒƒdS)z=Remove the keyed message; raise KeyError if it doesn't exist.N)rrrrxrÚ_lookup)rrrrrrIszMaildir.removec Cs0y|j|ƒWnttfk r+YnXdS)z'If the keyed message exists, remove it.N)rr!ÚFileNotFoundError)rrrrrr"MszMaildir.discardc Cs!|j|ƒ}|j|ƒ}|j|ƒ}t|tƒrE|}n|}tjj|ƒ}|j|krŒ|j|j|jƒd}nd}|j |ƒtjj |j |ƒ} tjj |j |||ƒ} t|tƒr tj | tjj | ƒ|jƒfƒtj| | ƒdS)z>Replace the keyed message; raise KeyError if it doesn't exist.rPr‚NrS)r™rrTr rrr�r‰rŒr"rxrr�rŽr�r�) rrrZ old_subpathZtemp_keyZ temp_subpathZdominant_subpathr”r•Ztmp_pathÚnew_pathrrrr#Us"    zMaildir.__setitem__c Csá|j|ƒ}ttjj|j|ƒdƒ�.}|jrN|j|ƒ}n t|ƒ}WdQRXtjj|ƒ\}}|j |ƒ|j |kr²|j |j|j ƒdƒ|j tjj tjj|j|ƒƒƒ|S)z4Return a Message representation or raise a KeyError.ÚrbNrPrS)r™Úopenrrrxrrr rŒÚ set_subdirr‰Úset_infoÚset_dateÚgetmtime)rrZsubpathÚfÚmsgr”r†rrrr'ps$  +zMaildir.get_messagec CsNttjj|j|j|ƒƒdƒ�}|jƒjtdƒSWdQRXdS)z2Return a bytes representation or raise a KeyError.rœs N) r�rrrxrr™rMr[r\)rrr¢rrrr.s-zMaildir.get_bytescCs4ttjj|j|j|ƒƒdƒ}t|ƒS)z6Return a file-like representation or raise a KeyError.rœ)r�rrrxrr™Ú _ProxyFile)rrr¢rrrr*„s*zMaildir.get_filec csP|jƒx?|jD]4}y|j|ƒWntk rBwYnX|VqWdS)zReturn an iterator over keys.N)Ú_refreshr}r™r!)rrrrrr1‰s  zMaildir.iterkeyscCs|jƒ||jkS)z9Return True if the keyed message exists, False otherwise.)r¥r})rrrrrr:“s zMaildir.__contains__cCs|jƒt|jƒS)z*Return a count of messages in the mailbox.)r¥Úlenr})rrrrr;˜s zMaildir.__len__cCsdS)z"Write any pending changes to disk.Nr)rrrrrD�sz Maildir.flushcCsdS)zLock the mailbox.Nr)rrrrrE£sz Maildir.lockcCsdS)z#Unlock the mailbox if it is locked.Nr)rrrrrF§szMaildir.unlockcCsdS)zFlush and close the mailbox.Nr)rrrrrG«sz Maildir.closecCs„g}xwtj|jƒD]c}t|ƒdkr|ddkrtjjtjj|j|ƒƒr|j|dd…ƒqW|S)zReturn a list of folder names.rPrÚ.N)rÚlistdirrr¦rÚisdirrxÚappend)rr=ÚentryrrrÚ list_folders¯s "$zMaildir.list_folderscCs/ttjj|jd|ƒd|jddƒS)z/Return a Maildir instance for the named folder.r§rrF)rrrrxrr)rÚfolderrrrÚ get_folder¸s zMaildir.get_foldercCs‚tjj|jd|ƒ}t|d|jƒ}tjj|dƒ}tjj|ƒs~tjtj|tj tj Bdƒƒ|S)z>Create a folder and return a Maildir instance representing it.r§rZ maildirfolderi¶) rrrxrrrrzrGr�ÚO_CREATÚO_WRONLY)rr­rr=Zmaildirfolder_pathrrrÚ add_folder¾s zMaildir.add_foldercCsœtjj|jd|ƒ}xttjtjj|dƒƒtjtjj|dƒƒD]8}t|ƒdks|ddkrWtd|ƒ‚qWWxrtj|ƒD]a}|dkr£|dkr£|dkr£tjjtjj||ƒƒr£td||fƒ‚q£Wx€tj|d d ƒD]i\}}}x*|D]"}tj tjj||ƒƒq4Wx*|D]"}tj tjj||ƒƒqaWqWtj |ƒd S) z-Delete the named folder, which must be empty.r§rvrwrPrzFolder contains message(s): %sruz%Folder contains subdirectory '%s': %sÚtopdownFN) rrrxrr¨r¦Ú NotEmptyErrorr©ÚwalkrÚrmdir)rr­rr«ÚrootÚdirsÚfilesrrrÚ remove_folderÈs #"$!%   $zMaildir.remove_foldercCs€tjƒ}xmtjtjj|jdƒƒD]J}tjj|jd|ƒ}|tjj|ƒdkr.tj|ƒq.WdS)zDelete old files in "tmp".rui@úN)Útimerr¨rrxrrŽr)rÚnowr«rrrrÚcleanÛs  (z Maildir.cleanrPcCstjƒ}tjƒ}d|kr6|jddƒ}d|krT|jddƒ}dt|ƒt|ddƒtjƒtj|f}tj j |j d|ƒ}ytj |ƒWnDt k rütjd7_yt|ƒSWntk r÷YnXYnXtd |ƒ‚d S) z=Create a file in the tmp subdirectory and open and return it.ú/z\057rtz\072z%s.M%sP%sQ%s.%srPg€„.Aruz&Name clash prevented file creation: %sN)rºÚsocketÚ gethostnamer[ÚintrÚgetpidrÚ_countrrxrÚstatršÚ_create_carefullyÚFileExistsErrorr“)rr»Zhostnamer–rrrrr„ås&    &   zMaildir._create_tmpcCs6tjƒ|jd|jkrƒd}xP|jD]E}tjj|j|ƒ}||j|krhd}||j|Replace the keyed message; raise KeyError if it doesn't exist.TN)r™rÕr}rÑ)rrrrrrr#fs z_singlefileMailbox.__setitem__ccs |jƒ|jjƒEdHdS)zReturn an iterator over keys.N)r™r}r3)rrrrr1ls z_singlefileMailbox.iterkeyscCs|jƒ||jkS)z9Return True if the keyed message exists, False otherwise.)r™r})rrrrrr:qs z_singlefileMailbox.__contains__cCs|jƒt|jƒS)z*Return a count of messages in the mailbox.)r™r¦r})rrrrr;vs z_singlefileMailbox.__len__cCs#|jst|jƒd|_dS)zLock the mailbox.TN)rÓÚ _lock_filerÏ)rrrrrE{s  z_singlefileMailbox.lockcCs#|jrt|jƒd|_dS)z#Unlock the mailbox if it is locked.FN)rÓÚ _unlock_filerÏ)rrrrrF�s  z_singlefileMailbox.unlockc CsŽ|js,|jr(t|jƒd|_dS|jdk sAt‚|jjddƒ|jjƒ}||jkr‹t d|j|fƒ‚t |j ƒ}yèi}|j |ƒx¿t |jjƒƒD]¨}|j|\}}|jj|ƒ|j|ƒ|jƒ}x@|jjtd||jjƒƒƒ}|s:P|j|ƒq W||jƒf||<|j|ƒqÆW|jƒ|_Wn%|jƒtj|jƒ‚YnXt|ƒ|jjƒtj|j ƒj} tj|j| ƒytj|j|j ƒWn8tk r=tj|j ƒtj|j|j ƒYnXt|j dƒ|_||_d|_d|_|jrŠt |jddƒdS) z"Write any pending changes to disk.FNrrOz4Size of mailbox file changed (expected %i, found %i)izrb+Údotlock)!rÑrÒÚ _sync_flushrÏr}ÚAssertionErrorrZÚtellrÔr“Ú_create_temporaryrÚ_pre_mailbox_hookÚsortedr3Ú_pre_message_hookrMÚminr]Ú_post_message_hookrGrrr†r‡rÃÚst_modeÚchmodr�rÅr�rÓrÖ) rZcur_lenZnew_fileZnew_tocrÚstartÚstopZ new_startrNÚmoderrrrD‡s`               z_singlefileMailbox.flushcCsdS)z,Called before writing the mailbox to file f.Nr)rr¢rrrrÝÇsz$_singlefileMailbox._pre_mailbox_hookcCsdS)z-Called before writing each message to file f.Nr)rr¢rrrrßËsz$_singlefileMailbox._pre_message_hookcCsdS)z,Called after writing each message to file f.Nr)rr¢rrrráÏsz%_singlefileMailbox._post_message_hookcCs>z|jƒWdz|jr'|jƒWd|jjƒXXdS)zFlush and close the mailbox.N)rDrÓrFrÏrG)rrrrrGÓs  z_singlefileMailbox.closec Cs]|jdkr|jƒ|dk rYy|j|SWn"tk rXtd|ƒ‚YnXdS)z'Return (start, stop) or raise KeyError.NzNo message with key: %s)r}Ú _generate_tocr!)rrrrrr™Þs   z_singlefileMailbox._lookupc CsÏ|jjddƒ|jjƒ}t|jƒdkrQ|j rQ|j|jƒy3|j|jƒ|j|ƒ}|j |jƒWn%t k r«|jj |ƒ‚YnX|jj ƒ|jjƒ|_ |S)z;Append message to mailbox and return (start, stop) offsets.rrO)rÏrZrÛr¦r}rÑrÝrßÚ_install_messagerár…ÚtruncaterDrÔ)rrZbeforeZoffsetsrrrrÕès  z"_singlefileMailbox._append_message)rprqrrrsrrrr#r1r:r;rErFrDrÝrßrárGr™rÕrrrrrË<s"         @     rËc@saeZdZdZdZdd„Zddd„Zddd „Zdd d „Zd d „Z dS)Ú _mboxMMDFzAn mbox or MMDF mailbox.TcCsž|j|ƒ\}}|jj|ƒ|jjƒjtdƒ}|jj||jjƒƒ}|j|jtdƒƒ}|j |dd…j dƒƒ|S)z4Return a Message representation or raise a KeyError.ós rQNr) r™rÏrZrgr[r\rMrÛÚ_message_factoryÚset_fromÚdecode)rrräråÚ from_lineÚstringr£rrrr's z_mboxMMDF.get_messageFcCs"tj|j|ƒƒjd|ƒS)z3Return a string representation or raise a KeyError.Úunixfrom)r,r-r.r/)rrÚfrom_rrrr0sz_mboxMMDF.get_stringcCsg|j|ƒ\}}|jj|ƒ|s8|jjƒ|jj||jjƒƒ}|jtdƒS)z3Return a string representation or raise a KeyError.s )r™rÏrZrgrMrÛr[r\)rrròrärårðrrrr.s  z_mboxMMDF.get_bytescCsT|j|ƒ\}}|jj|ƒ|s8|jjƒt|j|jjƒ|ƒS)z6Return a file-like representation or raise a KeyError.)r™rÏrZrgÚ _PartialFilerÛ)rrròrärårrrr*s  z_mboxMMDF.get_filecCs€d}t|tƒr$|j|ƒ}t|tƒr“|jdƒr“|jdƒ}|dkr„|d|…}||dd…}q|}d}nmt|tƒrÄ|jƒjdƒ}d|}n<t|t j j ƒr|j ƒ}|dk r|jdƒ}|dkr+dt jt jƒƒjƒ}|jjƒ}|jj|tƒ|j||j|jƒ|jjƒ}||fS) z1Format a message and blindly write to self._file.NsFrom s rPrërsFrom MAILER-DAEMON rS)rTr`rKrarhÚfindÚ_mboxMMDFMessageÚget_fromrHr,rrÚ get_unixfromrºÚasctimeÚgmtimerÏrÛr]r\roÚ _mangle_from_)rrrïÚnewlineZauthorrärårrrrè$s0      z_mboxMMDF._install_messageN) rprqrrrsrúr'r0r.r*rèrrrrrêÿs   rêc@sLeZdZdZdZdZdddd„Zdd„Zdd „ZdS) rzA classic mbox mailbox.TNcCs#t|_tj||||ƒdS)zInitialize an mbox mailbox.N)r rìrêr)rrrrrrrrJs z mbox.__init__cCs|jtƒdS)z,Called after writing each message to file f.N)r]r\)rr¢rrrráOszmbox._post_message_hookcCsJgg}}d}|jjdƒxÞ|jjƒ}|jjƒ}|jdƒr®t|ƒt|ƒkr˜|r‹|j|ttƒƒn |j|ƒ|j|ƒd}q&|så|rÔ|j|ttƒƒn |j|ƒPq&|tkrúd}q&d}q&Wtt t ||ƒƒƒ|_ t|j ƒ|_ |jjƒ|_ dS)z0Generate key-to-(start, stop) table of contents.FrsFrom TN)rÏrZrÛrgrhr¦rªr\ÚdictÚ enumerateÚzipr}rÐrÔ)rÚstartsÚstopsZlast_was_emptyÚline_posrnrrrrçSs0        zmbox._generate_toc) rprqrrrsrúr^rrárçrrrrrAs  c@sLeZdZdZdddd„Zdd„Zdd „Zd d „ZdS) rzAn MMDF mailbox.NTcCs#t|_tj||||ƒdS)zInitialize an MMDF mailbox.N)r rìrêr)rrrrrrrrxs z MMDF.__init__cCs|jdtƒdS)z-Called before writing each message to file f.sN)r]r\)rr¢rrrrß}szMMDF._pre_message_hookcCs|jtdtƒdS)z,Called after writing each message to file f.sN)r]r\)rr¢rrrrá�szMMDF._post_message_hookcCs;gg}}|jjdƒd}x¼|}|jjƒ}|jjƒ}|jdtƒr×|j|ƒxq|}|jjƒ}|jjƒ}|dtkr¼|j|ttƒƒPqm|sm|j|ƒPqmWq&|s&Pq&Wtt t ||ƒƒƒ|_ t|j ƒ|_ |jjddƒ|jjƒ|_ dS)z0Generate key-to-(start, stop) table of contents.rsrON)rÏrZrgrÛrhr\rªr¦rürýrþr}rÐrÔ)rrÿrÚnext_posrrnrrrrç…s2   zMMDF._generate_toc)rprqrrrsrrßrárçrrrrrus   c@s$eZdZdZdddd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„ZdS)0rzAn MH mailbox.NTcCs¢tj||||ƒtjj|jƒs•|r†tj|jdƒtjtjtjj |jdƒtj tj Btj Bdƒƒnt |jƒ‚d|_dS)zInitialize an MH instance.iÀz .mh_sequencesi€FN)rrrrrzrr{rGr�rxr¯ÚO_EXCLr°r|rÓ)rrrrrrrr¥s!!z MH.__init__cCs,|jƒ}t|ƒdkr'd}nt|ƒd}tjj|jt|ƒƒ}t|ƒ}d}z­|j r}t |ƒzy|j ||ƒWnEt k rÛ|j r·t |ƒt|ƒd}tj|ƒ‚YnXt|tƒrû|j||ƒWd|j rt |ƒXWd|s't|ƒX|S)z$Add message and return assigned key.rrPFTN)r3r¦Úmaxrrrxrr`rÄrÓrÖror…r×r‡rrTr Ú_dump_sequences)rrr3Znew_keyr›r¢Úclosedrrrr±s6            zMH.addcCsœtjj|jt|ƒƒ}yt|dƒ}WnMtk r€}z-|jtjkrkt d|ƒ‚n‚WYdd}~XnX|j ƒtj |ƒdS)z=Remove the keyed message; raise KeyError if it doesn't exist.zrb+zNo message with key: %sN) rrrxrr`r�r‘r’rÌr!rGr)rrrr¢r˜rrrrÓs z MH.removecCstjj|jt|ƒƒ}yt|dƒ}WnMtk r€}z-|jtjkrkt d|ƒ‚n‚WYdd}~XnXz„|j r—t |ƒzVtj tj|tj tjBƒƒ|j||ƒt|tƒrì|j||ƒWd|j rt|ƒXWdt|ƒXdS)z>Replace the keyed message; raise KeyError if it doesn't exist.zrb+zNo message with key: %sN)rrrxrr`r�r‘r’rÌr!rÓrÖrGr°ÚO_TRUNCrorTr rr×r‡)rrrrr¢r˜rrrr#ás$  # zMH.__setitem__c Cs6y^|jr6ttjj|jt|ƒƒdƒ}n'ttjj|jt|ƒƒdƒ}WnMtk r­}z-|jtj kr˜t d|ƒ‚n‚WYdd}~XnX|�?|jrÈt |ƒzt |ƒ}Wd|jrît |ƒXWdQRXx9|jƒjƒD]%\}}||kr |j|ƒq W|S)z4Return a Message representation or raise a KeyError.zrb+rœzNo message with key: %sN)rÓr�rrrxrr`r‘r’rÌr!rÖr r×Ú get_sequencesr9Ú add_sequence)rrr¢r˜r£r†Úkey_listrrrr'ùs& *+    zMH.get_messagec Csy^|jr6ttjj|jt|ƒƒdƒ}n'ttjj|jt|ƒƒdƒ}WnMtk r­}z-|jtj kr˜t d|ƒ‚n‚WYdd}~XnX|�I|jrÈt |ƒz|j ƒj tdƒSWd|jrøt|ƒXWdQRXdS)z2Return a bytes representation or raise a KeyError.zrb+rœzNo message with key: %sNs )rÓr�rrrxrr`r‘r’rÌr!rÖrMr[r\r×)rrr¢r˜rrrr.s *+   z MH.get_bytescCs…y+ttjj|jt|ƒƒdƒ}WnMtk rz}z-|jtjkret d|ƒ‚n‚WYdd}~XnXt |ƒS)z6Return a file-like representation or raise a KeyError.rœzNo message with key: %sN) r�rrrxrr`r‘r’rÌr!r¤)rrr¢r˜rrrr*'s+z MH.get_filecCs)ttdd„tj|jƒDƒƒƒS)zReturn an iterator over keys.css'|]}|jƒrt|ƒVqdS)N)ÚisdigitrÀ)Ú.0r«rrrú 4szMH.iterkeys..)ÚiterrÞrr¨r)rrrrr12sz MH.iterkeyscCs(tjjtjj|jt|ƒƒƒS)z9Return True if the keyed message exists, False otherwise.)rrrzrxrr`)rrrrrr:7szMH.__contains__cCstt|jƒƒƒS)z*Return a count of messages in the mailbox.)r¦r2r1)rrrrr;;sz MH.__len__cCsG|jsCttjj|jdƒdƒ|_t|jƒd|_dS)zLock the mailbox.z .mh_sequenceszrb+TN)rÓr�rrrxrrÏrÖ)rrrrrE?s $ zMH.lockcCs6|jr2t|jƒt|jƒ|`d|_dS)z#Unlock the mailbox if it is locked.FN)rÓr×rÏr‡)rrrrrFFs    z MH.unlockcCsdS)z&Write any pending changes to the disk.Nr)rrrrrDNszMH.flushcCs|jr|jƒdS)zFlush and close the mailbox.N)rÓrF)rrrrrGRs zMH.closecCsXg}xKtj|jƒD]7}tjjtjj|j|ƒƒr|j|ƒqW|S)zReturn a list of folder names.)rr¨rrr©rxrª)rr=r«rrrr¬Ws $zMH.list_folderscCs+ttjj|j|ƒd|jddƒS)z+Return an MH instance for the named folder.rrF)rrrrxrr)rr­rrrr®_sz MH.get_foldercCs%ttjj|j|ƒd|jƒS)z:Create a folder and return an MH instance representing it.r)rrrrxrr)rr­rrrr±dsz MH.add_foldercCsˆtjj|j|ƒ}tj|ƒ}|dgkrUtjtjj|dƒƒn"|gkrdntd|jƒ‚tj|ƒdS)z-Delete the named folder, which must be empty.z .mh_sequenceszFolder not empty: %sN)rrrxrr¨rr³rµ)rr­rÚentriesrrrr¹is zMH.remove_folderc s`i}ttjj|jdƒdddƒ�,}t|jƒƒ‰x|D]}y×|jdƒ\}}tƒ}xr|jƒD]d}|jƒr¥|j t |ƒƒq}dd„|jdƒDƒ\}} |j t || d ƒƒq}W‡fd d †t |ƒDƒ||.ú-rPcs"g|]}|ˆkr|‘qSrr)r r)Úall_keysrrú „s z$MH.get_sequences..rz"Invalid sequence specification: %sN)r�rrrxrÚsetr3rŒr rrÀrCÚrangerÞr¦rJÚ FormatErrorÚrstrip) rZresultsr¢rnr†Úcontentsr3Úspecrärår)rrrus&*   "#   zMH.get_sequencesc Csettjj|jdƒdddƒ}z,tjtj|jtjtjBƒƒxÿ|j ƒD]ñ\}}t |ƒdkr~q]|j |dƒd}d}xƒt t |ƒƒD]o}|d |krà|sd }|j d ƒn7|rd}|j d ||fƒn|j d |ƒ|}q®W|rA|j t|ƒdƒq]|j dƒq]WWdt|ƒXdS)z:Set sequences using the given name-to-key-list dictionary.z .mh_sequenceszr+rrrrtNFrPTrz%s %sz %sÚ )r�rrrxrrGr†r°rr9r¦r]rÞrr`r‡)rÚ sequencesr¢r†r3ÚprevZ completingrrrrÚ set_sequences�s.'& zMH.set_sequencesc Cs¦|jƒ}d}g}x|jƒD]ö}|d|kr|j||dfƒttdƒrÍtjtjj|jt |ƒƒtjj|jt |dƒƒƒtj tjj|jt |ƒƒƒnDtj tjj|jt |ƒƒtjj|jt |dƒƒƒ|d7}q%W|d|_ t |ƒdkrBdSxP|jƒD]B\}}x3|D]+\}}||krb|||j|ƒReplace the keyed message; raise KeyError if it doesn't exist.N)rËr#rTr r,r+)rrrrrrr#êszBabyl.__setitem__c Csm|j|ƒ\}}|jj|ƒ|jjƒtjƒ}xD|jjƒ}|dtksg| rhP|j|jtdƒƒqAWtjƒ}x@|jjƒ}|tks¶| r·P|j|jtdƒƒq”W||jj ƒ}|dksùt ‚|jj |ƒ}|jtdƒ}t |j ƒ|ƒ} | j|j ƒƒ||jkri| j|j|ƒ| S)z4Return a Message representation or raise a KeyError.s *** EOOH ***s r)r™rÏrZrgrUrVr\r]r[rÛrÚrMr rfÚ set_visibler+Ú set_labels) rrräråÚoriginal_headersrnZvisible_headersÚnZbodyr£rrrr'ðs0   zBabyl.get_messagec Cs |j|ƒ\}}|jj|ƒ|jjƒtjƒ}xD|jjƒ}|dtksg| rhP|j|jtdƒƒqAWx'|jjƒ}|tksª| rˆPqˆW|j ƒ}||jj ƒ}|dksàt ‚|jj |ƒ}|jtdƒ}||S)z3Return a string representation or raise a KeyError.s *** EOOH ***s r) r™rÏrZrgrUrVr\r]r[rfrÛrÚrM) rrrärår/rnZheadersr0rmrrrr. s&   zBabyl.get_bytescCs"tj|j|ƒjdtƒƒS)z6Return a file-like representation or raise a KeyError.s )rUrVr.r[r\)rrrrrr*"szBabyl.get_filecCsT|jƒtƒ}x$|jjƒD]}|j|ƒq#W|j|jƒt|ƒS)z4Return a list of user-defined labels in the mailbox.)r™rr+r7rCÚdifference_updateÚ_special_labelsr2)rÚlabelsZ label_listrrrr,&s   zBabyl.get_labelscCs¹gg}}|jjdƒd}g}x|}|jjƒ}|jjƒ}|dtkrÛt|ƒt|ƒkr�|j|ttƒƒ|j|ƒdd„|jjƒdd…jdƒDƒ}|j|ƒq,|dks÷|dtkr)t|ƒt|ƒkrG|j|ttƒƒq,|s,|j|ttƒƒPq,Wtt t ||ƒƒƒ|_ tt |ƒƒ|_ t|j ƒ|_ |jjdd ƒ|jjƒ|_dS) z0Generate key-to-(start, stop) table of contents.rs cSs(g|]}|jƒr|jƒ‘qSr)Ústrip)r Úlabelrrrr=s z'Babyl._generate_toc..rPNó,srO)rÏrZrgrÛr\r¦rªrŒrürýrþr}r+rÐrÔ)rrÿrrZ label_listsrrnr3rrrrç/s4   &zBabyl._generate_toccCsmdt}|dt7}|jƒ}dd„|Dƒ}|ddj|ƒt7}|d7}|j|ƒdS) z,Called before writing the mailbox to file f.sBABYL OPTIONS:s Version: 5css|]}|jƒVqdS)N)rH)r r5rrrr Rsz*Babyl._pre_mailbox_hook..sLabels:r6sN)r\r,rxr])rr¢Zbabylr3rrrrÝMs   zBabyl._pre_mailbox_hookcCs|jdtƒdS)z-Called before writing each message to file f.s N)r]r\)rr¢rrrrßWszBabyl._pre_message_hookcCs|jtdƒdS)z,Called after writing each message to file f.sN)r]r\)rr¢rrrrá[szBabyl._post_message_hookcCsð|jjƒ}t|tƒrúg}g}x@|jƒD]2}||jkr\|j|ƒq7|j|ƒq7W|jjdƒx(|D] }|jjd|jƒƒq„W|jjdƒx,|D]$}|jjd|jƒdƒq¿W|jjt ƒn|jjdt ƒt|t j j ƒrÐt jƒ}t jj|ddƒ}|j|ƒ|jdƒx@|jƒ}|jj|jd t ƒƒ|d ksŸ| rdPqdW|jjd t ƒt|tƒrDt jƒ} t jj| ddƒ} | j|jƒƒx“| jƒ}|jj|jd t ƒƒ|d ks<| rPqWnP|jdƒx@|jƒ}|jj|jd t ƒƒ|d ks�| rTPqTWx@|jd ƒ} | s­P|jj| jd t ƒƒq—Wnt|ttt jfƒrt|t jƒrtjd td ƒ|jƒ}t|tƒr:|j|ƒ}|jdƒd} | ddkræ|jj|d| …jd t ƒƒ|jjd t ƒ|jj|d| …jd t ƒƒ|jj|| d…jd t ƒƒq×|jjd t t ƒ|jj|jd t ƒƒnºt |dƒrÁt |dƒrWtjdtd ƒ|j!}|jƒ} d}x¹|jƒ}|j"dƒrž|dd…d }n#|j"dƒrÁ|dd…d }|jj|jd t ƒƒ|d ksð| rl|r d}|jjd t ƒ|j| ƒqlPqlWx¯|jƒ}|s;P|j"dƒra|dd…t }nI|j"dƒr‡|dd…t }n#|j"d ƒrª|dd…t }|jj|ƒq(Wnt#dt$|ƒƒ‚|jjƒ}||fS)z0Write message contents and return (start, stop).ó1s, s,,ó r6s1,,Frs s *** EOOH ***iz8Use of StringIO input is deprecated, use BytesIO insteadrLs rOrPNrgrNzDUse of text mode files is deprecated, use a binary mode file insteadTs s zInvalid message type: %srSrRrSrRrSrS)%rÏrÛrTr r,r2rªr]rHr\r,rrrUrVrWrXrYrZrgr[Ú get_visiblerMrar`rbrcrdrerfrKrôr@rNr_rirj)rrräZspecial_labelsr3r5Z orig_bufferZorig_generatorrnZ vis_bufferZ vis_generatorrNZ body_startZ original_posZ first_passrårrrrè_sÀ  "        #   &&)      zBabyl._install_message)rprqrrrsÚ frozensetr2rrrr#r'r.r*r,rçrÝrßrárèrrrrrÒs          c@s=eZdZdZddd„Zdd„Zdd„ZdS) rz0Message with mailbox-format-specific properties.NcCs)t|tjjƒrJ|jtj|ƒƒt|tƒr%|j|ƒnÛt|tƒrr|jtj |ƒƒn³t|t ƒrš|jtj |ƒƒn‹t|t j ƒrÅ|jtj|ƒƒn`t|dƒrí|jtj|ƒƒn8|dkrtjjj|ƒntdt|ƒƒ‚dS)zInitialize a Message instance.rMNzInvalid message type: %s)rTr,rrÚ_become_messageÚcopyÚdeepcopyÚ _explain_torar-r`Zmessage_from_stringrUÚ TextIOWrapperZmessage_from_filer@Zmessage_from_binary_filerrirj)rrrrrrÎs zMessage.__init__cCsJt|dgƒ}x1|jD]&}||kr|j||j|èszMessage._explain_to)rprqrrrsrr;r>rrrrrËs  c@s¸eZdZdZdddgZddd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)r z)Message with Maildir-specific properties.Ú_subdirÚ_infoÚ_dateNcCs5d|_d|_tjƒ|_tj||ƒdS)z%Initialize a MaildirMessage instance.rvr‚N)rCrDrºrErr)rrrrrrõs  zMaildirMessage.__init__cCs|jS)zReturn 'new' or 'cur'.)rC)rrrrrˆüszMaildirMessage.get_subdircCs8|dks|dkr$||_ntd|ƒ‚dS)zSet subdir to 'new' or 'cur'.rvrwz!subdir must be 'new' or 'cur': %sN)rCrJ)rr”rrrržs zMaildirMessage.set_subdircCs+|jjdƒr#|jdd…SdSdS)z*Return as a string the flags that are set.z2,rONr‚)rDrh)rrrrÚ get_flagsszMaildirMessage.get_flagscCs ddjt|ƒƒ|_dS)z)Set the given flags and unset all others.z2,r‚N)rxrÞrD)rÚflagsrrrÚ set_flagsszMaildirMessage.set_flagscCs0|jdjt|jƒƒt|ƒBƒƒdS)z.Set the given flag(s) without changing others.r‚N)rHrxrrF)rÚflagrrrÚadd_flagszMaildirMessage.add_flagcCs<|jƒr8|jdjt|jƒƒt|ƒƒƒdS)z7Unset the given string flag(s) without changing others.r‚N)rFrHrxr)rrIrrrÚ remove_flags zMaildirMessage.remove_flagcCs|jS)z1sN         "            zMaildirMessage._explain_to)rprqrrrsr@rrˆržrFrHrJrKr�r rŠrŸr>rrrrr ðs           c@s…eZdZdZdgZddd„Zdd„Zddd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)rõz/Message with mbox- or MMDF-specific properties.Ú_fromNcCsw|jddƒt|tjjƒrc|jƒ}|dk rc|jdƒrc|j|dd…ƒtj||ƒdS)z'Initialize an mboxMMDFMessage instance.z MAILER-DAEMONTNzFrom rQ)rírTr,rrr÷rhr)rrrñrrrrbs  z_mboxMMDFMessage.__init__cCs|jS)z Return contents of "From " line.)rY)rrrrröksz_mboxMMDFMessage.get_fromcCsH|dk r;|dkr$tjƒ}|dtj|ƒ7}||_dS)z>Set "From " line, formatting and appending time_ if specified.NTú )rºrùrørY)rròZtime_rrrríos    z_mboxMMDFMessage.set_fromcCs |jddƒ|jddƒS)z*Return as a string the flags that are set.ÚStatusr‚zX-Status)r&)rrrrrFwsz_mboxMMDFMessage.get_flagscCst|ƒ}d \}}x1d D])}||kr||7}|j|ƒqWx1d D])}||krS||7}|j|ƒqSW|djt|ƒƒ7}y|jd|ƒWn"tk rÑ|jd|ƒYnXy|jd|ƒWn"tk r |jd|ƒYnXd S) z)Set the given flags and unset all others.r‚rOrPrRrSrTr[zX-StatusN)r‚r‚)rOrP)rRrSrT)rrrxrÞÚreplace_headerr!Z add_header)rrGZ status_flagsZ xstatus_flagsrIrrrrH{s&          z_mboxMMDFMessage.set_flagscCs0|jdjt|jƒƒt|ƒBƒƒdS)z.Set the given flag(s) without changing others.r‚N)rHrxrrF)rrIrrrrJ‘sz_mboxMMDFMessage.add_flagcCsHd|ksd|krD|jdjt|jƒƒt|ƒƒƒdS)z7Unset the given string flag(s) without changing others.r[zX-Statusr‚N)rHrxrrF)rrIrrrrK•sz_mboxMMDFMessage.remove_flagc Csst|tƒrt|jƒƒ}d|kr:|jdƒd|krS|jdƒd|krl|jdƒd|kr…|jdƒd|krž|jdƒ|d =|d =d j|jƒjƒdd …ƒ}y&|j t j t j |dƒƒƒWqottfk rYqoXnZt|tƒrM|j|jƒƒ|j|jƒƒn"t|tƒrÊt|jƒƒ}d|kr‡|jdƒd|kr |jdƒd|kr¹|jdƒ|d =|d =n¥t|tƒrGt|jƒƒ}d|kr|jdƒd|kr|jdƒd|kr6|jdƒ|d =|d =n(t|tƒrYntdt|ƒƒ‚d S)zACopy mbox- or MMDF-specific state to message insofar as possible.rPrwrSrTrOrNrRrQZstatuszx-statusrZrQNz%a %b %d %H:%M:%S %Yr&rUrVr'r(z$Cannot convert to specified type: %séûÿÿÿ)rTr rrFržrJrxrörŒr ÚcalendarZtimegmrºZstrptimerJÚ OverflowErrorrõrHrír r r rXrrirj)rrrGZ maybe_daterrrr>šs^          %              z_mboxMMDFMessage._explain_to) rprqrrrsr@rrörírFrHrJrKr>rrrrrõ]s       rõc@seZdZdZdS)r z&Message with mbox-specific properties.N)rprqrrrsrrrrr Îs c@sjeZdZdZdgZddd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)r z$Message with MH-specific properties.Ú _sequencesNcCsg|_tj||ƒdS)z!Initialize an MHMessage instance.N)r`rr)rrrrrr×s zMHMessage.__init__cCs|jdd…S)z4Return a list of sequences that include the message.N)r`)rrrrrÜszMHMessage.get_sequencescCst|ƒ|_dS)z3Set the list of sequences that include the message.N)r2r`)rrrrrr àszMHMessage.set_sequencescCsKt|tƒr1||jkrG|jj|ƒntdt|ƒƒ‚dS)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rTr`r`rªrirj)rr%rrrr äszMHMessage.add_sequencec Cs-y|jj|ƒWntk r(YnXdS)zARemove sequence from the list of sequences including the message.N)r`rrJ)rr%rrrÚremove_sequenceìs zMHMessage.remove_sequencecCsÃt|tƒrŒt|jƒƒ}d|kr=|jdƒn|jdƒ|jdƒd|krp|jdƒd|kr¿|jdƒn3t|tƒr t|jƒƒ}d|krÉ|jdƒn |jd ƒd|krï|jdƒd|kr¿|jd ƒn´t|tƒrAx¢|jƒD]}|j|ƒq'Wn~t|t ƒr—t|jƒƒ}d|kr{|j dƒd|kr¿|j d ƒn(t|t ƒr©nt d t |ƒƒ‚d S)z6Copy MH-specific state to message insofar as possible.r&rwrNrVrSrUrOÚROrPrTr(z$Cannot convert to specified type: %sN)rTr rrržrJrõr r r rXrrirj)rrrr%rrrr>ós@              zMHMessage._explain_to) rprqrrrsr@rrr r rar>rrrrr Òs      c@s‘eZdZdZddgZddd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dS)r z'Message with Babyl-specific properties.r+Ú_visibleNcCs)g|_tƒ|_tj||ƒdS)z#Initialize a BabylMessage instance.N)r+rrcr)rrrrrrs  zBabylMessage.__init__cCs|jdd…S)z'Return a list of labels on the message.N)r+)rrrrr,%szBabylMessage.get_labelscCst|ƒ|_dS)z&Set the list of labels on the message.N)r2r+)rr3rrrr.)szBabylMessage.set_labelscCsKt|tƒr1||jkrG|jj|ƒntdt|ƒƒ‚dS)z+Add label to list of labels on the message.zlabel must be a string: %sN)rTr`r+rªrirj)rr5rrrrX-szBabylMessage.add_labelc Cs-y|jj|ƒWntk r(YnXdS)z4Remove label from the list of labels on the message.N)r+rrJ)rr5rrrÚ remove_label5s zBabylMessage.remove_labelcCs t|jƒS)z3Return a Message representation of visible headers.)rrc)rrrrr9<szBabylMessage.get_visiblecCst|ƒ|_dS)z2Set the Message representation of visible headers.N)rrc)rZvisiblerrrr-@szBabylMessage.set_visiblecCs‹xG|jjƒD]6}||kr<|jj|||ƒq|j|=qWx:dD]2}||krQ||jkrQ|||j|OsF               zBabylMessage._explain_to)rprqrrrsr@rr,r.rXrdr9r-rlr>rrrrr s         c@seZdZdZdS)r z&Message with MMDF-specific properties.N)rprqrrrsrrrrr ys c@súeZdZdZddd„Zddd„Zddd„Zdd d „Zdd d „Zd d„Z dd„Z ddd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zed$d%„ƒZdS)&r¤zA read-only wrapper of a file.NcCs4||_|dkr'|jƒ|_n ||_dS)zInitialize a _ProxyFile.N)rÏrÛÚ_pos)rr¢Úposrrrr€s  z_ProxyFile.__init__cCs|j||jjƒS)z Read bytes.)Ú_readrÏrM)rÚsizerrrrMˆsz_ProxyFile.readcCs|j||jjƒS)z Read bytes.)rorÏÚread1)rrprrrrqŒsz_ProxyFile.read1cCs|j||jjƒS)z Read a line.)rorÏrg)rrprrrrg�sz_ProxyFile.readlinecCsQg}xD|D]<}|j|ƒ|dk r |t|ƒ8}|dkr Pq W|S)zRead multiple lines.Nr)rªr¦)rÚsizehintr=rnrrrÚ readlines”s    z_ProxyFile.readlinesccs&x|jƒ}|sdS|VqWdS)zIterate over lines.N)rg)rrnrrrr6Ÿs  z_ProxyFile.__iter__cCs|jS)zReturn the position.)rm)rrrrrÛ§sz_ProxyFile.tellrcCsH|dkr|jj|jƒ|jj||ƒ|jjƒ|_dS)zChange position.rPN)rÏrZrmrÛ)rÚoffsetÚwhencerrrrZ«s z_ProxyFile.seekc Cs@t|dƒr<z#t|jdƒr1|jjƒWd|`XdS)zClose the file.rÏrGN)r@rÏrG)rrrrrG²s z_ProxyFile.closecCsG|dkrd}|jj|jƒ||ƒ}|jjƒ|_|S)z"Read size bytes using read_method.NrPrS)rÏrZrmrÛ)rrpÚ read_methodr=rrrro»s   z_ProxyFile._readcCs|S)z$Context management protocol support.r)rrrrÚ __enter__Äsz_ProxyFile.__enter__cGs|jƒdS)N)rG)rÚexcrrrÚ__exit__Èsz_ProxyFile.__exit__cCs |jjƒS)N)rÏÚreadable)rrrrrzËsz_ProxyFile.readablecCs |jjƒS)N)rÏÚwritable)rrrrr{Îsz_ProxyFile.writablecCs |jjƒS)N)rÏÚseekable)rrrrr|Ñsz_ProxyFile.seekablecCs |jjƒS)N)rÏrD)rrrrrDÔsz_ProxyFile.flushcCs3t|dƒsdSt|jdƒs)dS|jjS)NrÏTrF)r@rÏr)rrrrr×s z_ProxyFile.closed)rprqrrrsrrMrqrgrsr6rÛrZrGrorwryrzr{r|rDÚpropertyrrrrrr¤}s$         r¤c@s[eZdZdZdddd„Zdd„Zddd „Zd d „Zd d „ZdS)róz&A read-only wrapper of part of a file.NcCs)tj|||ƒ||_||_dS)zInitialize a _PartialFile.N)r¤rÚ_startÚ_stop)rr¢rärårrrrãs z_PartialFile.__init__cCstj|ƒ|jS)z*Return the position with respect to start.)r¤rÛr~)rrrrrÛész_PartialFile.tellrcCsV|dkr!|j|_d}n|dkr?|j|_d}tj|||ƒdS)z8Change position, possibly with respect to start or stop.rrPrON)r~rmrr¤rZ)rrtrurrrrZís     z_PartialFile.seekcCs]|j|j}|dkr dS|dksD|dksD||krJ|}tj|||ƒS)z;Read size bytes using read_method, honoring start and stop.rrëN)rrmr¤ro)rrprvZ remainingrrrro÷s  $z_PartialFile._readcCst|dƒr|`dS)NrÏ)r@rÏ)rrrrrGsz_PartialFile.close) rprqrrrsrrÛrZrorGrrrrróàs   róTc-Csäd}y™tr�ytj|tjtjBƒWn_tk rŽ}z?|jtjtjtjfkryt d|j ƒ‚n‚WYdd}~XnX|ržy!t |j dƒ}|j ƒWnGtk rÿ}z'|jtjtjfkrêdS‚WYdd}~XnXyft tdƒrEtj|j |j dƒd}tj|j ƒn tj|j |j dƒd}Wn5tk r�tj|j ƒt d|j ƒ‚YnXWn>tr¾tj|tjƒ|rØtj|j dƒ‚YnXdS)z(Lock file f using lockf and dot locking.Fzlockf: lock unavailable: %sNz.lockrƒTzdot lock unavailable: %s)ÚfcntlÚlockfZLOCK_EXZLOCK_NBr‘r’ZEAGAINrÍrÎr“r†rÜrGr@rrƒr!r�rÅrÚLOCK_UN)r¢rØZ dotlock_doner˜Zpre_lockrrrrÖsF!  rÖcCsJtrtj|tjƒtjj|jdƒrFtj|jdƒdS)z*Unlock file f using lockf and dot locking.z.lockN)r€r�r‚rrrzr†r)r¢rrrr×0sr×c CsLtj|tjtjBtjBdƒ}zt|dƒSWdtj|ƒXdS)zCCreate a file if it doesn't exist and open for reading and writing.i¶zrb+N)rr�r¯rÚO_RDWRrG)rÚfdrrrrÄ7s&rÄcCs2td|ttjƒƒtjƒtjƒfƒS)zBCreate a temp file based on path and open for reading and writing.z %s.%s.%s.%s)rÄrÀrºr¾r¿rrÁ)rrrrrÜ?s rÜcCs0|jƒttdƒr,tj|jƒƒdS)z0Ensure changes to file f are physically on disk.ÚfsyncN)rDr@rr…Úfileno)r¢rrrrÙEs rÙcCst|ƒ|jƒdS)z:Close file f, ensuring all changes are physically on disk.N)rÙrG)r¢rrrr‡Ks r‡c@seZdZdZdS)ÚErrorz"Raised for module-specific errors.N)rprqrrrsrrrrr‡Qs r‡c@seZdZdZdS)r|z:The specified mailbox does not exist and won't be created.N)rprqrrrsrrrrr|Ts r|c@seZdZdZdS)r³z>The specified mailbox is not empty and deletion was requested.N)rprqrrrsrrrrr³Ws r³c@seZdZdZdS)r“z)Another process caused an action to fail.N)rprqrrrsrrrrr“Zs r“c@seZdZdZdS)rz)A file appears to have an invalid format.N)rprqrrrsrrrrr]s r)0rsrrºr^r¾r’r<rcr,Z email.messageZemail.generatorrUr(r€Ú ImportErrorÚ__all__r\rHrrrËrêrrrrrrr rõr r r r r¤rórÖr×rÄrÜrÙr‡Ú Exceptionr‡r|r³r“rrrrrÚsd                çÿ6ÃB4-ÿ1ù%mqH_c')