ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/__pycache__/mailbox.cpython-37.pyc

B

� f>3�@sRdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZyddl
Z
Wnek
r�dZ
YnXddddddd	d
dd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�de�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.Gd<d�de+�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�Error�NoSuchMailboxError�
NotEmptyError�ExternalClashError�FormatError�asciic@seZdZdZdCdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dDdd�Z
dd�Zdd�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;�Zd<d=�Z d>d?�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�,/opt/alt/python37/lib64/python3.7/mailbox.py�__init__$szMailbox.__init__cCstd��dS)z$Add message and return assigned key.z&Method must be implemented by subclassN)�NotImplementedError)r�messagerrr�add)szMailbox.addcCstd��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|�|�dS)N)r$)rr#rrr�__delitem__1szMailbox.__delitem__cCs(y|�|�Wntk
r"YnXdS)z'If the keyed message exists, remove it.N)r$�KeyError)rr#rrr�discard4szMailbox.discardcCstd��dS)z>Replace the keyed message; raise KeyError if it doesn't exist.z&Method must be implemented by subclassN)r )rr#r!rrr�__setitem__;szMailbox.__setitem__cCs$y
|�|�Stk
r|SXdS)z9Return the keyed message, or default if it doesn't exist.N)�__getitem__r&)rr#�defaultrrr�get?s
zMailbox.getc	Cs6|js|�|�St�|�|���}|�|�SQRXdS)z=Return the keyed message; raise KeyError if it doesn't exist.N)r�get_message�
contextlib�closing�get_file)rr#�filerrrr)Fs
zMailbox.__getitem__cCstd��dS)z4Return a Message representation or raise a KeyError.z&Method must be implemented by subclassN)r )rr#rrrr,NszMailbox.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_bytes�	as_string)rr#rrr�
get_stringRszMailbox.get_stringcCstd��dS)z8Return a byte string representation or raise a KeyError.z&Method must be implemented by subclassN)r )rr#rrrr3YszMailbox.get_bytescCstd��dS)z6Return a file-like representation or raise a KeyError.z&Method must be implemented by subclassN)r )rr#rrrr/]szMailbox.get_filecCstd��dS)zReturn an iterator over keys.z&Method must be implemented by subclassN)r )rrrr�iterkeysaszMailbox.iterkeyscCst|���S)zReturn a list of keys.)�listr6)rrrr�keyseszMailbox.keysc	cs@x:|��D].}y||}Wntk
r0w
YnX|Vq
WdS)z%Return an iterator over all messages.N)r6r&)rr#�valuerrr�
itervaluesiszMailbox.itervaluescCs|��S)N)r:)rrrr�__iter__rszMailbox.__iter__cCst|���S)z,Return a list of messages. Memory intensive.)r7r:)rrrr�valuesuszMailbox.valuesc	csDx>|��D]2}y||}Wntk
r0w
YnX||fVq
WdS)z.Return an iterator over (key, message) tuples.N)r6r&)rr#r9rrr�	iteritemsyszMailbox.iteritemscCst|���S)z9Return a list of (key, message) tuples. Memory intensive.)r7r=)rrrr�items�sz
Mailbox.itemscCstd��dS)z9Return True if the keyed message exists, False otherwise.z&Method must be implemented by subclassN)r )rr#rrr�__contains__�szMailbox.__contains__cCstd��dS)z*Return a count of messages in the mailbox.z&Method must be implemented by subclassN)r )rrrr�__len__�szMailbox.__len__cCs x|��D]}|�|�q
WdS)zDelete all messages.N)r8r')rr#rrr�clear�sz
Mailbox.clearcCs0y||}Wntk
r |SX|�|�|S)z3Delete the keyed message and return it, or default.)r&r')rr#r*�resultrrr�pop�s
zMailbox.popcCs*x$|��D]}||�|�fSWtd��dS)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailboxN)r6rCr&)rr#rrr�popitem�szMailbox.popitemc	Csxt|d�r|��}nt|d�r(|��}n|}d}x6|D].\}}y|||<Wq6tk
rbd}Yq6Xq6W|rttd��dS)z4Change the messages that correspond to certain keys.r=r>FTzNo message with key(s)N)�hasattrr=r>r&)r�arg�sourceZbad_keyr#r!rrr�update�s



zMailbox.updatecCstd��dS)z&Write any pending changes to the disk.z&Method must be implemented by subclassN)r )rrrr�flush�sz
Mailbox.flushcCstd��dS)zLock the mailbox.z&Method must be implemented by subclassN)r )rrrr�lock�szMailbox.lockcCstd��dS)z#Unlock the mailbox if it is locked.z&Method must be implemented by subclassN)r )rrrr�unlock�szMailbox.unlockcCstd��dS)zFlush and close the mailbox.z&Method must be implemented by subclassN)r )rrrr�close�sz
Mailbox.closecCs,y
|�d�Stk
r&td��YnXdS)Nrz?String input must be ASCII-only; use bytes or a Message instead)�encode�UnicodeError�
ValueError)rr!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�}|�
|�|j�r�|�t��s�|�
t�n�t|d��r�t|d��r2t�d	td�|j}d
}x�|��}|�d��r^|d
d�d}n|�d
��rz|d
d�d}|�s�P|�r�|�d��r�d|dd
�}|�dt�}|�
|�|}�q8W|j�r�|�r�|�t��s�|�
t�ntdt|���d
S)z%Dump message contents to target file.r�
z8Use of StringIO input is deprecated, use BytesIO instead�s
From s
>From �read�bufferzDUse of text mode files is deprecated, use a binary mode file insteadNs
����
���sFrom s>From �zInvalid message type: %s)�
isinstancer1r!r�io�BytesIO�	generator�BytesGenerator�flatten�seekrS�replace�linesep�write�_append_newline�endswith�str�bytes�StringIO�warnings�warn�DeprecationWarning�getvaluerPrErT�readline�
startswith�	TypeError�type)	rr!�targetZmangle_from_rT�gen�dataZlastline�linerrr�
_dump_message�sZ







zMailbox._dump_message)NT)N)N)N)F)$�__name__�
__module__�__qualname__�__doc__rr"r$r%r'r(r+r)r,r5r3r/r6r8r:r;r<r=r>r?r@rArCrDrHrIrJrKrLrPrcrtrrrrr!sB

		
	
c@s�eZdZdZdZd6dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�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�x*|j�	�D]}t�|d�qnWn
t
|j��i|_ddd�|_d|_
d|_d	S)
zInitialize a Maildir instance.�tmp�new�cur)rzr{r|i�r)r|r{g�������?N)rrrr�joinr�_paths�exists�mkdirr<r�_toc�_toc_mtimes�
_last_read�_skewfactor)r�dirnamerrrrrrr
s
zMaildir.__init__c
Cs~|��}y|�||�Wn*tk
rB|��t�|j��YnXt|�t|t	�r||�
�}|j|��}||jkr�d}nd}d}tj
�|j��|j�d}tj
�|j|||�}t|t	�r�t�|jtj
�|j�|��f�yLyt�|j|�Wn(ttfk
�rt�|j|�YnXt�|j�WnNtk
�rx}z.t�|j�|jtjk�rftd|��n�Wdd}~XYnX|S)z$Add message and return assigned key.�r{rz$Name clash with existing message: %sN)�_create_tmprt�
BaseExceptionrLrr$�name�_sync_closerYr	�
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"!sB



zMaildir.addcCs t�tj�|j|�|���dS)z=Remove the keyed message; raise KeyError if it doesn't exist.N)rr$rr}r�_lookup)rr#rrrr$KszMaildir.removec	Cs,y|�|�Wnttfk
r&YnXdS)z'If the keyed message exists, remove it.N)r$r&�FileNotFoundError)rr#rrrr'OszMaildir.discardcCs�|�|�}|�|�}|�|�}t|t�r.|}n|}tj�|�}|j|kr`|j|�|j�d}nd}|�	|�tj�
|j|�}	tj�
|j|||�}
t|t�r�t�|	tj�
|	�|��f�t�|	|
�dS)z>Replace the keyed message; raise KeyError if it doesn't exist.rWr�N)r�r"rYr	rrr�r�r�r'r}rr�r�r�r�)rr#r!Zold_subpathZtemp_keyZtemp_subpathZdominant_subpathr�r�Ztmp_path�new_pathrrrr(Ws"






zMaildir.__setitem__c	Cs�|�|�}ttj�|j|�d�� }|jr4|�|�}nt|�}WdQRXtj�|�\}}|�	|�|j
|kr�|�|�|j
�d�|�tj�
tj�|j|���|S)z4Return a Message representation or raise a KeyError.�rbNrW)r��openrrr}rrr	r��
set_subdirr��set_info�set_date�getmtime)rr#Zsubpath�f�msgr�r�rrrr,rs


zMaildir.get_messagec	Cs8ttj�|j|�|��d��}|���td�SQRXdS)z2Return a bytes representation or raise a KeyError.r�rQN)	r�rrr}rr�rSr`ra)rr#r�rrrr3�szMaildir.get_bytescCs$ttj�|j|�|��d�}t|�S)z6Return a file-like representation or raise a KeyError.r�)r�rrr}rr��
_ProxyFile)rr#r�rrrr/�szMaildir.get_filec	csH|��x:|jD]0}y|�|�Wntk
r8wYnX|VqWdS)zReturn an iterator over keys.N)�_refreshr�r�r&)rr#rrrr6�szMaildir.iterkeyscCs|��||jkS)z9Return True if the keyed message exists, False otherwise.)r�r�)rr#rrrr?�szMaildir.__contains__cCs|��t|j�S)z*Return a count of messages in the mailbox.)r��lenr�)rrrrr@�szMaildir.__len__cCsdS)z"Write any pending changes to disk.Nr)rrrrrI�sz
Maildir.flushcCsdS)zLock the mailbox.Nr)rrrrrJ�szMaildir.lockcCsdS)z#Unlock the mailbox if it is locked.Nr)rrrrrK�szMaildir.unlockcCsdS)zFlush and close the mailbox.Nr)rrrrrL�sz
Maildir.closecCs`g}xVt�|j�D]F}t|�dkr|ddkrtj�tj�|j|��r|�|dd��qW|S)zReturn a list of folder names.�r�.N)r�listdirrr�r�isdirr}�append)rrB�entryrrr�list_folders�szMaildir.list_folderscCs ttj�|jd|�|jdd�S)z/Return a Maildir instance for the named folder.r�F)rr)rrrr}rr)r�folderrrr�
get_folder�szMaildir.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
maildirfolderi�)rrr}rrrrrLr��O_CREAT�O_WRONLY)rr�rrBZmaildirfolder_pathrrr�
add_folder�szMaildir.add_foldercCs,tj�|jd|�}xTt�tj�|d��t�tj�|d��D](}t|�dksZ|ddkr>td|��q>WxPt�|�D]B}|dkrv|dkrv|dkrvtj�tj�||��rvtd||f��qvWx`tj|d	d
�D]N\}}}x |D]}t�	tj�||��q�Wx |D]}t�
tj�||��q�Wq�Wt�
|�dS)z-Delete the named folder, which must be empty.r�r{r|r�rzFolder contains message(s): %srzz%Folder contains subdirectory '%s': %sF)�topdownN)rrr}rr�r�rr��walkr$�rmdir)rr�rr��root�dirs�filesrrr�
remove_folder�s 

zMaildir.remove_foldercCs\t��}xNt�tj�|jd��D]4}tj�|jd|�}|tj�|�dkr t�|�q WdS)zDelete old files in "tmp".rzi@�N)�timerr�rr}rr�r$)r�nowr�rrrr�clean�s
z
Maildir.cleanr�cCs�t��}t��}d|kr$|�dd�}d|kr8|�dd�}dt|�t|dd�t��tj|f}tj	�
|jd|�}yt�|�Wn@t
k
r�tjd7_yt|�Stk
r�YnXYnXtd	|��d
S)z=Create a file in the tmp subdirectory and open and return it.�/z\057ryz\072z%s.M%sP%sQ%s.%sr�g��.Arzz&Name clash prevented file creation: %sN)r��socket�gethostnamer`�intr�getpidr�_countrr}r�statr��_create_carefully�FileExistsErrorr)rr�Zhostnamer�rrrrr��s&zMaildir._create_tmpcCs�t��|jd|jkrbd}x<|jD]2}tj�|j|�}||j|krLd}||j|<q$W|sbdSi|_xl|jD]b}|j|}xRt�	|�D]D}tj�
||�}tj�|�r�q�|�|j
�d}tj�
||�|j|<q�WqpWt��|_dS)z!Update table of contents mapping.�FTNr)r�r�r�r�rrr�r~r�r�r}r�r�r�)rZrefreshr��mtimerr��pr�rrrr��s&
zMaildir._refreshcCs|y,tj�tj�|j|j|��r*|j|SWntk
r@YnX|��y
|j|Stk
rvtd|�d�YnXdS)z=Use TOC to return subpath for given key, or raise a KeyError.zNo message with key: %sN)rrrr}rr�r&r�)rr#rrrr�#s
zMaildir._lookupcCsVt|d�s|��|_x<y|t|j�Stk
r8dStk
rLwYqXqWdS)z0Return the next message in a one-time iteration.�
_onetime_keysN)rEr6r��next�
StopIterationr&)rrrrr�1s

zMaildir.next)NT)rurvrwrxr�rr"r$r'r(r,r3r/r6r?r@rIrJrKrLr�r�r�r�r�r�r�r�r�r�rrrrrs6
*
	
$c@s�eZdZdZd$dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd%d d!�Zd"d#�ZdS)&�_singlefileMailboxzA single-file mailbox.NTc
Cs�t�||||�yt|jd�}Wnntk
r�}zP|jtjkr\|rPt|jd�}q~t|j��n"|jtjtj	fkr|t|jd�}n�Wdd}~XYnX||_
d|_d|_d|_
d|_d|_d|_dS)z!Initialize a single-file mailbox.zrb+zwb+r�NrF)rrr�rr�r��ENOENTr�EACCES�EROFS�_filer��	_next_key�_pending�
_pending_sync�_locked�_file_length)rrrrr�r�rrrrAs$z_singlefileMailbox.__init__cCs8|��|�|�|j|j<|jd7_d|_|jdS)z$Add message and return assigned key.r�T)r��_append_messager�r�r�)rr!rrrr"Xs
z_singlefileMailbox.addcCs|�|�|j|=d|_dS)z=Remove the keyed message; raise KeyError if it doesn't exist.TN)r�r�r�)rr#rrrr$bs
z_singlefileMailbox.removecCs$|�|�|�|�|j|<d|_dS)z>Replace the keyed message; raise KeyError if it doesn't exist.TN)r�r�r�r�)rr#r!rrrr(hs
z_singlefileMailbox.__setitem__ccs|��|j��EdHdS)zReturn an iterator over keys.N)r�r�r8)rrrrr6nsz_singlefileMailbox.iterkeyscCs|��||jkS)z9Return True if the keyed message exists, False otherwise.)r�r�)rr#rrrr?ssz_singlefileMailbox.__contains__cCs|��t|j�S)z*Return a count of messages in the mailbox.)r�r�r�)rrrrr@xsz_singlefileMailbox.__len__cCs|jst|j�d|_dS)zLock the mailbox.TN)r��
_lock_filer�)rrrrrJ}s
z_singlefileMailbox.lockcCs|jrt|j�d|_dS)z#Unlock the mailbox if it is locked.FN)r��_unlock_filer�)rrrrrK�s
z_singlefileMailbox.unlockc
Cs�|js |jrt|j�d|_dS|jdk	s.t�|j�dd�|j��}||jkrbt	d|j|f��t
|j�}y�i}|�|�x�t
|j���D]|}|j|\}}|j�|�|�|�|��}x0|j�td||j����}|s�P|�|�q�W||��f||<|�|�q�W|��|_Wn"|��t�|j��YnXt|�|j��t�|j�j}	t�|j|	�yt�|j|j�Wn2tk
�r�t�|j�t�|j|j�YnXt|jd�|_||_d|_d|_|j�r�t |jdd�dS)	z"Write any pending changes to disk.FNrr�z4Size of mailbox file changed (expected %i, found %i)izrb+)�dotlock)!r�r��_sync_flushr�r��AssertionErrorr_�tellr�r�_create_temporaryr�_pre_mailbox_hook�sortedr8�_pre_message_hookrS�minrb�_post_message_hookrLrr$r�r�r��st_mode�chmodr�r�r�r�r�)
rZcur_lenZnew_fileZnew_tocr#�start�stopZ	new_startrT�moderrrrI�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_hookcCs4z|��Wdz|jr|��Wd|j��XXdS)zFlush and close the mailbox.N)rIr�rKr�rL)rrrrrL�sz_singlefileMailbox.closecCsL|jdkr|��|dk	rHy
|j|Stk
rFtd|�d�YnXdS)z'Return (start, stop) or raise KeyError.NzNo message with key: %s)r��
_generate_tocr&)rr#rrrr��s

z_singlefileMailbox._lookupcCs�|j�dd�|j��}t|j�dkr8|js8|�|j�y&|�|j�|�|�}|�	|j�Wn"t
k
r�|j�|��YnX|j��|j��|_
|S)z;Append message to mailbox and return (start, stop) offsets.rr�)r�r_r�r�r�r�r�r��_install_messager�r��truncaterIr�)rr!ZbeforeZoffsetsrrrr��s


z"_singlefileMailbox._append_message)NT)N)rurvrwrxrr"r$r(r6r?r@rJrKrIr�r�r�rLr�r�rrrrr�>s"

@

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)z4Return a Message representation or raise a KeyError.�rQrXNr)r�r�r_rlr`rarSr��_message_factory�set_from�decode)rr#r�r��	from_line�stringr�rrrr,sz_mboxMMDF.get_messageFcCst�|�|��j|d�S)z3Return a string representation or raise a KeyError.)�unixfrom)r1r2r3r4)rr#�from_rrrr5sz_mboxMMDF.get_stringcCsJ|�|�\}}|j�|�|s(|j��|j�||j���}|�td�S)z3Return a string representation or raise a KeyError.rQ)r�r�r_rlrSr�r`ra)rr#r�r�r�r�rrrr3s
z_mboxMMDF.get_bytescCs<|�|�\}}|j�|�|s(|j��t|j|j��|�S)z6Return a file-like representation or raise a KeyError.)r�r�r_rl�_PartialFiler�)rr#r�r�r�rrrr/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.NsFrom rQrWr�r�rsFrom MAILER-DAEMON )rYrerPrfrm�find�_mboxMMDFMessage�get_fromrMr1r!r�get_unixfromr��asctime�gmtimer�r�rbrart�
_mangle_from_)rr!r��newlineZauthorr�r�rrrr�&s0







z_mboxMMDF._install_messageN)F)F)F)
rurvrwrxrr,r5r3r/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)rrrrrrrrLsz
mbox.__init__cCs|�t�dS)z,Called after writing each message to file f.N)rbra)rr�rrrr�Qszmbox._post_message_hookcCs�gg}}d}|j�d�x�|j��}|j��}|�d�r|t|�t|�krl|rb|�|tt��n
|�|�|�|�d}q|s�|r�|�|tt��n
|�|�Pq|tkr�d}qd}qWtt	t
||���|_t|j�|_|j��|_
dS)z0Generate key-to-(start, stop) table of contents.FrsFrom TN)r�r_r�rlrmr�r�ra�dict�	enumerate�zipr�r�r�)r�starts�stopsZlast_was_empty�line_posrsrrrr�Us0






zmbox._generate_toc)NT)	rurvrwrxrrcrr�r�rrrrrCs
c@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
rzAn MMDF mailbox.NTcCst|_t�||||�dS)zInitialize an MMDF mailbox.N)r
r�r�r)rrrrrrrrzsz
MMDF.__init__cCs|�dt�dS)z-Called before writing each message to file f.sN)rbra)rr�rrrr�szMMDF._pre_message_hookcCs|�tdt�dS)z,Called after writing each message to file f.sN)rbra)rr�rrrr��szMMDF._post_message_hookcCs�gg}}|j�d�d}x�|}|j��}|j��}|�dt�r�|�|�xV|}|j��}|j��}|dtkr�|�|tt��PqN|sN|�|�PqNWq|sPqWtt	t
||���|_t|j�|_|j�dd�|j��|_
dS)z0Generate key-to-(start, stop) table of contents.rsr�N)r�r_rlr�rmrar�r�rrrr�r�r�)rrr�next_posrrsrrrr��s2






zMMDF._generate_toc)NT)rurvrwrxrr�r�r�rrrrrws

c@s�eZdZdZd0dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�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
tjBtjBd��n
t
|j��d|_dS)zInitialize an MH instance.i�z
.mh_sequencesi�FN)rrrrrrr�rLr�r}r��O_EXCLr�rr�)rrrrrrrr�s
zMH.__init__cCs�|��}t|�dkrd}nt|�d}tj�|jt|��}t|�}d}z�|j	rVt
|�zfy|�||�Wn:tk
r�|j	r�t
|�t|�d}t�|��YnXt|t�r�|�||�Wd|j	r�t
|�XWd|s�t|�X|S)z$Add message and return assigned key.rr�FTN)r8r��maxrrr}rrer�r�r�rtr�r�r�r$rYr�_dump_sequences)rr!r8Znew_keyr�r��closedrrrr"�s6


zMH.addc
Csxtj�|jt|��}yt|d�}Wn>tk
r`}z |jtjkrNt	d|��n�Wdd}~XYnX|�
�t�|�dS)z=Remove the keyed message; raise KeyError if it doesn't exist.zrb+zNo message with key: %sN)rrr}rrer�r�r�r�r&rLr$)rr#rr�r�rrrr$�sz	MH.removec
Cs�tj�|jt|��}yt|d�}Wn>tk
r`}z |jtjkrNt	d|��n�Wdd}~XYnXzd|j
rrt|�z@t�t�|tj
tjB��|�||�t|t�r�|�||�Wd|j
r�t|�XWdt|�XdS)z>Replace the keyed message; raise KeyError if it doesn't exist.zrb+zNo message with key: %sN)rrr}rrer�r�r�r�r&r�r�rLr��O_TRUNCrtrYrrr�r�)rr#r!rr�r�rrrr(�s$
zMH.__setitem__c
Cs�y@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn>tk
r~}z |jtj	krlt
d|��n�Wdd}~XYnX|�2|jr�t|�zt|�}Wd|jr�t
|�XWdQRXx*|����D]\}}||kr�|�|�q�W|S)z4Return a Message representation or raise a KeyError.zrb+r�zNo message with key: %sN)r�r�rrr}rrer�r�r�r&r�rr��
get_sequencesr>�add_sequence)rr#r�r�r�r��key_listrrrr,�s&zMH.get_messagec
Cs�y@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn>tk
r~}z |jtj	krlt
d|��n�Wdd}~XYnX|�6|jr�t|�z|���
td�S|jr�t|�XWdQRXdS)z2Return a bytes representation or raise a KeyError.zrb+r�zNo message with key: %sNrQ)r�r�rrr}rrer�r�r�r&r�rSr`rar�)rr#r�r�rrrr3szMH.get_bytesc
Csfyttj�|jt|��d�}Wn>tk
r\}z |jtjkrJt	d|��n�Wdd}~XYnXt
|�S)z6Return a file-like representation or raise a KeyError.r�zNo message with key: %sN)r�rrr}rrer�r�r�r&r�)rr#r�r�rrrr/)szMH.get_filecCsttdd�t�|j�D���S)zReturn an iterator over keys.css|]}|��rt|�VqdS)N)�isdigitr�)�.0r�rrr�	<genexpr>6szMH.iterkeys.<locals>.<genexpr>)�iterr�rr�r)rrrrr64szMH.iterkeyscCstj�tj�|jt|���S)z9Return True if the keyed message exists, False otherwise.)rrrr}rre)rr#rrrr?9szMH.__contains__cCstt|����S)z*Return a count of messages in the mailbox.)r�r7r6)rrrrr@=sz
MH.__len__cCs2|js.ttj�|jd�d�|_t|j�d|_dS)zLock the mailbox.z
.mh_sequenceszrb+TN)r�r�rrr}rr�r�)rrrrrJAs
zMH.lockcCs(|jr$t|j�t|j�|`d|_dS)z#Unlock the mailbox if it is locked.FN)r�r�r�r�)rrrrrKHs


z	MH.unlockcCsdS)z&Write any pending changes to the disk.Nr)rrrrrIPszMH.flushcCs|jr|��dS)zFlush and close the mailbox.N)r�rK)rrrrrLTszMH.closecCs@g}x6t�|j�D]&}tj�tj�|j|��r|�|�qW|S)zReturn a list of folder names.)rr�rrr�r}r�)rrBr�rrrr�Ys
zMH.list_folderscCsttj�|j|�|jdd�S)z+Return an MH instance for the named folder.F)rr)rrrr}rr)rr�rrrr�asz
MH.get_foldercCsttj�|j|�|jd�S)z:Create a folder and return an MH instance representing it.)r)rrrr}rr)rr�rrrr�fsz
MH.add_foldercCs`tj�|j|�}t�|�}|dgkr:t�tj�|d��n|gkrDntd|j��t�|�dS)z-Delete the named folder, which must be empty.z
.mh_sequenceszFolder not empty: %sN)rrr}rr�r$rr�)rr�r�entriesrrrr�ks

zMH.remove_folderc

si}ttj�|jd�ddd���}t|����x�|D]�}y�|�d�\}}t�}xT|��D]H}|��rr|�	t
|��qVdd�|�d�D�\}}	|�t||	d	��qVW�fd
d�t
|�D�||<t||�dkr�||=Wq2tk
r�td
|����Yq2Xq2WWdQRX|S)z=Return a name-to-key-list dictionary to define each sequence.z
.mh_sequences�r�ASCII)�encodingrycss|]}t|�VqdS)N)r�)r�xrrrr�sz#MH.get_sequences.<locals>.<genexpr>�-r�csg|]}|�kr|�qSrr)rr#)�all_keysrr�
<listcomp>�sz$MH.get_sequences.<locals>.<listcomp>rz"Invalid sequence specification: %sN)r�rrr}r�setr8r�rr"r�rH�ranger�r�rOr�rstrip)
rZresultsr�rsr��contentsr8�specr�r�r)rrrws&

 zMH.get_sequencescCs
ttj�|jd�ddd�}z�t�t�|jtjtjB��x�|�	�D]�\}}t
|�dkrXqB|�|d�d}d}xbtt
|��D]R}|d	|kr�|s�d
}|�d�n*|r�d}|�d||f�n|�d
|�|}q|W|r�|�t|�d�qB|�d�qBWWdt|�XdS)z:Set sequences using the given name-to-key-list dictionary.z
.mh_sequenceszr+r)rrryNFr�Trz%s %sz %s�
)r�rrr}rrLr�r�r
r>r�rbr�rrer�)r�	sequencesr�r�r8�prevZ
completingr#rrr�
set_sequences�s.zMH.set_sequencesc	
CsL|��}d}g}x�|��D]�}|d|kr�|�||df�y4t�tj�|jt|��tj�|jt|d���WnHt	t
fk
r�t�tj�|jt|��tj�|jt|d���YnXt�tj�|jt|���|d7}qW|d|_
t|�dkr�dSxB|��D]6\}}x*|D]"\}}||k�r|||�|�<�qW�qW|�|�dS)z?Re-name messages to eliminate numbering gaps. Invalidates keys.rr�N)rr6r�rr�rr}rrer�r�r��unlinkr�r�r>�indexr%)	rr#r$Zchangesr#r�r�oldr{rrr�pack�s, 

zMH.packcCs||��}|��}x<|��D]0\}}||kr6|�|�q||kr||�|�=qWx|D]}||krT|g||<qTW|�|�dS)z;Inspect a new MHMessage and update sequences appropriately.N)rr>r�r'r%)rr!r#Zpending_sequencesZ
all_sequencesr�r�sequencerrrr�s
zMH._dump_sequences)NT)rurvrwrxrr"r$r(r,r3r/r6r?r@rJrKrIrLr�r�r�r�rr%r)rrrrrr�s.
"c@s�eZdZdZedddddddh�Zd%dd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�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�_labels)rrrrrrrr�szBabyl.__init__cCs(t�||�}t|t�r$|��|j|<|S)z$Add message and return assigned key.)r�r"rYr�
get_labelsr0)rr!r#rrrr"�s
z	Babyl.addcCs"t�||�||jkr|j|=dS)z=Remove the keyed message; raise KeyError if it doesn't exist.N)r�r$r0)rr#rrrr$�s
zBabyl.removecCs*t�|||�t|t�r&|��|j|<dS)z>Replace the keyed message; raise KeyError if it doesn't exist.N)r�r(rYrr1r0)rr#r!rrrr(�s
zBabyl.__setitem__c
Cs|�|�\}}|j�|�|j��t��}x2|j��}|dtksH|sJP|�|�td��q.Wt��}x.|j��}|tks�|s�P|�|�td��qjW||j�	�}|dks�t
�|j�|�}|�td�}t|�
�|�}	|	�|�
��||jk�r|	�|j|�|	S)z4Return a Message representation or raise a KeyError.s*** EOOH ***rQr)r�r�r_rlrZr[rarbr`r�r�rSrrk�set_visibler0�
set_labels)
rr#r�r��original_headersrsZvisible_headers�nZbodyr�rrrr,�s0


zBabyl.get_messagec	Cs�|�|�\}}|j�|�|j��t��}x2|j��}|dtksH|sJP|�|�td��q.Wx|j��}|tksx|sbPqbW|�	�}||j�
�}|dks�t�|j�|�}|�td�}||S)z3Return a string representation or raise a KeyError.s*** EOOH ***rQr)
r�r�r_rlrZr[rarbr`rkr�r�rS)	rr#r�r�r4rsZheadersr5rrrrrr3s&


zBabyl.get_bytescCst�|�|��dt��S)z6Return a file-like representation or raise a KeyError.rQ)rZr[r3r`ra)rr#rrrr/%szBabyl.get_filecCs@|��t�}x|j��D]}|�|�qW|�|j�t|�S)z4Return a list of user-defined labels in the mailbox.)r�rr0r<rH�difference_update�_special_labelsr7)r�labelsZ
label_listrrrr1)szBabyl.get_labelscCs>gg}}|j�d�d}g}x�|}|j��}|j��}|dtkr�t|�t|�krf|�|tt��|�|�dd�|j��dd��d�D�}|�|�q |dks�|dtkr�t|�t|�kr�|�|tt��q |s |�|tt��Pq Wtt	t
||���|_tt	|��|_t|j�|_
|j�dd	�|j��|_dS)
z0Generate key-to-(start, stop) table of contents.rscSsg|]}|��r|���qSr)�strip)r�labelrrrr@sz'Babyl._generate_toc.<locals>.<listcomp>r�N�,�r�)r�r_rlr�rar�r�r�rrrr�r0r�r�)rrrrZlabel_listsrrsr8rrrr�2s4



zBabyl._generate_toccCsVdt}|dt7}|��}dd�|D�}|dd�|�t7}|d7}|�|�dS)	z,Called before writing the mailbox to file f.sBABYL OPTIONS:s
Version: 5css|]}|��VqdS)N)rM)rr:rrrrUsz*Babyl._pre_mailbox_hook.<locals>.<genexpr>sLabels:r;r<N)rar1r}rb)rr�Zbabylr8rrrr�PszBabyl._pre_mailbox_hookcCs|�dt�dS)z-Called before writing each message to file f.�N)rbra)rr�rrrr�ZszBabyl._pre_message_hookcCs|�td�dS)z,Called after writing each message to file f.r<N)rbra)rr�rrrr�^szBabyl._post_message_hookcCs�|j��}t|t�r�g}g}x0|��D]$}||jkr@|�|�q&|�|�q&W|j�d�x |D]}|j�d|���q`W|j�d�x$|D]}|j�d|��d�q�W|j�t	�n|j�dt	�t|t
jj��r*t
��}t
j�|dd�}|�|�|�d�x4|��}|j�|�d	t	��|d	k�s6|�s
P�q
W|j�d
t	�t|t��r�t
��}	t
j�|	dd�}
|
�|���xv|	��}|j�|�d	t	��|d	k�s�|�s�P�q�Wn@|�d�x4|��}|j�|�d	t	��|d	k�s�|�s�P�q�Wx,|�d�}|�sP|j�|�d	t	���q�W�nXt|ttt
jf��r&t|t
j��rbt�dtd
�|��}t|t��rx|�|�}|�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	���n\t |d��rrt |d��rRt�dtd
�|j!}|��}
d}x�|��}|�"d��r�|dd�d	}n|�"d��r�|dd�d	}|j�|�d	t	��|d	k�s�|�s`|�r�d}|j�d
t	�|�|
�nP�q`Wx�|��}|�sP|�"d��r$|dd�t	}n:|�"d��rB|dd�t	}n|�"d	��r^|dd�t	}|j�|��q�Wnt#dt$|���|j��}||fS)z0Write message contents and return (start, stop).�1s, s,,� r;s1,,FrrQs*** EOOH ***iz8Use of StringIO input is deprecated, use BytesIO insteadrRs

r�rWNrlrTzDUse of text mode files is deprecated, use a binary mode file insteadTs
rUrVzInvalid message type: %s)%r�r�rYrr1r7r�rbrMrar1r!rrZr[r\r]r^r_rlr`�get_visiblerSrfrergrhrirjrkrPr�rErTrdrnro)rr!r�Zspecial_labelsr8r:Zorig_bufferZorig_generatorrsZ
vis_bufferZ
vis_generatorrTZ
body_startZoriginal_posZ
first_passr�rrrr�bs�











zBabyl._install_message)NT)rurvrwrx�	frozensetr7rr"r$r(r,r3r/r1r�r�r�r�r�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.rSNzInvalid message type: %s)rYr1r!r�_become_message�copyZdeepcopy�_explain_torfr2reZmessage_from_stringrZ�
TextIOWrapperZmessage_from_filerEZmessage_from_binary_filerrnro)rr!rrrr�s



zMessage.__init__cCs8t|dg�}x&|jD]}||kr|j||j|<qWdS)z0Assume the non-format-specific state of message.�_type_specific_attributesN)�getattr�__dict__)rr!Z
type_specificr�rrrrB�szMessage._become_messagecCst|t�rdStd��dS)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rYrrn)rr!rrrrD�s
zMessage._explain_to)N)rurvrwrxrrBrDrrrrr�s
c@s|eZdZdZdddgZddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�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)rIrJr�rKrr)rr!rrrr�s
zMaildirMessage.__init__cCs|jS)zReturn 'new' or 'cur'.)rI)rrrrr��szMaildirMessage.get_subdircCs(|dks|dkr||_ntd|��dS)zSet subdir to 'new' or 'cur'.r{r|z!subdir must be 'new' or 'cur': %sN)rIrO)rr�rrrr�szMaildirMessage.set_subdircCs"|j�d�r|jdd�SdSdS)z*Return as a string the flags that are set.z2,r�Nr�)rJrm)rrrr�	get_flags
szMaildirMessage.get_flagscCsdd�t|��|_dS)z)Set the given flags and unset all others.z2,r�N)r}r�rJ)r�flagsrrr�	set_flagsszMaildirMessage.set_flagscCs$|�d�t|���t|�B��dS)z.Set the given flag(s) without changing others.r�N)rNr}rrL)r�flagrrr�add_flagszMaildirMessage.add_flagcCs,|��r(|�d�t|���t|���dS)z7Unset the given string flag(s) without changing others.r�N)rLrNr}r)rrOrrr�remove_flagszMaildirMessage.remove_flagcCs|jS)z<Return delivery date of message, in seconds since the epoch.)rK)rrrrr�szMaildirMessage.get_datecCs6yt|�|_Wn"tk
r0td|�d�YnXdS)z9Set delivery date of message, in seconds since the epoch.zcan't convert to float: %sN)�floatrKrOrn)rZdaterrrr�"szMaildirMessage.set_datecCs|jS)z%Get the message's "info" as a string.)rJ)rrrrr�)szMaildirMessage.get_infocCs&t|t�r||_ntdt|���dS)z Set the message's "info" string.zinfo must be a string: %sN)rYrerJrnro)r�inforrrr�-s
zMaildirMessage.set_infocCs�t|t�r8|�|���|�|���|�|����nht|t�r�t	|���}d|kr`|�
d�|��dkrv|�
d�d|kr�|�
d�d|kr�|�
d�d|kr�|�
d�|�d	t�
|����n�t|t��rt	|���}d|kr�|�d
�d|k�r|�d�d|k�r�|�d�n�t|t��r�t	|���}d|k�rD|�d
�d|k�rX|�d
�d|k�rl|�d�d|k�r�|�d�nt|t��r�ntdt|���dS)z;Copy Maildir-specific state to message insofar as possible.�S�Rr|�O�T�D�F�Az
MAILER-DAEMONr+�replied�flaggedr,r-�Pr.z$Cannot convert to specified type: %sN)rYr	rNrLr�r�r�r�r�rrPr�r�r�rrr�	add_labelrrnro)rr!rMrrrrD4sN

















zMaildirMessage._explain_to)N)rurvrwrxrFrr�r�rLrNrPrQr�r�r�r�rDrrrrr	�s

c@sZeZdZdZdgZddd�Zdd�Zddd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)r�z/Message with mbox- or MMDF-specific properties.�_fromNcCsV|�dd�t|tjj�rF|��}|dk	rF|�d�rF|�|dd��t�||�dS)z'Initialize an mboxMMDFMessage instance.z
MAILER-DAEMONTNzFrom rX)r�rYr1r!rr�rmr)rr!r�rrrresz_mboxMMDFMessage.__init__cCs|jS)z Return contents of "From " line.)r_)rrrrr�nsz_mboxMMDFMessage.get_fromcCs4|dk	r*|dkrt��}|dt�|�7}||_dS)z>Set "From " line, formatting and appending time_ if specified.NT� )r�r�r�r_)rr�Ztime_rrrr�rs
z_mboxMMDFMessage.set_fromcCs|�dd�|�dd�S)z*Return as a string the flags that are set.�Statusr�zX-Status)r+)rrrrrLzsz_mboxMMDFMessage.get_flagscCs�t|�}d\}}x&dD]}||kr||7}|�|�qWx&dD]}||kr>||7}|�|�q>W|d�t|��7}y|�d|�Wn tk
r�|�d|�YnXy|�d|�Wn tk
r�|�d|�YnXdS)z)Set the given flags and unset all others.)r�r�)rUrV)rXrYrZr�razX-StatusN)rr$r}r��replace_headerr&Z
add_header)rrMZstatus_flagsZ
xstatus_flagsrOrrrrN~s&

z_mboxMMDFMessage.set_flagscCs$|�d�t|���t|�B��dS)z.Set the given flag(s) without changing others.r�N)rNr}rrL)rrOrrrrP�sz_mboxMMDFMessage.add_flagcCs4d|ksd|kr0|�d�t|���t|���dS)z7Unset the given string flag(s) without changing others.razX-Statusr�N)rNr}rrL)rrOrrrrQ�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
��}y|�	t
�t�
|d���Wnttfk
r�YnX�n
t|t�r�|�|���|�|���n�t|t��rZt|���}d|k�r$|�d�d|k�r8|�d�d|k�rL|�d�|d	=|d
=n�t|t��r�t|���}d|k�r�|�d�d|k�r�|�d�d|k�r�|�d�|d	=|d
=nt|t��r�ntdt|���d
S)zACopy mbox- or MMDF-specific state to message insofar as possible.rVr|rYrZrUrTrXrWZstatuszx-statusr`���Nz%a %b %d %H:%M:%S %Yr+r[r\r,r-z$Cannot convert to specified type: %s)rYr	rrLr�rPr}r�r�r��calendarZtimegmr�ZstrptimerO�
OverflowErrorr�rNr�rrrr^rrnro)rr!rMZ
maybe_daterrrrD�s^



















z_mboxMMDFMessage._explain_to)N)N)
rurvrwrxrFrr�r�rLrNrPrQrDrrrrr�`s
	
r�c@seZdZdZdS)r
z&Message with mbox-specific properties.N)rurvrwrxrrrrr
�sc@sHeZdZdZdgZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)rz$Message with MH-specific properties.�
_sequencesNcCsg|_t�||�dS)z!Initialize an MHMessage instance.N)rfrr)rr!rrrr�szMHMessage.__init__cCs|jdd�S)z4Return a list of sequences that include the message.N)rf)rrrrr�szMHMessage.get_sequencescCst|�|_dS)z3Set the list of sequences that include the message.N)r7rf)rr#rrrr%�szMHMessage.set_sequencescCs6t|t�r"||jkr2|j�|�ntdt|���dS)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rYrerfr�rnro)rr*rrrr�s

zMHMessage.add_sequencecCs*y|j�|�Wntk
r$YnXdS)zARemove sequence from the list of sequences including the message.N)rfr$rO)rr*rrr�remove_sequence�szMHMessage.remove_sequencecCsJt|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�x||��D]}|�|�q�Wn`t|t	��r(t|���}d|k�r|�
d�d|k�rF|�
d�nt|t��r6ntdt
|���d
S)z6Copy MH-specific state to message insofar as possible.r+r|rTr\rYr[rU�ROrVrZr-z$Cannot convert to specified type: %sN)rYr	rrr�rPr�rrrr^rrnro)rr!r#r*rrrrD�s@










zMHMessage._explain_to)N)rurvrwrxrFrrr%rrgrDrrrrr�s
c@sbeZdZdZddgZddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)rz'Message with Babyl-specific properties.r0�_visibleNcCsg|_t�|_t�||�dS)z#Initialize a BabylMessage instance.N)r0rrir)rr!rrrr"szBabylMessage.__init__cCs|jdd�S)z'Return a list of labels on the message.N)r0)rrrrr1(szBabylMessage.get_labelscCst|�|_dS)z&Set the list of labels on the message.N)r7r0)rr8rrrr3,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)rYrer0r�rnro)rr:rrrr^0s

zBabylMessage.add_labelcCs*y|j�|�Wntk
r$YnXdS)z4Remove label from the list of labels on the message.N)r0r$rO)rr:rrr�remove_label8szBabylMessage.remove_labelcCs
t|j�S)z3Return a Message representation of visible headers.)rri)rrrrr@?szBabylMessage.get_visiblecCst|�|_dS)z2Set the Message representation of visible headers.N)rri)rZvisiblerrrr2CszBabylMessage.set_visiblecCsjx6|j��D](}||kr,|j�|||�q|j|=qWx,dD]$}||kr>||jkr>|||j|<q>WdS)z9Update and/or sensibly generate a set of visible headers.)ZDateZFromzReply-ToZToZCCZSubjectN)rir8rb)r�headerrrr�update_visibleGs
zBabylMessage.update_visiblecCsvt|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|k�r|�d�d|k�rr|�d�nXt|t	��rT|�
|���x<|��D]}|�|��q>Wnt|t
��rbntdt|���dS)z9Copy Babyl-specific state to message insofar as possible.r+r|rTr.r/r]r-rUr,rWrhrVrXrZr[z$Cannot convert to specified type: %sN)rYr	rr1r�rPr�rrrr2r@r^rrnro)rr!r8r:rrrrDRsF










zBabylMessage._explain_to)N)rurvrwrxrFrr1r3r^rjr@r2rlrDrrrrrs
c@seZdZdZdS)r
z&Message with MMDF-specific properties.N)rurvrwrxrrrrr
|sc@s�eZdZdZd&dd�Zd'dd�Zd(dd�Zd)d	d
�Zd*dd�Zd
d�Z	dd�Z
d+dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zed$d%��ZdS),r�zA read-only wrapper of a file.NcCs$||_|dkr|��|_n||_dS)zInitialize a _ProxyFile.N)r�r��_pos)rr��posrrrr�sz_ProxyFile.__init__cCs|�||jj�S)zRead bytes.)�_readr�rS)r�sizerrrrS�sz_ProxyFile.readcCs|�||jj�S)zRead bytes.)ror��read1)rrprrrrq�sz_ProxyFile.read1cCs|�||jj�S)zRead a line.)ror�rl)rrprrrrl�sz_ProxyFile.readlinecCs>g}x4|D],}|�|�|dk	r
|t|�8}|dkr
Pq
W|S)zRead multiple lines.Nr)r�r�)r�sizehintrBrsrrr�	readlines�s

z_ProxyFile.readlinesccs x|��}|sdS|VqWdS)zIterate over lines.N)rl)rrsrrrr;�s
z_ProxyFile.__iter__cCs|jS)zReturn the position.)rm)rrrrr��sz_ProxyFile.tellrcCs4|dkr|j�|j�|j�||�|j��|_dS)zChange position.r�N)r�r_rmr�)r�offset�whencerrrr_�sz_ProxyFile.seekcCs0t|d�r,zt|jd�r"|j��Wd|`XdS)zClose the file.r�rLN)rEr�rL)rrrrrL�s

z_ProxyFile.closecCs2|dkrd}|j�|j�||�}|j��|_|S)z"Read size bytes using read_method.NrW)r�r_rmr�)rrp�read_methodrBrrrro�sz_ProxyFile._readcCs|S)z$Context management protocol support.r)rrrr�	__enter__�sz_ProxyFile.__enter__cGs|��dS)N)rL)r�excrrr�__exit__�sz_ProxyFile.__exit__cCs
|j��S)N)r��readable)rrrrrz�sz_ProxyFile.readablecCs
|j��S)N)r��writable)rrrrr{�sz_ProxyFile.writablecCs
|j��S)N)r��seekable)rrrrr|�sz_ProxyFile.seekablecCs
|j��S)N)r�rI)rrrrrI�sz_ProxyFile.flushcCs&t|d�sdSt|jd�sdS|jjS)Nr�TrF)rEr�r)rrrrr�s

z_ProxyFile.closed)N)N)N)N)N)r)rurvrwrxrrSrqrlrsr;r�r_rLrorwryrzr{r|rI�propertyrrrrrr��s$





		r�c@s<eZdZdZddd�Zdd�Zddd	�Zd
d�Zdd
�ZdS)r�z&A read-only wrapper of part of a file.NcCst�|||�||_||_dS)zInitialize a _PartialFile.N)r�r�_start�_stop)rr�r�r�rrrr�sz_PartialFile.__init__cCst�|�|jS)z*Return the position with respect to start.)r�r�r~)rrrrr��sz_PartialFile.tellrcCs<|dkr|j|_d}n|dkr*|j|_d}t�|||�dS)z8Change position, possibly with respect to start or stop.rr�r�N)r~rmrr�r_)rrtrurrrr_�sz_PartialFile.seekcCsB|j|j}|dkrdS|dks0|dks0||kr4|}t�|||�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�)rEr�)rrrrrLs
z_PartialFile.close)NN)r)	rurvrwrxrr�r_rorLrrrrr��s


	r�Tc
Cs�d}�yZtrpyt�|tjtjB�WnJtk
rn}z,|jtjtjtjfkr\t	d|j
��n�Wdd}~XYnX|�r^yt|j
d�}|��Wn:tk
r�}z|jtjtjfkr�dS�Wdd}~XYnXy`yt
�|j
|j
d�d}Wn2ttfk
�rt
�|j
|j
d�d}YnXt
�|j
�Wn0tk
�r\t
�|j
�t	d|j
��YnXWn8t�r|t�|tj�|�r�t
�|j
d��YnXdS)z(Lock file f using lockf and dot locking.Fzlockf: lock unavailable: %sNz.lockTzdot lock unavailable: %s)�fcntl�lockfZLOCK_EXZLOCK_NBr�r�ZEAGAINr�r�rr�r�rLrr�r�r�r�r&r�r$�LOCK_UN)r�r�Zdotlock_doner�Zpre_lockrrrr�
sH
r�cCs8trt�|tj�tj�|jd�r4t�|jd�dS)z*Unlock file f using lockf and dot locking.z.lockN)r�r�r�rrrr�r$)r�rrrr�4sr�c	Cs8t�|tjtjBtjBd�}z
t|d�St�|�XdS)zCCreate a file if it doesn't exist and open for reading and writing.i�zrb+N)rr�r�r	�O_RDWRrL)r�fdrrrr�;s
r�cCs$td|tt���t��t��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�Csr�cCs$|��ttd�r t�|���dS)z0Ensure changes to file f are physically on disk.�fsyncN)rIrErr��fileno)r�rrrr�Is
r�cCst|�|��dS)z:Close file f, ensuring all changes are physically on disk.N)r�rL)r�rrrr�Osr�c@seZdZdZdS)rz"Raised for module-specific errors.N)rurvrwrxrrrrrUsc@seZdZdZdS)rz:The specified mailbox does not exist and won't be created.N)rurvrwrxrrrrrXsc@seZdZdZdS)rz>The specified mailbox is not empty and deletion was requested.N)rurvrwrxrrrrr[sc@seZdZdZdS)rz)Another process caused an action to fail.N)rurvrwrxrrrrr^sc@seZdZdZdS)rz)A file appears to have an invalid format.N)rurvrwrxrrrrras)T)0rxrr�rdr�r�rCrhr1Z
email.messageZemail.generatorrZr-r��ImportError�__all__rarMrrr�r�rrrrr!rr	r�r
rrr
r�r�r�r�r�r�r�r��	Exceptionrrrrrrrrr�<module>sp

h8DB4-3z%mqH_c'
*

Zerion Mini Shell 1.0