
    ,he"                     "   d dl Zd dlZ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 d dlmZmZ d dlmZ d d	lmZ d d
lmZmZmZmZ  ej<                  e      Z e jC                   ejD                                 G d de      Z#y)    N)decode_utf7)Parser)	constants)
Attachment)os_)DataNotFoundErrorIncompatibleOptionsError)MessageBase)	Recipient)addNumToDirinputToBytesinputToStringprepareFilenamec                   L    e Zd ZdZdedddej                  fdZd Zd	dZ	d Z
y)
Messagez5
    Parser for Microsoft Outlook message files.
     NFc           
      <    t        j                  | |||||||       y )N)r
   __init__)selfpathprefixattachmentClassfilenamedelayAttachmentsoverrideEncodingattachmentErrorBehaviors           U/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/extract_msg/message.pyr   zMessage.__init__   s(    T4(L\^n  qH  	I    c                     t        d       t        d| j                         t        d| j                         t        d       t        | j                         y)z5
        Prints out a summary of the message
        r   zSubject:zDate:zBody:N)printsubjectdatebody)r   s    r   dumpzMessage.dump   s;     	ij$,,'gtyy!gdiir   c           
         |rdnd}||rdndz  }|dkD  rt        d      t        | j                  d      }|dk7  r|dk7  r|}	n|rT| j                  <| j                  j	                  d      j                         j	                  d      d   }	nXt        d	       nL| j                  }
|
 d
j                  |
 }	nd}	| j                  d}nt        | j                        }|	dz   |z   }	|dk7  r|dk7  r|d   dk7  s|d   dk7  r|dz  }|	z   }		 t        j                  	       t        j                         }	 t        j                   |	       g }| j"                  D ]%  }|j%                  |j'                  ||||             ' |rdnd}d}d}t)        d|z   d      5 }|rt+        | j,                  d      t+        | j.                  d      t+        | j0                  d      t+        | j                  d      t+        | j2                  d      |t5        | j6                        d}|j9                  t        t;        j<                  |      d             n|rn|rn|j9                  dt        | j,                  d      z   |z          |j9                  dt        | j.                  d      z   |z          |j9                  dt        | j0                  d      z   |z          |j9                  dt        | j                  d      z   |z          |j9                  dt        | j2                  d      z   |z          |j9                  d|z   |z          |j9                  t        | j6                  d             ddd       t        j                   |       | S # t        $ r" t        	      }||}	nt        d|	z        Y w xY w# 1 sw Y   NxY w# t        $ r}| j?                           d}~ww xY w# t        j                   |       w xY w)a  
        Saves the message body and attachments found in the message. The body and
        attachments are stored in a folder. Setting useFileName to true will mean that
        the filename is used as the name of the folder; otherwise, the message's date
        and subject are used as the folder name.
        Here is the absolute order of prioity for the name of the folder:
            1. customFilename
            2. self.filename if useFileName
            3. {date} {subject}
           r   zOOnly one of the following options may be used at a time: toJson, raw, html, rtfzutf-8Nr   /.zYFilename must be specified, or path must have been an actual path, to save using filenamez&{0:02d}-{1:02d}-{2:02d}_{3:02d}{4:02d}UnknownDatez[No subject] \z7Failed to create directory '%s'. Does it already exist?jsontxtFzmessage.wb)fromtoccr!   r"   attachmentsr#   s   From: s   To: s   CC: s	   Subject: s   Date: s   -----------------) r	   r   crlfr   splitpop
ValueError
parsedDateformatr!   r   osmakedirs	Exceptionr   getcwduchdirr3   appendsaveopenr   senderr1   r2   r"   r   r#   writer-   dumpssaveRaw)r   toJsonuseFileNameraw	ContentId
customPathcustomFilenamecountr4   dirNamedr!   
newDirNameoldDirattachmentNames
attachmentfextuseHtmluseRtffemailObjes                         r   r@   zMessage.save)   s   8  	cq 19*+|}}DIIw/T!n&:$G==,"mm11#6::<BB3GJGsu OO=MFMMqQG+G<<',G-dll;G!C-'1*"2"~$
2$(>c!
 7*G
	KK  ;	HHW O".. ]
&&zy&+WZ'[\] $6DGF j4'. B!(5dkk7(K&3DGGW&E&3DGGW&E+8w+O(5dii(I/>(3DII(> @H GGLH)=wGH	Lg,N NQU UV,tww*H H4 OP,tww*H H4 OP|DLL'/R RUY YZ	LG,L Lt ST 4t ;d BCTYY @A3BB HHV S  	$W-J%$M  	JB B6  	LLN	 HHVsP   
N 4A$O  GN4'O  'N10N14N=9O   	O	OOO" "O9c                    t        j                         }	 d}t        j                  |       t        j                  |       t        j                         }| j	                         D ]  }dj                  |      }|d   dd  }|t        j                  v r|dz   t        j                  |   z   }t        j                  |       t        j                  |       |d   j                  d      rd}nd}t        |d	      5 }|j                  | j                  |             d d d        t        j                  |        	 t        j                  |       y # 1 sw Y   7xY w# t        j                  |       w xY w)
NrH   r'   r+   iz - 001Ezcontents.txtcontentsr/   )r:   r=   r;   r>   listdirjoinr   
PROPERTIESendswithrA   rC   
_getStream)	r   rP   rawDir	sysRawDirdir_sysdircoder   rV   s	            r   rE   zMessage.saveRaw   s-   	FKKHHV

I  $$Bx}9///#e^i.B.B4.HHFF#  8$$V,-H)H (D) 3QGGDOOD123 #'$, HHV3 3 HHVs$   C&E <!EE E	E E6)FFFFNN)__name__
__module____qualname____doc__r   r   ATTACHMENT_ERROR_THROWr   r$   r@   rE    r   r   r   r      sG     ')JSWlq  GK  gp  gG  gG IN` r   r   )$email.utilsemailr-   loggingrecompressed_rtfimapclient.imapclientr   email.parserr   EmailParserextract_msgr   extract_msg.attachmentr   extract_msg.compatr   r:   extract_msg.exceptionsr   r	   extract_msg.message_baser
   extract_msg.recipientr   extract_msg.utilsr   r   r   r   	getLoggerrf   logger
addHandlerNullHandlerr   rk   r   r   <module>r      sn       	  - . ! - ( N 0 + W W 
		8	$   %'%%' (Bk Br   