a
    ¡˜ëjá  ã                   @  s,  d Z ddlmZ ddlZddlmZmZ ddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ e ¡ dd„ ƒZe ¡ ejded�ddœdd„ƒƒZe ¡ ejded�ddœdd„ƒƒZdddœdd„Z dddœdd„Z!ddd œd!d"„Z"d#dd$œd%d&„Z#dS )'z\The command-line interface (CLI) for `python-oxmsg`.

The CLI provides the command `oxmsg`.
é    )ÚannotationsN)ÚIteratorÚcast)Ú	OleFileIO)Ú
Attachment)Ú	constants)Úencoding_from_codepage)ÚMessage)Ú
Properties)Ú	Recipient)ÚStoragec                   C  s   dS )zUtility CLI for `python-oxmsg`.

    Provides the subcommands listed below, useful for exploratory or diagnostic purposes.
    N© r   r   r   úH/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/oxmsg/cli.pyÚoxmsg   s    r   Úmsg_file_path)ÚtypeÚstr)r   c                 C  sh   t  | ¡}tt|ƒ› ƒ |jD ]}tt|ƒ› ƒ q|jD ]*}|jsTtd|j› d�ƒ tt	|ƒ› ƒ q8dS )z7Write a summary of the MSG file's properties to stdout.zattachment z- is not embedded in message, file unavailableN)
r	   ÚloadÚprintÚdump_message_propertiesZ
recipientsÚdump_recipient_propertiesÚattachmentsÚattached_by_valueÚ	file_nameÚdump_attachment_properties)r   ÚmsgÚrÚar   r   r   Údump%   s    


r   c                   s`   d
ddddœ‡ fdd„‰ t | ƒ�}t |¡}W d  ƒ n1 s@0    Y  td	 ˆ |ƒ¡ƒ dS )z=Summarize low-level "directories and files" structure of MSG.Ú r   r   úIterator[str])ÚstorageÚprefixÚreturnc                 3  sV   |› | j pd› �V  | jD ]}|› d|j › �V  q| jD ]}ˆ ||d ƒE d H  q8d S )NÚrootz    )ÚnameZstreamsZstorages)r!   r"   ÚstreamÚs©Úiter_storage_dump_linesr   r   r)   :   s
    

z(storage.<locals>.iter_storage_dump_linesNÚ
)r   )r   r   Zfrom_oler   Újoin)r   ZoleZroot_storager   r(   r   r!   5   s    
(r!   r	   )r   r#   c                   sT   ˆj j‰ˆj j‰ˆj  d¡}|du r(dnt|ƒ‰ ddœ‡ ‡‡‡fdd„}d |ƒ ¡S )z9A summary of this MS-OXMSG object's top-level properties.iÞ?  Nr    ©r#   c                   3  sö   dV  dV  dV  dV  dV  dV  dV  dˆj d › �V  dV  dV  d	V  d
ˆj› �V  dˆ › �V  dˆj› �V  dˆj› �V  dˆj› �V  dˆ› �V  ˆs®dˆ› �V  dtˆjƒ› �V  dtjˆj	ddd�› �V  dV  dV  t
ˆjƒV  d S )Nr   z------------------zMessage Propertieszheader-propertiesz-----------------zrecipient_count:    é   údistinguished-propertiesú------------------------zattachment_count:         zinternet_code_page:       zmessage_class:            zsender:                   zsent_date:                zstring_props_are_unicode: zstring_props_encoding:    zsubject:                  zmessage_headers:
é   T)ÚindentÚ	sort_keysúother properties)Z_header_prop_valuesZattachment_countZmessage_classZsenderZ	sent_dateÚreprÚsubjectÚjsonÚdumpsZmessage_headersÚdump_propertiesÚ
propertiesr   ©Zinternet_encodingr   Zstr_prop_encodingÚstring_props_are_unicoder   r   Ú
iter_linesP   s0    z+dump_message_properties.<locals>.iter_linesr*   )r9   r;   Z_str_prop_encodingZint_prop_valuer   r+   )r   Zinternet_code_pager<   r   r:   r   r   G   s    ÿr   r   )Ú
attachmentr#   c                   s   ddœ‡ fdd„}d  |ƒ ¡S )ú@Report of message properies suitable for writing to the console.r    r,   c                   3  sŽ   dV  dV  dV  dV  dV  dV  dV  dˆ j › �V  dˆ j› �V  dˆ j› �V  d	ˆ j› �V  d
ˆ jd›�V  dV  dV  tˆ jƒV  d S )Nr   ú---------------------zAttachment Propertiesr.   r/   zattached_by_value: zfile_name:         zlast_modified:     zmime_type:         zsize:              ú,r3   )r   r   Zlast_modifiedZ	mime_typeÚsizer8   r9   r   ©r=   r   r   r<   p   s    z.dump_attachment_properties.<locals>.iter_linesr*   ©r+   )r=   r<   r   rB   r   r   m   s    r   r   )Ú	recipientr#   c                   s   ddœ‡ fdd„}d  |ƒ ¡S )r>   r    r,   c                   3  sf   dV  dV  dV  dV  dV  dV  dV  dt ˆ jƒ› �V  dˆ j› �V  dV  dV  tˆ jƒV  d S )	Nr   r?   zRecipient Propertiesr.   r/   zname:          zemail_address: r3   )r4   r%   Zemail_addressr8   r9   r   ©rD   r   r   r<   ‡   s    z-dump_recipient_properties.<locals>.iter_linesr*   rC   )rD   r<   r   rE   r   r   „   s    r   r
   )Úselfr#   c                   s   ddœ‡ fdd„}d  |ƒ ¡S )zCA summary of these properties suitable for printing to the console.r    r,   c               	   3  sn  d› dd› dd› �} | V  dV  | V  ˆ D �]<}|j }|jtjtjfv r„ttˆ  |j¡ƒ}t	|ƒdkrzt
|ƒd d… d nt
|ƒ}nº|jtjkr¸|jtjkr¸t|tƒsªJ ‚|d d… }n†t|tƒrÔt	|ƒd›d	�}nj|jtjk�r>t|tƒsðJ ‚|d
@ }|d@ d? }|d@ d? }|d@ d? }|d›d|d›d|d›d|d›�}d|jd›d|jd›d|jd›d|› �V  q*d S )Nz5-----------------------------------------------------ú+z-----------------------zF----------------------------------------------------------------------zTproperty-id                                          | type                  | valueé@   z...r@   z byteséÿ   i ÿ  é   i  ÿ é   l      ~ é   Z02Xú Ú0xZ04Xz - z<43z | z<21)ÚvalueZptypÚcZPTYP_STRINGZPTYP_STRING8r   r   Zstr_prop_valueÚpidÚlenr4   ZPTYP_BINARYZPID_HTMLÚ
isinstanceÚbytesZPTYP_INTEGER_32Úintr%   Z	ptyp_name)Z	head_ruleÚprO   Zb0Úb1Úb2Zb3©rF   r   r   r<   ›   s,    
*
"z#dump_properties.<locals>.iter_linesr*   rC   )rF   r<   r   rY   r   r8   ˜   s    r8   )$Ú__doc__Ú
__future__r   r6   Útypingr   r   ZclickZolefiler   Zoxmsg.attachmentr   Zoxmsg.domainr   rP   Zoxmsg.domain.encodingsr   Zoxmsg.messager	   Zoxmsg.propertiesr
   Zoxmsg.recipientr   Zoxmsg.storager   Úgroupr   ÚcommandÚargumentr   r   r!   r   r   r   r8   r   r   r   r   Ú<module>   s0   
&