forked from Unstructured-IO/unstructured
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
partition_msg
for MSFT Outlook files (Unstructured-IO#412)
* added msg-parser dependency * pass through kwargs in convert_file_to_text * added partition_msg for processing msft outlook files * version bump and changelog * added tests for partition_msg * added test for msg with plain text * add partition_msg docs; fix underlines in integration docs * add .msg to file list * finish tests for auto msg * linting, linting, linting
- Loading branch information
1 parent
e1a8db5
commit 75cf233
Showing
15 changed files
with
194 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
install_requires=[ | ||
"argilla", | ||
"lxml", | ||
"msg_parser", | ||
"nltk", | ||
"openpyxl", | ||
"pandas", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import pathlib | ||
|
||
import msg_parser | ||
import pytest | ||
|
||
from unstructured.documents.elements import ListItem, NarrativeText, Title | ||
from unstructured.partition.msg import partition_msg | ||
|
||
DIRECTORY = pathlib.Path(__file__).parent.resolve() | ||
EXAMPLE_DOCS_DIRECTORY = os.path.join(DIRECTORY, "..", "..", "example-docs") | ||
|
||
EXPECTED_MSG_OUTPUT = [ | ||
NarrativeText(text="This is a test email to use for unit tests."), | ||
Title(text="Important points:"), | ||
ListItem(text="Roses are red"), | ||
ListItem(text="Violets are blue"), | ||
] | ||
|
||
|
||
def test_partition_msg_from_filename(): | ||
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-email.msg") | ||
elements = partition_msg(filename=filename) | ||
assert elements == EXPECTED_MSG_OUTPUT | ||
|
||
|
||
class MockMsOxMessage: | ||
def __init__(self, filename): | ||
self.body = "Here is an email with plain text." | ||
|
||
|
||
def test_partition_msg_from_filename_with_text_content(monkeypatch): | ||
monkeypatch.setattr(msg_parser, "MsOxMessage", MockMsOxMessage) | ||
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-email.msg") | ||
elements = partition_msg(filename=filename) | ||
assert str(elements[0]) == "Here is an email with plain text." | ||
|
||
|
||
def test_partition_msg_raises_with_missing_file(): | ||
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "doesnt-exist.msg") | ||
with pytest.raises(FileNotFoundError): | ||
partition_msg(filename=filename) | ||
|
||
|
||
def test_partition_msg_from_file(): | ||
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-email.msg") | ||
with open(filename, "rb") as f: | ||
elements = partition_msg(file=f) | ||
assert elements == EXPECTED_MSG_OUTPUT | ||
|
||
|
||
def test_partition_msg_raises_with_both_specified(): | ||
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-email.msg") | ||
with open(filename, "rb") as f, pytest.raises(ValueError): | ||
partition_msg(filename=filename, file=f) | ||
|
||
|
||
def test_partition_msg_raises_with_neither(): | ||
with pytest.raises(ValueError): | ||
partition_msg() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.5.7" # pragma: no cover | ||
__version__ = "0.5.8-dev0" # pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.