
    dh                         S SK r S SKJr  S SKJrJrJrJr  S SKJ	r	  S SK
Jr  S SKJrJr   " S S\5      r " S	 S
\5      rg)    N)Path)AnyIteratorListUnion)Document)
BaseLoader)UnstructuredFileLoader"satisfies_min_unstructured_versionc                   Z   ^  \ rS rSrSr S
S\\\4   S\S\4U 4S jjjr	S\
4S jrS	rU =r$ )UnstructuredEmailLoader   ag  Load email files using `Unstructured`.

Works with both
.eml and .msg files. You can process attachments in addition to the
e-mail message itself by passing process_attachments=True into the
constructor for the loader. By default, attachments will be processed
with the unstructured partition function. If you already know the document
types of the attachments, you can specify another partitioning function
with the attachment partitioner kwarg.

Example
-------
from langchain_community.document_loaders import UnstructuredEmailLoader

loader = UnstructuredEmailLoader("example_data/fake-email.eml", mode="elements")
loader.load()

Example
-------
from langchain_community.document_loaders import UnstructuredEmailLoader

loader = UnstructuredEmailLoader(
    "example_data/fake-email-attachment.eml",
    mode="elements",
    process_attachments=True,
)
loader.load()
	file_pathmodeunstructured_kwargsc                    > UR                  S5      nUR                  S5      nU(       a  Uc
  SSKJn  XcS'   [        TU ]  " SXS.UD6  g )Nprocess_attachmentsattachment_partitionerr   )	partition)r   r    )getunstructured.partition.autor   super__init__)selfr   r   r   r   r   r   	__class__s          b/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/document_loaders/email.pyr    UnstructuredEmailLoader.__init__,   sT     2556KL!4!8!89Q!R#9#A=<E 89O9O;NO    returnc                 @   SSK JnJn  U" U R                  5      nX1R                  :X  a$  SSKJn  U" S	SU R                  0U R                  D6$ [        S5      (       a3  X1R                  :X  a$  SSK
Jn  U" S	SU R                  0U R                  D6$ [        SU S35      e)
Nr   )FileTypedetect_filetype)partition_emailfilenamez0.5.8)partition_msgz	Filetype z- is not supported in UnstructuredEmailLoader.r   ) unstructured.file_utils.filetyper"   r#   r   EMLunstructured.partition.emailr$   r   r   MSGunstructured.partition.msgr&   
ValueError)r   r"   r#   filetyper$   r&   s         r   _get_elements%UnstructuredEmailLoader._get_elements<   s    N"4>>2||#D"WDNNWd>V>VWW/88X=U@ U$..UD<T<TUUH:%RS r   r   )single)__name__
__module____qualname____firstlineno____doc__r   strr   r   r   r   r.   __static_attributes____classcell__)r   s   @r   r   r      sS    @ Pd#P P  #	P P t  r   r   c                   D    \ rS rSrSrS\\\4   4S jrS\	\
   4S jrSrg)	OutlookMessageLoaderO   zc
Loads Outlook Message files using extract_msg.

https://github.com/TeamMsgExtractor/msg-extractor
r   c                     [        U5      U l        [        R                  R	                  U R                  5      (       d  [        SU R                   S35      e SSKng! [         a    [        S5      ef = f)zYInitialize with a file path.

Args:
    file_path: The path to the Outlook Message file.
z
File path z is not a valid filer   NzNextract_msg is not installed. Please install it with `pip install extract_msg`)r6   r   ospathisfiler,   extract_msgImportError)r   r   r@   s      r   r   OutlookMessageLoader.__init__V   si     Yww~~dnn--z$..)99MNOO	 	, 	s   A A4r    c              #      #    SS K nUR                  U R                  5      n[        UR                  U R                  UR
                  UR                  UR                  S.S9v   UR                  5         g 7f)Nr   )sourcesubjectsenderdate)page_contentmetadata)	r@   Messager   r   bodyrE   rF   rG   close)r   r@   msgs      r   	lazy_loadOutlookMessageLoader.lazy_loadj   s\     !!$..1..;;**	
 	
 			s   A4A6)r   N)r1   r2   r3   r4   r5   r   r6   r   r   r   r   rN   r7   r   r   r   r:   r:   O   s-    %T	"2 (8H- r   r:   )r=   pathlibr   typingr   r   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser	   1langchain_community.document_loaders.unstructuredr
   r   r   r:   r   r   r   <module>rU      s6    	  - - - @>4 >B(: (r   