Hacked By AnonymousFox

Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/mailbox.cpython-35.opt-1.pyc



��YfR2�@s0dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZyddl
Z
Wnek
r�dZ
YnXddddddd	d
dd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�de�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�Zdd�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(szMailbox.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__cCs*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__cCs.y|j|�SWntk
r)|SYnXdS)z9Return the keyed message, or default if it doesn't exist.N)�__getitem__r!)rr�defaultrrr�get>s
zMailbox.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.clearcCs8y||}Wntk
r&|SYnX|j|�|S)z3Delete the keyed message and return it, or default.)r!r")rrr%�resultrrr�pop�s
	
zMailbox.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|||<WqOtk
r�d}YqOXqOW|r�td��dS)z4Change the messages that correspond to certain keys.r8r9FTzNo message with key(s)N)�hasattrr8r9r!)r�arg�sourceZbad_keyrrrrr�update�s
zMailbox.updatecCstd��dS)z&Write any pending changes to the disk.z&Method must be implemented by subclassN)r)rrrr�flush�sz
Mailbox.flushcCstd��dS)zLock the mailbox.z&Method must be implemented by subclassN)r)rrrr�lock�szMailbox.lockcCstd��dS)z#Unlock the mailbox if it is locked.z&Method must be implemented by subclassN)r)rrrr�unlock�szMailbox.unlockcCstd��dS)zFlush and close the mailbox.z&Method must be implemented by subclassN)r)rrrr�close�sz
Mailbox.closecCs6y|jd�SWntk
r1td��YnXdS)Nrz?String input must be ASCII-only; use bytes or a Message instead)�encode�UnicodeError�
ValueError)rrrrr�_string_to_bytes�s
zMailbox._string_to_bytesFc	Cs�t|tjj�r�tj�}tjj||d�}|j|�|j	d�|j
�}|jdt�}|j
|�|jr�|jt�r�|j
t�nt|tttjf�rqt|tj�r�tjdtd�|j�}t|t�r|j|�}|r)|jdd�}|jdt�}|j
|�|jr�|jt�r�|j
t�n6t|d�r�t|d�r�tjd	td�|j}d
}x�|j�}|jd�r�|d
d�d}n#|jd
�r	|d
d�d}|sP|r9|jd�r9d|dd
�}|jdt�}|j
|�|}q�W|jr�|r�|jt�r�|j
t�ntdt|���d
S)z%Dump message contents to target file.rs
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
�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
�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)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�}||jkr�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@


	%"
zMaildir.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.discardcCs!|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�)rrrZold_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
|�dS)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
|jd|�}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|<q0W|s�dSi|_x�|jD]�}|j|}xstj	|�D]b}tjj
||�}tjj|�r�q�|j|j
�d}tjj
||�|j|<q�Wq�Wtj�|_dS)z!Update table of contents mapping.rOFTNr)r�rr�r~rrr�ryr}r�rxr�r�r�)rZrefreshr��mtimerr��pr�rrrr��s& 	
$zMaildir._refreshcCs�y:tjjtjj|j|j|��r9|j|SWntk
rNYnX|j�y|j|SWn"tk
r�td|��YnXdS)z=Use TOC to return subpath for given key, or raise a KeyError.zNo message with key: %sN)rrrzrxrr}r!r�)rrrrrr�!s+


zMaildir._lookupcCskt|d�s|j�|_xFy|t|j�SWq!tk
rNdSYq!tk
rbw!Yq!Xq!WdS)z0Return the next message in a one-time iteration.�
_onetime_keysN)r@r1r��next�
StopIterationr!)rrrrr�/s

zMaildir.next)rprqrrrsr�rrrr"r#r'r.r*r1r:r;rDrErFrGr�r�r�r�r�r�r�r�r�r�rrrrrs6)
	
$c@s�eZdZdZdddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd d!�Zd"d#�ZdS)$�_singlefileMailboxzA single-file mailbox.NTcCs	tj||||�yt|jd�}Wn�tk
r�}zw|jtjkr�|rnt|jd�}q�t|j��n3|jtjtj	fkr�t|jd�}n�WYdd}~XnX||_
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�rrrr?s$						z_singlefileMailbox.__init__cCsF|j�|j|�|j|j<|jd7_d|_|jdS)z$Add message and return assigned key.rPT)r��_append_messager}r�r�)rrrrrrVs

	z_singlefileMailbox.addcCs$|j|�|j|=d|_dS)z=Remove the keyed message; raise KeyError if it doesn't exist.TN)r�r}r�)rrrrrr`s

z_singlefileMailbox.removecCs0|j|�|j|�|j|<d|_dS)z>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
Csy|js,|jr(t|j�d|_dS|jjdd�|jj�}||jkrvtd|j|f��t|j	�}y�i}|j
|�x�t|jj
��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|_|jrut|jdd�dS)	z"Write any pending changes to disk.FNrrOz4Size of mailbox file changed (expected %i, found %i)izrb+�dotlock) r�r��_sync_flushr�rZ�tellr�r��_create_temporaryr�_pre_mailbox_hook�sortedr}r3�_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.closecCs]|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._lookupcCs�|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�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)0rzAn MH mailbox.NTcCs�tj||||�tjj|j�s�|r�tj|jd�tjtjtjj	|jd�tj
tjBtjBd��nt
|j��d|_dS)zInitialize an MH instance.i�z
.mh_sequencesi�FN)rrrrrzrr{rGr�rxr��O_EXCLr�r|r�)rrrrrrrr�s!!zMH.__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_TRUNCrorTrrr�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�rr��
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+zMH.get_filecCs)ttdd�tj|j�D���S)zReturn an iterator over keys.css'|]}|j�rt|�VqdS)N)�isdigitr�)�.0r�rrr�	<genexpr>4szMH.iterkeys.<locals>.<genexpr>)�iterr�rr�r)rrrrr12szMH.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�\}}	|jt||	d	��q}W�fd
d�t
|�D�||<t||�dkr%||=WqItk
rPtd
|j���YqIXqIWWdQRX|S)z=Return a name-to-key-list dictionary to define each sequence.z
.mh_sequences�r�encoding�ASCIIrtcss|]}t|�VqdS)N)r�)r�xrrrr�sz#MH.get_sequences.<locals>.<genexpr>�-rPcs"g|]}|�kr|�qSrr)rr)�all_keysrr�
<listcomp>�s	z$MH.get_sequences.<locals>.<listcomp>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
}|jd�n7|rd}|jd||f�n|jd
|�|}q�W|rA|jt|�d�q]|jd�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	|���nDtjtjj|jt	|��tjj|jt	|d���|d7}q%W|d|_t
|�dkrBdSxP|j�D]B\}}x3|D]+\}}||krb|||j|�<qbWqOW|j|�dS)z?Re-name messages to eliminate numbering gaps. Invalidates keys.rrPr�N)rr1r�r@rr�rrxrr`�unlinkr�r�r�r9�indexr)	rrrZchangesrr�r	�oldrvrrr�pack�s*!#(!#
zMH.packcCs�|j�}|j�}xR|j�D]D\}}||krM|j|�q%||kr%||j|�=q%Wx'|D]}||krt|g||<qtW|j|�dS)z;Inspect a new MHMessage and update sequences appropriately.N)rr9r�r!r)rrrZpending_sequencesZ
all_sequencesr�r	�sequencerrrr�s
zMH._dump_sequences)rprqrrrsrrrr#r'r.r*r1r:r;rErFrDrGr�r�r�r�rrr#rrrrrr�s."c@s�eZdZdZedddddddh�Zd	d
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�resentNTcCs#tj||||�i|_dS)zInitialize a Babyl mailbox.N)r�r�_labels)rrrrrrrr�szBabyl.__init__cCs8tj||�}t|t�r4|j�|j|<|S)z$Add message and return assigned key.)r�rrTr�
get_labelsr*)rrrrrrr�sz	Babyl.addcCs-tj||�||jkr)|j|=dS)z=Remove the keyed message; raise KeyError if it doesn't exist.N)r�rr*)rrrrrr�szBabyl.removecCs9tj|||�t|t�r5|j�|j|<dS)z>Replace the keyed message; raise KeyError if it doesn't exist.N)r�r#rTrr+r*)rrrrrrr#�szBabyl.__setitem__c
Cs[|j|�\}}|jj|�|jj�tj�}xD|jj�}|dtksg|rhP|j|jtd��qAWtj�}x@|jj�}|tks�|r�P|j|jtd��q�W||jj	�}|jj
|�}|jtd�}t|j�|�}	|	j
|j��||jkrW|	j|j|�|	S)z4Return a Message representation or raise a KeyError.s*** EOOH ***s
)r�r�rZrgrUrVr\r]r[r�rMrrf�set_visibler*�
set_labels)
rrr�r��original_headersrnZvisible_headers�nZbodyr�rrrr'�s.
zBabyl.get_messagec	Cs�|j|�\}}|jj|�|jj�tj�}xD|jj�}|dtksg|rhP|j|jtd��qAWx'|jj�}|tks�|r�Pq�W|j	�}||jj
�}|jj|�}|jtd�}||S)z3Return a string representation or raise a KeyError.s*** EOOH ***s
)r�r�rZrgrUrVr\r]r[rfr�rM)	rrr�r�r.rnZheadersr/rmrrrr.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.<locals>.<listcomp>rPN�,srO)r�rZrgr�r\r�r�r�r�r�r�r}r*r�r�)rr�r�rZlabel_listsrrnr2rrrr�/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)rr4rrrrRsz*Babyl._pre_mailbox_hook.<locals>.<genexpr>sLabels:r5sN)r\r+rxr])rr�Zbabylr2rrrr�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
jj�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,,� r5s1,,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+r1r�r]rHr\r,rrrUrVrWrXrYrZrgr[�get_visiblerMrar`rbrcrdrerfrKr�r@rNr_rirj)rrr�Zspecial_labelsr2r4Zorig_bufferZorig_generatorrnZ
vis_bufferZ
vis_generatorrNZ
body_startZoriginal_posZ
first_passr�rrrr�_s�

"


#	
&&)	
	zBabyl._install_message)rprqrrrs�	frozensetr1rrrr#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|<qWdS)z0Assume the non-format-specific state of message.�_type_specific_attributesN)�getattr�__dict__)rrZ
type_specificr�rrrr:�szMessage._become_messagecCs#t|t�rdStd��dS)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rTrri)rrrrrr=�szMessage._explain_to)rprqrrrsrr:r=rrrrr�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�_dateNcCs5d|_d|_tj�|_tj||�dS)z%Initialize a MaildirMessage instance.rvr�N)rBrCr�rDrr)rrrrrr�s		zMaildirMessage.__init__cCs|jS)zReturn 'new' or 'cur'.)rB)rrrrr��szMaildirMessage.get_subdircCs8|dks|dkr$||_ntd|��dS)zSet subdir to 'new' or 'cur'.rvrwz!subdir must be 'new' or 'cur': %sN)rBrJ)rr�rrrr�szMaildirMessage.set_subdircCs+|jjd�r#|jdd�SdSdS)z*Return as a string the flags that are set.z2,rONr�)rCrh)rrrr�	get_flagsszMaildirMessage.get_flagscCs ddjt|��|_dS)z)Set the given flags and unset all others.z2,r�N)rxr�rC)r�flagsrrr�	set_flagsszMaildirMessage.set_flagscCs0|jdjt|j��t|�B��dS)z.Set the given flag(s) without changing others.r�N)rGrxrrE)r�flagrrr�add_flagszMaildirMessage.add_flagcCs<|j�r8|jdjt|j��t|���dS)z7Unset the given string flag(s) without changing others.r�N)rErGrxr)rrHrrr�remove_flagszMaildirMessage.remove_flagcCs|jS)z<Return delivery date of message, in seconds since the epoch.)rD)rrrrr�szMaildirMessage.get_datecCs<yt|�|_Wn"tk
r7td|��YnXdS)z9Set delivery date of message, in seconds since the epoch.zcan't convert to float: %sN)�floatrDrJri)rZdaterrrr�s
zMaildirMessage.set_datecCs|jS)z%Get the message's "info" as a string.)rC)rrrrr�&szMaildirMessage.get_infocCs5t|t�r||_ntdt|���dS)z Set the message's "info" string.zinfo must be a string: %sN)rTr`rCrirj)r�inforrrr�*szMaildirMessage.set_infocCs4t|t�rK|j|j��|j|j��|j|j��n�t|t�rt	|j��}d|kr�|j
d�|j�dkr�|j
d�d|kr�|j
d�d|kr�|j
d�d|kr�|j
d�|jd	tj
|j���nt|t�r�t	|j��}d|krK|jd
�d|krd|jd�d|kr0|jd�n�t|t�rt	|j��}d|kr�|jd
�d|kr�|jd
�d|kr�|jd�d|kr0|jd�n(t|t�rntdt|���dS)z;Copy Maildir-specific state to message insofar as possible.�S�Rrw�O�T�D�F�Az
MAILER-DAEMONr%�replied�flaggedr&r'�Pr(z$Cannot convert to specified type: %sN)rTr	rGrEr�r�r�r�r�rrIr�r�r�rrr�	add_labelrrirj)rrrFrrrr=1sN




"




zMaildirMessage._explain_to)rprqrrrsr?rr�r�rErGrIrJr�r�r�r�r=rrrrr	�sc@s�eZdZdZdgZddd�Zdd�Zddd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�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.)rX)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�rX)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&)rrrrrEwsz_mboxMMDFMessage.get_flagscCst|�}d
\}}x1dD])}||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�rNrOrQrRrSrZzX-StatusN)r�r�)rNrO)rQrRrS)rrrxr��replace_headerr!Z
add_header)rrFZstatus_flagsZ
xstatus_flagsrHrrrrG{s&





z_mboxMMDFMessage.set_flagscCs0|jdjt|j��t|�B��dS)z.Set the given flag(s) without changing others.r�N)rGrxrrE)rrHrrrrI�sz_mboxMMDFMessage.add_flagcCsHd|ksd|krD|jdjt|j��t|���dS)z7Unset the given string flag(s) without changing others.rZzX-Statusr�N)rGrxrrE)rrHrrrrJ�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
=dj|j�j�dd
��}y&|j	t
jt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.rOrwrRrSrNrMrQrPZstatuszx-statusrYrQNz%a %b %d %H:%M:%S %Yr%rTrUr&r'z$Cannot convert to specified type: %s���)rTr	rrEr�rIrxr�r�r��calendarZtimegmr�ZstrptimerJ�
OverflowErrorr�rGr�rrrrWrrirj)rrrFZ
maybe_daterrrr=�s^




%







z_mboxMMDFMessage._explain_to)
rprqrrrsr?rr�r�rErGrIrJr=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)rz$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_sequencecCs-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�rt|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%rwrMrUrRrTrN�ROrOrSr'z$Cannot convert to specified type: %sN)rTr	rrr�rIr�rrrrWrrirj)rrrr$rrrr=�s@





zMHMessage._explain_to)rprqrrrsr?rrrrr`r=rrrrr�s	c@s�eZdZdZddgZddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)rz'Message with Babyl-specific properties.r*�_visibleNcCs)g|_t�|_tj||�dS)z#Initialize a BabylMessage instance.N)r*rrbr)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*)rr2rrrr-)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)rr4rrrrW-szBabylMessage.add_labelcCs-y|jj|�Wntk
r(YnXdS)z4Remove label from the list of labels on the message.N)r*rrJ)rr4rrr�remove_label5s
zBabylMessage.remove_labelcCs
t|j�S)z3Return a Message representation of visible headers.)rrb)rrrrr8<szBabylMessage.get_visiblecCst|�|_dS)z2Set the Message representation of visible headers.N)rrb)rZvisiblerrrr,@szBabylMessage.set_visiblecCs�xG|jj�D]6}||kr<|jj|||�q|j|=qWx:dD]2}||krQ||jkrQ|||j|<qQWdS)	z9Update and/or sensibly generate a set of visible headers.�Date�From�Reply-To�To�CC�SubjectN)rdrerfrgrhri)rbr3r[)r�headerrrr�update_visibleDs
zBabylMessage.update_visiblecCs�t|t�r�t|j��}d|kr=|jd�n|jd�|jd�d|ksod|kr||jd�d|kr�|jd�d	|kr�|jd
�nFt|t�r0t|j��}d|kr�|jd�n
|jd�d	|kr|jd
�d|kr�|jd�n�t|t�r�t|j��}d|krj|jd�d|kr�|jd�nqt|t	�r�|j
|j��xL|j�D]}|j|�q�Wn(t|t
�r�ntdt|���dS)z9Copy Babyl-specific state to message insofar as possible.r%rwrMr(r)rVr'rNr&rPrarOrQrSrTz$Cannot convert to specified type: %sN)rTr	rr+r�rIr�rrrr,r8rWrrirj)rrr2r4rrrr=OsF






zBabylMessage._explain_to)rprqrrrsr?rr+r-rWrcr8r,rkr=rrrrrsc@seZdZdZdS)r
z&Message with MMDF-specific properties.N)rprqrrrsrrrrr
ysc@s�eZdZdZddd�Zddd�Zddd�Zdd	d
�Zddd�Zd
d�Z	dd�Z
ddd�Zdd�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)zRead bytes.)�_readr�rM)r�sizerrrrM�sz_ProxyFile.readcCs|j||jj�S)zRead bytes.)rnr��read1)rrorrrrp�sz_ProxyFile.read1cCs|j||jj�S)zRead a line.)rnr�rg)rrorrrrg�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.)rl)rrrrr��sz_ProxyFile.tellrcCsH|dkr|jj|j�|jj||�|jj�|_dS)zChange position.rPN)r�rZrlr�)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�rZrlr�)rro�read_methodr=rrrrn�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)rrrrry�sz_ProxyFile.readablecCs
|jj�S)N)r��writable)rrrrrz�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)rprqrrrsrrMrprgrrr6r�rZrGrnrvrxryrzr{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}rlr~r�rZ)rrsrtrrrrZ�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)r~rlr�rn)rroruZ	remainingrrrrn�s$z_PartialFile._readcCst|d�r|`dS)Nr�)r@r�)rrrrrGsz_PartialFile.close)	rprqrrrsrr�rZrnrGrrrrr��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)rr�r�rrrzr�r)r�rrrr�0sr�cCsLtj|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
rrr
r�r�r�r�r�r�r�r��	Exceptionr�r|r�r�rrrrr�<module>sd
��6�B4-�1�%mqH_c')

Hacked By AnonymousFox1.0, Coded By AnonymousFox