
    ,h)'                         d dl Z d dl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mZmZ  ej                  e      Zej%                   ej&                                 G d dej(                        Zy)	    N)	constants)
Attachment)
Properties)	Recipient)has_leninputToStringwindowsUnicodec                       e Zd ZdZddZddZddZd Zd ZddZ	dd	Z
ed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zej*                  d        Zy)Messagezk
    Developer version of the `extract_msg.message.Message` class.
    Useful for malformed msg files.
    Nc           	         t         j                  ddj                  |             || _        t        j
                  j                  | |       g }|dk7  }|rht        |d      }	 dj                  |      }|j                  dd      }|j                  d      }|d	   dk(  r|j                          |}|d	   dk7  r|dz  }|| _        || _        |r| j#                  |d
d	 dgz   d      }||| _        nt         j                  ddj                  t'        |                   t'        |      rzt)        |      dk  r6|| _        t         j                  ddj                  t)        |                   n=t         j                  ddj                  t)        |                   d
| _        nd
| _        | j*                   g }| j-                         D ]l  }|t)        | j                            j/                  d      s+|t)        | j                            |vsF|j1                  |t)        | j                                   n | j2                   | j4                   | j6                   y
#  t        dt        t        |            z   dz         xY w)z
        :param path: path to the msg file in the system or is the raw msg file.
        :param prefix: used for extracting embedded msg files
            inside the main one. Do not set manually unless
            you know what you are doing.
           z
prefix: {} utf-8/zInvalid prefix type: z7
(This was probably caused by you setting it manually).\Nz__substg1.0_3001Fprefixz':param path: has __len__ attribute?: {}i   z::param path: length is {}; Using :param path: as file pathz?:param path: length is {}; Using :param path: as raw msg stream__recip)loggerlogformat_Message__patholefile	OleFileIO__init__r   join	TypeErrorstrtypereplacesplitpop_Message__prefix_Message__prefixList_getStringStreamfilenamer   lenmainPropertieslistDir
startswithappend
recipientsattachmentsdate)	selfpathr   r'   prefixltmp_conditiongrecipientDirsdir_s	            a/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/extract_msg/dev_classes/message.pyr   zMessage.__init__   sJ    	

1l))&12""4.""673F\&) ^^D#.FS!Au{GbzS ##,,WSb\=O<P-PY^,_H$DMJJqCJJ7SW=YZt}t9t#$(DMJJq"^"e"efijnfo"pqJJq"c"j"jknoskt"uv$(DM $LLN 	CDC))*+66yAT../0E$$T#d.?.?*@%AB	C
 			O\ 7#d6l:K K Z![ \ \s   #I %Jc                     | j                  ||      }| j                  |      r!| j                  |      }|j                         S t        j                  dj                  |             y )NzCStream "{}" was requested but could not be found. Returning `None`.)fix_pathexists
openstreamreadr   infor   )r0   r'   r   streams       r7   
_getStreamzMessage._getStreamN   sT    ==62;;x __X.F;;= KK]ddemno    c                     | j                  ||      }| j                  rt        | j                  |dz   d            S | j                  |dz   d      }|dS |j	                  | j
                        S )z
        Gets a string representation of the requested filename.
        This should ALWAYS return a string (Unicode in python 2)
        001FFr   001EN)r9   areStringsUnicoder	   r?   decodestringEncoding)r0   r'   preferr   tmps        r7   r&   zMessage._getStringStreamW   so     ==62!!!$//(V2Ce/"TUU//(V"3e/DC;4KCJJt7J7J,KKr@   c                 F    | j                  |      }| j                  |      S )zD
        Checks if :param filename: exists in the msg file.
        r9   r:   r0   r'   s     r7   ExistszMessage.Existsd   s!     ==*{{8$$r@   c                 x    | j                  |      }| j                  |dz         xs | j                  |dz         S )zR
        Checks if string stream :param filename: exists in the msg file.
        rB   rC   rJ   rK   s     r7   sExistszMessage.sExistsk   s9     ==*{{8f,-OX=N1OOr@   c                 v    t        |t        t        f      rdj                  |      }|r| j                  |z   }|S )z
        Changes paths so that they have the proper
        prefix (should :param prefix: be True) and
        are strings rather than lists or tuples.
        r   )
isinstancelisttupler   r$   )r0   r'   r   s      r7   r9   zMessage.fix_pathr   s6     hu.xx)H}}x/Hr@   c                 t   | j                  ||      }| j                  dk(  r|S | j                  j                  d      }|d   dk(  r|j                          g }|D ]Z  }d}t	        |      t	        |      k  rd}|r't        t	        |            D ]  }||   ||   k7  sd} |sJ|j                  |       \ |S )z^
        Replacement for OleFileIO.listdir that runs at the current prefix directory.
        r   r   r   TF)listdirr$   r"   r#   r(   ranger,   )	r0   streamsstoragestempr   outxgoodys	            r7   r*   zMessage.listDir~   s     ||GX.==BK$$S)":JJL 		AD1vV$s6{+ %Atvay($% 

1		 
r@   c                     	 | j                   S # t        $ re | j                  j                  d      r4| j                  d   j                  dz  dk7  rd| _         | j                   cY S d| _         | j                   cY S w xY w)zO
        Returns a boolean telling if the strings are unicode encoded.
        340D0003i   r   TF)_Message__bStringsUnicodeAttributeErrorr)   has_keyvaluer0   s    r7   rD   zMessage.areStringsUnicode   s|    
	*))) 	*""**:6''
399GCI-1D*111%*D")))	*s    AA<&A<;A<c                    	 | j                   S # t        $ r g }| j                         D ]l  }|t        | j                           j                  d      s+|t        | j                           |vsF|j                  |t        | j                                  n g | _         |D ]'  }| j                   j                  t        | |             ) | j                   cY S w xY w)z4
        Returns a list of all attachments.
        __attach)_attachmentsr`   r*   r(   r%   r+   r,   r   )r0   attachmentDirsr6   attachmentDirs       r7   r.   zMessage.attachments   s    
	%$$$ 	%N HD--./:::FS!2!234NJ"))$s43D3D/E*FGH
 !#D!/ J!!((D-)HIJ $$$	%    ACC/A(CCc                     	 | j                   S # t        $ r* | j                  j                  | _         | j                   cY S w xY w)z6
        Returns the send date, if it exists.
        )_dater`   _propr/   rc   s    r7   r/   zMessage.date   s9    
	:: 	DJ::	s    0A Ac                     	 | j                   S # t        $ r\ t        | j                  d      | j                  dk(  rt
        j                  nt
        j                        | _         | j                   cY S w xY w)zO
        Returns the Properties instance used by the Message instance.
        z__properties_version1.0r   )rl   r`   r   r?   r$   r   TYPE_MESSAGETYPE_MESSAGE_EMBEDrc   s    r7   r)   zMessage.mainProperties   s`    
	:: 	#DOO4M$N>Bmmr>QI$:$:W`WsWsuDJ::	s    A"A32A3c                     | j                   S )z
        Returns the message path if generated from a file,
        otherwise returns the data used to generate the
        Message instance.
        )r   rc   s    r7   r1   zMessage.path   s     {{r@   c                     | j                   S )za
        Returns the prefix of the Message instance.
        Intended for developer use.
        )r$   rc   s    r7   r   zMessage.prefix   s     }}r@   c                 @    t        j                  | j                        S )zf
        Returns the prefix list of the Message instance.
        Intended for developer use.
        )copydeepcopyr%   rc   s    r7   
prefixListzMessage.prefixList   s     }}T..//r@   c                    	 | j                   S # t        $ r g }| j                         D ]l  }|t        | j                           j                  d      s+|t        | j                           |vsF|j                  |t        | j                                  n g | _         |D ]'  }| j                   j                  t        ||              ) | j                   cY S w xY w)z3
        Returns a list of all recipients.
        r   )_recipientsr`   r*   r(   r%   r+   r,   r   )r0   r5   r6   recipientDirs       r7   r-   zMessage.recipients   s    
	$### 	$M GD--./::9ES!2!234MI!((c$2C2C.D)EFG
  "D - G  ''	,(EFG ###	$ri   c                 p   	 | j                   S # t        $ r | j                  rd| _         | j                   cY S | j                  j	                  d      s*t
        j                  d       d| _         | j                   cY S | j                  d   j                  }t        |      | _         | j                   cY S w xY w)Nz	utf-16-le3FFD0003zlString encoding is not unicode, but was also not specified. Malformed MSG file detected. Defaulting to utf-8r   )	_Message__stringEncodingr`   rD   r)   ra   r   errorrb   r   r0   encs     r7   rF   zMessage.stringEncoding  s    	-((( 	- %%(3%,,, **22:>LL  "P  Q,3D)000))*5;; ),C%,,,!	-s    (B5AB5=5B54B5c                     || _         y )N)r{   r}   s     r7   rF   zMessage.stringEncoding  s
     #r@   )r   N)T)unicodeT)TF)__name__
__module____qualname____doc__r   r?   r&   rL   rN   r9   r*   propertyrD   r.   r/   r)   r1   r   ru   r-   rF   setter r@   r7   r   r      s    
7rL%P
. * * % %,   	 	     0 0 $ $, - -* $ $r@   r   )rs   loggingr   extract_msgr   "extract_msg.dev_classes.attachmentr   extract_msg.propertiesr   extract_msg.recipientr   extract_msg.utilsr   r   r	   	getLoggerr   r   
addHandlerNullHandlerr   r   r   r@   r7   <module>r      s`       ! 9 - + D D			8	$   %'%%' (K$g K$r@   