
    :Qg                       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j2                         d        Zej7                          ej8                  de      dd              Zej7                          ej8                  de      dd              ZddZ ddZ!ddZ"ddZ#y)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                      y)zUtility CLI for `python-oxmsg`.

    Provides the subcommands listed below, useful for exploratory or diagnostic purposes.
    N r       F/var/www/html/answerous/venv/lib/python3.12/site-packages/oxmsg/cli.pyoxmsgr      s     	r   msg_file_path)typec                :   t        j                  |       }t        t        |              |j                  D ]  }t        t        |               |j                  D ]<  }|j                  st        d|j                   d       t        t        |              > y)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-.01 __ 2""K},YZ[+A./12r   c                    ddfdt        |       5 }t        j                  |      }ddd       t        dj	                                      y# 1 sw Y   *xY w)z=Summarize low-level "directories and files" structure of MSG.c              3     K   | | j                   xs d  | j                  D ]  }| d|j                      | j                  D ]  } ||dz         E d {     y 7 w)Nrootz    )namestreamsstorages)storageprefixstreamsiter_storage_dump_liness       r   r-   z(storage.<locals>.iter_storage_dump_lines:   sv     /011oo 	/FHD..	/!! 	CA.q&6/BBB	CBs   AA&A$A&N
) )r)   r   r*   strreturnIterator[str])r   r   from_oler   join)r   oleroot_storager-   s      @r   r)   r)   5   sS    
C 
=	! -S'',- 
$))+L9
:;- -s   AAc                      j                   j                   j                   j                   j                   j                  d      }|dn
t	        |      d fd}dj                   |             S )z9A summary of this MS-OXMSG object's top-level properties.i?  Nc               3    K   d d d d d d d dj                   d     d d d	 d
j                    d   dj                    dj                    dj                    d  sd  dt        j                          dt        j                  j                  dd        d d t        j                         y w)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&    """"""!!!!$S%<%<Q%?$@AA((((*3+?+?*@AA*+<*=>>*3+<+<*=>>*3::,77*3==/::*+C*DEE'./@.ABB*4+<*=>>"4::c.A.A!W[#\"]^^  cnn--s   C9C<r.   r1   r2   )rK   rN   _str_prop_encodingint_prop_valuer	   r4   )r   internet_code_pagerO   rL   rM   rN   s   `  @@@r   r   r   G   sk    "~~FF9966v>"*0FGY0Z . .4 99Z\""r   c                <     d fd}dj                   |             S )@Report of message properies suitable for writing to the console.c               3  0  K   d d d d d d d d j                     d j                    d j                    d	 j                    d
 j                  d d d t         j                         y w)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   )
attachments   r   rO   z.dump_attachment_properties.<locals>.iter_linesp   s     %%%%%%((((#J$@$@#ABB#J$8$8#9::#J$<$<#=>>#J$8$8#9::#JOOA#677  j3344s   BBr.   rP   r4   )r\   rO   s   ` r   r   r   m   s    5" 99Z\""r   c                <     d fd}dj                   |             S )rU   c               3     K   d d d d d d d dt         j                          d j                    d d t         j                         y w)	Nr/   rW   zRecipient Propertiesr:   r;   zname:          zemail_address: r?   )rE   r&   email_addressrJ   rK   )	recipients   r   rO   z-dump_recipient_properties.<locals>.iter_lines   sv     %%$$%%((((Y^^ 4566	 7 7899  i2233s   A(A+r.   rP   r]   )ra   rO   s   ` r   r   r      s    4 99Z\""r   c                <     d fd}dj                   |             S )zCA summary of these properties suitable for printing to the console.c            	   3  d  K   d dd dd } |  d |  D ]  }|j                   }|j                  t        j                  t        j                  fv rTt        t        j                  |j                              }t        |      dkD  rt        |      d d dz   n
t        |      }n|j                  t        j                  k(  r5|j                  t        j                  k(  rt        |t              sJ |d d }n}t        |t              rt        |      dd	}n]|j                  t        j                  k(  r@t        |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|   y w)Nz5-----------------------------------------------------+z-----------------------zF----------------------------------------------------------------------zTproperty-id                                          | type                  | value@   z...rX   z bytes   i      i      l      ~    02X 0x04Xz - z<43z | z<21)valueptypcPTYP_STRINGPTYP_STRING8r   r0   str_prop_valuepidlenrE   PTYP_BINARYPID_HTML
isinstancebytesPTYP_INTEGER_32intr&   	ptyp_name)	head_ruleprn   b0b1b2b3selfs          r   rO   z#dump_properties.<locals>.iter_lines   s    haxq1	HH 	PAGGEvv!--88S$"5"5aee"<=47JOUCR(50e1==(QUUajj-@!%///cr
E5)u:a./1,,,!%---T\fn*h&2-j(R/c(!Bs81RHAbX>quuSkQVVCLAKK3DCwOO%	Ps   F-F0r.   rP   r]   )r   rO   s   ` r   rJ   rJ      s    P4 99Z\""r   )r   r0   )r   r
   r1   r0   )r\   r   r1   r0   )ra   r   r1   r0   )r   r   r1   r0   )$__doc__
__future__r   rG   typingr   r   clickolefiler   oxmsg.attachmentr   oxmsg.domainr   rp   oxmsg.domain.encodingsr	   oxmsg.messager
   oxmsg.propertiesr   oxmsg.recipientr   oxmsg.storager   groupr   commandargumentr0   r"   r)   r   r   r   rJ   r   r   r   <module>r      s   
 #  !   ' ' 9 ! ' % ! 	 	 c*2 + 2 c*< + < ##L#.#(#r   