OwlCyberSecurity - MANAGER
Edit File: mailbox.cpython-36.opt-1.pyc
3 � \ 3�����������������@���sR��d�Z�ddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl ZddlZddlZyddl Z W�n�ek r����dZ Y�nX�ddddddd d ddd ddddddgZejjd�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�jjt�jj|��|�_||�_dS�)zInitialize a Mailbox instance.N)�os�path�abspath� expanduser�_path�_factory)�selfr����factory�create��r����/usr/lib64/python3.6/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���|�j�|��d�S�)N)r$���)r���r#���r���r���r����__delitem__1���s����zMailbox.__delitem__c�������������C���s(���y|�j�|��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 |�j�|�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|�j|�S�tj|�j|���}|�j�|�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�j|�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)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�|�j���S�)zReturn a list of keys.)�listr6���)r���r���r���r����keyse���s����zMailbox.keysc�������������c���s@���x:|�j���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���|�j���S�)N)r:���)r���r���r���r����__iter__r���s����zMailbox.__iter__c�������������C���s���t�|�j���S�)z,Return a list of messages. Memory intensive.)r7���r:���)r���r���r���r����valuesu���s����zMailbox.valuesc�������������c���sD���x>|�j���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�|�j���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|�j���D�]}|�j|��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�|�j|��|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$|�j���D�]}||�j|�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|j��}nt�|d�r(|j��}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 |j�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�rxtj��}tjj||d�}|j|��|j d��|j ��}|jdt�}|j |��|�jrt|jt��rt|j t���n�t�|tttjf��rt�|tj�r�tjdtd��|j��}t�|t�r�|�j|�}|r�|jdd�}|jdt�}|j |��|�jo�|jt���r�|j t��n�t|d��r�t|d��r4tjd td��|j}d }x�|j��}|jd��r`|d d��d�}n|jd ��r||d d��d�}|�s�P�|�r�|jd��r�d|dd ���}|jdt�}|j |��|}�q:W�|�j�r�|�r�|jt���r�|j 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���re���rv���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�j|�|||��tjj|�jd�tjj|�jd�tjj|�jd�d�|�_tjj|�j�s�|r�tj|�jd��x*|�jj ��D�]}tj|d��qnW�n t |�j��i�|�_ddd�|�_d|�_ d|�_d S�) zInitialize a Maildir instance.�tmp�new�cur)r|���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~��|�j���}y|�j||��W�n*�tk rB���|j���tj|j����Y�nX�t|��t|t �r||j ��}|�j|j���}||�jkr�d}nd}d}tj j|j�j|�j�d�}tj j|�j|||��}t|t �r�tj|jtj j|j�|j��f��yLytj|j|��W�n(�ttfk �r���tj|j|��Y�nX�tj|j��W�nN�tk �rx�}�z0tj|j��|jtjk�rftd|���n��W�Y�dd}~X�nX�|S�)z$Add message and return assigned key.��r}���r���z$Name clash with existing message: %sN)�_create_tmprv���� BaseExceptionrL���r���r$����name�_sync_closer[���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�jt�jj|�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|�j�|��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����|�j�|�}|�j|�}|�j�|�}t|t�r.|}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.rW���r����NrZ���)r����r"���r[���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����|�j�|�}ttjj|�j|�d�� }|�jr4|�j|�}nt|�}W�dQ�R�X�tjj|�\}}|j |��|�j |kr�|j|j|�j �d���|jtjj tjj|�j|����|S�)z4Return a Message representation or raise a KeyError.�rbNrW���rZ���)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�tjj|�j|�j|��d��}|j��jtd�S�Q�R�X�dS�)z2Return a bytes representation or raise a KeyError.r����rQ���N) r����r���r���r���r���r����rS���rb���rc���)r���r#���r����r���r���r���r3������s����zMaildir.get_bytesc�������������C���s$���t�tjj|�j|�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���|�j����x:|�jD�]0}y|�j|��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���|�j����||�jkS�)z9Return True if the keyed message exists, False otherwise.)r����r����)r���r#���r���r���r���r?������s����zMaildir.__contains__c�������������C���s���|�j����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|�j�D�]F}t|�dkr|d�dkrt�jjt�jj|�j|��r|j|dd����qW�|S�)zReturn a list of folder names.rW���r����.N)r����listdirr���r����r����isdirr����append)r���rB����entryr���r���r����list_folders���s����zMaildir.list_foldersc�������������C���s ���t�tjj|�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�jj|�jd|��}t||�jd�}t�jj|d�}t�jj|�sXt�jt�j|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�jj|�jd|��}xTt�jt�jj|d��t�jt�jj|d���D�](}t|�dk�sZ|d�dkr>td|���q>W�xPt�j|�D�]B}|dkrv|dkrv|dkrvt�jjt�jj||��rvtd||f���qvW�x`t�j|d d �D�]N\}}}x |D�]}t�j t�jj||���q�W�x |D�]}t�j t�jj||���q�W�q�W�t�j |��dS�)z-Delete the named folder, which must be empty.r����r}���r~���rW���r���zFolder contains message(s): %sr|���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�j���}xNtjtjj|�jd��D�]4}tjj|�jd|�}|tjj|��dkr tj|��q W�dS�)zDelete old files in "tmp".r|���i@��N)�timer���r����r���r���r���r����r$���)r����nowr����r���r���r���r����clean���s ����z Maildir.cleanrW���c�������������C���s����t�j���}tj��}d|kr$|jdd�}d|kr8|jdd�}dt|�t|d�d��tj��tj|f�}tj j |�jd|�}ytj|��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\057r{���z\072z%s.M%sP%sQ%s.%srW���g������.Ar|���z&Name clash prevented file creation: %sN)r�����socket�gethostnamerb����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���|�j�d|�j�krbd}x<|�jD�]2}tjj|�j|��}||�j|�krLd}||�j|<�q$W�|sbdS�i�|�_xl|�jD�]b}|�j|�}xRtj |�D�]D}tjj ||�}tjj|�r�q�|j|�j �d�}tjj ||�|�j|<�q�W�qpW�t�j���|�_dS�)z!Update table of contents mapping.rU���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���sz���y,t�jjt�jj|�j|�j|���r*|�j|�S�W�n�tk r@���Y�nX�|�j���y |�j|�S��tk rt���td|���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|�j��|�_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)rw���rx���ry���rz���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�j|�|||��yt|�jd�}W�nn�tk r��}�zR|jtjkr\|rPt|�jd�}q~t|�j��n"|jtjtj fkr|t|�jd�}n��W�Y�dd}~X�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|�|�j|�j<�|��jd7��_d|�_|�jd�S�)z$Add message and return assigned key.rW���T)r�����_append_messager����r����r����)r���r!���r���r���r���r"���X��s ����z_singlefileMailbox.addc�������������C���s���|�j�|��|�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�|��|�j|�|�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����|�jj��E�dH��dS�)zReturn an iterator over keys.N)r����r����r8���)r���r���r���r���r6���n��s����z_singlefileMailbox.iterkeysc�������������C���s���|�j����||�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���|�j����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�|�jjdd��|�jj��}||�jkrTtd|�j|f���t|�j �}y�i�}|�j |��x�t|�jj ���D�]|}|�j|�\}}|�jj|��|�j|��|j��}x0|�jjtd||�jj�����}|s�P�|j|��q�W�||j��f||<�|�j|��q~W�|j��|�_W�n"���|j���tj|j����Y�nX�t|��|�jj���tj|�j �j} tj|j| ��ytj|j|�j ��W�n2�tk �r����tj|�j ��tj|j|�j ��Y�nX�t|�j d�|�_||�_d|�_�d|�_|�j�r�t|�jdd��dS�) z"Write any pending changes to disk.FNr���rU���z4Size of mailbox file changed (expected %i, found %i)i���zrb+)�dotlock) r����r�����_sync_flushr����ra����tellr����r����_create_temporaryr����_pre_mailbox_hook�sortedr����r8����_pre_message_hookrS����minrd����_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|�j����W�dz|�jr|�j���W�d|�jj���X�X�dS�)zFlush and close the mailbox.N)rI���r����rK���r����rL���)r���r���r���r���rL������s����z_singlefileMailbox.closec�������������C���sJ���|�j�dkr|�j���|dk rFy |�j�|�S��tk rD���td|���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�jdd��|�j�j��}t|�j�dkr:|�j�r:|�j|�j���y&|�j|�j���|�j|�}|�j |�j���W�n"�t k r����|�j�j|����Y�nX�|�j�j���|�j�j��|�_ |S�)z;Append message to mailbox and return (start, stop) offsets.r���rU���)r����ra���r����r����r����r����r����r�����_install_messager����r�����truncaterI���r����)r���r!���ZbeforeZoffsetsr���r���r���r�������s���� z"_singlefileMailbox._append_message)NT)N)rw���rx���ry���rz���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�|�\}}|�jj|��|�jj��jtd�}|�jj||�jj����}|�j|jtd��}|j |dd��j d���|S�)z4Return a Message representation or raise a KeyError.�����rQ���rX���Nr���)r����r����ra���rn���rb���rc���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|�j|��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�|�\}}|�jj|��|s(|�jj���|�jj||�jj����}|jtd�S�)z3Return a string representation or raise a KeyError.rQ���)r����r����ra���rn���rS���r����rb���rc���)r���r#���r����r����r����r����r���r���r���r3�����s���� z_mboxMMDF.get_bytesc�������������C���s<���|�j�|�\}}|�jj|��|s(|�jj���t|�j|�jj��|�S�)z6Return a file-like representation or raise a KeyError.)r����r����ra���rn����_PartialFiler����)r���r#���r����r����r����r���r���r���r/�����s ���� z_mboxMMDF.get_filec�������������C���s��d}t�|t�r|�j|�}t�|t�rf|jd�rf|jd�}|dkr\|d|��}||d�d��}q�|}d}nJt�|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.Ns���From rQ���rW���r����r���s���From MAILER-DAEMON rZ���)r[���rg���rP���rh���ro����find�_mboxMMDFMessage�get_fromrM���r1���r!���r����get_unixfromr�����asctime�gmtimer����r����rd���rc���rv���� _mangle_from_)r���r!���r�����newlineZauthorr����r����r���r���r���r����&��s0���� z_mboxMMDF._install_messageN)F)F)F) rw���rx���ry���rz���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�|�_tj|�|||��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���|j�t��dS�)z,Called after writing each message to file f.N)rd���rc���)r���r����r���r���r���r����Q��s����zmbox._post_message_hookc�������������C���s����g�g��}}d}|�j�jd��x�|�j�j��}|�j�j��}|jd�r|t|�t|�k�rl|rb|j|tt����n |j|��|j|��d}q|s�|r�|j|tt����n |j|��P�q|tkr�d}qd}qW�tt t ||���|�_t|�j�|�_|�j�j��|�_ dS�)z0Generate key-to-(start, stop) table of contents.Fr���s���From TN)r����ra���r����rn���ro���r����r����rc����dict� enumerate�zipr����r����r����)r����starts�stopsZlast_was_empty�line_posru���r���r���r���r����U��s0���� zmbox._generate_toc)NT) rw���rx���ry���rz���r����re���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�|�_tj|�|||��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���|j�dt���dS�)z-Called before writing each message to file f.s���N)rd���rc���)r���r����r���r���r���r������s����zMMDF._pre_message_hookc�������������C���s���|j�td�t���dS�)z,Called after writing each message to file f.s���N)rd���rc���)r���r����r���r���r���r�������s����zMMDF._post_message_hookc�������������C���s����g�g��}}|�j�jd��d}x�|}|�j�j��}|�j�j��}|jdt��r�|j|��xV|}|�j�j��}|�j�j��}|dt�kr�|j|tt����P�qN|sN|j|��P�qNW�q|sP�qW�tt t ||���|�_t|�j�|�_|�j�jdd��|�j�j��|�_ dS�)z0Generate key-to-(start, stop) table of contents.r���s���rU���N)r����ra���rn���r����ro���rc���r����r����r��r��r��r����r����r����)r���r��r���next_posr��ru���r���r���r���r�������s2���� zMMDF._generate_toc)NT)rw���rx���ry���rz���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�j|�|||��tjj|�j�sj|r`tj|�jd��tjtjtjj |�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����|�j���}t|�dkrd}nt|�d�}tjj|�jt|��}t|�}d}z�|�j rVt |��zfy|�j||��W�n:�tk r����|�j r�t |��t|��d}tj|����Y�nX�t|t�r�|�j||��W�d|�j r�t |��X�W�d|s�t|��X�|S�)z$Add message and return assigned key.r���rW���FTN)r8���r�����maxr���r���r���r���rg���r����r����r����rv���r����r����r����r$���r[���r����_dump_sequences)r���r!���r8���Znew_keyr����r�����closedr���r���r���r"������s6���� zMH.addc�������������C���sx���t�jj|�jt|��}yt|d�}W�n>�tk r`�}�z"|jtjkrNt d|���n��W�Y�dd}~X�nX�|j ���t�j|��dS�)z=Remove the keyed message; raise KeyError if it doesn't exist.zrb+zNo message with key: %sN)r���r���r���r���rg���r����r����r����r����r&���rL���r$���)r���r#���r���r����r����r���r���r���r$������s����z MH.removec�������������C���s����t�jj|�jt|��}yt|d�}W�n>�tk r`�}�z"|jtjkrNt d|���n��W�Y�dd}~X�nX�zd|�j rrt|��z@t�jt�j|t�j t�jB����|�j||��t|t�r�|�j||��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���rg���r����r����r����r����r&���r����r����rL���r�����O_TRUNCrv���r[���r���r ��r����r����)r���r#���r!���r���r����r����r���r���r���r(������s$���� zMH.__setitem__c���������� ���C���s����y@|�j�r$ttjj|�jt|��d�}nttjj|�jt|��d�}W�n>�tk r~�}�z"|jtj krlt d|���n��W�Y�dd}~X�nX�|�2�|�j�r�t|��zt|�}W�d|�j�r�t |��X�W�dQ�R�X�x*|�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����r���r���r���r���rg���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$ttjj|�jt|��d�}nttjj|�jt|��d�}W�n>�tk r~�}�z"|jtj krlt d|���n��W�Y�dd}~X�nX�|�6�|�j�r�t|��z|j��j 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���rg���r����r����r����r&���r����rS���rb���rc���r����)r���r#���r����r����r���r���r���r3�����s����zMH.get_bytesc�������������C���sf���yt�tjj|�jt|��d�}W�n>�tk r\�}�z"|jtjkrJt d|���n��W�Y�dd}~X�nX�t |�S�)z6Return a file-like representation or raise a KeyError.r����zNo message with key: %sN)r����r���r���r���r���rg���r����r����r����r&���r����)r���r#���r����r����r���r���r���r/���)��s����zMH.get_filec�������������C���s���t�tdd��tj|�j�D����S�)zReturn an iterator over keys.c�������������s���s���|�]}|j���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�jjt�jj|�jt|���S�)z9Return True if the keyed message exists, False otherwise.)r���r���r����r���r���rg���)r���r#���r���r���r���r?���9��s����zMH.__contains__c�������������C���s���t�t|�j����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.ttjj|�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|�j���dS�)zFlush and close the mailbox.N)r����rK���)r���r���r���r���rL���T��s����zMH.closec�������������C���s@���g�}x6t�j|�j�D�]&}t�jjt�jj|�j|��r|j|��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�tjj|�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�tjj|�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�jj|�j|�}t�j|�}|dgkr:t�jt�jj|d���n|g�krDntd|�j���t�j|��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���Zentriesr���r���r���r����k��s���� zMH.remove_folderc������� ���������s��i�}t�tjj|�jd�ddd���}t|�j�����x�|D�]�}y�|jd�\}}t��}xT|j��D�]H}|j��rr|j t |���qVdd��|jd�D��\}} |jt|| d ����qVW���fd d�t |�D��||<�t||��dkr�||=�W�q2�tk r����td |j�����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)�encodingr{���c�������������s���s���|�]}t�|�V��qd�S�)N)r����)r���xr���r���r���r�����s����z#MH.get_sequences.<locals>.<genexpr>�-rW���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����ru���r�����contentsr8����specr����r����r���)r��r���r ��w��s&���� zMH.get_sequencesc�������������C���s ��t�tjj|�jd�ddd�}z�tjtj�|jtjtjB����x�|j ��D�]�\}}t |�dkrXqB|j|d���d}d}xbtt |��D�]R}|d �|kr�|s�d }|jd��n*|r�d}|jd||f���n|jd |���|}q|W�|r�|jt|�d���qB|jd��qBW�W�dt|��X�dS�)z:Set sequences using the given name-to-key-list dictionary.z .mh_sequenceszr+r��)r��r���r{���NFrW���Tr��z%s %sz %s� )r����r���r���r���r���rL���r����r����r��r>���r����rd���r����r��rg���r����)r���� sequencesr����r����r8����prevZ completingr#���r���r���r���� set_sequences���s.����zMH.set_sequencesc������� ������C���sL��|�j���}d}g�}x�|�j��D�]�}|d�|kr�|j||d�f��y4tjtjj|�jt|��tjj|�jt|d�����W�nH�t t fk r����tjtjj|�jt|��tjj|�jt|d�����Y�nX�tjtjj|�jt|����|d7�}qW�|d�|�_ t|�dkr�dS�xB|j��D�]6\}}x*|D�]"\}}||k�r|||j|�<��qW��qW�|�j|��dS�)z?Re-name messages to eliminate numbering gaps. Invalidates keys.r���rW���N)r ��r6���r����r���r����r���r���r���rg���r����r����r�����unlinkr����r����r>����indexr#��) r���r!��r"��Zchangesr#���r����r���oldr}���r���r���r����pack���s,���� zMH.packc�������������C���s|���|j���}|�j���}x<|j��D�]0\}}||kr6|j|��q||kr||j|�=�qW�x|D�]}||krT|g||<�qTW�|�j|��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)rw���rx���ry���rz���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�j|�|||��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�j|�|�}t|t�r$|j��|�j|<�|S�)z$Add message and return assigned key.)r����r"���r[���r���� get_labelsr.��)r���r!���r#���r���r���r���r"������s���� z Babyl.addc�������������C���s"���t�j|�|��||�jkr|�j|=�dS�)z=Remove the keyed message; raise KeyError if it doesn't exist.N)r����r$���r.��)r���r#���r���r���r���r$������s���� zBabyl.removec�������������C���s*���t�j|�||��t|t�r&|j��|�j|<�dS�)z>Replace the keyed message; raise KeyError if it doesn't exist.N)r����r(���r[���r���r/��r.��)r���r#���r!���r���r���r���r(������s���� zBabyl.__setitem__c������� ������C���s����|�j�|�\}}|�jj|��|�jj���tj��}x4|�jj��}|dt�ksJ|�rLP�|j|jtd���q.W�tj��}x0|�jj��}|tks�|�r�P�|j|jtd���qlW�||�jj ���}|�jj |�}|jtd�}t|j��|��} | j |j����||�jkr�| j|�j|���| S�)z4Return a Message representation or raise a KeyError.s���*** EOOH ***rQ���)r����r����ra���rn���r\���r]���rc���rd���rb���r����rS���r���rm����set_visibler.��� set_labels) r���r#���r����r�����original_headersru���Zvisible_headers�nZbodyr����r���r���r���r,������s.���� zBabyl.get_messagec������� ������C���s����|�j�|�\}}|�jj|��|�jj���tj��}x4|�jj��}|dt�ksJ|�rLP�|j|jtd���q.W�x|�jj��}|tks||�rdP�qdW�|j ��}||�jj ���}|�jj|�}|jtd�}||�S�)z3Return a string representation or raise a KeyError.s���*** EOOH ***rQ���)r����r����ra���rn���r\���r]���rc���rd���rb���rm���r����rS���) r���r#���r����r����r2��ru���Zheadersr3��rt���r���r���r���r3�����s$���� zBabyl.get_bytesc�������������C���s���t�j|�j|�jdt��S�)z6Return a file-like representation or raise a KeyError.rQ���)r\���r]���r3���rb���rc���)r���r#���r���r���r���r/���%��s����zBabyl.get_filec�������������C���s@���|�j����t��}x|�jj��D�]}|j|��qW�|j|�j��t|�S�)z4Return a list of user-defined labels in the mailbox.)r����r��r.��r<���rH����difference_update�_special_labelsr7���)r����labelsZ label_listr���r���r���r/��)��s����zBabyl.get_labelsc�������������C���s>��g�g��}}|�j�jd��d}g�}x�|}|�j�j��}|�j�j��}|dt�kr�t|�t|�k�rf|j|tt����|j|��dd��|�j�j��dd��jd�D��}|j|��q |dks�|dt�kr�t|�t|�k�r�|j|tt����q |s |j|tt����P�q W�tt t ||���|�_tt |��|�_t|�j�|�_ |�j�jdd ��|�j�j��|�_dS�) z0Generate key-to-(start, stop) table of contents.r���s���c�������������S���s���g�|�]}|j���r|j����qS�r���)�strip)r���labelr���r���r���r��@��s����z'Babyl._generate_toc.<locals>.<listcomp>rW���N����,����rU���)r����ra���rn���r����rc���r����r����r����r��r��r��r����r.��r����r����)r���r��r��r��Zlabel_listsr��ru���r6��r���r���r���r����2��s4���� zBabyl._generate_tocc�������������C���sV���dt��}|dt��7�}|�j��}dd��|D��}|ddj|��t��7�}|d7�}|j|��dS�) z,Called before writing the mailbox to file f.s���BABYL OPTIONS:s ���Version: 5c�������������s���s���|�]}|j���V��qd�S�)N)rM���)r��r8��r���r���r���r��U��s����z*Babyl._pre_mailbox_hook.<locals>.<genexpr>s���Labels:r9��r:��N)rc���r/��r���rd���)r���r����Zbabylr6��r���r���r���r����P��s����zBabyl._pre_mailbox_hookc�������������C���s���|j�dt���dS�)z-Called before writing each message to file f.����N)rd���rc���)r���r����r���r���r���r����Z��s����zBabyl._pre_message_hookc�������������C���s���|j�td���dS�)z,Called after writing each message to file f.r:��N)rd���rc���)r���r����r���r���r���r����^��s����zBabyl._post_message_hookc�������������C���s���|�j�j��}t|t�r�g�}g�}x0|j��D�]$}||�jkr@|j|��q&|j|��q&W�|�j�jd��x |D�]}|�j�jd|j�����q`W�|�j�jd��x$|D�]}|�j�jd|j���d���q�W�|�j�jt ��n|�j�jdt ���t|t jj��r0t j��}t jj|dd�}|j|��|jd��x6|j��}|�j�j|jd t ���|d k�s8|��r P��q W�|�j�jd t ���t|t��r�t j��} t jj| dd�} | j|j����xz| j��}|�j�j|jd t ���|d k�s�|��r�P��q�W�nB|jd��x6|j��}|�j�j|jd t ���|d k�s�|��r�P��q�W�x,|jd�}|�sP�|�j�j|jd t ����q�W��nZt|ttt jf��r,t|t j��rhtjdtd ��|j��}t|t��r~|�j|�}|jd�d�}|d�dk�r�|�j�j|d|��jd t ���|�j�jd t ���|�j�j|d|��jd t ���|�j�j||d��jd t ���n(|�j�jd t �t ���|�j�j|jd t ����n^t |d��rzt |d��rXtjdtd ��|j!}|j��} d}x�|j��}|j"d��r�|dd��d �}n|j"d��r�|dd��d �}|�j�j|jd t ���|d k�s�|��rf|�r�d}|�j�jd t ���|j| ��nP��qfW�x�|j��}|�sP�|j"d��r,|dd��t �}n:|j"d��rJ|dd��t �}n|j"d ��rf|dd��t �}|�j�j|���q�W�nt#dt$|����|�j�j��}||fS�)z0Write message contents and return (start, stop).����1s���, s���,,���� r9��s���1,,Fr���rQ���s���*** EOOH ***i���z8Use of StringIO input is deprecated, use BytesIO insteadrR���s��� rU���rW���Nrn���rT���zDUse of text mode files is deprecated, use a binary mode file insteadTs��� rV���zInvalid message type: %srZ���rY���rZ���rY���rZ���rZ���)%r����r����r[���r���r/��r5��r����rd���rM���rc���r1���r!���r���r\���r]���r^���r_���r`���ra���rn���rb����get_visiblerS���rh���rg���ri���rj���rk���rl���rm���rP���r����rE���rT���rf���rp���rq���)r���r!���r����Zspecial_labelsr6��r8��Zorig_bufferZorig_generatorru���Z vis_bufferZ vis_generatorrT���Z body_startZoriginal_posZ first_passr����r���r���r���r����b��s����� zBabyl._install_message)NT)rw���rx���ry���rz���� frozensetr5��r���r"���r$���r(���r,���r3���r/���r/��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|�jtj|���t�|t�r�|j|���n�t�|t�rP|�jtj |���n~t�|t �rl|�jtj|���nbt�|tj �r�|�jtj|���nDt|d�r�|�jtj|���n(|dkr�tjjj|���ntdt|����dS�)zInitialize a Message instance.rS���NzInvalid message type: %s)r[���r1���r!���r����_become_message�copy�deepcopy�_explain_torh���r2���rg���Zmessage_from_stringr\���� TextIOWrapperZmessage_from_filerE���Zmessage_from_binary_filer���rp���rq���)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���r@�����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)r[���r���rp���)r���r!���r���r���r���rC�����s���� zMessage._explain_to)N)rw���rx���ry���rz���r���r@��rC��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|�_tj��|�_tj|�|��dS�)z%Initialize a MaildirMessage instance.r}���r����N)rH��rI��r����rJ��r���r���)r���r!���r���r���r���r������s���� zMaildirMessage.__init__c�������������C���s���|�j�S�)zReturn 'new' or 'cur'.)rH��)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)rH��rO���)r���r����r���r���r���r������s����zMaildirMessage.set_subdirc�������������C���s"���|�j�jd�r|�j�dd��S�dS�dS�)z*Return as a string the flags that are set.z2,rU���Nr����)rI��ro���)r���r���r���r���� get_flags ��s����zMaildirMessage.get_flagsc�������������C���s���ddj�t|���|�_dS�)z)Set the given flags and unset all others.z2,r����N)r���r����rI��)r����flagsr���r���r���� set_flags��s����zMaildirMessage.set_flagsc�������������C���s$���|�j�djt|�j���t|�B����dS�)z.Set the given flag(s) without changing others.r����N)rM��r���r��rK��)r����flagr���r���r����add_flag��s����zMaildirMessage.add_flagc�������������C���s,���|�j���r(|�jdjt|�j����t|�����dS�)z7Unset the given string flag(s) without changing others.r����N)rK��rM��r���r��)r���rN��r���r���r����remove_flag��s����zMaildirMessage.remove_flagc�������������C���s���|�j�S�)z<Return delivery date of message, in seconds since the epoch.)rJ��)r���r���r���r���r������s����zMaildirMessage.get_datec�������������C���s4���yt�|�|�_W�n �tk r.���td|���Y�nX�dS�)z9Set delivery date of message, in seconds since the epoch.zcan't convert to float: %sN)�floatrJ��rO���rp���)r���Zdater���r���r���r����"��s����zMaildirMessage.set_datec�������������C���s���|�j�S�)z%Get the message's "info" as a string.)rI��)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)r[���rg���rI��rp���rq���)r����infor���r���r���r����-��s���� zMaildirMessage.set_infoc�������������C���s���t�|t�r8|j|�j����|j|�j����|j|�j�����nht�|t�r�t |�j���}d|kr`|j d��|�j��dkrv|j d��d|kr�|j d��d|kr�|j d��d|kr�|j d��|jd tj |�j�����n�t�|t��rt |�j���}d|kr�|jd ��d|k�r|jd��d|k�r�|jd��n�t�|t��r�t |�j���}d|k�rD|jd ��d|k�rX|jd ��d|k�rl|jd��d|k�r�|jd��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)r[���r ���rM��rK��r����r����r����r����r����r��rO��r����r����r����r���r��r���� add_labelr���rp���rq���)r���r!���rL��r���r���r���rC��4��sN���� zMaildirMessage._explain_to)N)rw���rx���ry���rz���rE��r���r����r����rK��rM��rO��rP��r����r����r����r����rC��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���|�j�dd��t|tjj�rF|j��}|dk rF|jd�rF|�j�|dd����tj|�|��dS�)z'Initialize an mboxMMDFMessage instance.z MAILER-DAEMONTNzFrom rX���)r����r[���r1���r!���r���r����ro���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�j��}|dt�j|��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���|�j�dd�|�j�dd��S�)z*Return as a string the flags that are set.�Statusr����zX-Status)r+���)r���r���r���r���rK��z��s����z_mboxMMDFMessage.get_flagsc�������������C���s����t�|�}d \}}x&dD�]}||kr||7�}|j|��qW�x&dD�]}||kr>||7�}|j|��q>W�|djt|��7�}y|�jd|��W�n �tk r����|�jd|��Y�nX�y|�jd|��W�n �tk r����|�jd|��Y�nX�d S�) z)Set the given flags and unset all others.r����rT��rU��rW��rX��rY��r`��zX-StatusN)r����r����)rT��rU��)rW��rX��rY��)r��r$���r���r�����replace_headerr&���Z add_header)r���rL��Zstatus_flagsZ xstatus_flagsrN��r���r���r���rM��~��s&���� z_mboxMMDFMessage.set_flagsc�������������C���s$���|�j�djt|�j���t|�B����dS�)z.Set the given flag(s) without changing others.r����N)rM��r���r��rK��)r���rN��r���r���r���rO�����s����z_mboxMMDFMessage.add_flagc�������������C���s4���d|�ksd|�kr0|�j�djt|�j���t|�����dS�)z7Unset the given string flag(s) without changing others.r`��zX-Statusr����N)rM��r���r��rK��)r���rN��r���r���r���rP�����s����z_mboxMMDFMessage.remove_flagc�������������C���s���t�|t�r�t|�j���}d|kr(|jd��d|kr:|jd��d|krL|jd��d|kr^|jd��d|krp|jd��|d =�|d =�dj|�j��j��dd ���}y|j t jtj |d����W�n�ttfk r����Y�nX��n t�|t�r�|j|�j����|j|�j����n�t�|t��rZt|�j���}d|k�r$|jd��d|k�r8|jd��d|k�rL|jd��|d =�|d =�n�t�|t��r�t|�j���}d|k�r�|jd��d|k�r�|jd��d|k�r�|jd��|d =�|d =�nt�|t��r�ntdt|����d S�)zACopy mbox- or MMDF-specific state to message insofar as possible.rU��r~���rX��rY��rT��rS��rW��rV��Zstatuszx-statusr_��rX���Nz%a %b %d %H:%M:%S %Yr)��rZ��r[��r*��r+��z$Cannot convert to specified type: %s���)r[���r ���r��rK��r����rO��r���r����r����r�����calendarZtimegmr����ZstrptimerO���� OverflowErrorr����rM��r����r���r��r���r]��r���rp���rq���)r���r!���rL��Z maybe_dater���r���r���rC�����s^���� z_mboxMMDFMessage._explain_to)N)N) rw���rx���ry���rz���rE��r���r����r����rK��rM��rO��rP��rC��r���r���r���r���r����`��s��� r����c���������������@���s���e�Zd�ZdZdS�)r ���z&Message with mbox-specific properties.N)rw���rx���ry���rz���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�|�_�tj|�|��dS�)z!Initialize an MHMessage instance.N)re��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)re��)r���r���r���r���r �����s����zMHMessage.get_sequencesc�������������C���s���t�|�|�_dS�)z3Set the list of sequences that include the message.N)r7���re��)r���r!��r���r���r���r#�����s����zMHMessage.set_sequencesc�������������C���s6���t�|t�r"||�jkr2|�jj|��ntdt|����dS�)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)r[���rg���re��r����rp���rq���)r���r(��r���r���r���r�����s���� zMHMessage.add_sequencec�������������C���s*���y|�j�j|��W�n�tk r$���Y�nX�dS�)zARemove sequence from the list of sequences including the message.N)re��r$���rO���)r���r(��r���r���r����remove_sequence���s����zMHMessage.remove_sequencec�������������C���sJ��t�|t�rdt|�j���}d|kr*|jd��n|jd��|jd��d|krP|jd��d|krb|jd��n�t�|t�r�t|�j���}d|kr�|jd��n |jd ��d|kr�|jd��d|kr�|jd ��n�t�|t�r�x||�j��D�]}|j|��q�W�n`t�|t ��r(t|�j���}d|k�r|j d��d|k�rF|j d��nt�|t��r6ntdt |����d S�)z6Copy MH-specific state to message insofar as possible.r)��r~���rS��r[��rX��rZ��rT���ROrU��rY��r+��z$Cannot convert to specified type: %sN)r[���r ���r��r ��r����rO��r����r���r��r���r]��r���rp���rq���)r���r!���r!��r(��r���r���r���rC�����s@���� zMHMessage._explain_to)N)rw���rx���ry���rz���rE��r���r ��r#��r��rf��rC��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.r.���_visibleNc�������������C���s���g�|�_�t��|�_tj|�|��dS�)z#Initialize a BabylMessage instance.N)r.��r���rh��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)r.��)r���r���r���r���r/��(��s����zBabylMessage.get_labelsc�������������C���s���t�|�|�_dS�)z&Set the list of labels on the message.N)r7���r.��)r���r6��r���r���r���r1��,��s����zBabylMessage.set_labelsc�������������C���s6���t�|t�r"||�jkr2|�jj|��ntdt|����dS�)z+Add label to list of labels on the message.zlabel must be a string: %sN)r[���rg���r.��r����rp���rq���)r���r8��r���r���r���r]��0��s���� zBabylMessage.add_labelc�������������C���s*���y|�j�j|��W�n�tk r$���Y�nX�dS�)z4Remove label from the list of labels on the message.N)r.��r$���rO���)r���r8��r���r���r����remove_label8��s����zBabylMessage.remove_labelc�������������C���s ���t�|�j�S�)z3Return a Message representation of visible headers.)r���rh��)r���r���r���r���r>��?��s����zBabylMessage.get_visiblec�������������C���s���t�|�|�_dS�)z2Set the Message representation of visible headers.N)r���rh��)r���Zvisibler���r���r���r0��C��s����zBabylMessage.set_visiblec�������������C���sj���x6|�j�j��D�](}||�kr,|�j�j||�|���q|�j�|=�qW�x,dD�]$}||�kr>||�j�kr>|�|�|�j�|<�q>W�dS�) z9Update and/or sensibly generate a set of visible headers.�Date�From�Reply-To�To�CC�SubjectN)rj��rk��rl��rm��rn��ro��)rh��r8���ra��)r����headerr���r���r����update_visibleG��s���� zBabylMessage.update_visiblec�������������C���sv��t�|t�r~t|�j���}d|kr*|jd��n|jd��|jd��d|ksNd|krX|jd��d|krj|jd��d |kr||jd ��n�t�|t�r�t|�j���}d|kr�|jd��n |jd��d |kr�|jd ��d|kr�|jd��n�t�|t��rt|�j���}d|k�r|jd��d|k�rr|jd��nXt�|t ��rT|j |�j����x<|�j��D�]}|j|���q>W�nt�|t ��rbntdt|����dS�)z9Copy Babyl-specific state to message insofar as possible.r)��r~���rS��r,��r-��r\��r+��rT��r*��rV��rg��rU��rW��rY��rZ��z$Cannot convert to specified type: %sN)r[���r ���r��r/��r����rO��r����r���r��r���r0��r>��r]��r���rp���rq���)r���r!���r6��r8��r���r���r���rC��R��sF���� zBabylMessage._explain_to)N)rw���rx���ry���rz���rE��r���r/��r1��r]��ri��r>��r0��rq��rC��r���r���r���r���r�����s��� c���������������@���s���e�Zd�ZdZdS�)r ���z&Message with MMDF-specific properties.N)rw���rx���ry���rz���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|j��|�_n||�_dS�)zInitialize a _ProxyFile.N)r����r�����_pos)r���r�����posr���r���r���r������s����z_ProxyFile.__init__c�������������C���s���|�j�||�jj�S�)zRead bytes.)�_readr����rS���)r����sizer���r���r���rS������s����z_ProxyFile.readc�������������C���s���|�j�||�jj�S�)zRead bytes.)rt��r�����read1)r���ru��r���r���r���rv�����s����z_ProxyFile.read1c�������������C���s���|�j�||�jj�S�)zRead a line.)rt��r����rn���)r���ru��r���r���r���rn������s����z_ProxyFile.readlinec�������������C���s>���g�}x4|�D�],}|j�|��|dk r |t|�8�}|dkr P�q W�|S�)zRead multiple lines.Nr���)r����r����)r����sizehintrB���ru���r���r���r���� readlines���s���� z_ProxyFile.readlinesc�������������c���s ���x|�j���}|sdS�|V��qW�dS�)zIterate over lines.N)rn���)r���ru���r���r���r���r;������s ����z_ProxyFile.__iter__c�������������C���s���|�j�S�)zReturn the position.)rr��)r���r���r���r���r�������s����z_ProxyFile.tellr���c�������������C���s4���|dkr|�j�j|�j��|�j�j||��|�j�j��|�_dS�)zChange position.rW���N)r����ra���rr��r����)r����offset�whencer���r���r���ra������s����z_ProxyFile.seekc���������� ���C���s0���t�|�d�r,zt�|�jd�r"|�jj���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��||�}|�j�j��|�_|S�)z"Read size bytes using read_method.NrW���rZ���)r����ra���rr��r����)r���ru���read_methodrB���r���r���r���rt�����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���|�j����d�S�)N)rL���)r����excr���r���r����__exit__���s����z_ProxyFile.__exit__c�������������C���s ���|�j�j��S�)N)r�����readable)r���r���r���r���r�����s����z_ProxyFile.readablec�������������C���s ���|�j�j��S�)N)r�����writable)r���r���r���r���r������s����z_ProxyFile.writablec�������������C���s ���|�j�j��S�)N)r�����seekable)r���r���r���r���r������s����z_ProxyFile.seekablec�������������C���s ���|�j�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���)rw���rx���ry���rz���r���rS���rv��rn���rx��r;���r����ra���rL���rt��r|��r~��r��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�j|�||��||�_||�_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|��|�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}tj|�||��dS�)z8Change position, possibly with respect to start or stop.r���rW���rU���N)r���rr��r���r����ra���)r���ry��rz��r���r���r���ra������s����z_PartialFile.seekc�������������C���sB���|�j�|�j�}|dkrdS�|dks0|dk�s0||kr4|}tj|�||�S�)z;Read size bytes using read_method, honoring start and stop.r���r����N)r���rr��r����rt��)r���ru��r{��Z remainingr���r���r���rt�����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���) rw���rx���ry���rz���r���r����ra���rt��rL���r���r���r���r���r�������s��� r����Tc����������4���C���s���d}�yZt�rpyt�j|�t�jt�jB���W�nJ�tk rn�}�z.|jtjtjtjfkr\t d|�j ���n��W�Y�dd}~X�nX�|�r^yt|�j d��}|j���W�n:�tk r��}�z|jtjtjfkr�dS���W�Y�dd}~X�nX�y`yt j|j |�j d���d}W�n2�ttfk �r���t j|j |�j d���d}Y�nX�t j|j ��W�n0�tk �r\���t j|j ��t d|�j ���Y�nX�W�n8���t��r|t�j|�t�j��|�r�t j|�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�j|�t�j��tjj|�jd��r4tj|�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�j|�t�jt�jB�t�jB�d�}z t|�d�S�t�j|��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|�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����r���r����)r���r���r���r���r����C��s����r����c�������������C���s$���|�j����ttd�r tj|�j����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�|���|�j���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)rw���rx���ry���rz���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)rw���rx���ry���rz���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)rw���rx���ry���rz���r���r���r���r���r���[��s���c���������������@���s���e�Zd�ZdZdS�)r���z)Another process caused an action to fail.N)rw���rx���ry���rz���r���r���r���r���r���^��s���c���������������@���s���e�Zd�ZdZdS�)r���z)A file appears to have an invalid format.N)rw���rx���ry���rz���r���r���r���r���r���a��s���)T)0rz���r���r����rc��r����r����rA��rj���r1���Z email.messageZemail.generatorr\���r-���r����ImportError�__all__rc���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' *