Edit File: mailbox.cpython-37.pyc
B ����q}�c>3�����������������@���sR��d�Z�ddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl ZddlZddlZyddl Z W�n�ek r����dZ Y�nX�ddddddd d ddd ddddddgZej�d�ZG�dd��d�ZG�dd��de�ZG�dd��de�ZG�dd��de�ZG�dd��de�ZG�dd��de�ZG�dd��de�ZG�dd��de�ZG�dd ��d ejj�ZG�d d ��d e�ZG�d!d"��d"e�ZG�d#d��de�ZG�d$d��de�ZG�d%d ��d e�Z G�d&d��de�Z!G�d'd(��d(�Z"G�d)d*��d*e"�Z#d=d,d-�Z$d.d/��Z%d0d1��Z&d2d3��Z'd4d5��Z(d6d7��Z)G�d8d��de*�Z+G�d9d��de+�Z,G�d:d��de+�Z-G�d;d��de+�Z.G�d<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���������������@���s��e�Zd�ZdZdCdd�Zdd��Zdd ��Zd d��Zdd ��Zdd��Z dDdd�Z dd��Zdd��Zdd��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�)Hr���z*A group of messages in a particular place.NTc�������������C���s ���t�j�t�j�|��|�_||�_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__$���s����zMailbox.__init__c�������������C���s���t�d��dS�)z$Add message and return assigned key.z&Method must be implemented by subclassN)�NotImplementedError)r����messager���r���r����add)���s����zMailbox.addc�������������C���s���t�d��dS�)z=Remove the keyed message; raise KeyError if it doesn't exist.z&Method must be implemented by subclassN)r ���)r����keyr���r���r����remove-���s����zMailbox.removec�������������C���s���|���|��d�S�)N)r$���)r���r#���r���r���r����__delitem__1���s����zMailbox.__delitem__c�������������C���s(���y|���|��W�n�tk r"���Y�nX�dS�)z'If the keyed message exists, remove it.N)r$����KeyError)r���r#���r���r���r����discard4���s����zMailbox.discardc�������������C���s���t�d��dS�)z>Replace the keyed message; raise KeyError if it doesn't exist.z&Method must be implemented by subclassN)r ���)r���r#���r!���r���r���r����__setitem__;���s����zMailbox.__setitem__c�������������C���s$���y |���|�S��tk r���|S�X�dS�)z9Return the keyed message, or default if it doesn't exist.N)�__getitem__r&���)r���r#����defaultr���r���r����get?���s���� zMailbox.getc���������� ���C���s6���|�j�s|��|�S�t�|��|���}|���|�S�Q�R�X�dS�)z=Return the keyed message; raise KeyError if it doesn't exist.N)r����get_message� contextlib�closing�get_file)r���r#����filer���r���r���r)���F���s���� zMailbox.__getitem__c�������������C���s���t�d��dS�)z4Return a Message representation or raise a KeyError.z&Method must be implemented by subclassN)r ���)r���r#���r���r���r���r,���N���s����zMailbox.get_messagec�������������C���s���t��|��|�����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)r���r#���r���r���r���� get_stringR���s����zMailbox.get_stringc�������������C���s���t�d��dS�)z8Return a byte string representation or raise a KeyError.z&Method must be implemented by subclassN)r ���)r���r#���r���r���r���r3���Y���s����zMailbox.get_bytesc�������������C���s���t�d��dS�)z6Return a file-like representation or raise a KeyError.z&Method must be implemented by subclassN)r ���)r���r#���r���r���r���r/���]���s����zMailbox.get_filec�������������C���s���t�d��dS�)zReturn an iterator over keys.z&Method must be implemented by subclassN)r ���)r���r���r���r����iterkeysa���s����zMailbox.iterkeysc�������������C���s���t�|�����S�)zReturn a list of keys.)�listr6���)r���r���r���r����keyse���s����zMailbox.keysc���������� ���c���s@���x:|�����D�].}y|�|�}W�n�tk r0���w Y�nX�|V��q W�dS�)z%Return an iterator over all messages.N)r6���r&���)r���r#����valuer���r���r���� itervaluesi���s����zMailbox.itervaluesc�������������C���s���|�����S�)N)r:���)r���r���r���r����__iter__r���s����zMailbox.__iter__c�������������C���s���t�|�����S�)z,Return a list of messages. Memory intensive.)r7���r:���)r���r���r���r����valuesu���s����zMailbox.valuesc���������� ���c���sD���x>|�����D�]2}y|�|�}W�n�tk r0���w Y�nX�||fV��q W�dS�)z.Return an iterator over (key, message) tuples.N)r6���r&���)r���r#���r9���r���r���r���� iteritemsy���s����zMailbox.iteritemsc�������������C���s���t�|�����S�)z9Return a list of (key, message) tuples. Memory intensive.)r7���r=���)r���r���r���r����items����s����z Mailbox.itemsc�������������C���s���t�d��dS�)z9Return True if the keyed message exists, False otherwise.z&Method must be implemented by subclassN)r ���)r���r#���r���r���r����__contains__����s����zMailbox.__contains__c�������������C���s���t�d��dS�)z*Return a count of messages in the mailbox.z&Method must be implemented by subclassN)r ���)r���r���r���r����__len__����s����zMailbox.__len__c�������������C���s ���x|�����D�]}|��|��q W�dS�)zDelete all messages.N)r8���r'���)r���r#���r���r���r����clear����s����z Mailbox.clearc�������������C���s0���y|�|�}W�n�t�k r ���|S�X�|��|��|S�)z3Delete the keyed message and return it, or default.)r&���r'���)r���r#���r*����resultr���r���r����pop����s���� zMailbox.popc�������������C���s*���x$|�����D�]}||��|�fS�W�td��dS�)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailboxN)r6���rC���r&���)r���r#���r���r���r����popitem����s����zMailbox.popitemc���������� ���C���sx���t�|d�r|���}nt�|d�r(|���}n|}d}x6|D�].\}}y||�|<�W�q6�tk rb���d}Y�q6X�q6W�|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!���r���r���r����update����s���� zMailbox.updatec�������������C���s���t�d��dS�)z&Write any pending changes to the disk.z&Method must be implemented by subclassN)r ���)r���r���r���r����flush����s����z Mailbox.flushc�������������C���s���t�d��dS�)zLock the mailbox.z&Method must be implemented by subclassN)r ���)r���r���r���r����lock����s����zMailbox.lockc�������������C���s���t�d��dS�)z#Unlock the mailbox if it is locked.z&Method must be implemented by subclassN)r ���)r���r���r���r����unlock����s����zMailbox.unlockc�������������C���s���t�d��dS�)zFlush and close the mailbox.z&Method must be implemented by subclassN)r ���)r���r���r���r����close����s����z Mailbox.closec�������������C���s,���y |��d�S��tk r&���td��Y�nX�d�S�)Nr���z?String input must be ASCII-only; use bytes or a Message instead)�encode�UnicodeError� ValueError)r���r!���r���r���r����_string_to_bytes����s���� zMailbox._string_to_bytesFc������� ������C���s���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��� ������� ���s���From s���>From ����zInvalid message type: %s)� isinstancer1���r!���r����io�BytesIO� generator�BytesGenerator�flatten�seekrS����replace�linesep�write�_append_newline�endswith�str�bytes�StringIO�warnings�warn�DeprecationWarning�getvaluerP���rE���rT����readline� startswith� TypeError�type) r���r!����targetZmangle_from_rT����gen�dataZlastline�liner���r���r���� _dump_message����sZ���� zMailbox._dump_message)NT)N)N)N)F)$�__name__� __module__�__qualname__�__doc__r���r"���r$���r%���r'���r(���r+���r)���r,���r5���r3���r/���r6���r8���r:���r;���r<���r=���r>���r?���r@���rA���rC���rD���rH���rI���rJ���rK���rL���rP���rc���rt���r���r���r���r���r���!���sB��� c���������������@���s����e�Zd�ZdZdZd6dd�Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��Zdd��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�)7r���zA qmail-style Maildir mailbox.�:NTc�������������C���s����t��|�|||��tj�|�jd�tj�|�jd�tj�|�jd�d�|�_tj�|�j�s�|r�t�|�jd��x*|�j� ��D�]}t�|d��qnW�n t |�j��i�|�_ddd�|�_d|�_ d|�_d S�) zInitialize a Maildir instance.�tmp�new�cur)rz���r{���r|���i���r���)r|���r{���g�������?N)r���r���r���r����joinr����_paths�exists�mkdirr<���r����_toc�_toc_mtimes� _last_read�_skewfactor)r����dirnamer���r���r���r���r���r���r��� ��s���� zMaildir.__init__c���������� ���C���s~��|�����}y|��||��W�n*�tk rB���|����t�|j����Y�nX�t|��t|t �r||� ��}|�j|����}||�jkr�d}nd}d}tj �|j��|�j�d�}tj �|�j|||��}t|t �r�t�|jtj �|j�|���f��yLyt�|j|��W�n(�ttfk �r���t�|j|��Y�nX�t�|j��W�nN�tk �rx�}�z.t�|j��|jtjk�rftd|���n��W�dd}~X�Y�nX�|S�)z$Add message and return assigned key.��r{���r���z$Name clash with existing message: %sN)�_create_tmprt���� BaseExceptionrL���r���r$����name�_sync_closerY���r ���� get_subdir�colon�get_infor����basename�splitr}���r����utime�getatime�get_date�link�AttributeError�PermissionError�rename�OSError�errnoZEEXISTr���)r���r!���Ztmp_file�subdir�suffix�uniq�dest�er���r���r���r"���!��sB���� zMaildir.addc�������������C���s ���t��t�j�|�j|��|����dS�)z=Remove the keyed message; raise KeyError if it doesn't exist.N)r���r$���r���r}���r����_lookup)r���r#���r���r���r���r$���K��s����zMaildir.removec���������� ���C���s,���y|���|��W�n�ttfk r&���Y�nX�dS�)z'If the keyed message exists, remove it.N)r$���r&����FileNotFoundError)r���r#���r���r���r���r'���O��s����zMaildir.discardc�������������C���s����|���|�}|��|�}|���|�}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.rW���r����N)r����r"���rY���r ���r���r���r����r����r����r'���r}���r���r����r����r����r����)r���r#���r!���Zold_subpathZtemp_keyZtemp_subpathZdominant_subpathr����r����Ztmp_path�new_pathr���r���r���r(���W��s"���� zMaildir.__setitem__c���������� ���C���s����|���|�}ttj�|�j|�d�� }|�jr4|��|�}nt|�}W�dQ�R�X�tj�|�\}}|� |��|�j |kr�|�|�|�j �d���|�tj� tj�|�j|����|S�)z4Return a Message representation or raise a KeyError.�rbNrW���)r�����openr���r���r}���r���r���r ���r����� set_subdirr�����set_info�set_date�getmtime)r���r#���Zsubpath�f�msgr����r����r���r���r���r,���r��s���� zMaildir.get_messagec���������� ���C���s8���t�tj�|�j|��|��d��}|����td�S�Q�R�X�dS�)z2Return a bytes representation or raise a KeyError.r����rQ���N) r����r���r���r}���r���r����rS���r`���ra���)r���r#���r����r���r���r���r3������s����zMaildir.get_bytesc�������������C���s$���t�tj�|�j|��|��d�}t|�S�)z6Return a file-like representation or raise a KeyError.r����)r����r���r���r}���r���r����� _ProxyFile)r���r#���r����r���r���r���r/������s����zMaildir.get_filec���������� ���c���sH���|������x:|�jD�]0}y|��|��W�n�tk r8���wY�nX�|V��qW�dS�)zReturn an iterator over keys.N)�_refreshr����r����r&���)r���r#���r���r���r���r6������s����zMaildir.iterkeysc�������������C���s���|������||�jkS�)z9Return True if the keyed message exists, False otherwise.)r����r����)r���r#���r���r���r���r?������s����zMaildir.__contains__c�������������C���s���|������t|�j�S�)z*Return a count of messages in the mailbox.)r�����lenr����)r���r���r���r���r@������s����zMaildir.__len__c�������������C���s���dS�)z"Write any pending changes to disk.Nr���)r���r���r���r���rI������s����z Maildir.flushc�������������C���s���dS�)zLock the mailbox.Nr���)r���r���r���r���rJ������s����zMaildir.lockc�������������C���s���dS�)z#Unlock the mailbox if it is locked.Nr���)r���r���r���r���rK������s����zMaildir.unlockc�������������C���s���dS�)zFlush and close the mailbox.Nr���)r���r���r���r���rL������s����z Maildir.closec�������������C���s`���g�}xVt��|�j�D�]F}t|�dkr|d�dkrt�j�t�j�|�j|��r|�|dd����qW�|S�)zReturn a list of folder names.����r����.N)r����listdirr���r����r����isdirr}����append)r���rB����entryr���r���r����list_folders���s����zMaildir.list_foldersc�������������C���s ���t�tj�|�jd|��|�jdd�S�)z/Return a Maildir instance for the named folder.r����F)r���r���)r���r���r���r}���r���r���)r����folderr���r���r���� get_folder���s����zMaildir.get_folderc�������������C���s\���t�j�|�jd|��}t||�jd�}t�j�|d�}t�j�|�sXt��t��|t�j t�j B�d���|S�)z>Create a folder and return a Maildir instance representing it.r����)r���Z maildirfolderi���)r���r���r}���r���r���r���r���rL���r�����O_CREAT�O_WRONLY)r���r����r���rB���Zmaildirfolder_pathr���r���r���� add_folder���s����zMaildir.add_folderc�������������C���s,��t�j�|�jd|��}xTt��t�j�|d��t��t�j�|d���D�](}t|�dk�sZ|d�dkr>td|���q>W�xPt��|�D�]B}|dkrv|dkrv|dkrvt�j�t�j�||��rvtd||f���qvW�x`t�j|d d �D�]N\}}}x |D�]}t�� t�j�||���q�W�x |D�]}t�� t�j�||���q�W�q�W�t�� |��dS�)z-Delete the named folder, which must be empty.r����r{���r|���r����r���zFolder contains message(s): %srz���z%Folder contains subdirectory '%s': %sF)�topdownN)r���r���r}���r���r����r����r���r�����walkr$����rmdir)r���r����r���r�����root�dirs�filesr���r���r���� remove_folder���s ���� zMaildir.remove_folderc�������������C���s\���t�����}xNt�tj�|�jd��D�]4}tj�|�jd|�}|tj�|��dkr t�|��q W�dS�)zDelete old files in "tmp".rz���i@��N)�timer���r����r���r}���r���r����r$���)r����nowr����r���r���r���r����clean���s ����z Maildir.cleanr����c�������������C���s����t�����}t���}d|kr$|�dd�}d|kr8|�dd�}dt|�t|d�d��t���tj|f�}tj � |�jd|�}yt�|��W�n@�t k r����t�jd7��_yt|�S��tk r����Y�nX�Y�nX�td |���d S�)z=Create a file in the tmp subdirectory and open and return it.�/z\057ry���z\072z%s.M%sP%sQ%s.%sr����g������.Arz���z&Name clash prevented file creation: %sN)r�����socket�gethostnamer`����intr����getpidr����_countr���r}���r����statr�����_create_carefully�FileExistsErrorr���)r���r����Zhostnamer����r���r���r���r���r�������s&����zMaildir._create_tmpc�������������C���s����t�����|�j�d|�j�krbd}x<|�jD�]2}tj�|�j|��}||�j|�krLd}||�j|<�q$W�|sbdS�i�|�_xl|�jD�]b}|�j|�}xRt� |�D�]D}tj� ||�}tj�|�r�q�|�|�j �d�}tj� ||�|�j|<�q�W�qpW�t�����|�_dS�)z!Update table of contents mapping.����FTNr���)r����r����r����r����r���r���r����r~���r����r����r}���r����r����r����)r���Zrefreshr�����mtimer���r�����pr����r���r���r���r�������s&���� zMaildir._refreshc�������������C���s|���y,t�j�t�j�|�j|�j|���r*|�j|�S�W�n�tk r@���Y�nX�|�����y |�j|�S��tk rv���td|��d�Y�nX�dS�)z=Use TOC to return subpath for given key, or raise a KeyError.zNo message with key: %sN)r���r���r���r}���r���r����r&���r����)r���r#���r���r���r���r����#��s���� zMaildir._lookupc�������������C���sV���t�|�d�s|����|�_x<y|�t|�j��S��tk r8���dS��tk rL���wY�qX�qW�dS�)z0Return the next message in a one-time iteration.� _onetime_keysN)rE���r6���r�����next� StopIterationr&���)r���r���r���r���r����1��s���� zMaildir.next)NT)ru���rv���rw���rx���r����r���r"���r$���r'���r(���r,���r3���r/���r6���r?���r@���rI���rJ���rK���rL���r����r����r����r����r����r����r����r����r����r����r���r���r���r���r�����s6��� * $c���������������@���s����e�Zd�ZdZd$dd�Zdd��Zdd ��Zd d��Zdd ��Zdd��Z dd��Z dd��Zdd��Zdd��Z dd��Zdd��Zdd��Zdd��Zd%d d!�Zd"d#��ZdS�)&�_singlefileMailboxzA single-file mailbox.NTc���������� ���C���s����t��|�|||��yt|�jd�}W�nn�tk r��}�zP|jtjkr\|rPt|�jd�}q~t|�j��n"|jtjtj fkr|t|�jd�}n��W�dd}~X�Y�nX�||�_ d|�_d|�_d|�_ d|�_d|�_d|�_dS�)z!Initialize a single-file mailbox.zrb+zwb+r����Nr���F)r���r���r����r���r����r�����ENOENTr����EACCES�EROFS�_filer����� _next_key�_pending� _pending_sync�_locked�_file_length)r���r���r���r���r����r����r���r���r���r���A��s$����z_singlefileMailbox.__init__c�������������C���s8���|������|��|�|�j|�j<�|��jd7��_d|�_|�jd�S�)z$Add message and return assigned key.r����T)r�����_append_messager����r����r����)r���r!���r���r���r���r"���X��s ����z_singlefileMailbox.addc�������������C���s���|���|��|�j|=�d|�_dS�)z=Remove the keyed message; raise KeyError if it doesn't exist.TN)r����r����r����)r���r#���r���r���r���r$���b��s���� z_singlefileMailbox.removec�������������C���s$���|���|��|��|�|�j|<�d|�_dS�)z>Replace the keyed message; raise KeyError if it doesn't exist.TN)r����r����r����r����)r���r#���r!���r���r���r���r(���h��s���� z_singlefileMailbox.__setitem__c�������������c���s���|������|�j���E�dH��dS�)zReturn an iterator over keys.N)r����r����r8���)r���r���r���r���r6���n��s����z_singlefileMailbox.iterkeysc�������������C���s���|������||�jkS�)z9Return True if the keyed message exists, False otherwise.)r����r����)r���r#���r���r���r���r?���s��s����z_singlefileMailbox.__contains__c�������������C���s���|������t|�j�S�)z*Return a count of messages in the mailbox.)r����r����r����)r���r���r���r���r@���x��s����z_singlefileMailbox.__len__c�������������C���s���|�j�st|�j��d|�_�dS�)zLock the mailbox.TN)r����� _lock_filer����)r���r���r���r���rJ���}��s���� z_singlefileMailbox.lockc�������������C���s���|�j�rt|�j��d|�_�dS�)z#Unlock the mailbox if it is locked.FN)r�����_unlock_filer����)r���r���r���r���rK������s���� z_singlefileMailbox.unlockc������� ������C���s���|�j�s |�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�|���|�_W�n"���|����t�|j����Y�nX�t|��|�j����t�|�j�j} t�|j| ��yt�|j|�j��W�n2�tk �r����t�|�j��t�|j|�j��Y�nX�t|�jd�|�_||�_d|�_�d|�_|�j�r�t |�jdd��dS�) z"Write any pending changes to disk.FNr���r����z4Size of mailbox file changed (expected %i, found %i)i���zrb+)�dotlock)!r����r�����_sync_flushr����r�����AssertionErrorr_����tellr����r����_create_temporaryr����_pre_mailbox_hook�sortedr8����_pre_message_hookrS����minrb����_post_message_hookrL���r���r$���r����r����r�����st_mode�chmodr����r����r����r����r����) r���Zcur_lenZnew_fileZnew_tocr#����start�stopZ new_startrT����moder���r���r���rI������s`���� z_singlefileMailbox.flushc�������������C���s���dS�)z,Called before writing the mailbox to file f.Nr���)r���r����r���r���r���r�������s����z$_singlefileMailbox._pre_mailbox_hookc�������������C���s���dS�)z-Called before writing each message to file f.Nr���)r���r����r���r���r���r�������s����z$_singlefileMailbox._pre_message_hookc�������������C���s���dS�)z,Called after writing each message to file f.Nr���)r���r����r���r���r���r�������s����z%_singlefileMailbox._post_message_hookc�������������C���s4���z|������W�dz|�jr|�����W�d|�j����X�X�dS�)zFlush and close the mailbox.N)rI���r����rK���r����rL���)r���r���r���r���rL������s����z_singlefileMailbox.closec�������������C���sL���|�j�dkr|�����|dk rHy |�j�|�S��tk rF���td|��d�Y�nX�dS�)z'Return (start, stop) or raise KeyError.NzNo message with key: %s)r����� _generate_tocr&���)r���r#���r���r���r���r�������s���� z_singlefileMailbox._lookupc�������������C���s����|�j��dd��|�j����}t|�j�dkr8|�js8|��|�j���y&|��|�j���|��|�}|�� |�j���W�n"�t k r����|�j��|����Y�nX�|�j�����|�j����|�_ |S�)z;Append message to mailbox and return (start, stop) offsets.r���r����)r����r_���r����r����r����r����r����r�����_install_messager����r�����truncaterI���r����)r���r!���ZbeforeZoffsetsr���r���r���r�������s���� z"_singlefileMailbox._append_message)NT)N)ru���rv���rw���rx���r���r"���r$���r(���r6���r?���r@���rJ���rK���rI���r����r����r����rL���r����r����r���r���r���r���r����>��s"��� @ r����c���������������@���sB���e�Zd�ZdZdZdd��Zddd�Zddd �Zdd d�Zdd ��Z dS�)� _mboxMMDFzAn mbox or MMDF mailbox.Tc�������������C���sp���|���|�\}}|�j�|��|�j����td�}|�j�||�j�����}|��|�td��}|� |dd��� d���|S�)z4Return a Message representation or raise a KeyError.�����rQ���rX���Nr���)r����r����r_���rl���r`���ra���rS���r�����_message_factory�set_from�decode)r���r#���r����r����� from_line�stringr����r���r���r���r,�����s����z_mboxMMDF.get_messageFc�������������C���s���t��|��|��j|d�S�)z3Return a string representation or raise a KeyError.)�unixfrom)r1���r2���r3���r4���)r���r#����from_r���r���r���r5�����s����z_mboxMMDF.get_stringc�������������C���sJ���|���|�\}}|�j�|��|s(|�j����|�j�||�j�����}|�td�S�)z3Return a string representation or raise a KeyError.rQ���)r����r����r_���rl���rS���r����r`���ra���)r���r#���r����r����r����r����r���r���r���r3�����s���� z_mboxMMDF.get_bytesc�������������C���s<���|���|�\}}|�j�|��|s(|�j����t|�j|�j���|�S�)z6Return a file-like representation or raise a KeyError.)r����r����r_���rl����_PartialFiler����)r���r#���r����r����r����r���r���r���r/�����s ���� z_mboxMMDF.get_filec�������������C���s��d}t�|t�r|��|�}t�|t�rf|�d�rf|�d�}|dkr\|d|��}||d�d��}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.Ns���From rQ���rW���r����r����r���s���From MAILER-DAEMON )rY���re���rP���rf���rm����find�_mboxMMDFMessage�get_fromrM���r1���r!���r����get_unixfromr�����asctime�gmtimer����r����rb���ra���rt���� _mangle_from_)r���r!���r�����newlineZauthorr����r����r���r���r���r����&��s0���� z_mboxMMDF._install_messageN)F)F)F) ru���rv���rw���rx���r���r,���r5���r3���r/���r����r���r���r���r���r������s��� r����c���������������@���s2���e�Zd�ZdZdZdZd dd�Zdd��Zdd ��ZdS�)r���zA classic mbox mailbox.TNc�������������C���s���t�|�_t�|�|||��dS�)zInitialize an mbox mailbox.N)r ���r����r����r���)r���r���r���r���r���r���r���r���L��s����z mbox.__init__c�������������C���s���|��t��dS�)z,Called after writing each message to file f.N)rb���ra���)r���r����r���r���r���r����Q��s����zmbox._post_message_hookc�������������C���s����g�g��}}d}|�j��d��x�|�j����}|�j����}|�d�r|t|�t|�k�rl|rb|�|tt����n |�|��|�|��d}q|s�|r�|�|tt����n |�|��P�q|tkr�d}qd}qW�tt t ||���|�_t|�j�|�_|�j����|�_ dS�)z0Generate key-to-(start, stop) table of contents.Fr���s���From TN)r����r_���r����rl���rm���r����r����ra����dict� enumerate�zipr����r����r����)r����starts�stopsZlast_was_empty�line_posrs���r���r���r���r����U��s0���� zmbox._generate_toc)NT) ru���rv���rw���rx���r���rc���r���r����r����r���r���r���r���r���C��s��� c���������������@���s2���e�Zd�ZdZddd�Zdd��Zdd ��Zd d��ZdS�) r���zAn MMDF mailbox.NTc�������������C���s���t�|�_t�|�|||��dS�)zInitialize an MMDF mailbox.N)r ���r����r����r���)r���r���r���r���r���r���r���r���z��s����z MMDF.__init__c�������������C���s���|��dt���dS�)z-Called before writing each message to file f.s���N)rb���ra���)r���r����r���r���r���r������s����zMMDF._pre_message_hookc�������������C���s���|��td�t���dS�)z,Called after writing each message to file f.s���N)rb���ra���)r���r����r���r���r���r�������s����zMMDF._post_message_hookc�������������C���s����g�g��}}|�j��d��d}x�|}|�j����}|�j����}|�dt��r�|�|��xV|}|�j����}|�j����}|dt�kr�|�|tt����P�qN|sN|�|��P�qNW�q|sP�qW�tt t ||���|�_t|�j�|�_|�j��dd��|�j����|�_ dS�)z0Generate key-to-(start, stop) table of contents.r���s���r����N)r����r_���rl���r����rm���ra���r����r����r��r��r��r����r����r����)r���r��r���next_posr��rs���r���r���r���r�������s2���� zMMDF._generate_toc)NT)ru���rv���rw���rx���r���r����r����r����r���r���r���r���r���w��s ��� c���������������@���s����e�Zd�ZdZd0dd�Zdd��Zdd ��Zd d��Zdd ��Zdd��Z dd��Z dd��Zdd��Zdd��Z dd��Zdd��Zdd��Zdd��Zd d!��Zd"d#��Zd$d%��Zd&d'��Zd(d)��Zd*d+��Zd,d-��Zd.d/��ZdS�)1r���zAn MH mailbox.NTc�������������C���st���t��|�|||��tj�|�j�sj|r`t�|�jd��t�t�tj� |�jd�tj tjB�tjB�d���n t |�j��d|�_dS�)zInitialize an MH instance.i���z .mh_sequencesi���FN)r���r���r���r���r���r���r����rL���r����r}���r�����O_EXCLr����r���r����)r���r���r���r���r���r���r���r������s���� zMH.__init__c�������������C���s����|�����}t|�dkrd}nt|�d�}tj�|�jt|��}t|�}d}z�|�j rVt |��zfy|��||��W�n:�tk r����|�j r�t |��t|��d}t�|����Y�nX�t|t�r�|��||��W�d|�j r�t |��X�W�d|s�t|��X�|S�)z$Add message and return assigned key.r���r����FTN)r8���r�����maxr���r���r}���r���re���r����r����r����rt���r����r����r����r$���rY���r����_dump_sequences)r���r!���r8���Znew_keyr����r�����closedr���r���r���r"������s6���� zMH.addc���������� ���C���sx���t�j�|�jt|��}yt|d�}W�n>�tk r`�}�z |jtjkrNt d|���n��W�dd}~X�Y�nX�|� ���t��|��dS�)z=Remove the keyed message; raise KeyError if it doesn't exist.zrb+zNo message with key: %sN)r���r���r}���r���re���r����r����r����r����r&���rL���r$���)r���r#���r���r����r����r���r���r���r$������s����z MH.removec���������� ���C���s����t�j�|�jt|��}yt|d�}W�n>�tk r`�}�z |jtjkrNt d|���n��W�dd}~X�Y�nX�zd|�j rrt|��z@t��t��|t�j t�jB����|��||��t|t�r�|��||��W�d|�j r�t|��X�W�dt|��X�dS�)z>Replace the keyed message; raise KeyError if it doesn't exist.zrb+zNo message with key: %sN)r���r���r}���r���re���r����r����r����r����r&���r����r����rL���r�����O_TRUNCrt���rY���r���r��r����r����)r���r#���r!���r���r����r����r���r���r���r(������s$���� zMH.__setitem__c���������� ���C���s����y@|�j�r$ttj�|�jt|��d�}nttj�|�jt|��d�}W�n>�tk r~�}�z |jtj krlt d|���n��W�dd}~X�Y�nX�|�2�|�j�r�t|��zt|�}W�d|�j�r�t |��X�W�dQ�R�X�x*|�������D�]\}}||kr�|�|��q�W�|S�)z4Return a Message representation or raise a KeyError.zrb+r����zNo message with key: %sN)r����r����r���r���r}���r���re���r����r����r����r&���r����r���r����� get_sequencesr>����add_sequence)r���r#���r����r����r����r�����key_listr���r���r���r,������s&����zMH.get_messagec���������� ���C���s����y@|�j�r$ttj�|�jt|��d�}nttj�|�jt|��d�}W�n>�tk r~�}�z |jtj krlt d|���n��W�dd}~X�Y�nX�|�6�|�j�r�t|��z|���� td�S�|�j�r�t|��X�W�dQ�R�X�dS�)z2Return a bytes representation or raise a KeyError.zrb+r����zNo message with key: %sNrQ���)r����r����r���r���r}���r���re���r����r����r����r&���r����rS���r`���ra���r����)r���r#���r����r����r���r���r���r3�����s����zMH.get_bytesc���������� ���C���sf���yt�tj�|�jt|��d�}W�n>�tk r\�}�z |jtjkrJt d|���n��W�dd}~X�Y�nX�t |�S�)z6Return a file-like representation or raise a KeyError.r����zNo message with key: %sN)r����r���r���r}���r���re���r����r����r����r&���r����)r���r#���r����r����r���r���r���r/���)��s����zMH.get_filec�������������C���s���t�tdd��t�|�j�D����S�)zReturn an iterator over keys.c�������������s���s���|�]}|����rt|�V��qd�S�)N)�isdigitr����)�.0r����r���r���r���� <genexpr>6��s����zMH.iterkeys.<locals>.<genexpr>)�iterr����r���r����r���)r���r���r���r���r6���4��s����zMH.iterkeysc�������������C���s���t�j�t�j�|�jt|���S�)z9Return True if the keyed message exists, False otherwise.)r���r���r���r}���r���re���)r���r#���r���r���r���r?���9��s����zMH.__contains__c�������������C���s���t�t|������S�)z*Return a count of messages in the mailbox.)r����r7���r6���)r���r���r���r���r@���=��s����z MH.__len__c�������������C���s2���|�j�s.ttj�|�jd�d�|�_t|�j��d|�_�dS�)zLock the mailbox.z .mh_sequenceszrb+TN)r����r����r���r���r}���r���r����r����)r���r���r���r���rJ���A��s���� zMH.lockc�������������C���s(���|�j�r$t|�j��t|�j��|�`d|�_�dS�)z#Unlock the mailbox if it is locked.FN)r����r����r����r����)r���r���r���r���rK���H��s ���� z MH.unlockc�������������C���s���dS�)z&Write any pending changes to the disk.Nr���)r���r���r���r���rI���P��s����zMH.flushc�������������C���s���|�j�r|�����dS�)zFlush and close the mailbox.N)r����rK���)r���r���r���r���rL���T��s����zMH.closec�������������C���s@���g�}x6t��|�j�D�]&}t�j�t�j�|�j|��r|�|��qW�|S�)zReturn a list of folder names.)r���r����r���r���r����r}���r����)r���rB���r����r���r���r���r����Y��s ����zMH.list_foldersc�������������C���s���t�tj�|�j|�|�jdd�S�)z+Return an MH instance for the named folder.F)r���r���)r���r���r���r}���r���r���)r���r����r���r���r���r����a��s����z MH.get_folderc�������������C���s���t�tj�|�j|�|�jd�S�)z:Create a folder and return an MH instance representing it.)r���)r���r���r���r}���r���r���)r���r����r���r���r���r����f��s����z MH.add_folderc�������������C���s`���t�j�|�j|�}t��|�}|dgkr:t��t�j�|d���n|g�krDntd|�j���t��|��dS�)z-Delete the named folder, which must be empty.z .mh_sequenceszFolder not empty: %sN)r���r���r}���r���r����r$���r���r����)r���r����r����entriesr���r���r���r����k��s���� zMH.remove_folderc������� ��� ������s��i�}t�tj�|�jd�ddd���}t|�������x�|D�]�}y�|�d�\}}t��}xT|���D�]H}|���rr|� t |���qVdd��|�d�D��\}} |�t|| d ����qVW���fd d�t |�D��||<�t||��dkr�||=�W�q2�tk r����td |������Y�q2X�q2W�W�dQ�R�X�|S�)z=Return a name-to-key-list dictionary to define each sequence.z .mh_sequences�r�ASCII)�encodingry���c�������������s���s���|�]}t�|�V��qd�S�)N)r����)r���xr���r���r���r�����s����z#MH.get_sequences.<locals>.<genexpr>�-r����c����������������s���g�|�]}|��kr|�qS�r���r���)r��r#���)�all_keysr���r���� <listcomp>���s����z$MH.get_sequences.<locals>.<listcomp>r���z"Invalid sequence specification: %sN)r����r���r���r}���r����setr8���r����r��r"���r����rH����ranger����r����rO���r����rstrip) r���Zresultsr����rs���r�����contentsr8����specr����r����r���)r��r���r��w��s&���� zMH.get_sequencesc�������������C���s ��t�tj�|�jd�ddd�}z�t�t��|jtjtjB����x�|� ��D�]�\}}t |�dkrXqB|�|d���d}d}xbtt |��D�]R}|d �|kr�|s�d }|�d��n*|r�d}|�d||f���n|�d |���|}q|W�|r�|�t|�d���qB|�d��qBW�W�dt|��X�dS�)z:Set sequences using the given name-to-key-list dictionary.z .mh_sequenceszr+r��)r��r���ry���NFr����Tr��z%s %sz %s� )r����r���r���r}���r���rL���r����r����r ��r>���r����rb���r����r��re���r����)r���� sequencesr����r����r8����prevZ completingr#���r���r���r���� set_sequences���s.����zMH.set_sequencesc������� ��� ���C���sL��|�����}d}g�}x�|����D�]�}|d�|kr�|�||d�f��y4t�tj�|�jt|��tj�|�jt|d�����W�nH�t t fk r����t�tj�|�jt|��tj�|�jt|d�����Y�nX�t�tj�|�jt|����|d7�}qW�|d�|�_ t|�dkr�dS�xB|���D�]6\}}x*|D�]"\}}||k�r|||�|�<��qW��qW�|��|��dS�)z?Re-name messages to eliminate numbering gaps. Invalidates keys.r���r����N)r��r6���r����r���r����r���r}���r���re���r����r����r�����unlinkr����r����r>����indexr%��) r���r#��r$��Zchangesr#���r����r���oldr{���r���r���r����pack���s,���� zMH.packc�������������C���s|���|����}|�����}x<|���D�]0\}}||kr6|�|��q||kr||�|�=�qW�x|D�]}||krT|g||<�qTW�|��|��dS�)z;Inspect a new MHMessage and update sequences appropriately.N)r��r>���r����r'��r%��)r���r!���r#���Zpending_sequencesZ all_sequencesr����r���sequencer���r���r���r�����s���� zMH._dump_sequences)NT)ru���rv���rw���rx���r���r"���r$���r(���r,���r3���r/���r6���r?���r@���rJ���rK���rI���rL���r����r����r����r����r��r%��r)��r��r���r���r���r���r������s.��� "c���������������@���s����e�Zd�ZdZedddddddh�Zd%dd�Zd d��Zdd��Zdd��Z dd��Z dd��Zdd��Zdd��Z dd��Zdd��Zdd ��Zd!d"��Zd#d$��Zd S�)&r���zAn Rmail-style Babyl mailbox.�unseen�deletedZfiled�answered� forwardedZedited�resentNTc�������������C���s���t��|�|||��i�|�_dS�)zInitialize a Babyl mailbox.N)r����r����_labels)r���r���r���r���r���r���r���r������s����zBabyl.__init__c�������������C���s(���t��|�|�}t|t�r$|���|�j|<�|S�)z$Add message and return assigned key.)r����r"���rY���r���� get_labelsr0��)r���r!���r#���r���r���r���r"������s���� z Babyl.addc�������������C���s"���t��|�|��||�jkr|�j|=�dS�)z=Remove the keyed message; raise KeyError if it doesn't exist.N)r����r$���r0��)r���r#���r���r���r���r$������s���� zBabyl.removec�������������C���s*���t��|�||��t|t�r&|���|�j|<�dS�)z>Replace the keyed message; raise KeyError if it doesn't exist.N)r����r(���rY���r���r1��r0��)r���r#���r!���r���r���r���r(������s���� zBabyl.__setitem__c������� ������C���s��|���|�\}}|�j�|��|�j����t���}x2|�j���}|dt�ksH|sJP�|�|�td���q.W�t���}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 ***rQ���r���)r����r����r_���rl���rZ���r[���ra���rb���r`���r����r����rS���r���rk����set_visibler0��� set_labels) r���r#���r����r�����original_headersrs���Zvisible_headers�nZbodyr����r���r���r���r,������s0���� zBabyl.get_messagec������� ������C���s����|���|�\}}|�j�|��|�j����t���}x2|�j���}|dt�ksH|sJP�|�|�td���q.W�x|�j���}|tksx|sbP�qbW�|� ��}||�j� ���}|dks�t�|�j�|�}|�td�}||�S�)z3Return a string representation or raise a KeyError.s���*** EOOH ***rQ���r���) r����r����r_���rl���rZ���r[���ra���rb���r`���rk���r����r����rS���) r���r#���r����r����r4��rs���Zheadersr5��rr���r���r���r���r3�����s&���� zBabyl.get_bytesc�������������C���s���t��|��|��dt��S�)z6Return a file-like representation or raise a KeyError.rQ���)rZ���r[���r3���r`���ra���)r���r#���r���r���r���r/���%��s����zBabyl.get_filec�������������C���s@���|������t��}x|�j���D�]}|�|��qW�|�|�j��t|�S�)z4Return a list of user-defined labels in the mailbox.)r����r��r0��r<���rH����difference_update�_special_labelsr7���)r����labelsZ label_listr���r���r���r1��)��s����zBabyl.get_labelsc�������������C���s>��g�g��}}|�j��d��d}g�}x�|}|�j����}|�j����}|dt�kr�t|�t|�k�rf|�|tt����|�|��dd��|�j����dd���d�D��}|�|��q |dks�|dt�kr�t|�t|�k�r�|�|tt����q |s |�|tt����P�q W�tt t ||���|�_tt |��|�_t|�j�|�_ |�j��dd ��|�j����|�_dS�) z0Generate key-to-(start, stop) table of contents.r���s���c�������������S���s���g�|�]}|����r|�����qS�r���)�strip)r���labelr���r���r���r��@��s����z'Babyl._generate_toc.<locals>.<listcomp>r����N����,����r����)r����r_���rl���r����ra���r����r����r����r��r��r��r����r0��r����r����)r���r��r��r��Zlabel_listsr��rs���r8��r���r���r���r����2��s4���� zBabyl._generate_tocc�������������C���sV���dt��}|dt��7�}|����}dd��|D��}|dd�|��t��7�}|d7�}|�|��dS�) z,Called before writing the mailbox to file f.s���BABYL OPTIONS:s ���Version: 5c�������������s���s���|�]}|����V��qd�S�)N)rM���)r��r:��r���r���r���r��U��s����z*Babyl._pre_mailbox_hook.<locals>.<genexpr>s���Labels:r;��r<��N)ra���r1��r}���rb���)r���r����Zbabylr8��r���r���r���r����P��s����zBabyl._pre_mailbox_hookc�������������C���s���|��dt���dS�)z-Called before writing each message to file f.����N)rb���ra���)r���r����r���r���r���r����Z��s����zBabyl._pre_message_hookc�������������C���s���|��td���dS�)z,Called after writing each message to file f.r<��N)rb���ra���)r���r����r���r���r���r����^��s����zBabyl._post_message_hookc�������������C���s���|�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�W�n@|�d��x4|���}|�j��|�d t ���|d k�s�|�s�P��q�W�x,|�d�}|�sP�|�j��|�d t ����q�W��nXt|ttt jf��r&t|t j��rbt�dtd ��|���}t|t��rx|��|�}|�d�d�}|d�dk�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`W�x�|���}|�sP�|�"d��r$|dd��t �}n:|�"d��rB|dd��t �}n|�"d ��r^|dd��t �}|�j��|���q�W�nt#dt$|����|�j����}||fS�)z0Write message contents and return (start, stop).����1s���, s���,,���� r;��s���1,,Fr���rQ���s���*** EOOH ***i���z8Use of StringIO input is deprecated, use BytesIO insteadrR���s��� r����rW���Nrl���rT���zDUse of text mode files is deprecated, use a binary mode file insteadTs��� rU���rV���zInvalid message type: %s)%r����r����rY���r���r1��r7��r����rb���rM���ra���r1���r!���r���rZ���r[���r\���r]���r^���r_���rl���r`����get_visiblerS���rf���re���rg���rh���ri���rj���rk���rP���r����rE���rT���rd���rn���ro���)r���r!���r����Zspecial_labelsr8��r:��Zorig_bufferZorig_generatorrs���Z vis_bufferZ vis_generatorrT���Z body_startZoriginal_posZ first_passr����r���r���r���r����b��s����� zBabyl._install_message)NT)ru���rv���rw���rx���� frozensetr7��r���r"���r$���r(���r,���r3���r/���r1��r����r����r����r����r����r���r���r���r���r������s ��� c���������������@���s*���e�Zd�ZdZd dd�Zdd��Zdd��ZdS�) r���z0Message with mailbox-format-specific properties.Nc�������������C���s����t�|tjj�r4|��t�|���t�|t�r�|�|���n�t�|t�rP|��t� |���n~t�|t �rl|��t�|���nbt�|tj �r�|��t�|���nDt|d�r�|��t�|���n(|dkr�tjj�|���ntdt|����dS�)zInitialize a Message instance.rS���NzInvalid message type: %s)rY���r1���r!���r����_become_message�copyZdeepcopy�_explain_torf���r2���re���Zmessage_from_stringrZ���� TextIOWrapperZmessage_from_filerE���Zmessage_from_binary_filer���rn���ro���)r���r!���r���r���r���r������s���� zMessage.__init__c�������������C���s8���t�|dg��}x&|jD�]}||kr|j|�|�j|<�qW�dS�)z0Assume the non-format-specific state of message.�_type_specific_attributesN)�getattr�__dict__)r���r!���Z type_specificr����r���r���r���rB�����s����zMessage._become_messagec�������������C���s���t�|t�rdS�td��dS�)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rY���r���rn���)r���r!���r���r���r���rD�����s���� zMessage._explain_to)N)ru���rv���rw���rx���r���rB��rD��r���r���r���r���r������s��� c���������������@���s|���e�Zd�ZdZdddgZddd�Zdd ��Zd d��Zdd ��Zdd��Z dd��Z dd��Zdd��Zdd��Z dd��Zdd��Zdd��ZdS�)r ���z)Message with Maildir-specific properties.�_subdir�_info�_dateNc�������������C���s&���d|�_�d|�_t���|�_t�|�|��dS�)z%Initialize a MaildirMessage instance.r{���r����N)rI��rJ��r����rK��r���r���)r���r!���r���r���r���r������s���� zMaildirMessage.__init__c�������������C���s���|�j�S�)zReturn 'new' or 'cur'.)rI��)r���r���r���r���r�������s����zMaildirMessage.get_subdirc�������������C���s(���|dks|dkr||�_�ntd|���dS�)zSet subdir to 'new' or 'cur'.r{���r|���z!subdir must be 'new' or 'cur': %sN)rI��rO���)r���r����r���r���r���r������s����zMaildirMessage.set_subdirc�������������C���s"���|�j��d�r|�j�dd��S�dS�dS�)z*Return as a string the flags that are set.z2,r����Nr����)rJ��rm���)r���r���r���r���� get_flags ��s����zMaildirMessage.get_flagsc�������������C���s���dd��t|���|�_dS�)z)Set the given flags and unset all others.z2,r����N)r}���r����rJ��)r����flagsr���r���r���� set_flags��s����zMaildirMessage.set_flagsc�������������C���s$���|���d�t|�����t|�B����dS�)z.Set the given flag(s) without changing others.r����N)rN��r}���r��rL��)r����flagr���r���r����add_flag��s����zMaildirMessage.add_flagc�������������C���s,���|�����r(|��d�t|������t|�����dS�)z7Unset the given string flag(s) without changing others.r����N)rL��rN��r}���r��)r���rO��r���r���r����remove_flag��s����zMaildirMessage.remove_flagc�������������C���s���|�j�S�)z<Return delivery date of message, in seconds since the epoch.)rK��)r���r���r���r���r������s����zMaildirMessage.get_datec�������������C���s6���yt�|�|�_W�n"�tk r0���td|��d�Y�nX�dS�)z9Set delivery date of message, in seconds since the epoch.zcan't convert to float: %sN)�floatrK��rO���rn���)r���Zdater���r���r���r����"��s����zMaildirMessage.set_datec�������������C���s���|�j�S�)z%Get the message's "info" as a string.)rJ��)r���r���r���r���r����)��s����zMaildirMessage.get_infoc�������������C���s&���t�|t�r||�_ntdt|����dS�)z Set the message's "info" string.zinfo must be a string: %sN)rY���re���rJ��rn���ro���)r����infor���r���r���r����-��s���� zMaildirMessage.set_infoc�������������C���s���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)rY���r ���rN��rL��r����r����r����r����r����r��rP��r����r����r����r���r��r���� add_labelr���rn���ro���)r���r!���rM��r���r���r���rD��4��sN���� zMaildirMessage._explain_to)N)ru���rv���rw���rx���rF��r���r����r����rL��rN��rP��rQ��r����r����r����r����rD��r���r���r���r���r ������s��� c���������������@���sZ���e�Zd�ZdZdgZddd�Zdd��Zddd �Zd d��Zdd ��Z dd��Z dd��Zdd��ZdS�)r����z/Message with mbox- or MMDF-specific properties.�_fromNc�������������C���sV���|���dd��t|tjj�rF|���}|dk rF|�d�rF|���|dd����t�|�|��dS�)z'Initialize an mboxMMDFMessage instance.z MAILER-DAEMONTNzFrom rX���)r����rY���r1���r!���r���r����rm���r���)r���r!���r����r���r���r���r���e��s����z_mboxMMDFMessage.__init__c�������������C���s���|�j�S�)z Return contents of "From " line.)r_��)r���r���r���r���r����n��s����z_mboxMMDFMessage.get_fromc�������������C���s4���|dk r*|dkrt����}|dt��|��7�}||�_dS�)z>Set "From " line, formatting and appending time_ if specified.NT� )r����r����r����r_��)r���r����Ztime_r���r���r���r����r��s ����z_mboxMMDFMessage.set_fromc�������������C���s���|���dd�|���dd��S�)z*Return as a string the flags that are set.�Statusr����zX-Status)r+���)r���r���r���r���rL��z��s����z_mboxMMDFMessage.get_flagsc�������������C���s����t�|�}d\}}x&dD�]}||kr||7�}|�|��qW�x&dD�]}||kr>||7�}|�|��q>W�|d�t|��7�}y|��d|��W�n �tk r����|��d|��Y�nX�y|��d|��W�n �tk r����|��d|��Y�nX�dS�)z)Set the given flags and unset all others.)r����r����)rU��rV��)rX��rY��rZ��r����ra��zX-StatusN)r��r$���r}���r�����replace_headerr&���Z add_header)r���rM��Zstatus_flagsZ xstatus_flagsrO��r���r���r���rN��~��s&���� z_mboxMMDFMessage.set_flagsc�������������C���s$���|���d�t|�����t|�B����dS�)z.Set the given flag(s) without changing others.r����N)rN��r}���r��rL��)r���rO��r���r���r���rP�����s����z_mboxMMDFMessage.add_flagc�������������C���s4���d|�ksd|�kr0|���d�t|�����t|�����dS�)z7Unset the given string flag(s) without changing others.ra��zX-Statusr����N)rN��r}���r��rL��)r���rO��r���r���r���rQ�����s����z_mboxMMDFMessage.remove_flagc���������� ���C���s���t�|t�r�t|�����}d|kr(|�d��d|kr:|�d��d|krL|�d��d|kr^|�d��d|krp|�d��|d =�|d =�d�|�������dd ���}y|� t �t� |d����W�n�ttfk r����Y�nX��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.rV��r|���rY��rZ��rU��rT��rX��rW��Zstatuszx-statusr`�����Nz%a %b %d %H:%M:%S %Yr+��r[��r\��r,��r-��z$Cannot convert to specified type: %s)rY���r ���r��rL��r����rP��r}���r����r����r�����calendarZtimegmr����ZstrptimerO���� OverflowErrorr����rN��r����r���r��r���r^��r���rn���ro���)r���r!���rM��Z maybe_dater���r���r���rD�����s^���� z_mboxMMDFMessage._explain_to)N)N) ru���rv���rw���rx���rF��r���r����r����rL��rN��rP��rQ��rD��r���r���r���r���r����`��s��� r����c���������������@���s���e�Zd�ZdZdS�)r ���z&Message with mbox-specific properties.N)ru���rv���rw���rx���r���r���r���r���r ������s���c���������������@���sH���e�Zd�ZdZdgZddd�Zdd��Zdd ��Zd d��Zdd ��Z dd��Z dS�)r���z$Message with MH-specific properties.� _sequencesNc�������������C���s���g�|�_�t�|�|��dS�)z!Initialize an MHMessage instance.N)rf��r���r���)r���r!���r���r���r���r������s����zMHMessage.__init__c�������������C���s���|�j�dd��S�)z4Return a list of sequences that include the message.N)rf��)r���r���r���r���r�����s����zMHMessage.get_sequencesc�������������C���s���t�|�|�_dS�)z3Set the list of sequences that include the message.N)r7���rf��)r���r#��r���r���r���r%�����s����zMHMessage.set_sequencesc�������������C���s6���t�|t�r"||�jkr2|�j�|��ntdt|����dS�)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rY���re���rf��r����rn���ro���)r���r*��r���r���r���r�����s���� zMHMessage.add_sequencec�������������C���s*���y|�j��|��W�n�tk r$���Y�nX�dS�)zARemove sequence from the list of sequences including the message.N)rf��r$���rO���)r���r*��r���r���r����remove_sequence���s����zMHMessage.remove_sequencec�������������C���sJ��t�|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�W�n`t�|t ��r(t|�����}d|k�r|� d��d|k�rF|� d��nt�|t��r6ntdt |����d S�)z6Copy MH-specific state to message insofar as possible.r+��r|���rT��r\��rY��r[��rU���ROrV��rZ��r-��z$Cannot convert to specified type: %sN)rY���r ���r��r��r����rP��r����r���r��r���r^��r���rn���ro���)r���r!���r#��r*��r���r���r���rD�����s@���� zMHMessage._explain_to)N)ru���rv���rw���rx���rF��r���r��r%��r��rg��rD��r���r���r���r���r������s��� c���������������@���sb���e�Zd�ZdZddgZddd�Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��Zdd��Z dS�)r���z'Message with Babyl-specific properties.r0���_visibleNc�������������C���s���g�|�_�t��|�_t�|�|��dS�)z#Initialize a BabylMessage instance.N)r0��r���ri��r���)r���r!���r���r���r���r���"��s����zBabylMessage.__init__c�������������C���s���|�j�dd��S�)z'Return a list of labels on the message.N)r0��)r���r���r���r���r1��(��s����zBabylMessage.get_labelsc�������������C���s���t�|�|�_dS�)z&Set the list of labels on the message.N)r7���r0��)r���r8��r���r���r���r3��,��s����zBabylMessage.set_labelsc�������������C���s6���t�|t�r"||�jkr2|�j�|��ntdt|����dS�)z+Add label to list of labels on the message.zlabel must be a string: %sN)rY���re���r0��r����rn���ro���)r���r:��r���r���r���r^��0��s���� zBabylMessage.add_labelc�������������C���s*���y|�j��|��W�n�tk r$���Y�nX�dS�)z4Remove label from the list of labels on the message.N)r0��r$���rO���)r���r:��r���r���r����remove_label8��s����zBabylMessage.remove_labelc�������������C���s ���t�|�j�S�)z3Return a Message representation of visible headers.)r���ri��)r���r���r���r���r@��?��s����zBabylMessage.get_visiblec�������������C���s���t�|�|�_dS�)z2Set the Message representation of visible headers.N)r���ri��)r���Zvisibler���r���r���r2��C��s����zBabylMessage.set_visiblec�������������C���sj���x6|�j����D�](}||�kr,|�j��||�|���q|�j�|=�qW�x,dD�]$}||�kr>||�j�kr>|�|�|�j�|<�q>W�dS�)z9Update and/or sensibly generate a set of visible headers.)ZDateZFromzReply-ToZToZCCZSubjectN)ri��r8���rb��)r����headerr���r���r����update_visibleG��s���� zBabylMessage.update_visiblec�������������C���sv��t�|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>W�nt�|t ��rbntdt|����dS�)z9Copy Babyl-specific state to message insofar as possible.r+��r|���rT��r.��r/��r]��r-��rU��r,��rW��rh��rV��rX��rZ��r[��z$Cannot convert to specified type: %sN)rY���r ���r��r1��r����rP��r����r���r��r���r2��r@��r^��r���rn���ro���)r���r!���r8��r:��r���r���r���rD��R��sF���� zBabylMessage._explain_to)N)ru���rv���rw���rx���rF��r���r1��r3��r^��rj��r@��r2��rl��rD��r���r���r���r���r�����s��� c���������������@���s���e�Zd�ZdZdS�)r ���z&Message with MMDF-specific properties.N)ru���rv���rw���rx���r���r���r���r���r ���|��s���c���������������@���s����e�Zd�ZdZd&dd�Zd'dd�Zd(dd�Zd)d d �Zd*dd�Zd d��Z dd��Z d+dd�Zdd��Zdd��Z dd��Zdd��Zdd��Zdd��Zd d!��Zd"d#��Zed$d%���ZdS�),r����zA read-only wrapper of a file.Nc�������������C���s$���||�_�|dkr|���|�_n||�_dS�)zInitialize a _ProxyFile.N)r����r�����_pos)r���r�����posr���r���r���r������s����z_ProxyFile.__init__c�������������C���s���|���||�jj�S�)zRead bytes.)�_readr����rS���)r����sizer���r���r���rS������s����z_ProxyFile.readc�������������C���s���|���||�jj�S�)zRead bytes.)ro��r�����read1)r���rp��r���r���r���rq�����s����z_ProxyFile.read1c�������������C���s���|���||�jj�S�)zRead a line.)ro��r����rl���)r���rp��r���r���r���rl������s����z_ProxyFile.readlinec�������������C���s>���g�}x4|�D�],}|��|��|dk r |t|�8�}|dkr P�q W�|S�)zRead multiple lines.Nr���)r����r����)r����sizehintrB���rs���r���r���r���� readlines���s���� z_ProxyFile.readlinesc�������������c���s ���x|�����}|sdS�|V��qW�dS�)zIterate over lines.N)rl���)r���rs���r���r���r���r;������s ����z_ProxyFile.__iter__c�������������C���s���|�j�S�)zReturn the position.)rm��)r���r���r���r���r�������s����z_ProxyFile.tellr���c�������������C���s4���|dkr|�j��|�j��|�j��||��|�j����|�_dS�)zChange position.r����N)r����r_���rm��r����)r����offset�whencer���r���r���r_������s����z_ProxyFile.seekc�������������C���s0���t�|�d�r,zt�|�jd�r"|�j����W�d|�`X�dS�)zClose the file.r����rL���N)rE���r����rL���)r���r���r���r���rL������s ���� z_ProxyFile.closec�������������C���s2���|dkrd}|�j��|�j��||�}|�j����|�_|S�)z"Read size bytes using read_method.NrW���)r����r_���rm��r����)r���rp���read_methodrB���r���r���r���ro�����s����z_ProxyFile._readc�������������C���s���|�S�)z$Context management protocol support.r���)r���r���r���r���� __enter__���s����z_ProxyFile.__enter__c�������������G���s���|������d�S�)N)rL���)r����excr���r���r����__exit__���s����z_ProxyFile.__exit__c�������������C���s ���|�j����S�)N)r�����readable)r���r���r���r���rz�����s����z_ProxyFile.readablec�������������C���s ���|�j����S�)N)r�����writable)r���r���r���r���r{�����s����z_ProxyFile.writablec�������������C���s ���|�j����S�)N)r�����seekable)r���r���r���r���r|�����s����z_ProxyFile.seekablec�������������C���s ���|�j����S�)N)r����rI���)r���r���r���r���rI������s����z_ProxyFile.flushc�������������C���s&���t�|�d�sdS�t�|�jd�sdS�|�jjS�)Nr����Tr��F)rE���r����r��)r���r���r���r���r�����s ���� z_ProxyFile.closed)N)N)N)N)N)r���)ru���rv���rw���rx���r���rS���rq��rl���rs��r;���r����r_���rL���ro��rw��ry��rz��r{��r|��rI����propertyr��r���r���r���r���r�������s$��� r����c���������������@���s<���e�Zd�ZdZddd�Zdd��Zddd �Zd d��Zdd ��ZdS�)r����z&A read-only wrapper of part of a file.Nc�������������C���s���t��|�||��||�_||�_dS�)zInitialize a _PartialFile.N)r����r����_start�_stop)r���r����r����r����r���r���r���r������s����z_PartialFile.__init__c�������������C���s���t��|��|�j�S�)z*Return the position with respect to start.)r����r����r~��)r���r���r���r���r�������s����z_PartialFile.tellr���c�������������C���s<���|dkr|�j�|�_d}n|dkr*|�j|�_d}t�|�||��dS�)z8Change position, possibly with respect to start or stop.r���r����r����N)r~��rm��r��r����r_���)r���rt��ru��r���r���r���r_������s����z_PartialFile.seekc�������������C���sB���|�j�|�j�}|dkrdS�|dks0|dk�s0||kr4|}t�|�||�S�)z;Read size bytes using read_method, honoring start and stop.r���r����N)r��rm��r����ro��)r���rp��rv��Z remainingr���r���r���ro�����s����z_PartialFile._readc�������������C���s���t�|�d�r|�`d�S�)Nr����)rE���r����)r���r���r���r���rL�����s���� z_PartialFile.close)NN)r���) ru���rv���rw���rx���r���r����r_���ro��rL���r���r���r���r���r�������s��� r����Tc���������� ���C���s���d}�yZt�rpyt��|�t�jt�jB���W�nJ�tk rn�}�z,|jtjtjtjfkr\t d|�j ���n��W�dd}~X�Y�nX�|�r^yt|�j d��}|����W�n:�tk r��}�z|jtjtjfkr�dS���W�dd}~X�Y�nX�y`yt �|j |�j d���d}W�n2�ttfk �r���t �|j |�j d���d}Y�nX�t �|j ��W�n0�tk �r\���t �|j ��t d|�j ���Y�nX�W�n8���t��r|t��|�t�j��|�r�t �|�j d�����Y�nX�dS�)z(Lock file f using lockf and dot locking.Fzlockf: lock unavailable: %sNz.lockTzdot lock unavailable: %s)�fcntl�lockfZLOCK_EXZLOCK_NBr����r����ZEAGAINr����r����r���r����r����rL���r���r����r����r����r����r&��r����r$����LOCK_UN)r����r����Zdotlock_doner����Zpre_lockr���r���r���r���� ��sH���� r����c�������������C���s8���t�rt��|�t�j��tj�|�jd��r4t�|�jd���dS�)z*Unlock file f using lockf and dot locking.z.lockN)r���r���r���r���r���r���r����r$���)r����r���r���r���r����4��s����r����c���������� ���C���s8���t��|�t�jt�jB�t�jB�d�}z t|�d�S�t��|��X�dS�)zCCreate a file if it doesn't exist and open for reading and writing.i���zrb+N)r���r����r����r ���O_RDWRrL���)r����fdr���r���r���r����;��s���� r����c�������������C���s$���t�d|�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����r���r����)r���r���r���r���r����C��s����r����c�������������C���s$���|������ttd�r t�|������dS�)z0Ensure changes to file f are physically on disk.�fsyncN)rI���rE���r���r����fileno)r����r���r���r���r����I��s���� r����c�������������C���s���t�|���|�����dS�)z:Close file f, ensuring all changes are physically on disk.N)r����rL���)r����r���r���r���r����O��s����r����c���������������@���s���e�Zd�ZdZdS�)r���z"Raised for module-specific errors.N)ru���rv���rw���rx���r���r���r���r���r���U��s���c���������������@���s���e�Zd�ZdZdS�)r���z:The specified mailbox does not exist and won't be created.N)ru���rv���rw���rx���r���r���r���r���r���X��s���c���������������@���s���e�Zd�ZdZdS�)r���z>The specified mailbox is not empty and deletion was requested.N)ru���rv���rw���rx���r���r���r���r���r���[��s���c���������������@���s���e�Zd�ZdZdS�)r���z)Another process caused an action to fail.N)ru���rv���rw���rx���r���r���r���r���r���^��s���c���������������@���s���e�Zd�ZdZdS�)r���z)A file appears to have an invalid format.N)ru���rv���rw���rx���r���r���r���r���r���a��s���)T)0rx���r���r����rd��r����r����rC��rh���r1���Z email.messageZemail.generatorrZ���r-���r����ImportError�__all__ra���rM���r���r���r����r����r���r���r���r���r!���r���r ���r����r ���r���r���r ���r����r����r����r����r����r����r����r����� Exceptionr���r���r���r���r���r���r���r���r����<module>���sp��� �h��8�DB4-��3�z%mqH_c' *