a �DOg�3�@s:ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl Z ddl Z ddl m Z z ddlZWney�dZYn0gd�Zej�d�ZGdd�d�ZGdd�de�ZGd d �d e�ZGd d �d e�ZGd d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dejj�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd �d e�Z!Gd!d"�d"e�Z"Gd#d$�d$�Z#Gd%d&�d&e#�Z$d>d(d)�Z%d*d+�Z&d,d-�Z'd.d/�Z(d0d1�Z)d2d3�Z*Gd4d5�d5e+�Z,Gd6d7�d7e,�Z-Gd8d9�d9e,�Z.Gd:d;�d;e,�Z/Gd�Z d?Z!dFd@dA�Z"e#e$�Z%dS)GrNTcCs tj�tj�|��|_||_dS�N)�os�path�abspath� expanduser�_path�_factory��selfr�factory�create�r �/usr/lib64/python3.9/mailbox.py�__init__%szMailbox.__init__cCs td��dS�Nz&Method must be implemented by subclass��NotImplementedError�r�messager r r!�add*sz Mailbox.addcCs td��dSr#r$�r�keyr r r!�remove.szMailbox.removecCs|�|�dSr)r+r)r r r!� __delitem__2szMailbox.__delitem__cCs&z|�|�Wnty Yn0dSr)r+�KeyErrorr)r r r!�discard5s zMailbox.discardcCs td��dSr#r$�rr*r'r r r!� __setitem__<szMailbox.__setitem__cCs(z |�|�WSty"|YS0dSr)� __getitem__r-)rr*�defaultr r r!�get@s  z Mailbox.getcCsN|js|�|�St�|�|���}|�|�Wd�S1s@0YdSr)r� get_message� contextlib�closing�get_file)rr*�filer r r!r1Gs zMailbox.__getitem__cCs td��dSr#r$r)r r r!r4OszMailbox.get_messagecCst�|�|����Sr��email�message_from_bytes� get_bytesZ as_stringr)r r r!� get_stringSszMailbox.get_stringcCs td��dSr#r$r)r r r!r<ZszMailbox.get_bytescCs td��dSr#r$r)r r r!r7^szMailbox.get_filecCs td��dSr#r$�rr r r!�iterkeysbszMailbox.iterkeyscCs t|���Sr)�listr?r>r r r!�keysfsz Mailbox.keysc cs<|��D].}z ||}Wnty.YqYn0|VqdSr�r?r-�rr*�valuer r r!� itervaluesjs     zMailbox.itervaluescCs|��Sr)rEr>r r r!�__iter__sszMailbox.__iter__cCs t|���Sr)r@rEr>r r r!�valuesvszMailbox.valuesc cs@|��D]2}z ||}Wnty.YqYn0||fVqdSrrBrCr r r!� iteritemszs     zMailbox.iteritemscCs t|���Sr)r@rHr>r r r!�items�sz Mailbox.itemscCs td��dSr#r$r)r r r!� __contains__�szMailbox.__contains__cCs td��dSr#r$r>r r r!�__len__�szMailbox.__len__cCs|��D]}|�|�qdSr)rAr.r)r r r!�clear�s z Mailbox.clearcCs2z ||}Wnty"|YS0|�|�|Sr)r-r.)rr*r2�resultr r r!�pop�s     z Mailbox.popcCs*|��D]}||�|�fStd��dS)NzNo messages in mailbox)r?rNr-r)r r r!�popitem�s zMailbox.popitemc Csrt|d�r|��}nt|d�r(|��}n|}d}|D],\}}z |||<Wq4ty^d}Yq40q4|rntd��dS)NrHrIFTzNo message with key(s))�hasattrrHrIr-)r�arg�sourceZbad_keyr*r'r r r!�update�s        zMailbox.updatecCs td��dSr#r$r>r r r!�flush�sz Mailbox.flushcCs td��dSr#r$r>r r r!�lock�sz Mailbox.lockcCs td��dSr#r$r>r r r!�unlock�szMailbox.unlockcCs td��dSr#r$r>r r r!�close�sz Mailbox.closecCs,z |�d�WSty&td��Yn0dS)Nrz?String input must be ASCII-only; use bytes or a Message instead)�encode� UnicodeError� ValueErrorr&r r r!�_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 �}|� |�|j�r�|�t ��s�|� t �n�t|d��r�t|d��r2t�d td�|j}d}|��}|�d ��r\|dd �d}n|�d ��rx|dd �d}|�s��q�|�r�|�d��r�d|dd�}|� dt �}|� |�|}�q6|j�r�|�r�|�t ��s�|� t �ntdt|���dS)Nr� �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 instead� ������ ������From s>From ��Invalid message type: %s)� isinstancer:r'r �io�BytesIO� generator�BytesGenerator�flatten�seekr_�replace�linesep�write�_append_newline�endswith�str�bytes�StringIO�warnings�warn�DeprecationWarning�getvaluer[rPr`�readline� startswith� TypeError�type) rr'�targetZ mangle_from_r`�gen�dataZlastline�liner r r!� _dump_message�s\     �        �     zMailbox._dump_message)NT)N)N)N)F)&�__name__� __module__� __qualname__r"r(r+r,r.r0r3r1r4r=r<r7r?rArErFrGrHrIrJrKrLrNrOrSrTrUrVrWr[rsr�� classmethodr�__class_getitem__r r r r!r"sB        6rc@s�eZdZdZd5dd�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,Zd-d.�Zd/d0�Zd1d2�Zd3d4�ZdS)6r�: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|_dS) N�tmp�new�cur)r�r�r���r)r�r�g�������?)rr"rr�joinr�_paths�exists�mkdirrGr�_toc� _toc_mtimes� _last_read� _skewfactor)r�dirnamerrrr r r!r"s�  zMaildir.__init__c Cs||��}z|�||�Wn(ty@|��t�|j��Yn0t|�t|t �rz|� �}|j |� �}||j kr�d}nd}d}tj �|j��|j �d}tj �|j|||�}t|t �r�t�|jtj �|j�|��f�zJzt�|j|�Wn&ttf�yt�|j|�Yn0t�|j�WnPt�yv}z6t�|j�|jtjk�r`td|��n�WYd}~n d}~00|S)N�r�rz$Name clash with existing message: %s)� _create_tmpr�� BaseExceptionrWrr+�name� _sync_closerir � get_subdir�colon�get_infor�basename�splitr�r�utime�getatime�get_date�link�AttributeError�PermissionError�rename�OSError�errno�EEXISTr)rr'Ztmp_file�subdir�suffix�uniq�dest�er r r!r($sF     � �z Maildir.addcCs t�tj�|j|�|���dSr)rr+rr�r�_lookupr)r r r!r+NszMaildir.removec Cs*z|�|�Wnttfy$Yn0dSr)r+r-�FileNotFoundErrorr)r r r!r.RszMaildir.discardc Cs�|�|�}|�|�}|�|�}t|t�r.|}n|}tj�|�}|j|vr`|j|�|j�d}nd}|� |�tj� |j |�} tj� |j |||�} t|t�r�t� | tj� | �|��f�t�| | �dS)Nrer�)r�r(rir rrr�r�r�r.r�rr�r�r�r�) rr*r'Z old_subpathZtemp_keyZ temp_subpathZdominant_subpathr�r�Ztmp_path�new_pathr r r!r0Zs$        �zMaildir.__setitem__cCs�|�|�}ttj�|j|�d��*}|jr4|�|�}nt|�}Wd�n1sP0Ytj�|�\}}|� |�|j |vr�|� |�|j �d�|� tj� tj�|j|���|S)N�rbre)r��openrrr�rrr r�� set_subdirr��set_info�set_date�getmtime)rr*�subpath�f�msgr�r�r r r!r4us  &  zMaildir.get_messagecCsPttj�|j|�|��d�� }|���td�Wd�S1sB0YdS)Nr�r\) r�rrr�rr�r_rprq�rr*r�r r r!r<�szMaildir.get_bytescCs$ttj�|j|�|��d�}t|�S)Nr�)r�rrr�rr�� _ProxyFiler�r r r!r7�szMaildir.get_filec csD|��|jD]0}z|�|�Wnty6YqYn0|VqdSr)�_refreshr�r�r-r)r r r!r?�s   zMaildir.iterkeyscCs|��||jvSr)r�r�r)r r r!rJ�szMaildir.__contains__cCs|��t|j�Sr)r��lenr�r>r r r!rK�szMaildir.__len__cCsdSrr r>r r r!rT�sz Maildir.flushcCsdSrr r>r r r!rU�sz Maildir.lockcCsdSrr r>r r r!rV�szMaildir.unlockcCsdSrr r>r r r!rW�sz Maildir.closecCs\g}t�|j�D]F}t|�dkr|ddkrtj�tj�|j|��r|�|dd��q|S)N�r�.)r�listdirrr�r�isdirr��append�rrM�entryr r r!� list_folders�s�zMaildir.list_folderscCs ttj�|jd|�|jdd�S)Nr�F�rr)rrrr�rr�r�folderr r r!� get_folder�s�zMaildir.get_foldercCs\tj�|jd|�}t||jd�}tj�|d�}tj�|�sXt�t�|tj tj Bd��|S)Nr��rZ maildirfolder�) rrr�rrrr�rWr��O_CREAT�O_WRONLY)rr�rrMZmaildirfolder_pathr r r!� add_folder�s �zMaildir.add_foldercCstj�|jd|�}t�tj�|d��t�tj�|d��D](}t|�dksX|ddkrr r r!r�4s    z Maildir.next)NT)r�r�r�r�r"r(r+r.r0r4r<r7r?rJrKrTrUrVrWr�r�r�r�r�r�r�r�r�r�r r r r!r s4 *   $rc@s�eZdZd#dd�Zdd�Zdd�Zd d �Zd d �Zd d�Zdd�Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�Zd$dd �Zd!d"�ZdS)%�_singlefileMailboxNTc Cs�t�||||�zt|jd�}Wnpty�}zX|jtjkrZ|rNt|jd�}q|t|j��n"|jtjtj fvrzt|jd�}n�WYd}~n d}~00||_ d|_ d|_ d|_ d|_d|_d|_dS)N�rb+zwb+r�rF)rr"r�rr�r��ENOENTr�EACCES�EROFS�_filer�� _next_key�_pending� _pending_sync�_locked� _file_length)rrrrr�r�r r r!r"Ds$  z_singlefileMailbox.__init__cCs8|��|�|�|j|j<|jd7_d|_|jdS)Nr�T)r��_append_messager�r�r�r&r r r!r([s z_singlefileMailbox.addcCs|�|�|j|=d|_dS�NT)r�r�r�r)r r r!r+es z_singlefileMailbox.removecCs$|�|�|�|�|j|<d|_dSr�)r�r�r�r�r/r r r!r0ks z_singlefileMailbox.__setitem__ccs|��|j��EdHdSr)r�r�rAr>r r r!r?qsz_singlefileMailbox.iterkeyscCs|��||jvSr)r�r�r)r r r!rJvsz_singlefileMailbox.__contains__cCs|��t|j�Sr)r�r�r�r>r r r!rK{sz_singlefileMailbox.__len__cCs|jst|j�d|_dSr�)r�� _lock_filer�r>r r r!rU�s z_singlefileMailbox.lockcCs|jrt|j�d|_dS�NF)r�� _unlock_filer�r>r r r!rV�s z_singlefileMailbox.unlockc Cs�|js |jrt|j�d|_dS|j�dd�|j��}||jkrTtd|j|f��t|j �}z�i}|� |�t |j � ��D]x}|j |\}}|j�|�|�|�|��}|j�td||j����}|s�q�|�|�q�||��f||<|�|�q||��|_Wn"|��t�|j��Yn0t|�|j��t�|j �j} t�|j| �zt�|j|j �Wn0t�y�t�|j �t�|j|j �Yn0t|j d�|_||_ d|_d|_|j�r�t|jdd�dS)NFrr�z4Size of mailbox file changed (expected %i, found %i)�r�)�dotlock) r�r�� _sync_flushr�ro�tellr�r�_create_temporaryr�_pre_mailbox_hook�sortedr�rA�_pre_message_hookr_�minrr�_post_message_hookrWrr+r�r�r��st_mode�chmodr�r�r�r�r�) rZcur_lenZnew_fileZnew_tocr*�start�stopZ new_startr`�moder r r!rT�s`    �      �     z_singlefileMailbox.flushcCsdSrr �rr�r r r!r�sz$_singlefileMailbox._pre_mailbox_hookcCsdSrr r r r r!r�sz$_singlefileMailbox._pre_message_hookcCsdSrr r r r r!r�sz%_singlefileMailbox._post_message_hookcCshz6|��Wz|jr|��W|j��qd|j��0n,z|jrH|��W|j��n |j��00dSr)rTr�rVr�rWr>r r r!rW�s  � z_singlefileMailbox.closecCsL|jdur|��|durHz |j|WStyFtd|�d�Yn0dSr�)r�� _generate_tocr-r)r r r!r��s   z_singlefileMailbox._lookupcCs�|j�dd�|j��}t|j�dkr8|js8|�|j�z&|�|j�|�|�}|� |j�Wn t y~|j� |��Yn0|j� �|j��|_ |S)Nrr�)r�rorr�r�r�rr�_install_messagerr��truncaterTr�)rr'�beforeZoffsetsr r r!r��s        z"_singlefileMailbox._append_message)NT)N)r�r�r�r"r(r+r0r?rJrKrUrVrTrrrrWr�r�r r r r!r�As   @ r�c@s>eZdZdZdd�Zddd�Zddd�Zdd d �Zd d �Zd S)� _mboxMMDFTcCsp|�|�\}}|j�|�|j���td�}|j�||j���}|�|�td��}|� |dd�� d��|S)N�r\rgr) r�r�ror|rprqr_r�_message_factory�set_from�decode)rr*r r � from_line�stringr�r r r!r4 s z_mboxMMDF.get_messageFcCst�|�||��j|d�S)N)�unixfromr9)rr*�from_r r r!r=s  ��z_mboxMMDF.get_stringcCsJ|�|�\}}|j�|�|s(|j��|j�||j���}|�td�S�Nr\)r�r�ror|r_rrprq)rr*rr r rr r r!r<s   z_mboxMMDF.get_bytescCs<|�|�\}}|j�|�|s(|j��t|j|j��|�Sr)r�r�ror|� _PartialFiler)rr*rr r r r r!r7!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�|� �}|dur�|�d�}|dur�dt �t �����}|j��}|j�|t�|�||j|j�|j��}||fS)Nrfr\rer�rrsFrom MAILER-DAEMON )rirur[rvr}�find�_mboxMMDFMessage�get_fromrXr:r'r � get_unixfromr��asctime�gmtimer�rrrrqr�� _mangle_from_)rr'r�newlineZauthorr r r r r!r)s0         z_mboxMMDF._install_messageN)F)F)F) r�r�r�r#r4r=r<r7rr r r r!rs   rc@s.eZdZdZdZd dd�Zdd�Zdd�ZdS) rTNcCst|_t�||||�dSr)r rrr"rr r r!r"Osz mbox.__init__cCs|�t�dSr�rrrqr r r r!rTszmbox._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)NFrrfT)r�rorr|r}r�r�rq�dict� enumerate�zipr�r�r�)r�starts�stopsZlast_was_empty�line_posr�r r r!rXs.         zmbox._generate_toc)NT)r�r�r�r#rsr"rrr r r r!rFs  rc@s.eZdZd dd�Zdd�Zdd�Zd d �ZdS) rNTcCst|_t�||||�dSr)rrrr"rr r r!r"}sz MMDF.__init__cCs|�dt�dS�N�r%r r r r!r�szMMDF._pre_message_hookcCs|�tdt�dSr,r%r r r r!r�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)Nrr-r�)r�ror|rr}rqr�r�r&r'r(r�r�r�)rr)r*�next_posr+r�r r r!r�s.          zMMDF._generate_toc)NT)r�r�r�r"rrrr r r r!rzs rc@s�eZdZd/dd�Zdd�Zdd�Zd d �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.�ZdS)0rNTcCstt�||||�tj�|j�sj|r`t�|jd�t�t�tj� |jd�tj tj Btj Bd��n t |j��d|_dS)Nr�� .mh_sequencesi�F)rr"rrr�rr�rWr�r�r��O_EXCLr�rr�rr r r!r"�s� z MH.__init__cCs�|��}t|�dkrd}n t|�d}tj�|jt|��}t|�}d}z�|j rVt |�zrz|� ||�Wn8t y�|j r�t |�t|�d}t�|��Yn0t|t�r�|�||�W|j r�t |�n|j r�t |�0W|s�t|�n|s�t|�0|S)Nrr�FT)rAr��maxrrr�rrur�r�r�r�r�r�r�r+rir �_dump_sequences)rr'rAZnew_keyr�r��closedr r r!r(�s>      �  � zMH.addc Csztj�|jt|��}zt|d�}Wn@tyb}z(|jtjkrLt d|��n�WYd}~nd}~00|� �t� |�dS�Nr�r�) rrr�rrur�r�r�r�r-rWr+)rr*rr�r�r r r!r+�s z MH.removec Cs�tj�|jt|��}zt|d�}Wn@tyb}z(|jtjkrLt d|��n�WYd}~n d}~00zz|j rtt |�zNt� t�|tj tjB��|�||�t|t�r�|�||�W|j r�t|�n|j r�t|�0Wt|�n t|�0dSr4)rrr�rrur�r�r�r�r-r�r�rWr��O_TRUNCr�rir r2r�r�)rr*r'rr�r�r r r!r0�s(    � zMH.__setitem__c Cs z@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn@ty�}z(|jtj krjt d|��n�WYd}~n d}~00|�J|jr�t |�zt |�}W|jr�t |�n|jr�t |�0Wd�n1s�0Y|����D]\}}||vr�|�|�q�|S)Nr�r�r�)r�r�rrr�rrur�r�r�r-r�r r�� get_sequencesrI� add_sequence)rr*r�r�r�r��key_listr r r!r4�s*   �( zMH.get_messagec Cs�z@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn@ty�}z(|jtj krjt d|��n�WYd}~n d}~00|�`|jr�t |�z0|� �� td�W|jr�t|�Wd�Sn|jr�t|�0Wd�n1s�0YdS)Nr�r�r�r\)r�r�rrr�rrur�r�r�r-r�r_rprqr��rr*r�r�r r r!r<s( ��z MH.get_bytesc Cshzttj�|jt|��d�}Wn@ty^}z(|jtjkrHt d|��n�WYd}~n d}~00t |�S)Nr�r�) r�rrr�rrur�r�r�r-r�r9r r r!r7,s z MH.get_filecCsttdd�t�|j�D���S)Ncss|]}|��rt|�VqdSr)�isdigitr�)�.0r�r r r!� 9s�zMH.iterkeys..)�iterrrr�rr>r r r!r?7sz MH.iterkeyscCstj�tj�|jt|���Sr)rrr�r�rrur)r r r!rJ<szMH.__contains__cCstt|����Sr)r�r@r?r>r r r!rK@sz MH.__len__cCs2|js.ttj�|jd�d�|_t|j�d|_dS)Nr/r�T)r�r�rrr�rr�r�r>r r r!rUDs zMH.lockcCs(|jr$t|j�t|j�|`d|_dSr�)r�r�r�r�r>r r r!rVKs   z MH.unlockcCsdSrr r>r r r!rTSszMH.flushcCs|jr|��dSr)r�rVr>r r r!rWWszMH.closecCs<g}t�|j�D]&}tj�tj�|j|��r|�|�q|Sr)rr�rrr�r�r�r�r r r!r�\s  zMH.list_folderscCsttj�|j|�|jdd�S)NFr��rrrr�rrr�r r r!r�ds�z MH.get_foldercCsttj�|j|�|jd�S)Nr�r>r�r r r!r�is�z MH.add_foldercCs`tj�|j|�}t�|�}|dgkr:t�tj�|d��n|gkrDntd|j��t�|�dS)Nr/zFolder not empty: %s)rrr�rr�r+rr�)rr�r�entriesr r r!r�ns  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�||=Wq0ty�td |����Yq00q0Wd�n1�s 0Y|S)Nr/�r�ASCII��encodingr�css|]}t|�VqdSr)r�)r;�xr r r!r<�rz#MH.get_sequences..�-r�csg|]}|�vr|�qSr r )r;r*�Zall_keysr r!� �s�z$MH.get_sequences..rz"Invalid sequence specification: %s)r�rrr�r�setrAr�r:r(r�rS�rangerr�rZr�rstrip) r�resultsr�r�r��contentsrA�specr r r rFr!r6zs(    �.zMH.get_sequencescCs ttj�|jd�ddd�}z�t�t�|jtjtjB��|� �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@Wt|�n t|�0dS)Nr/zr+rArBrr�Fr�TrEz%s %sz %s� )r�rrr�rrWr�r�r5rIr�rrrrHrur�)r� sequencesr�r�rA�prevZ completingr*r r r!� set_sequences�s.   zMH.set_sequencesc Cs<|��}d}g}|��D]�}|d|kr�|�||df�z4t�tj�|jt|��tj�|jt|d���WnFt t fy�t� tj�|jt|��tj�|jt|d���Yn0t� tj�|jt|���|d7}q|d|_ t|�dkr�dS|��D]0\}}|D]"\}}||v�r|||�|�<�qq�|�|�dS)Nrr�)r6r?r�rr�rr�rrur�r�r��unlinkr�r�rI�indexrQ) rrOrPZchangesr*r�r8�oldr�r r r!�pack�s0  ��      zMH.packcCst|��}|��}|��D]0\}}||vr4|�|�q||vr||�|�=q|D]}||vrN|g||<qN|�|�dSr)r6rIr�rSrQ)rr'r*Zpending_sequencesZ all_sequencesr�r8�sequencer r r!r2�s  zMH._dump_sequences)NT)r�r�r�r"r(r+r0r4r<r7r?rJrKrUrVrTrWr�r�r�r�r6rQrUr2r r r r!r�s, "  rc@s�eZdZehd��Zddd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd�ZdS)r>Zedited�resentZfiled�deleted�answered�unseen� forwardedNTcCst�||||�i|_dSr)r�r"�_labelsrr r r!r"�szBabyl.__init__cCs(t�||�}t|t�r$|��|j|<|Sr)r�r(rir � get_labelsr\)rr'r*r r r!r(�s  z Babyl.addcCs"t�||�||jvr|j|=dSr)r�r+r\r)r r r!r+�s  z Babyl.removecCs*t�|||�t|t�r&|��|j|<dSr)r�r0rir r]r\r/r r r!r0�s zBabyl.__setitem__c Cs�|�|�\}}|j�|�|j��t��}|j��}|dtks\|sHq\|�|�td��q,t��}|j��}|tks�|s|q�|�|�td��qd||j� �}|j� |�}|�td�}t |� �|�} | � |� ��||jvr�| �|j|�| S�N� *** EOOH ***r\)r�r�ror|rjrkrqrrrprr_r r{� set_visibler\� set_labels) rr*r r �original_headersr�Zvisible_headers�n�bodyr�r r r!r4�s*        zBabyl.get_messagec Cs�|�|�\}}|j�|�|j��t��}|j��}|dtks\|sHq\|�|�td��q,|j��}|tksv|s\qvq\|� �}||j� �}|j� |�}|�td�}||Sr^) r�r�ror|rjrkrqrrrpr{rr_) rr*r r rbr�Zheadersrcr�r r r!r<s        zBabyl.get_bytescCst�|�|��dt��Sr)rjrkr<rprqr)r r r!r7(szBabyl.get_filecCs<|��t�}|j��D]}|�|�q|�|j�t|�Sr)r�rHr\rGrS�difference_update�_special_labelsr@)r�labelsZ label_listr r r!r],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) Nrs cSsg|]}|��r|���qSr )�strip�r;�labelr r r!rGCs�z'Babyl._generate_toc..r��,�r�)r�ror|rrqr�r�r�r&r'r(r�r\r�r�)rr)r*r.Z label_listsr+r�rgr r r!r5s4      �  zBabyl._generate_toccCsVdt}|dt7}|��}dd�|D�}|dd�|�t7}|d7}|�|�dS)NsBABYL OPTIONS:s Version: 5css|]}|��VqdSr)rXrir r r!r<Xrz*Babyl._pre_mailbox_hook..sLabels:rkrl)rqr]r�rr)rr�Zbabylrgr r r!rSs zBabyl._pre_mailbox_hookcCs|�dt�dS)N� r%r r r r!r]szBabyl._pre_message_hookcCs|�td�dS)Nrlr%r r r r!raszBabyl._post_message_hookcCsx|j��}t|t�r�g}g}|��D]$}||jvr>|�|�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 k�s,|s��q,q�|j�d t �t|t��r�t ��} t j�| dd�} | �|���| ��}|j�|�d t ��|d k�s�|�sn�q�qnn>|�d�|��}|j�|�d t ��|d k�s�|�s��q�q�|�d �} | �s��qf|j�| �d t ���q�nTt|ttt jf��rt|t j��rJt�d td �|��}t|t��r`|�|�}|�d�d} | ddk�r�|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 k�s�|�sF|�r�d}|j�d t �|�| �n�qڐqF|��}|�s�qf|�"d��r |dd�t }n:|�"d��r(|dd�t }n|�"d ��rD|dd�t }|j�|��q�nt#dt$|���|j��}||fS)N�1s, s,,� rks1,,Frr\r_r�r]r^s r�rer|r`raTrbrcrdrh)%r�rrir r]rfr�rrrXrqr:r'r rjrkrlrmrnror|rp� get_visibler_rvrurwrxryrzr{r[rrPr`rtr~r)rr'r Zspecial_labelsrgrjZ orig_bufferZorig_generatorr�Z vis_bufferZ vis_generatorr`Z body_startZ original_posZ first_passr r r r!res�              �    �       zBabyl._install_message)NT)r�r�r�� frozensetrfr"r(r+r0r4r<r7r]rrrrrr r r r!r�s    rc@s&eZdZddd�Zdd�Zdd�ZdS) r 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(|dur�tjj�|�ntdt|���dS)Nr_rh)rir:r'r �_become_message�copy�deepcopy� _explain_torvr;ruZmessage_from_stringrj� TextIOWrapperZmessage_from_filerPZmessage_from_binary_filer"r~rr&r r r!r"�s      zMessage.__init__cCs4t|dg�}|jD]}||vr|j||j|<qdS)N�_type_specific_attributes)�getattr�__dict__)rr'Z type_specificr�r r r!rr�s  zMessage._become_messagecCst|t�rdStd��dS)Nz Cannot convert to specified type)rir r~r&r r r!ru�s zMessage._explain_to)N)r�r�r�r"rrrur r r r!r �s r c@sveZdZgd�Zddd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�ZdS)r )�_subdir�_info�_dateNcCs&d|_d|_t��|_t�||�dS)Nr�r�)rzr{r�r|r r"r&r r r!r"�s zMaildirMessage.__init__cCs|jSr)rzr>r r r!r�szMaildirMessage.get_subdircCs(|dks|dkr||_n td|��dS)Nr�r�z!subdir must be 'new' or 'cur': %s)rzrZ)rr�r r r!r�szMaildirMessage.set_subdircCs"|j�d�r|jdd�SdSdS)N�2,r�r�)r{r}r>r r r!� get_flags s zMaildirMessage.get_flagscCsdd�t|��|_dS)Nr}r�)r�rr{)r�flagsr r r!� set_flagsszMaildirMessage.set_flagscCs$|�d�t|���t|�B��dS�Nr��r�r�rHr~�r�flagr r r!�add_flagszMaildirMessage.add_flagcCs,|��r(|�d�t|���t|���dSr�)r~r�r�rHr�r r r!� remove_flagszMaildirMessage.remove_flagcCs|jSr)r|r>r r r!r�!szMaildirMessage.get_datecCs4zt|�|_Wn ty.td|�d�Yn0dS)Nzcan't convert to float: %s)�floatr|rZr~)r�dater r r!r�%s zMaildirMessage.set_datecCs|jSr)r{r>r r r!r�,szMaildirMessage.get_infocCs&t|t�r||_ntdt|���dS)Nzinfo must be a string: %s)rirur{r~r)r�infor r r!r�0s zMaildirMessage.set_infocCs�t|t�r8|�|���|�|���|�|����nht|t�r�t |���}d|vr`|� d�|��dkrv|� d�d|vr�|� d�d|vr�|� d�d|vr�|� d�|� d t � |����n�t|t��rt |���}d|vr�|�d �d|v�r|�d �d|v�r�|�d �n�t|t��r�t |���}d|v�rD|�d �d|v�rX|�d �d|v�rl|�d�d|v�r�|�d�nt|t��r�ntdt|���dS)N�S�Rr��O�T�D�F�A� MAILER-DAEMONrZ�replied�flaggedrXrY�Pr[�$Cannot convert to specified type: %s)rir r�r~r�r�r�r�rrHr�rr�r"r r7r � add_labelr r~r)rr'rr r r!ru7sP                           �zMaildirMessage._explain_to)N)r�r�r�rwr"r�r�r~r�r�r�r�r�r�r�rur r r r!r �s r c@sVeZdZdgZddd�Zdd�Zddd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dS)r�_fromNcCsV|�dd�t|tjj�rF|��}|durF|�d�rF|�|dd��t�||�dS)Nr�TzFrom rg)rrir:r'r r r}r")rr'rr r r!r"hs  z_mboxMMDFMessage.__init__cCs|jSr)r�r>r r r!rqsz_mboxMMDFMessage.get_fromcCs4|dur*|durt��}|dt�|�7}||_dS)NT� )r�r"r!r�)rrZtime_r r r!rus z_mboxMMDFMessage.set_fromcCs|�dd�|�dd�S)N�Statusr��X-Status)r3r>r r r!r~}sz_mboxMMDFMessage.get_flagscCs�t|�}d\}}dD]}||vr||7}|�|�qdD]}||vr8||7}|�|�q8|d�t|��7}z|�d|�Wnty�|�d|�Yn0z|�d|�Wnty�|�d|�Yn0dS)N)r�r�)r�r�)r�r�r�r�r�r�)rHr+r�r�replace_headerr-Z add_header)rrZ status_flagsZ xstatus_flagsr�r r r!r��s&    z_mboxMMDFMessage.set_flagscCs$|�d�t|���t|�B��dSr�r�r�r r r!r��sz_mboxMMDFMessage.add_flagcCs4d|vsd|vr0|�d�t|���t|���dS)Nr�r�r�r�r�r r r!r��sz_mboxMMDFMessage.remove_flagc Cs�t|t�r�t|���}d|vr(|�d�d|vr:|�d�d|vrL|�d�d|vr^|�d�d|vrp|�d�|d =|d =d �|����d d��}z|� t � t � |d ���Wnttfy�Yn0�n t|t�r�|�|���|�|���n�t|t��rXt|���}d|v�r"|�d�d|v�r6|�d�d|v�rJ|�d�|d =|d =n�t|t��r�t|���}d|v�r�|�d�d|v�r�|�d�d|v�r�|�d�|d =|d =nt|t��r�ntdt|���dS)Nr�r�r�r�r�r�r�r��statuszx-statusr������z%a %b %d %H:%M:%S %YrZr�r�rXrYr�)rir rHr~r�r�r�rr�r��calendarZtimegmr��strptimerZ� OverflowErrorrr�rr r7r r�r r~r)rr'rZ maybe_dater r r!ru�sb       �                    �z_mboxMMDFMessage._explain_to)N)N) r�r�r�rwr"rrr~r�r�r�rur r r r!rcs  rc@s eZdZdS)r N�r�r�r�r r r r!r �sr c@sDeZdZdgZddd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dS)r � _sequencesNcCsg|_t�||�dSr)r�r r"r&r r r!r"�szMHMessage.__init__cCs|jdd�Sr)r�r>r r r!r6�szMHMessage.get_sequencescCst|�|_dSr)r@r�)rrOr r r!rQ�szMHMessage.set_sequencescCs6t|t�r"||jvr2|j�|�ntdt|���dS)Nzsequence type must be str: %s)rirur�r�r~r�rrVr r r!r7�s  zMHMessage.add_sequencecCs(z|j�|�Wnty"Yn0dSr)r�r+rZr�r r r!�remove_sequence�s zMHMessage.remove_sequencecCsFt|t�rdt|���}d|vr*|�d�n|�d�|�d�d|vrP|�d�d|vrb|�d�n�t|t�r�t|���}d|vr�|�d�n |�d �d|vr�|�d�d|vr�|�d �n�t|t�r�|��D]}|�|�q�n`t|t ��r$t|���}d|v�r|� d�d|v�rB|� d �nt|t ��r2nt d t |���dS) NrZr�r�r�r�r�r��ROr�r�rYr�)rir rHr6r�r�rr r7r r�r r~r)rr'rOrVr r r!ru�sB                      �zMHMessage._explain_to)N) r�r�r�rwr"r6rQr7r�rur r r r!r �s r c@s^eZdZddgZddd�Zdd�Zdd �Zd d �Zd d �Zdd�Z dd�Z dd�Z dd�Z dS)r r\�_visibleNcCsg|_t�|_t�||�dSr)r\r r�r"r&r r r!r"%szBabylMessage.__init__cCs|jdd�Sr)r\r>r r r!r]+szBabylMessage.get_labelscCst|�|_dSr)r@r\)rrgr r r!ra/szBabylMessage.set_labelscCs6t|t�r"||jvr2|j�|�ntdt|���dS)Nzlabel must be a string: %s)rirur\r�r~r�rrjr r r!r�3s  zBabylMessage.add_labelcCs(z|j�|�Wnty"Yn0dSr)r\r+rZr�r r r!� remove_label;s zBabylMessage.remove_labelcCs t|j�Sr�r r�r>r r r!rpBszBabylMessage.get_visiblecCst|�|_dSrr�)rZvisibler r r!r`FszBabylMessage.set_visiblecCsb|j��D](}||vr*|j�|||�q |j|=q dD]$}||vr8||jvr8|||j|<q8dS)N)ZDateZFromzReply-ToZToZCCZSubject)r�rAr�)r�headerr r r!�update_visibleJs zBabylMessage.update_visiblecCsrt|t�r~t|���}d|vr*|�d�n|�d�|�d�d|vsNd|vrX|�d�d|vrj|�d�d |vr||�d �n�t|t�r�t|���}d|vr�|�d �n |�d �d |vr�|�d �d|vr�|�d�n�t|t��rt|���}d|v�r|�d�d|v�rn|�d�nTt|t ��rP|� |� ��|��D]}|� |��qr r r!r�sz_ProxyFile.tellrcCs4|dkr|j�|j�|j�||�|j��|_dS)Nr��r�ror�r�r�offset�whencer r r!ro�sz_ProxyFile.seekcCs4t|d�r0zt|jd�r"|j��W|`n|`0dS)Nr�rW)rPr�rWr>r r r!rW�s    z_ProxyFile.closecCs2|dur d}|j�|j�||�}|j��|_|S)Nrer�)rr�� read_methodrMr r r!r��s  z_ProxyFile._readcCs|Srr r>r r r!� __enter__�sz_ProxyFile.__enter__cGs |��dSr)rW)r�excr r r!�__exit__�sz_ProxyFile.__exit__cCs |j��Sr)r��readabler>r r r!r��sz_ProxyFile.readablecCs |j��Sr)r��writabler>r r r!r��sz_ProxyFile.writablecCs |j��Sr)r��seekabler>r r r!r��sz_ProxyFile.seekablecCs |j��Sr)r�rTr>r r r!rT�sz_ProxyFile.flushcCs&t|d�sdSt|jd�sdS|jjS)Nr�Tr3F)rPr�r3r>r r r!r3�s   z_ProxyFile.closed)N)N)N)N)N)r)r�r�r�r"r_r�r|r�rFrrorWr�r�r�r�r�r�rT�propertyr3r�rr�r r r r!r��s&         r�c@s8eZdZd dd�Zdd�Zddd�Zd d �Zd d �ZdS)rNcCst�|||�||_||_dSr)r�r"�_start�_stop)rr�r r r r r!r"�sz_PartialFile.__init__cCst�|�|jSr)r�rr�r>r r r!r�sz_PartialFile.tellrcCs<|dkr|j|_d}n|dkr*|j|_d}t�|||�dS)Nrr�r�)r�r�r�r�ror�r r r!ro�sz_PartialFile.seekcCsB|j|j}|dkrdS|dus0|dks0||kr4|}t�|||�S)Nrr)r�r�r�r�)rr�r�� remainingr r r!r��s  z_PartialFile._readcCst|d�r|`dS)Nr�)rPr�r>r r r!rWs z_PartialFile.close)NN)r)r�r�r�r"rror�rWr r r r!r�s    rTc Cs�d}�zftrrzt�|tjtjB�WnLtyp}z4|jtjtjtjfvrZt d|j ��n�WYd}~n d}~00|�rjzt |j d�}|� �WnHty�}z0|jtjtjfvr�WYd}~WdS�WYd}~n d}~00z^zt �|j |j d�d}Wn0ttf�y*t �|j |j d�d}Yn0t �|j �Wn.t�yht �|j �t d|j ��Yn0Wn8t�r�t�|tj�|�r�t �|j d��Yn0dS)NFzlockf: lock unavailable: %s�.lockTzdot lock unavailable: %s)�fcntl�lockfZLOCK_EXZLOCK_NBr�r��EAGAINr�r�rr�rrWrr�r�r�r�rRr�r+�LOCK_UN)r�r�Z dotlock_doner�Zpre_lockr r r!r�sL�   �r�cCs8trt�|tj�tj�|jd�r4t�|jd�dS)Nr�)r�r�r�rrr�r�r+�r�r r r!r�9sr�c CsDt�|tjtjBtjBd�}zt|d�Wt�|�St�|�0dS)Nr�r�)rr�r�r0�O_RDWRrW)r�fdr r r!r�@s   �r�cCs$td|tt���t��t��f�S)Nz %s.%s.%s.%s)r�r�r�r�r�rr�)rr r r!rHs�rcCs$|��ttd�r t�|���dS)N�fsync)rTrPrr��filenor�r r r!rNs rcCst|�|��dSr)rrWr�r r r!r�Tsr�c@s eZdZdS)rNr�r r r r!rZsrc@s eZdZdS)rNr�r r r r!r]src@s eZdZdS)rNr�r r r r!r`src@s eZdZdS)rNr�r r r r!rcsrc@s eZdZdS)rNr�r r r r!rfsr)T)1rr�r�r�r�rsrxr:Z email.messageZemail.generatorrjr5�typesrr�� ImportError�__all__rqrXrrr�rrrrrr'r r rr r r rr�rr�r�r�rrr�� Exceptionrrrrrr r r r!� sj     j8DB4-3z%mqH_e' *