
    yiBeK                     F    d Z ddlZddlZdZ G d dej                        Zy)zUseful utilities for working with the `mbox`_-formatted
mailboxes. Credit to Mark Williams for these.

.. _mbox: https://en.wikipedia.org/wiki/Mbox
    Ni  @ c                       e Zd ZdZddZd Zy)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
    Nc                 V    t         j                  j                  | |||       || _        y )N)mailboxmbox__init__maxmem)selfpathfactorycreater	   s        1lib/python3.12/site-packages/boltons/mboxutils.pyr   zmbox_readonlydir.__init__H   s!    dD'6:    c           
      ,   | j                   s3| j                  r&t        j                  | j                         d| _        y| j
                  J | j                  j                  dd       | j                  j                         }|| j                  k7  r$t        j                  d| j                  |fz        | j                  j                  d       t        j                         5 }i }| j                  |       t        | j
                  j                               D ]  }| j
                  |   \  }}| j                  j                  |       | j                  |       |j                         }	 | j                  j!                  t#        d|| j                  j                         z
              }|dk(  rn|j%                  |       X||j                         f||<   | j'                  |        |j                         | _        | j                  j                  d       |j                  d       | j                  | j(                  k  r*| j                  j%                  |j!                                n1	 |j!                  d      }|sn| j                  j%                  |       0| j                  j+                          ddd       | _        d| _         d| _        | j,                  r"t        j.                  | j                  d       yy# 1 sw Y   MxY w)	zWrite 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    )dotlock)_pending_pending_syncr   _sync_flush_file_tocseektell_file_lengthExternalClashErrortempfileTemporaryFile_pre_mailbox_hooksortedkeys_pre_message_hookreadminwrite_post_message_hookr	   truncate_locked
_lock_file)	r
   cur_lennew_filenew_tockeystartstop	new_startbuffers	            r   flushzmbox_readonlydir.flushL   s    }}!! ##DJJ/%*"
 yy$$ 	

1**//#d''',, .G.2.?.?-I.J K K 	

 ##%  	"G""8,diinn./ 2"iint

&&&x0$MMO	!ZZ__S15

8I1I.K LF|NN6*  !*8==?;''12 !)DJJOOAMM!   DKK/

  1%]]40F!JJ$$V,	  JJ!A 	"F 	"<<tzz59 M 	"  	"s   &GL

L)NTi   )__name__
__module____qualname____doc__r   r2    r   r   r   r   .   s    2L:r   r   )r6   r   r   DEFAULT_MAXMEMr   r   r7   r   r   <module>r9      s,   B   !j:w|| j:r   