
    ,h                         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  e j                  e      Zej                   e j                                  G d de      Zy)	    N)	constants)NamedAttachmentProperties)FixedLengthProp)
Properties)verifyPropertyId
verifyTypec                       e Zd ZdZd ZddZd Zd Zd Zd Z	dd	Z
dd
ZddZddZd Zd ZddZed        Zed        Zed        Zed        Zy)AttachmentBasez
    Stores the attachment data of a Message instance.
    Should the attachment be an embeded message, the
    class used to create it will be the same as the
    Message class used to create the attachment.
    c                     t         j                  |        || _        || _        t	        | j                  d      t        j                        | _        t        |       | _
        y)z
        :param msg: the Message instance that the attachment belongs to.
        :param dir_: the directory inside the msg file where the attachment is located.
        z__properties_version1.0N)object__init___AttachmentBase__msg_AttachmentBase__dirr   
_getStreamr   TYPE_ATTACHMENT_AttachmentBase__propsr    _AttachmentBase__namedProperties)selfmsgdir_s      ]/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/extract_msg/attachment_base.pyr   zAttachmentBase.__init__   sI    
 	

!$//2K"LiNgNgh!:4!@    c                     	 t        | |      S # t        $ r7 |r| j                  |      }n| j                  |      }t	        | ||       |cY S w xY w)z
        Ensures that the variable exists, otherwise will set it using the specified stream.
        After that, return said variable.

        If the specified stream is not a string stream, make sure to set :param string stream: to False.
        )getattrAttributeError_getStringStreamr   setattr)r   variablestreamIDstringStreamvalues        r   
_ensureSetzAttachmentBase._ensureSet!   sU    	4** 	--h71D(E*L	s    =AAc                     	 t        | |      S # t        $ r- | j                  j                  |      }t	        | ||       |cY S w xY w)z
        Ensures that the variable exists, otherwise will set it using the named property.
        After that, return said variable.
        )r   r   namedgetNamedValuer   r   r   propertyNamer!   s       r   _ensureSetNamedzAttachmentBase._ensureSetNamed2   sH    
	4** 	JJ,,\:ED(E*L	s    3AAc                     	 t        | |      S # t        $ rD 	 | j                  |   j                  }n# t        t        f$ r d}Y nw xY wt        | ||       |cY S w xY w)z
        Ensures that the variable exists, otherwise will set it using the property.
        After that, return said variable.
        N)r   r   propsr!   KeyErrorr   r&   s       r   _ensureSetPropertyz!AttachmentBase._ensureSetProperty>   sf    
	4** 	

<066n- D(E*L	s/    	A2AAAAAAc                 P    | j                   j                  | j                  |g      S N)r   r   r   r   filenames     r   r   zAttachmentBase._getStreamM   s     zz$$djj(%;<<r   c                 P    | j                   j                  | j                  |g      S )a!  
        Gets a string representation of the requested filename.
        Checks for both ASCII and Unicode representations and returns
        a value if possible.  If there are both ASCII and Unicode
        versions, then :param prefer: specifies which will be
        returned.
        )r   r   r   r/   s     r   r   zAttachmentBase._getStringStreamP   s"     zz**DJJ+ABBr   Nc                     t        |       |j                         }| j                  d|z   |      \  }}|r|S | j                  ||      \  }}|r|S dS )ao  
        Gets the data for the specified id as the type that it is
        supposed to be. :param id: MUST be a 4 digit hexadecimal
        string.

        If you know for sure what type the data is before hand,
        you can specify it as being one of the strings in the
        constant FIXED_LENGTH_PROPS_STRING or
        VARIABLE_LENGTH_PROPS_STRING.
        z__substg1.0_N)r   upper_getTypedStream_getTypedProperty)r   id_typefoundresults        r   _getTypedDatazAttachmentBase._getTypedDataZ   s]     	XXZ,,^b-@%HvM 222u=ME6"6,,r   c                    t        |       t        |       |j                         }|||z   fn| j                  D ]G  }|j	                  |      s| j                  |   }dt        |t              r|j                  fc S |fc S  y)ax  
        Gets the property with the specified id as the type that it
        is supposed to be. :param id: MUST be a 4 digit hexadecimal
        string.

        If you know for sure what type the property is before hand,
        you can specify it as being one of the strings in the
        constant FIXED_LENGTH_PROPS_STRING or
        VARIABLE_LENGTH_PROPS_STRING.
        T)FN)r   r   r3   r*   
startswith
isinstancer   r!   )r   
propertyIDr7   xprops        r   r5   z AttachmentBase._getTypedPropertyn   s     	$5%%'
*/*;*u$& 	YA||J'zz!}Jt_,MdjjXXSWXX	Y r   c                 T    | j                   j                  | j                  |gd|      S )am  
        Gets the contents of the specified stream as the type that
        it is supposed to be.

        Rather than the full filename, you should only feed this
        function the filename sans the type. So if the full name
        is "__substg1.0_001A001F", the filename this function
        should receive should be "__substg1.0_001A".

        If you know for sure what type the stream is before hand,
        you can specify it as being one of the strings in the
        constant FIXED_LENGTH_PROPS_STRING or
        VARIABLE_LENGTH_PROPS_STRING.

        If you have not specified the type, the type this function
        returns in many cases cannot be predicted. As such, when
        using this function it is best for you to check the type
        that it returns. If the function returns None, that means
        it could not find the stream specified.
        T)r   r4   r   )r   r0   r7   s      r   r4   zAttachmentBase._getTypedStream   s&    * zz))4::x*@$NNr   c                 >    | j                   j                  |||       y r.   )r   defineProperty)r   entryr7   names       r   _registerNamedPropertyz%AttachmentBase._registerNamedProperty   s    --eUDAr   c                 P    | j                   j                  | j                  |g      S )zG
        Checks if stream exists inside the attachment folder.
        )r   Existsr   r/   s     r   rH   zAttachmentBase.Exists   s"     zz  $**h!788r   c                 P    | j                   j                  | j                  |g      S )zR
        Checks if the string stream exists inside the attachment folder.
        )r   sExistsr   r/   s     r   rJ   zAttachmentBase.sExists   s"     zz!!4::x"899r   c                 h    | j                   j                  || j                  |d| j                        S )z
        Determines if the stream with the provided id exists. The return of this
        function is 2 values, the first being a boolean for if anything was found,
        and the second being how many were found.
        T)r   ExistsTypedPropertyr   r   )r   r6   r7   s      r   rL   z"AttachmentBase.ExistsTypedProperty   s)     zz--b$**eT4<<XXr   c                     | j                   S )z\
        Returns the directory inside the msg file where the attachment is located.
        )r   r   s    r   dirzAttachmentBase.dir       
 zzr   c                     | j                   S )zI
        Returns the Message instance the attachment belongs to.
        )r   rN   s    r   r   zAttachmentBase.msg   rP   r   c                     | j                   S )zM
        The NamedAttachmentProperties instance for this attachment.
        )r   rN   s    r   namedPropertieszAttachmentBase.namedProperties   s    
 %%%r   c                     | j                   S )zD
        Returns the Properties instance of the attachment.
        )r   rN   s    r   r*   zAttachmentBase.props   s    
 ||r   )Tr.   )__name__
__module____qualname____doc__r   r"   r(   r,   r   r   r:   r5   r4   rF   rH   rJ   rL   propertyrO   r   rS   r*    r   r   r
   r
      s    	A"
=C-((O.B9:Y     & &  r   r
   )loggingextract_msgr   extract_msg.namedr   extract_msg.propr   extract_msg.propertiesr   extract_msg.utilsr   r   	getLoggerrU   logger
addHandlerNullHandlerr   r
   rZ   r   r   <module>re      sQ     ! 7 , - :			8	$   %'%%' (}V }r   