
    Ng]                         d dl Z d dlmZ d dlmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZmZ  G d de          Z G d	 d
e          ZdS )    N)Path)AnyIteratorListUnion)Document)
BaseLoader)UnstructuredFileLoader"satisfies_min_unstructured_versionc                   P     e Zd ZdZ	 d	deeef         dedef fdZde	fdZ
 xZS )
UnstructuredEmailLoadera  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()
    single	file_pathmodeunstructured_kwargsc                     |                     d          }|                     d          }|r|ddlm} ||d<    t                      j        d||d| d S )Nprocess_attachmentsattachment_partitionerr   )	partition)r   r    )getunstructured.partition.autor   super__init__)selfr   r   r   r   r   r   	__class__s          f/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/email.pyr   z UnstructuredEmailLoader.__init__,   s     2556KLL!4!8!89Q!R!R 	F#9#A======<E 89O94OO;NOOOOO    returnc                 
   ddl m}m}  || j                  }||j        k    rddlm}  |d	d| j        i| j        S t          d          r%||j	        k    rddl
m}  |d	d| j        i| j        S t          d| d          )
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_elementsz%UnstructuredEmailLoader._get_elements<   s    NNNNNNNN"?4>22x|##DDDDDD"?WWDNWd>VWWW/88 	X=U=U@@@@@@ =UU$.UD<TUUUSHSSS  r   )r   )__name__
__module____qualname____doc__r   strr   r   r   r   r-   __classcell__)r   s   @r   r   r      s         @ P Pd#P P  #	P P P P P P t        r   r   c                   F    e Zd ZdZdeeef         fdZdee	         fdZ
dS )OutlookMessageLoaderzo
    Loads Outlook Message files using extract_msg.

    https://github.com/TeamMsgExtractor/msg-extractor
    r   c                     t          |          | _        t          j                            | j                  st          d| j         d          	 ddl}dS # t          $ r t          d          w xY w)zqInitialize 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`)r2   r   ospathisfiler+   extract_msgImportError)r   r   r:   s      r   r   zOutlookMessageLoader.__init__V   s     Yw~~dn-- 	PN$.NNNOOO	 	 	 	,  	s   A A2r   c              #      K   dd l }|                    | j                  }t          |j        | j        |j        |j        |j        d          V  |                                 d S )Nr   )sourcesubjectsenderdate)page_contentmetadata)	r:   Messager   r   bodyr>   r?   r@   close)r   r:   msgs      r   	lazy_loadzOutlookMessageLoader.lazy_loadj   s~      !!$.11.;*	 
 
 
 	
 	
 	
 			r   N)r.   r/   r0   r1   r   r2   r   r   r   r   rG   r   r   r   r5   r5   O   sb         %T	"2    (8H-      r   r5   )r7   pathlibr   typingr   r   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser	   1langchain_community.document_loaders.unstructuredr
   r   r   r5   r   r   r   <module>rM      s    				       - - - - - - - - - - - - - - - - - - @ @ @ @ @ @       > > > > >4 > > >B( ( ( ( (: ( ( ( ( (r   