
    Ng                       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j                    d             Ze                                 ej        de          d d                        Ze                                 ej        de          d d                        Zd!dZ d"dZ!d#dZ"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                     dS )zUtility CLI for `python-oxmsg`.

    Provides the subcommands listed below, useful for exploratory or diagnostic purposes.
    N r       E/var/www/html/ai-engine/env/lib/python3.11/site-packages/oxmsg/cli.pyoxmsgr      s	     	Dr   msg_file_path)typestrc                B   t          j        |           }t          t          |                      |j        D ]}t          t          |                       |j        D ]>}|j        st          d|j         d           t          t          |                      ?d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_properties
recipientsdump_recipient_propertiesattachmentsattached_by_value	file_namedump_attachment_properties)r   msgras       r   dumpr#   %   s     ,}
%
%C	$S))
+,,,^ 1 1*1--/0000_ 2 2" 	\ZZZZ[[[+A..011112 2r   c                    ddfdt          |           5 }t          j        |          }d	d	d	           n# 1 swxY w Y   t          d
                     |                               d	S )z=Summarize low-level "directories and files" structure of MSG. storager   prefixr   returnIterator[str]c              3     K   | | j         pd V  | j        D ]}| d|j          V  | j        D ]} ||dz             E d {V  d S )Nrootz    )namestreamsstorages)r&   r'   streamsiter_storage_dump_liness       r   r1   z(storage.<locals>.iter_storage_dump_lines:   s      1/11111o 	/ 	/F........! 	C 	CA..q&6/BBBBBBBBBB	C 	Cr   N
)r%   )r&   r   r'   r   r(   r)   )r   r   from_oler   join)r   oleroot_storager1   s      @r   r&   r&   5   s    
C C C C C C C 
=	!	! -S',,- - - - - - - - - - - - - - - 
$))++L99
:
:;;;;;s   9= =r    r
   r(   c                      j         j         j         j         j                             d          }|dnt	          |          d fd}d                     |                      S )z9A summary of this MS-OXMSG object's top-level properties.i?  Nr(   r)   c               3    K   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           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)_header_prop_valuesattachment_countmessage_classsender	sent_datereprsubjectjsondumpsmessage_headersdump_properties
properties)internet_encodingr    str_prop_encodingstring_props_are_unicodes   r   
iter_linesz+dump_message_properties.<locals>.iter_linesP   s     """"""""""""!!!!!!!!AS%<Q%?AAAAA((((((((A3+?AAAAA>+<>>>>>>3+<>>>>>73:77777:3=:::::E+CEEEEE' 	CB/@BBBBB>4+<+<>>>>>^4:c.A!W[#\#\#\^^^^^    cn-------r   r2   r(   r)   )rK   rN   _str_prop_encodingint_prop_valuer	   r4   )r    internet_code_pagerO   rL   rM   rN   s   `  @@@r   r   r   G   s    "~F966v>>"*0FGY0Z0Z . . . . . . . . .4 99ZZ\\"""r   
attachmentr   c                J     d fd}d                      |                      S )@Report of message properies suitable for writing to the console.r(   r)   c               3     K   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:              ,r?   )r   r   last_modified	mime_typesizerJ   rK   )rT   s   r   rO   z.dump_attachment_properties.<locals>.iter_linesp   s      %%%%%%%%%%%%((((((((BJ$@BBBBB:J$8:::::>J$<>>>>>:J$8:::::7JO777777    j34444444r   r2   rP   r4   )rT   rO   s   ` r   r   r   m   s;    5 5 5 5 5 5" 99ZZ\\"""r   	recipientr   c                J     d fd}d                      |                      S )rV   r(   r)   c               3     K   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%   rX   zRecipient Propertiesr:   r;   zname:          zemail_address: r?   )rE   r,   email_addressrJ   rK   )r^   s   r   rO   z-dump_recipient_properties.<locals>.iter_lines   s      %%%%$$$$%%%%((((((((6Y^ 4 4666669	 799999    i23333333r   r2   rP   r]   )r^   rO   s   ` r   r   r      s;    4 4 4 4 4 4 99ZZ\\"""r   selfr   c                J     d fd}d                      |                      S )zCA summary of these properties suitable for printing to the console.r(   r)   c            	   3  H  K   d dd dd } | V  dV  | V  D ]}|j         }|j        t          j        t          j        fv rjt          t                              |j                            }t          |          dk    rt          |          d d         dz   nt          |          }n|j        t          j        k    r7|j        t          j        k    r"t          |t                    sJ |d d         }nt          |t                    rt          |          dd	}nZ|j        t          j        k    rEt          |t                     sJ |d
z  }|dz  dz	  }|dz  dz	  }|dz  dz	  }|dd|dd|dd|d}d|j        dd|j        dd|j        dd| V  d S )Nz5-----------------------------------------------------+z-----------------------zF----------------------------------------------------------------------zTproperty-id                                          | type                  | value@   z...rY   z bytes   i      i      l      ~    02X 0x04Xz - z<43z | z<21)valueptypcPTYP_STRINGPTYP_STRING8r   r   str_prop_valuepidlenrE   PTYP_BINARYPID_HTML
isinstancebytesPTYP_INTEGER_32intr,   	ptyp_name)	head_rulepro   b0b1b2b3rb   s          r   rO   z#dump_properties.<locals>.iter_lines   s     111111	HHHH 	P 	PAGEv!-888S$"5"5ae"<"<==47JJOOUCRC(500e1=((QUaj-@-@!%/////crc
E5)) ?u::////1,,,!%-----T\fn*h&2-j(R/>>>B>>>R>>>b>>>OquOOOQVOOOAKOOOOOOOOO%	P 	Pr   r2   rP   r]   )rb   rO   s   ` r   rJ   rJ      sA    P P P P P P4 99ZZ\\"""r   )r   r   )r    r
   r(   r   )rT   r   r(   r   )r^   r   r(   r   )rb   r   r(   r   )$__doc__
__future__r   rG   typingr   r   clickolefiler   oxmsg.attachmentr   oxmsg.domainr   rq   oxmsg.domain.encodingsr	   oxmsg.messager
   oxmsg.propertiesr   oxmsg.recipientr   oxmsg.storager   groupr   commandargumentr   r#   r&   r   r   r   rJ   r   r   r   <module>r      s   
 # " " " " "  ! ! ! ! ! ! ! !        ' ' ' ' ' ' ' ' ' ' ' ' 9 9 9 9 9 9 ! ! ! ! ! ! ' ' ' ' ' ' % % % % % % ! ! ! ! ! ! 	 	 	 c***2 2 2 +* 2 c***< < < +* < ## ## ## ##L# # # #.# # # #(# # # # # #r   