U e5dE3ã@sRdZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl Zddl Z ddl Z z ddl Z Wnek rˆdZ YnXddddddd d d d d ddddddgZej d¡ZGdd„dƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd „d ejjƒZGd d „d eƒZGd!d"„d"eƒZGd#d „d eƒZGd$d „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%d0d1„Z&d2d3„Z'd4d5„Z(d6d7„Z)Gd8d„de*ƒZ+Gd9d„de+ƒZ,Gd:d„de+ƒZ-Gd;d„de+ƒZ.GdzDRead/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.éNÚMailboxÚMaildirÚmboxÚMHÚBabylÚMMDFÚMessageÚMaildirMessageÚ mboxMessageÚ MHMessageÚ BabylMessageÚ MMDFMessageÚErrorÚNoSuchMailboxErrorÚ NotEmptyErrorÚExternalClashErrorÚ FormatErrorÚasciic@seZdZdZdCdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dDdd„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/„ZdEd0d1„Zd2d3„ZdFd4d5„Zd6d7„Zd8d9„Zd:d;„Zdd?„Z!d@Z"dGdAdB„Z#dS)Hrz*A group of messages in a particular place.NTcCs tj tj |¡¡|_||_dS)zInitialize a Mailbox instance.N)ÚosÚpathÚabspathÚ expanduserÚ_pathÚ_factory©ÚselfrÚfactoryÚcreate©rú/usr/lib64/python3.8/mailbox.pyÚ__init__$szMailbox.__init__cCs tdƒ‚dS)ú$Add message and return assigned key.ú&Method must be implemented by subclassN©ÚNotImplementedError©rÚmessagerrrÚadd)sz Mailbox.addcCs tdƒ‚dS)ú=Remove the keyed message; raise KeyError if it doesn't exist.r"Nr#©rÚkeyrrrÚremove-szMailbox.removecCs| |¡dS©N)r+r)rrrÚ __delitem__1szMailbox.__delitem__cCs(z| |¡Wntk r"YnXdS©z'If the keyed message exists, remove it.N)r+ÚKeyErrorr)rrrÚdiscard4szMailbox.discardcCs tdƒ‚dS)ú>Replace the keyed message; raise KeyError if it doesn't exist.r"Nr#©rr*r&rrrÚ __setitem__;szMailbox.__setitem__cCs*z | |¡WStk r$|YSXdS)z9Return the keyed message, or default if it doesn't exist.N)Ú __getitem__r/)rr*ÚdefaultrrrÚget?s z Mailbox.getc CsB|js| |¡St | |¡¡}| |¡W5QR£SQRXdS)z=Return the keyed message; raise KeyError if it doesn't exist.N)rÚ get_messageÚ contextlibÚclosingÚget_file)rr*Úfilerrrr4Fs zMailbox.__getitem__cCs tdƒ‚dS)ú4Return a Message representation or raise a KeyError.r"Nr#r)rrrr7NszMailbox.get_messagecCst | |¡¡ ¡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_bytesZ as_stringr)rrrÚ get_stringRszMailbox.get_stringcCs tdƒ‚dS)z8Return a byte string representation or raise a KeyError.r"Nr#r)rrrr@YszMailbox.get_bytescCs tdƒ‚dS)ú6Return a file-like representation or raise a KeyError.r"Nr#r)rrrr:]szMailbox.get_filecCs tdƒ‚dS)úReturn an iterator over keys.r"Nr#©rrrrÚiterkeysaszMailbox.iterkeyscCs t| ¡ƒS)zReturn a list of keys.)ÚlistrErDrrrÚkeysesz Mailbox.keysc cs>| ¡D]0}z ||}Wntk r0YqYnX|VqdS)z%Return an iterator over all messages.N©rEr/©rr*ÚvaluerrrÚ itervaluesis    zMailbox.itervaluescCs| ¡Sr,)rKrDrrrÚ__iter__rszMailbox.__iter__cCs t| ¡ƒS)z,Return a list of messages. Memory intensive.)rFrKrDrrrÚvaluesuszMailbox.valuesc csB| ¡D]4}z ||}Wntk r0YqYnX||fVqdS)z.Return an iterator over (key, message) tuples.NrHrIrrrÚ iteritemsys    zMailbox.iteritemscCs t| ¡ƒS)z9Return a list of (key, message) tuples. Memory intensive.)rFrNrDrrrÚitems‚sz Mailbox.itemscCs tdƒ‚dS)ú9Return True if the keyed message exists, False otherwise.r"Nr#r)rrrÚ __contains__†szMailbox.__contains__cCs tdƒ‚dS)ú*Return a count of messages in the mailbox.r"Nr#rDrrrÚ__len__ŠszMailbox.__len__cCs| ¡D]}| |¡qdS)zDelete all messages.N)rGr0r)rrrÚclearŽs z Mailbox.clearcCs4z ||}Wntk r$|YSX| |¡|S)z3Delete the keyed message and return it, or default.)r/r0)rr*r5ÚresultrrrÚpop“s    z Mailbox.popcCs*| ¡D]}|| |¡fStdƒ‚dS)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailboxN)rErVr/r)rrrÚpopitemœs zMailbox.popitemc Cstt|dƒr| ¡}nt|dƒr(| ¡}n|}d}|D].\}}z |||<Wq4tk r`d}Yq4Xq4|rptdƒ‚dS)z4Change the messages that correspond to certain keys.rNrOFTzNo message with key(s)N)ÚhasattrrNrOr/)rÚargÚsourceZbad_keyr*r&rrrÚupdate£s       zMailbox.updatecCs tdƒ‚dS)ú&Write any pending changes to the disk.r"Nr#rDrrrÚflush´sz Mailbox.flushcCs tdƒ‚dS)úLock the mailbox.r"Nr#rDrrrÚlock¸sz Mailbox.lockcCs tdƒ‚dS)ú#Unlock the mailbox if it is locked.r"Nr#rDrrrÚunlock¼szMailbox.unlockcCs tdƒ‚dS)úFlush and close the mailbox.r"Nr#rDrrrÚcloseÀsz Mailbox.closecCs.z | d¡WStk r(tdƒ‚YnXdS)Nrz?String input must be ASCII-only; use bytes or a Message instead)ÚencodeÚ UnicodeErrorÚ ValueErrorr%rrrÚ_string_to_bytesÄs zMailbox._string_to_bytesFc Csüt|tjjƒrvt ¡}tj ||d¡}| |¡|  d¡|  ¡}|  dt ¡}|  |¡|jrr| t ¡sr|  t ¡n‚t|tttjfƒrt|tjƒr¬t dtd¡| ¡}t|tƒrÀ| |¡}|rÐ|  dd¡}|  dt ¡}|  |¡|jrø| t ¡sø|  t ¡nòt|dƒrèt|dƒr2t d td¡|j}d }| ¡}| d ¡r\|d d …d}n| d ¡rx|d d…d}|s‚qÂ|r¤| d¡r¤d|dd …}|  dt ¡}|  |¡|}q6|jrø|rø| t ¡sø|  t ¡ntdt|ƒƒ‚d S)z%Dump message contents to target file.ró ú8Use of StringIO input is deprecated, use BytesIO insteadés From s >From ÚreadÚbufferúDUse of text mode files is deprecated, use a binary mode file insteadNó éþÿÿÿó éÿÿÿÿóFrom s>From éúInvalid message type: %s)Ú isinstancer>r&rÚioÚBytesIOÚ generatorÚBytesGeneratorÚflattenÚseekrkÚreplaceÚlinesepÚwriteÚ_append_newlineÚendswithÚstrÚbytesÚStringIOÚwarningsÚwarnÚDeprecationWarningÚgetvaluergrXrlÚreadlineÚ startswithÚ TypeErrorÚtype) rr&ÚtargetZ mangle_from_rlÚgenÚdataZlastlineÚlinerrrÚ _dump_messageÑs`     ÿ        ÿ     zMailbox._dump_message)NT)N)N)N)F)$Ú__name__Ú __module__Ú __qualname__Ú__doc__r r'r+r-r0r3r6r4r7rAr@r:rErGrKrLrMrNrOrQrSrTrVrWr[r]r_rarcrgrrrrrrr!sB       c@sÚeZdZdZdZd6dd„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)7rzA qmail-style Maildir mailbox.ú:NTcCs¬t ||||¡tj |jd¡tj |jd¡tj |jd¡dœ|_tj |j¡sŠ|r€t |jd¡|j  ¡D]}t |d¡qln t |jƒ‚i|_ dddœ|_ d|_ d|_d S) zInitialize a Maildir instance.ÚtmpÚnewÚcur)r–r—r˜éÀr)r˜r—gš™™™™™¹?N)rr rrÚjoinrÚ_pathsÚexistsÚmkdirrMrÚ_tocÚ _toc_mtimesÚ _last_readÚ _skewfactor)rÚdirnamerrrrrrr sý  zMaildir.__init__c Cs~| ¡}z| ||¡Wn*tk rB| ¡t |j¡‚YnXt|ƒt|t ƒr||  ¡}|j |  ¡}||j kr„d}nd}d}tj  |j¡ |j ¡d}tj  |j|||¡}t|t ƒrÞt |jtj  |j¡| ¡f¡zLzt |j|¡Wn(ttfk rt |j|¡YnXt |j¡WnNtk rx}z.t |j¡|jtjkrftd|ƒ‚n‚W5d}~XYnX|S)r!Úr—rz$Name clash with existing message: %sN)Ú _create_tmprÚ BaseExceptionrcrr+ÚnameÚ _sync_closerur Ú get_subdirÚcolonÚget_inforÚbasenameÚsplitršrÚutimeÚgetatimeÚget_dateÚlinkÚAttributeErrorÚPermissionErrorÚrenameÚOSErrorÚerrnoZEEXISTr)rr&Ztmp_fileÚsubdirÚsuffixÚuniqÚdestÚerrrr'!sF    ÿ ÿz Maildir.addcCs t tj |j| |¡¡¡dS©r(N)rr+rršrÚ_lookupr)rrrr+KszMaildir.removec Cs,z| |¡Wnttfk r&YnXdSr.)r+r/ÚFileNotFoundErrorr)rrrr0OszMaildir.discardc CsÊ| |¡}| |¡}| |¡}t|tƒr.|}n|}tj |¡}|j|kr`|j| |j¡d}nd}|  |¡tj  |j |¡} tj  |j |||¡} t|tƒrºt  | tj  | ¡| ¡f¡t | | ¡dS)r1rqr£N)r¼r'rur rrr¢r©r¬r0ršrr­r®r¯r³) rr*r&Z old_subpathZtemp_keyZ temp_subpathZdominant_subpathr¶r·Ztmp_pathÚnew_pathrrrr3Ws$        ÿzMaildir.__setitem__c Cs¢| |¡}ttj |j|¡dƒ }|jr4| |¡}nt|ƒ}W5QRXtj |¡\}}|  |¡|j |kr€|  | |j ¡d¡|  tj  tj |j|¡¡¡|S)r<Úrbrq)r¼Úopenrrršrrr r¬Ú set_subdirr©Úset_infoÚset_dateÚgetmtime)rr*ZsubpathÚfÚmsgr¶r¦rrrr7rs    zMaildir.get_messagec CsDttj |j| |¡¡dƒ}| ¡ td¡W5QR£SQRXdS)ú2Return a bytes representation or raise a KeyError.r¿rhN) rÀrrršrr¼rkr|r}©rr*rÅrrrr@szMaildir.get_bytescCs$ttj |j| |¡¡dƒ}t|ƒS)rBr¿)rÀrrršrr¼Ú _ProxyFilerÈrrrr:†szMaildir.get_filec csF| ¡|jD]2}z| |¡Wntk r8YqYnX|VqdS©rCN)Ú_refreshržr¼r/r)rrrrE‹s  zMaildir.iterkeyscCs| ¡||jkS©rP)rËržr)rrrrQ•szMaildir.__contains__cCs| ¡t|jƒS©rR)rËÚlenržrDrrrrSšszMaildir.__len__cCsdS)ú"Write any pending changes to disk.NrrDrrrr]Ÿsz Maildir.flushcCsdS)r^NrrDrrrr_¥sz Maildir.lockcCsdS)r`NrrDrrrra©szMaildir.unlockcCsdS©rbNrrDrrrrc­sz Maildir.closecCs\g}t |j¡D]F}t|ƒdkr|ddkrtj tj |j|¡¡r| |dd…¡q|S)úReturn a list of folder names.érÚ.N)rÚlistdirrrÎrÚisdirršÚappend©rrUÚentryrrrÚ list_folders±sÿzMaildir.list_folderscCs ttj |jd|¡|jddS)z/Return a Maildir instance for the named folder.rÓF©rr)rrrršrr©rÚfolderrrrÚ get_folderºsþzMaildir.get_foldercCs\tj |jd|¡}t||jd}tj |d¡}tj |¡sXt t |tj tj Bd¡¡|S)z>Create a folder and return a Maildir instance representing it.rÓ©rZ maildirfolderé¶) rrršrrrrœrcrÀÚO_CREATÚO_WRONLY)rrÜrrUZmaildirfolder_pathrrrÚ add_folderÀs ÿzMaildir.add_foldercCstj |jd|¡}t tj |d¡¡t tj |d¡¡D](}t|ƒdksX|ddkrs"  @ rþc@sBeZdZdZdZdd„Zddd„Zddd „Zdd d „Zd d „Z dS)Ú _mboxMMDFzAn mbox or MMDF mailbox.TcCsp| |¡\}}|j |¡|j ¡ td¡}|j ||j ¡¡}| | td¡¡}|  |dd…  d¡¡|S)r<órhrsNr) r¼rr{rˆr|r}rkrÚ_message_factoryÚset_fromÚdecode)rr*rrÚ from_lineÚstringrÆrrrr7s z_mboxMMDF.get_messageFcCst | ||¡¡j|dS)ú3Return a string representation or raise a KeyError.)Úunixfromr=)rr*Úfrom_rrrrAs  ÿÿz_mboxMMDF.get_stringcCsJ| |¡\}}|j |¡|s(|j ¡|j ||j ¡¡}| td¡S)r+rh)r¼rr{rˆrkrr|r})rr*r-rrr*rrrr@s   z_mboxMMDF.get_bytescCs<| |¡\}}|j |¡|s(|j ¡t|j|j ¡|ƒS)rB)r¼rr{rˆÚ _PartialFiler)rr*r-rrrrrr:s   z_mboxMMDF.get_filecCs d}t|tƒr| |¡}t|tƒrf| d¡rf| d¡}|dkr\|d|…}||dd…}q°|}d}nJt|tƒrˆ| ¡ d¡}d|}n(t|t j j ƒr°|  ¡}|dk r°| d¡}|dkrÎdt  t  ¡¡ ¡}|j ¡}|j |t¡| ||j|j¡|j ¡}||fS) z1Format a message and blindly write to self._file.NrrrhrqrÒr%rsFrom MAILER-DAEMON )rurrgr‚r‰ÚfindÚ_mboxMMDFMessageÚget_fromrdr>r&rÚ get_unixfromrëÚasctimeÚgmtimerrr~r}rÚ _mangle_from_)rr&r)ÚnewlineZauthorrrrrrr"&s0         z_mboxMMDF._install_messageN)F)F)F) r‘r’r“r”r5r7rAr@r:r"rrrrr$s  r$c@s2eZdZdZdZdZd dd„Zdd„Zdd „ZdS) rzA classic mbox mailbox.TNcCst|_t ||||¡dS)zInitialize an mbox mailbox.N)r r&r$r rrrrr Lsz mbox.__init__cCs| t¡dSr©r~r}rrrrrQszmbox._post_message_hookcCsègg}}d}|j d¡|j ¡}|j ¡}| d¡rzt|ƒt|ƒkrj|r`| |ttƒ¡n | |¡| |¡d}q|s¤|r–| |ttƒ¡q¸| |¡q¸q|tkr²d}qd}qtt t ||ƒƒƒ|_ t|j ƒ|_ |j ¡|_ dS)ú0Generate key-to-(start, stop) table of contents.FrrrTN)rr{rrˆr‰rÎrÖr}ÚdictÚ enumerateÚzipržrr)rÚstartsÚstopsZlast_was_emptyÚline_posrrrrr!Us.         zmbox._generate_toc)NT) r‘r’r“r”r5rr rr!rrrrrCs  c@s2eZdZdZd dd„Zdd„Zdd „Zd d „ZdS) rzAn MMDF mailbox.NTcCst|_t ||||¡dS)zInitialize an MMDF mailbox.N)r r&r$r rrrrr zsz MMDF.__init__cCs| dt¡dS)róNr7rrrrrszMMDF._pre_message_hookcCs| tdt¡dS)r r?Nr7rrrrrƒszMMDF._post_message_hookcCsÞgg}}|j d¡d}|}|j ¡}|j ¡}| dt¡r˜| |¡|}|j ¡}|j ¡}|dtkr„| |ttƒ¡qžqJ|sJ| |¡qžqJq|sq qtt t ||ƒƒƒ|_ t|j ƒ|_ |j dd¡|j ¡|_ dS)r8rr?r÷N)rr{rˆrr‰r}rÖrÎr9r:r;ržrr)rr<r=Únext_posr>rrrrr!‡s.          zMMDF._generate_toc)NT)r‘r’r“r”r rrr!rrrrrws  c@sÂeZdZdZd0dd„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)1rzAn MH mailbox.NTcCstt ||||¡tj |j¡sj|r`t |jd¡t t tj  |jd¡tj tj Btj Bd¡¡n t |jƒ‚d|_dS)zInitialize an MH instance.r™ú .mh_sequencesi€FN)rr rrrœrrrcrÀršràÚO_EXCLrárrrrrrr §sÿ z MH.__init__cCsä| ¡}t|ƒdkrd}n t|ƒd}tj |jt|ƒ¡}t|ƒ}d}zŠ|j rVt |ƒzfz|  ||¡Wn:tk r¢|j r†t |ƒt |ƒd}t |¡‚YnXt|tƒrº| ||¡W5|j rÌt |ƒXW5|sÞt |ƒX|S)r!rrÒFT)rGrÎÚmaxrrršrrrõr§rr r rr¥r+rur Ú_dump_sequences)rr&rGZnew_keyr¾rÅÚclosedrrrr'³s6     zMH.addc Csxtj |jt|ƒ¡}zt|dƒ}Wn>tk r`}z |jtjkrNt d|ƒ‚n‚W5d}~XYnX|  ¡t  |¡dS)r(rÿrúN) rrršrrrÀr´rµrr/rcr+)rr*rrÅrºrrrr+Õs z MH.removec CsÖtj |jt|ƒ¡}zt|dƒ}Wn>tk r`}z |jtjkrNt d|ƒ‚n‚W5d}~XYnXzd|j rrt |ƒz@t t |tjtjB¡¡| ||¡t|tƒr°| ||¡W5|j rÂt |ƒXW5t |ƒXdS)r1rÿrúN)rrršrrrÀr´rµrr/r§rr r rcráÚO_TRUNCrrur rD)rr*r&rrÅrºrrrr3ãs$   zMH.__setitem__c Csèz@|jr$ttj |jt|ƒ¡dƒ}nttj |jt|ƒ¡dƒ}Wn>tk r~}z |jtj krlt d|ƒ‚n‚W5d}~XYnX|2|jr”t |ƒz t |ƒ}W5|jr°t |ƒXW5QRX| ¡ ¡D]\}}||krÈ| |¡qÈ|S)r<rÿr¿rúN)rrÀrrršrrr´rµrr/r r r Ú get_sequencesrOÚ add_sequence)rr*rÅrºrÆr¦Úkey_listrrrr7ûs&   zMH.get_messagec CsÔz@|jr$ttj |jt|ƒ¡dƒ}nttj |jt|ƒ¡dƒ}Wn>tk r~}z |jtj krlt d|ƒ‚n‚W5d}~XYnX|F|jr”t |ƒz |  ¡ td¡W¢W5QR£S|jrÄt |ƒXW5QRXdS)rÇrÿr¿rúNrh)rrÀrrršrrr´rµrr/r r rkr|r}©rr*rÅrºrrrr@s  z MH.get_bytesc Csfzttj |jt|ƒ¡dƒ}Wn>tk r\}z |jtjkrJt d|ƒ‚n‚W5d}~XYnXt |ƒS)rBr¿rúN) rÀrrršrrr´rµrr/rÉrJrrrr:)s z MH.get_filecCsttdd„t |j¡DƒƒƒS)rCcss|]}| ¡rt|ƒVqdSr,)Úisdigitrñ)Ú.0rØrrrÚ 6sÿzMH.iterkeys..)ÚiterrrrÔrrDrrrrE4sz MH.iterkeyscCstj tj |jt|ƒ¡¡SrÌ)rrrœršrrr)rrrrQ9szMH.__contains__cCstt| ¡ƒƒSrÍ)rÎrFrErDrrrrS=sz MH.__len__cCs2|js.ttj |jd¡dƒ|_t|jƒd|_dS)r^rArÿTN)rrÀrrršrrr rDrrrr_As zMH.lockcCs(|jr$t|jƒt|jƒ|`d|_dSr )rr rr§rDrrrraHs   z MH.unlockcCsdS)r\NrrDrrrr]PszMH.flushcCs|jr| ¡dSrÐ)rrarDrrrrcTszMH.closecCs<g}t |j¡D]&}tj tj |j|¡¡r| |¡q|S)rÑ)rrÔrrrÕršrÖr×rrrrÙYs  zMH.list_folderscCsttj |j|¡|jddS)z+Return an MH instance for the named folder.FrÚ©rrrršrrrÛrrrrÝasÿz MH.get_foldercCsttj |j|¡|jdS)z:Create a folder and return an MH instance representing it.rÞrOrÛrrrrâfsÿz MH.add_foldercCs`tj |j|¡}t |¡}|dgkr:t tj |d¡¡n|gkrDntd|jƒ‚t |¡dS)rãrAzFolder not empty: %sN)rrršrrÔr+rræ)rrÜrÚentriesrrrrêks  zMH.remove_folderc si}ttj |jd¡dddÜ}t| ¡ƒ‰|D]Ä}zš| d¡\}}tƒ}| ¡D]H}| ¡rn|  t |ƒ¡qRdd„| d¡Dƒ\}} |  t || d ƒ¡qR‡fd d „t |ƒDƒ||<t||ƒd krÌ||=Wq0tk ròtd | ¡ƒ‚Yq0Xq0W5QRX|S)z=Return a name-to-key-list dictionary to define each sequence.rAÚrÚASCII©Úencodingr•css|]}t|ƒVqdSr,)rñ)rLÚxrrrrM„sz#MH.get_sequences..ú-rÒcsg|]}|ˆkr|‘qSrr)rLr*©Zall_keysrrÚ †sÿz$MH.get_sequences..rz"Invalid sequence specification: %s)rÀrrršrÚsetrGr¬rKr'rñr[ÚrangerrÎrfrÚrstrip) rZresultsrÅrr¦ÚcontentsrGÚspecrrrrWrrGws(   ÿzMH.get_sequencescCsttj |jd¡ddd}zØt t |jtjtj B¡¡|  ¡D]®\}}t |ƒdkrVq@|  |d¡d}d}t t|ƒƒD]R}|d |krœ|sÆd }|  d ¡n*|r¸d}|  d ||f¡n|  d |¡|}qx|rä|  t|ƒd¡q@|  d¡q@W5t|ƒXdS)z:Set sequences using the given name-to-key-list dictionary.rAzr+rRrSrr•NFrÒTrVz%s %sz %sÚ )rÀrrršrr§rcr¦rárFrOrÎr~rrYr)rÚ sequencesrÅr¦rGÚprevZ completingr*rrrÚ set_sequencess.   zMH.set_sequencesc Cs>| ¡}d}g}| ¡D]Â}|d|krÒ| ||df¡z4t tj |jt|ƒ¡tj |jt|dƒ¡¡WnHt t fk r¶t  tj |jt|ƒ¡tj |jt|dƒ¡¡YnXt  tj |jt|ƒ¡¡|d7}q|d|_ t|ƒdkrödS| ¡D]0\}}|D]"\}}||kr ||| |¡<q qþ| |¡dS)z?Re-name messages to eliminate numbering gaps. Invalidates keys.rrÒN)rGrErÖrr°rršrrr±r²r³ÚunlinkrrÎrOÚindexra) rr_r`Zchangesr*r¦rIÚoldr—rrrÚpack¬s0  ÿÿ      zMH.packcCst| ¡}| ¡}| ¡D]0\}}||kr4| |¡q||kr|| |¡=q|D]}||krN|g||<qN| |¡dS)z;Inspect a new MHMessage and update sequences appropriately.N)rGrOrÖrcra)rr&r*Zpending_sequencesZ all_sequencesr¦rIÚsequencerrrrDÆs  zMH._dump_sequences)NT)r‘r’r“r”r r'r+r3r7r@r:rErQrSr_rar]rcrÙrÝrârêrGrarerDrrrrr¤s. "  c@seZdZdZedddddddhƒZd%d d „Zd d„Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd „Zd!d"„Zd#d$„Zd S)&rzAn Rmail-style Babyl mailbox.ÚunseenÚdeletedZfiledÚansweredÚ forwardedZeditedÚresentNTcCst ||||¡i|_dS)zInitialize a Babyl mailbox.N)rþr Ú_labelsrrrrr ÛszBabyl.__init__cCs(t ||¡}t|tƒr$| ¡|j|<|S)r!)rþr'rur Ú get_labelsrl)rr&r*rrrr'às  z Babyl.addcCs"t ||¡||jkr|j|=dSr»)rþr+rlr)rrrr+çs  z Babyl.removecCs*t |||¡t|tƒr&| ¡|j|<dS)r1N)rþr3rur rmrlr2rrrr3ís zBabyl.__setitem__c Csò| |¡\}}|j |¡|j ¡t ¡}|j ¡}|dtks\|sHq\| | td¡¡q,t ¡}|j ¡}|tks|s|q| | td¡¡qd||j  ¡}|j  |¡}| td¡}t |  ¡|ƒ} |   |  ¡¡||jkrî|  |j|¡| S)r<ó *** EOOH ***rh)r¼rr{rˆrvrwr}r~r|rrkr r‡Ú set_visiblerlÚ set_labels) rr*rrÚoriginal_headersrZvisible_headersÚnZbodyrÆrrrr7ós*        zBabyl.get_messagec Cs¬| |¡\}}|j |¡|j ¡t ¡}|j ¡}|dtks\|sHq\| | td¡¡q,|j ¡}|tksv|s\qvq\|  ¡}||j  ¡}|j  |¡}| td¡}||S)r+rnrh) r¼rr{rˆrvrwr}r~r|r‡rrk) rr*rrrqrZheadersrrrŽrrrr@s        zBabyl.get_bytescCst | |¡ dt¡¡S)rBrh)rvrwr@r|r}r)rrrr:%szBabyl.get_filecCs<| ¡tƒ}|j ¡D]}| |¡q| |j¡t|ƒS)z4Return a list of user-defined labels in the mailbox.)r¼rYrlrMr[Údifference_updateÚ_special_labelsrF)rÚlabelsZ label_listrrrrm)s   zBabyl.get_labelscCs:gg}}|j d¡d}g}|}|j ¡}|j ¡}|dtkrœt|ƒt|ƒkrd| |ttƒ¡| |¡dd„|j ¡dd… d¡Dƒ}| |¡q|dks°|dtkrÔt|ƒt|ƒkrì| |ttƒ¡q|s| |ttƒ¡qîqtt t ||ƒƒƒ|_ tt |ƒƒ|_ t|j ƒ|_ |j dd ¡|j ¡|_dS) r8rs cSsg|]}| ¡r| ¡‘qSr)Ústrip©rLÚlabelrrrrX@sþz'Babyl._generate_toc..rÒNó,ór÷)rr{rˆrr}rÎrÖr¬r9r:r;ržrlrr)rr<r=r@Z label_listsr>rrurrrr!2s4      ÿ  zBabyl._generate_toccCsVdt}|dt7}| ¡}dd„|Dƒ}|dd |¡t7}|d7}| |¡dS) rsBABYL OPTIONS:s Version: 5css|]}| ¡VqdSr,)rdrwrrrrMUsz*Babyl._pre_mailbox_hook..sLabels:ryrzN)r}rmršr~)rrÅZbabylrurrrrPs zBabyl._pre_mailbox_hookcCs| dt¡dS)ró Nr7rrrrrZszBabyl._pre_message_hookcCs| td¡dS)r rzNr7rrrrr^szBabyl._post_message_hookcCsx|j ¡}t|tƒr°g}g}| ¡D]$}||jkr>| |¡q$| |¡q$|j d¡|D]}|j d| ¡¡qZ|j d¡|D]}|j d| ¡d¡q„|j t ¡n|j dt ¡t|t j j ƒrt  ¡}t j |dd¡}| |¡| d¡| ¡}|j | d t ¡¡|d ks,|süq,qü|j d t ¡t|tƒr¤t  ¡} t j | dd¡} |  | ¡¡|  ¡}|j | d t ¡¡|d ks¢|snqâqnn>| d¡| ¡}|j | d t ¡¡|d ksâ|s®qâq®| d ¡} | söqf|j |  d t ¡¡qânTt|ttt jfƒrt|t jƒrJt d td ¡| ¡}t|tƒr`| |¡}| d¡d} | ddkrâ|j |d| … d t ¡¡|j d t ¡|j |d| … d t ¡¡|j || d… d t ¡¡n(|j d t t ¡|j | d t ¡¡nXt |dƒrVt |dƒr:t dtd ¡|j!}| ¡} d}| ¡}| "d¡rl|dd…d }n| "d¡rˆ|dd…d }|j | d t ¡¡|d ks¬|sF|rÚd}|j d t ¡| | ¡nqÚqF| ¡}|sìqf| "d¡r |dd…t }n:| "d¡r(|dd…t }n| "d ¡rD|dd…t }|j |¡qÚnt#dt$|ƒƒ‚|j ¡}||fS)z0Write message contents and return (start, stop).ó1s, s,,ó rys1,,Frrhrnr rirjs r÷rqNrˆrlrmTrnrorprt)%rrrur rmrtrÖr~rdr}r>r&rrvrwrxryrzr{rˆr|Ú get_visiblerkr‚rrƒr„r…r†r‡rgr/rXrlr€rŠr‹)rr&rZspecial_labelsrurxZ orig_bufferZorig_generatorrZ vis_bufferZ vis_generatorrlZ body_startZ original_posZ first_passrrrrr"bs¼              ÿ    ÿ       zBabyl._install_message)NT)r‘r’r“r”Ú frozensetrtr r'r+r3r7r@r:rmr!rrrr"rrrrrÕs& ÿ   c@s*eZdZdZd dd„Zdd„Zdd„ZdS) rz0Message with mailbox-format-specific properties.NcCsÒt|tjjƒr4| t |¡¡t|tƒrÎ| |¡nšt|tƒrP| t  |¡¡n~t|t ƒrl| t  |¡¡nbt|t j ƒrŠ| t |¡¡nDt|dƒr¦| t |¡¡n(|dkr¾tjj |¡ntdt|ƒƒ‚dS)zInitialize a Message instance.rkNrt)rur>r&rÚ_become_messageÚcopyZdeepcopyÚ _explain_tor‚r?rZmessage_from_stringrvÚ TextIOWrapperZmessage_from_filerXZmessage_from_binary_filer rŠr‹r%rrrr Ñs      zMessage.__init__cCs4t|dgƒ}|jD]}||kr|j||j|<qdS)z0Assume the non-format-specific state of message.Ú_type_specific_attributesN)ÚgetattrÚ__dict__)rr&Z type_specificr¦rrrr€äs  zMessage._become_messagecCst|tƒrdStdƒ‚dS)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rurrŠr%rrrr‚ës zMessage._explain_to)N)r‘r’r“r”r r€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Ú_dateNcCs&d|_d|_t ¡|_t ||¡dS)z%Initialize a MaildirMessage instance.r—r£N)r‡rˆrër‰rr r%rrrr øs zMaildirMessage.__init__cCs|jS)zReturn 'new' or 'cur'.)r‡rDrrrr¨ÿszMaildirMessage.get_subdircCs(|dks|dkr||_n td|ƒ‚dS)zSet subdir to 'new' or 'cur'.r—r˜z!subdir must be 'new' or 'cur': %sN)r‡rf)rr¶rrrrÁszMaildirMessage.set_subdircCs"|j d¡r|jdd…SdSdS)ú*Return as a string the flags that are set.ú2,r÷Nr£)rˆr‰rDrrrÚ get_flags s zMaildirMessage.get_flagscCsdd t|ƒ¡|_dS)ú)Set the given flags and unset all others.r‹r£N)ršrrˆ)rÚflagsrrrÚ set_flagsszMaildirMessage.set_flagscCs$| d t| ¡ƒt|ƒB¡¡dS©z.Set the given flag(s) without changing others.r£N©rršrYrŒ©rÚflagrrrÚadd_flagszMaildirMessage.add_flagcCs,| ¡r(| d t| ¡ƒt|ƒ¡¡dS)ú7Unset the given string flag(s) without changing others.r£N)rŒrršrYr’rrrÚ remove_flagszMaildirMessage.remove_flagcCs|jS)zr&rr2r‰r )rr&r,rrrr es  z_mboxMMDFMessage.__init__cCs|jS)z Return contents of "From " line.)r§rDrrrr1nsz_mboxMMDFMessage.get_fromcCs4|dk r*|dkrt ¡}|dt |¡7}||_dS)z>Set "From " line, formatting and appending time_ if specified.NTú )rër4r3r§)rr-Ztime_rrrr'rs z_mboxMMDFMessage.set_fromcCs| dd¡| dd¡S)rŠÚStatusr£úX-Status)r6rDrrrrŒzsz_mboxMMDFMessage.get_flagscCsÒt|ƒ}d\}}dD]}||kr||7}| |¡qdD]}||kr8||7}| |¡q8|d t|ƒ¡7}z| d|¡Wn tk rš| d|¡YnXz| d|¡Wn tk rÌ| d|¡YnXdS)r)r£r£)r›rœ)ržrŸr r£r©rªN)rYr+ršrÚreplace_headerr/Z add_header)rrŽZ status_flagsZ xstatus_flagsr“rrrr~s&  z_mboxMMDFMessage.set_flagscCs$| d t| ¡ƒt|ƒB¡¡dSrr‘r’rrrr””sz_mboxMMDFMessage.add_flagcCs4d|ksd|kr0| d t| ¡ƒt|ƒ¡¡dS)r•r©rªr£Nr‘r’rrrr–˜sz_mboxMMDFMessage.remove_flagc CsÞt|tƒrÐt| ¡ƒ}d|kr(| d¡d|kr:| d¡d|krL| d¡d|kr^| d¡d|krp| d¡|d =|d =d  | ¡ ¡d d …¡}z|  t   t   |d¡¡¡Wnttfk rÊYnXn t|tƒrø| | ¡¡| | ¡¡nât|tƒrZt| ¡ƒ}d|kr$| d¡d|kr8| d¡d|krL| d¡|d =|d =n€t|tƒr¼t| ¡ƒ}d|kr†| d¡d|krš| d¡d|kr®| d¡|d =|d =nt|tƒrÊntdt|ƒƒ‚d S)zACopy mbox- or MMDF-specific state to message insofar as possible.rœr˜rŸr r›ršržrZstatuszx-statusr¨éûÿÿÿNz%a %b %d %H:%M:%S %Yrgr¢r£rhrir¥)rur rYrŒrÁr”ršr1r¬rÃÚcalendarZtimegmrëÚstrptimerfÚ OverflowErrorr0rr'r rHr r¦rrŠr‹)rr&rŽZ maybe_daterrrr‚sb       ÿ                    ÿz_mboxMMDFMessage._explain_to)N)N) r‘r’r“r”r„r r1r'rŒrr”r–r‚rrrrr0`s  r0c@seZdZdZdS)r z&Message with mbox-specific properties.N©r‘r’r“r”rrrrr Ñsc@sHeZdZdZdgZddd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)r z$Message with MH-specific properties.Ú _sequencesNcCsg|_t ||¡dS)z!Initialize an MHMessage instance.N)r±rr r%rrrr ÚszMHMessage.__init__cCs|jdd…S)z4Return a list of sequences that include the message.N)r±rDrrrrGßszMHMessage.get_sequencescCst|ƒ|_dS)z3Set the list of sequences that include the message.N)rFr±)rr_rrrraãszMHMessage.set_sequencescCs6t|tƒr"||jkr2|j |¡ntdt|ƒƒ‚dS)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rurr±rÖrŠr‹©rrfrrrrHçs  zMHMessage.add_sequencecCs*z|j |¡Wntk r$YnXdS)zARemove sequence from the list of sequences including the message.N)r±r+rfr²rrrÚremove_sequenceïszMHMessage.remove_sequencecCsFt|tƒrdt| ¡ƒ}d|kr*| d¡n| d¡| d¡d|krP| d¡d|krb| d¡nÞt|tƒr¾t| ¡ƒ}d|krŽ| d¡n | d ¡d|krª| d¡d|kr¼| d ¡n„t|tƒrâ| ¡D]}| |¡qÐn`t|t ƒr$t| ¡ƒ}d|kr|  d¡d|krB|  d ¡nt|t ƒr2nt d t |ƒƒ‚d S)z6Copy MH-specific state to message insofar as possible.rgr˜ršr£rŸr¢r›ÚROrœr rir¥N)rur rYrGrÁr”r0r rHr r¦rrŠr‹)rr&r_rfrrrr‚ösB                      ÿzMHMessage._explain_to)N) r‘r’r“r”r„r rGrarHr³r‚rrrrr Õs c@sbeZdZdZddgZddd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dS)r z'Message with Babyl-specific properties.rlÚ_visibleNcCsg|_tƒ|_t ||¡dS)z#Initialize a BabylMessage instance.N)rlrrµr r%rrrr "szBabylMessage.__init__cCs|jdd…S)z'Return a list of labels on the message.N)rlrDrrrrm(szBabylMessage.get_labelscCst|ƒ|_dS)z&Set the list of labels on the message.N)rFrl)rrurrrrp,szBabylMessage.set_labelscCs6t|tƒr"||jkr2|j |¡ntdt|ƒƒ‚dS)z+Add label to list of labels on the message.zlabel must be a string: %sN)rurrlrÖrŠr‹©rrxrrrr¦0s  zBabylMessage.add_labelcCs*z|j |¡Wntk r$YnXdS)z4Remove label from the list of labels on the message.N)rlr+rfr¶rrrÚ remove_label8szBabylMessage.remove_labelcCs t|jƒS)z3Return a Message representation of visible headers.©rrµrDrrrr~?szBabylMessage.get_visiblecCst|ƒ|_dS)z2Set the Message representation of visible headers.Nr¸)rZvisiblerrrroCszBabylMessage.set_visiblecCsb|j ¡D](}||kr*|j |||¡q |j|=q dD]$}||kr8||jkr8|||j|<q8dS)z9Update and/or sensibly generate a set of visible headers.)ZDateZFromzReply-ToZToZCCZSubjectN)rµrGr«)rÚheaderrrrÚupdate_visibleGs zBabylMessage.update_visiblecCsrt|tƒr~t| ¡ƒ}d|kr*| d¡n| d¡| d¡d|ksNd|krX| d¡d|krj| d¡d |kr|| d ¡nðt|tƒrØt| ¡ƒ}d|kr¨| d ¡n | d ¡d |krÄ| d ¡d|krÖ| d¡n–t|tƒrt| ¡ƒ}d|kr| d¡d|krn| d¡nTt|t ƒrP|  |  ¡¡| ¡D]}|  |¡qThe specified mailbox is not empty and deletion was requested.Nr°rrrrr[sc@seZdZdZdS)rz)Another process caused an action to fail.Nr°rrrrr^sc@seZdZdZdS)rz)A file appears to have an invalid format.Nr°rrrrras)T)0r”rrër­rïrµrr„r>Z email.messageZemail.generatorrvr8rÓÚ ImportErrorÚ__all__r}rdrrrþr$rrrrr&rr r0r r r r rÉr.r r rõrrr§Ú ExceptionrrrrrrrrrÚs‚   ý h8DB4-3z%mqH_c' *