
    :Qg                        d Z ddlmZ ddlZddlmZmZ ddlm	Z	 ddl
mZmZmZ ddlmZ ej                    G d d	             Zej                    G d
 d             Zy)aF  A "folder" in Microsoft Compound File Binary (CFB) format.

The CFB/OLE file format encloses a filesystem, to a first appoximation, much like a Zip
archive does. In this format, a "storage" corresponds to a directory and a "stream"
corresponds to a file. A storage can contain both streams and other storages.

Each MSG file has a "root" storage, represented in this package by `MessageStorage`.
Each attachment and recipient has their own storage in the root, with a pre-defined
name, and there are other top-level objects than can appear in a MSG file that get their
own storage.
    )annotationsN)IteratorMapping)	OleFileIO)STGTY_STORAGESTGTY_STREAMOleDirectoryEntry)lazypropertyc                      e Zd ZU dZded<   ded<   ded<   ddZe	 d	 	 	 	 	 	 	 dd
       ZddZddZ	e
dd       Ze
dd       ZddZe
dd       Zy	)Storagez'Container for streams and sub-storages.strpathztuple[Stream, ...]streamsztuple[Storage, ...]storagesc                    dt        | j                         dt        | j                         dt        | j                         dS )NzStorage(path=, z
 streams, z
 storages))reprr   lenr   r   selfs    J/var/www/html/answerous/venv/lib/python3.12/site-packages/oxmsg/storage.py__repr__zStorage.__repr__    sC    DO,Bs4<</@.A BDMM"#:/	
    Nc                     |r|nj                   }dd}t         ||            }t         fd|j                  D              }  ||      S )zPReturn a Storage loaded from `node` and containing its streams and sub-storages.c              3    K   d |j                   D        D ]Y  }|r| d|j                   n|j                  }| j                  |      5 }|j                         }ddd       t	        |       [ y# 1 sw Y   xY ww)z4Generate `Stream` object for each stream in `nodes`.c              3  H   K   | ]  }|j                   t        k(  s|  y w)N)
entry_typer   ).0ks     r   	<genexpr>z:Storage.from_ole.<locals>._iter_streams.<locals>.<genexpr>0   s     Ua8TUs   ""/N)kidsname
openstreamreadStream)olenodeprefixstream_noder   fbytes_s          r   _iter_streamsz'Storage.from_ole.<locals>._iter_streams.   sy     U499U +9?&;#3#3"45[EUEU^^D) &QVVXF&T6**	+& &s   AA?	A3A?3A<	8A?c              3     K   | ]G  }|j                   t        k(  r2j                  |r d |j                   n|j                         I yw)r!   N)r   r   from_oler#   )r   r   clsr'   r)   s     r   r    z#Storage.from_ole.<locals>.<genexpr>7   sI      
||}, LLaF81QVVH!5QVVL
s   AA)r   r   r   )r'   r   r(   r	   r)   r   returnzIterator[Stream])roottupler"   )r0   r'   r(   r)   r-   r   sub_storagess   `` `   r   r/   zStorage.from_ole&   sX     t	+ c489 
YY
 

 ,GGr   c              #  n   K   | j                   D ]"  }|j                  j                  d      s| $ yw)zDGenerate storage object specific to each attachment in this message.z__attach_version1.0_#Nr   r#   
startswithr   ss     r   iter_attachment_storagesz Storage.iter_attachment_storages>   s1      	Avv  !89	   +55c              #  n   K   | j                   D ]"  }|j                  j                  d      s| $ yw)zBGenerate storage object specific to each recipent in this message.z__recip_version1.0_#Nr6   r8   s     r   iter_recipient_storageszStorage.iter_recipient_storagesD   s1      	Avv  !78	r;   c                >    | j                   j                  d      d   S )z:The "directory-name" of this storage, with no path-prefix.r!   r   splitr   s    r   r#   zStorage.nameJ        yys#B''r   c                4    | j                   d   j                  S )zDThe bytes of the one-and-only-one properties stream in this storage.z__properties_version1.0_streams_by_namer,   r   s    r   properties_stream_byteszStorage.properties_stream_bytesO   s     $$%>?FFFr   c                B    | j                   d|d|d   j                  S )zCRead variable-length property bytes from the stream it's stored in.z__substg1.0_04XrD   )r   pidptyps      r   property_stream_byteszStorage.property_stream_bytesU   s*    
 $$|C9T#J%GHOOOr   c                V    | j                   D ci c]  }|j                  | c}S c c}w )z*dict semantics on streams of this storage.)r   r#   r8   s     r   rE   zStorage._streams_by_name\   s$     $(<<0a	000s   &r1   r   )N )r'   r   r(   zOleDirectoryEntry | Noner)   r   r1   r   )r1   zIterator[Storage])r1   bytes)rI   intrJ   rP   r1   rO   )r1   zMapping[str, Stream])__name__
__module____qualname____doc____annotations__r   classmethodr/   r:   r=   r
   r#   rF   rK   rE    r   r   r   r      s    1
I!!
 RTHH#;HLOH	H H. ( ( G G
P 1 1r   r   c                  @    e Zd ZU dZded<   ded<   d	dZed	d       Zy)
r&   z;Bytes of a property of a top-level object in an OXMSG file.r   r   rO   r,   c                b    dt        | j                         dt        | j                        ddS )NzStream(path=r   ,z bytes))r   r   r   r,   r   s    r   r   zStream.__repr__i   s,    d499o.bT[[1A!0DGLLr   c                >    | j                   j                  d      d   S )z3The "filename" of this stream, with no path-prefix.r!   r?   r@   r   s    r   r#   zStream.namel   rB   r   NrM   )rQ   rR   rS   rT   rU   r   r
   r#   rW   r   r   r&   r&   b   s)    E
IMM ( (r   r&   )rT   
__future__r   dataclassesdctypingr   r   olefiler   olefile.olefiler   r   r	   
oxmsg.utilr
   	dataclassr   r&   rW   r   r   <module>rd      s_   
 #  $  J J # F1 F1 F1R ( ( (r   