Skip to content

Commit

Permalink
Merge branch 'main' into textExtract
Browse files Browse the repository at this point in the history
  • Loading branch information
Olthoff231381 committed Sep 2, 2024
2 parents 7666065 + 55e08fb commit 4ebbe08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mailcom/inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
from email.parser import BytesParser
import eml_parser
from pathlib import Path
import os


def list_of_files(directory_name: str) -> list[Path]:
"""Get all the eml files in the directory and put them in a list."""
if not os.path.exists(directory_name): # check if given dir exists raises error otherwise
raise OSError("Path {} does not exist".format(directory_name))
mypath = Path(directory_name)
pattern = [".eml", ".html"] # we would not change the file type through user input
email_list = [mp.resolve() for mp in mypath.glob("**/*") if mp.suffix in pattern]
if len(email_list) == 0:
raise ValueError("The directory {} does not contain .eml or .html files".format(mypath))
raise ValueError("The directory {} does not contain .eml or .html files. Please check that the directory is containing the email data files".format(mypath))
return email_list


Expand Down
3 changes: 3 additions & 0 deletions mailcom/test/test_inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def test_list_of_files_empty(tmp_path):
with pytest.raises(ValueError):
list_of_files(tmp_path)

def test_list_of_files_dir_not_existing():
with pytest.raises(OSError):
list_of_files("nonexistingDir")

def test_list_of_files_correct_format(tmp_path):
p = tmp_path / "test.eml"
Expand Down

0 comments on commit 4ebbe08

Please sign in to comment.