Skip to content

Commit

Permalink
Included changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Olthoff231381 committed Aug 1, 2024
1 parent 2fd9212 commit 5fc0fc9
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
@@ -1,15 +1,17 @@
from email import policy
from email.parser import BytesParser
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 5fc0fc9

Please sign in to comment.