[docs]classUnstructuredEmailLoader(UnstructuredFileLoader):"""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() """
def_get_elements(self)->List:fromunstructured.file_utils.filetypeimportFileType,detect_filetypefiletype=detect_filetype(self.file_path)# type: ignore[arg-type]iffiletype==FileType.EML:fromunstructured.partition.emailimportpartition_emailreturnpartition_email(filename=self.file_path,**self.unstructured_kwargs)# type: ignore[arg-type]elifsatisfies_min_unstructured_version("0.5.8")andfiletype==FileType.MSG:fromunstructured.partition.msgimportpartition_msgreturnpartition_msg(filename=self.file_path,**self.unstructured_kwargs)# type: ignore[arg-type]else:raiseValueError(f"Filetype {filetype} is not supported in UnstructuredEmailLoader.")
[docs]classOutlookMessageLoader(BaseLoader):""" Loads Outlook Message files using extract_msg. https://github.com/TeamMsgExtractor/msg-extractor """
[docs]def__init__(self,file_path:Union[str,Path]):"""Initialize with a file path. Args: file_path: The path to the Outlook Message file. """self.file_path=str(file_path)ifnotos.path.isfile(self.file_path):raiseValueError(f"File path {self.file_path} is not a valid file")try:importextract_msg# noqa:F401exceptImportError:raiseImportError("extract_msg is not installed. Please install it with ""`pip install extract_msg`")