
    ,hT                        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
mZ d dlmZ d dlmZmZmZmZmZ  e j(                  e      Zej/                   e j0                                 G d d	e      Z G d
 de      Z G d de      Zy)    N)	constants)AttachmentBase)NamedAttachmentProperties)FixedLengthPropVariableLengthProp)
Properties)openMsginputToStringprepareFilenameverifyPropertyId
verifyTypec                       e Zd ZdZd Z	 	 ddZ	 	 ddZed        ZeZ	ed        Z
ed        Zed	        Zed
        Zy)
Attachmentz
    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                 Z   t        j                  | ||       | j                  d      rd| _        | j	                  d      | _        y| j                  d      r| j                  d   j                  dz  dk7  rt        d      |j                  |dgz   | _
        d| _        t        | j                  j                  | j                  | j                  |j                  |j                   	      | _        y| j                  d   j                  dz  dk(  rd
| _        t        d      t#        d      )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__substg1.0_37010102dataz__substg1.0_3701000D37050003      ziCurrent version of extract_msg does not support extraction of containers that are not embedded msg files.msg)overrideEncodingattachmentErrorBehaviorwebzAAttachments of type afByWebReference are not currently supported.zUnknown attachment type.N)r   __init__Exists_Attachment__type
_getStream_Attachment__datapropsvalueNotImplementedError
prefixList_Attachment__prefixr	   r   path	__class__r   r   	TypeError)selfr   dir_s      X/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/extract_msg/attachment.pyr   zAttachment.__init__   s   
 	c40 ;;-. DK//*@ADK[[/0

:&,,s2s:)A A !$$8N1O O#%dhhmmT]]DNNgjg{g{  X[  Xs  Xs  tjj$**S0S8DK%&ijj677    Nc                     d }||dk7  r|}nS|r| j                   }|| j                  }|| j                  }|'ddj                  d t	        d      D              z   dz   }t        t        || j                  j                              }||dk7  r|d   dk7  s|d   dk7  r|dz  }||z   }| j                  d	k(  r2t        |d
      5 }|j                  | j                         d d d        |S | j                  ||||||       |S # 1 sw Y   |S xY w)N zUnknownFilename c              3      K   | ]8  }t        j                  t        j                  t        j                  z          : y w)N)randomchoicestringascii_uppercasedigits).0_s     r(   	<genexpr>z"Attachment.save.<locals>.<genexpr>G   s0      #6'( $*==1G1G&--1W#X #6s   >A r   z.bin/\r   wb)cidlongFilenameshortFilenamejoinranger   r
   r   stringEncodingr   openwriter   saveEmbededMessage)	r&   	contentIdjsonuseFileNameraw
customPathcustomFilenamefilenamefs	            r(   savezAttachment.save3   s;    %.B*>%H 88,,---77 #6,1!H#6 668>?
 #=488;R;R#ST!jB&6"~$
2$(>c!
!H,H;;& h% %$%  ##It[#zSab	% s   DDc                 D    | j                   j                  ||||||       y)zh
        Seperate function from save to allow it to
        easily be overridden by a subclass.
        N)r   rJ   )r&   rB   rC   rD   rE   rF   rG   s          r(   rA   zAttachment.saveEmbededMessageY   s     			t[#y*nUr)   c                 &    | j                  dd      S )zI
        Returns the Content ID of the attachment, if it exists.
        _cidz__substg1.0_3712
_ensureSetr&   s    r(   r9   zAttachment.cida   s    
 v'9::r)   c                     | j                   S )z.
        Returns the attachment data.
        )r   rP   s    r(   r   zAttachment.dataj       
 {{r)   c                 &    | j                  dd      S )zM
        Returns the long file name of the attachment, if it exists.
        _longFilenamez__substg1.0_3707rN   rP   s    r(   r:   zAttachment.longFilenameq   s    
 0BCCr)   c                 &    | j                  dd      S )zN
        Returns the short file name of the attachment, if it exists.
        _shortFilenamez__substg1.0_3704rN   rP   s    r(   r;   zAttachment.shortFilenamex   s    
 /1CDDr)   c                     | j                   S )zA
        Returns the (internally used) type of the data.
        )r   rP   s    r(   typezAttachment.type   rR   r)   )FFFFNN)__name__
__module____qualname____doc__r   rJ   rA   propertyr9   
contend_idr   r:   r;   rX    r)   r(   r   r      s    86 dh"$L rv,0V ; ; J  D D E E  r)   r   c                       e Zd ZdZy)BrokenAttachmentzt
    An attachment that has suffered a fatal error. Will not generate from a
    NotImplementedError exception.
    NrY   rZ   r[   r\   r_   r)   r(   ra   ra      s     	r)   ra   c                       e Zd ZdZy)UnsupportedAttachmentz>
    An attachment whose type is not currently supported.
    Nrb   r_   r)   r(   rd   rd      s     	r)   rd   )loggingr-   r/   extract_msgr   extract_msg.attachment_baser   extract_msg.namedr   extract_msg.propr   r   extract_msg.propertiesr   extract_msg.utilsr	   r
   r   r   r   	getLoggerrY   logger
addHandlerNullHandlerr   ra   rd   r_   r)   r(   <module>rp      sv       ! 6 7 @ - c c			8	$   %'%%' (t tp	~ 		N 	r)   