a
    þdK  ã                   @   s.   d Z ddlZddlZdZG dd„ dejƒZdS )z”Useful utilities for working with the `mbox`_-formatted
mailboxes. Credit to Mark Williams for these.

.. _mbox: https://en.wikipedia.org/wiki/Mbox
é    Ni  @ c                   @   s"   e Zd ZdZd	dd„Zdd„ ZdS )
Úmbox_readonlydira&  A subclass of :class:`mailbox.mbox` suitable for use with mboxs
    insides a read-only mail directory, e.g., ``/var/mail``. Otherwise
    the API is exactly the same as the built-in mbox.

    Deletes messages via truncation, in the manner of `Heirloom mailx`_.

    Args:
        path (str): Path to the mbox file.
        factory (type): Message type (defaults to :class:`rfc822.Message`)
        create (bool): Create mailbox if it does not exist. (defaults
                       to ``True``)
        maxmem (int): Specifies, in bytes, the largest sized mailbox
                      to attempt to copy into memory. Larger mailboxes
                      will be copied incrementally which is more
                      hazardous. (defaults to 4MB)

    .. note::

       Because this truncates and rewrites parts of the mbox file,
       this class can corrupt your mailbox.  Only use this if you know
       the built-in :class:`mailbox.mbox` does not work for your use
       case.

    .. _Heirloom mailx: http://heirloom.sourceforge.net/mailx.html
    NTé   c                 C   s   t j | |||¡ || _d S )N)ÚmailboxÚmboxÚ__init__Úmaxmem)ÚselfÚpathÚfactoryÚcreater   © r   úZ/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/boltons/mboxutils.pyr   H   s    zmbox_readonlydir.__init__c           	   	   C   sÔ  | j s"| jrt | j¡ d| _dS | jdus0J ‚| j dd¡ | j ¡ }|| jkrft 	d| j|f ¡‚| j d¡ t
 ¡ }i }|  |¡ t| j ¡ ƒD ]|}| j| \}}| j |¡ |  |¡ | ¡ }| j td|| j ¡  ƒ¡}|dkrðqü| |¡ qÊ|| ¡ f||< |  |¡ qš| ¡ | _| j d¡ | d¡ | j| jkrX| j | ¡ ¡ n$| d¡}|slq|| j |¡ qX| j ¡  W d  ƒ n1 sœ0    Y  || _d| _ d| _| jrÐtj| jdd dS )	zñWrite any pending changes to disk. This is called on mailbox
        close and is usually not called explicitly.

        .. note::

           This deletes messages via truncation. Interruptions may
           corrupt your mailbox.
        FNr   é   z4Size of mailbox file changed (expected %i, found %i)i   Ú )Zdotlock)Z_pendingZ_pending_syncr   Z_sync_flushÚ_fileZ_tocÚseekÚtellZ_file_lengthZExternalClashErrorÚtempfileÚTemporaryFileZ_pre_mailbox_hookÚsortedÚkeysZ_pre_message_hookÚreadÚminÚwriteZ_post_message_hookr   ÚtruncateZ_lockedZ
_lock_file)	r   Úcur_lenZnew_fileZnew_tocÚkeyÚstartÚstopZ	new_startÚbufferr   r   r   ÚflushL   sX    

þ


ÿ


*zmbox_readonlydir.flush)NTr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r   r   r   r   r   .   s   
r   )r$   r   r   ZDEFAULT_MAXMEMr   r   r   r   r   r   Ú<module>!   s   