
    Ng                        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dS )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d
S )%Storagez'Container for streams and sub-storages.strpathztuple[Stream, ...]streamsztuple[Storage, ...]storagesreturnc                    dt          | j                   dt          | j                   dt          | j                   dS )NzStorage(path=, z
 streams, z
 storages))reprr   lenr   r   selfs    I/var/www/html/ai-engine/env/lib/python3.11/site-packages/oxmsg/storage.py__repr__zStorage.__repr__    sR    /DOO / /s4</@/@ / /DM""/ / /	
    N oler   nodeOleDirectoryEntry | Noneprefixc                     |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.r   r   r   r	   r   r   r   Iterator[Stream]c              3    K   d |j         D             D ]j}|r| d|j         n|j        }|                     |          5 }|                                }ddd           n# 1 swxY w Y   t	          ||          V  kdS )z4Generate `Stream` object for each stream in `nodes`.c              3  :   K   | ]}|j         t          k    |V  d S )N)
entry_typer   ).0ks     r   	<genexpr>z:Storage.from_ole.<locals>._iter_streams.<locals>.<genexpr>0   s.      UUa8T8T8T8T8T8TUUr   /N)kidsname
openstreamreadStream)r   r   r   stream_noder   fbytes_s          r   _iter_streamsz'Storage.from_ole.<locals>._iter_streams.   s      UU49UUU + +9?U&55;#3555[EU^^D)) &QVVXXF& & & & & & & & & & & & & & &T6******	+ +s    A!!A%	(A%	c              3     K   | ]>}|j         t          k                        |r d |j         n|j                  V  ?dS )r(   N)r$   r   from_oler*   )r%   r&   clsr   r   s     r   r'   z#Storage.from_ole.<locals>.<genexpr>7   sh       
 
|},, LLa!KF!5!5QV!5!5!5QVLL,,,,
 
r   )r   r   r   )r   r   r   r	   r   r   r   r!   )roottupler)   )r4   r   r   r   r1   r   sub_storagess   `` `   r   r3   zStorage.from_ole&   s     )tt	+ 	+ 	+ 	+ c48899 
 
 
 
 
 
Y
 
 
 
 

 s,GGGGr   Iterator[Storage]c              #  Z   K   | j         D ] }|j                            d          r|V  !dS )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>   sD       	 	Av  !899 	 	r   c              #  Z   K   | j         D ] }|j                            d          r|V  !dS )zBGenerate storage object specific to each recipent in this message.z__recip_version1.0_#Nr:   r<   s     r   iter_recipient_storageszStorage.iter_recipient_storagesD   sD       	 	Av  !788 	 	r   c                B    | j                             d          d         S )z:The "directory-name" of this storage, with no path-prefix.r(   r   splitr   s    r   r*   zStorage.nameJ        ys##B''r   bytesc                &    | j         d         j        S )zDThe bytes of the one-and-only-one properties stream in this storage.z__properties_version1.0_streams_by_namer0   r   s    r   properties_stream_byteszStorage.properties_stream_bytesO   s     $%>?FFr   pidintptypc                4    | j         d|d|d         j        S )zCRead variable-length property bytes from the stream it's stored in.z__substg1.0_04XrH   )r   rK   rM   s      r   property_stream_byteszStorage.property_stream_bytesU   s)    
 $%GC%G%GT%G%G%GHOOr   Mapping[str, Stream]c                $    d | j         D             S )z*dict semantics on streams of this storage.c                    i | ]
}|j         |S  )r*   )r%   r=   s     r   
<dictcomp>z,Storage._streams_by_name.<locals>.<dictcomp>_   s    000a000r   )r   r   s    r   rI   zStorage._streams_by_name\   s     104<0000r   r   r   )Nr   )r   r   r   r   r   r   r   r   )r   r8   )r   rF   )rK   rL   rM   rL   r   rF   )r   rQ   )__name__
__module____qualname____doc____annotations__r   classmethodr3   r>   r@   r
   r*   rJ   rP   rI   rT   r   r   r   r      s"        11III!!!!
 
 
 
 RTH H H H [H.       ( ( ( \( G G G \G
P P P P 1 1 1 \1 1 1r   r   c                  H    e Zd ZU dZded<   ded<   d
dZed
d            Zd	S )r-   z;Bytes of a property of a top-level object in an OXMSG file.r   r   rF   r0   r   c                ^    dt          | j                   dt          | j                  ddS )NzStream(path=r   ,z bytes))r   r   r   r0   r   s    r   r   zStream.__repr__i   s0    Ld49ooLLT[1A1ALLLLLr   c                B    | j                             d          d         S )z3The "filename" of this stream, with no path-prefix.r(   rB   rC   r   s    r   r*   zStream.namel   rE   r   NrV   )rW   rX   rY   rZ   r[   r   r
   r*   rT   r   r   r-   r-   b   sf         EEIIIMMMM M M M ( ( ( \( ( (r   r-   )rZ   
__future__r   dataclassesdctypingr   r   olefiler   olefile.olefiler   r   r	   
oxmsg.utilr
   	dataclassr   r-   rT   r   r   <module>ri      s  
 
 # " " " " "     $ $ $ $ $ $ $ $       J J J J J J J J J J # # # # # # F1 F1 F1 F1 F1 F1 F1 F1R ( ( ( ( ( ( ( ( ( (r   