Add file deletion *NEEDS TESTS*

This commit is contained in:
Alex Selimov 2025-04-21 22:13:09 -04:00
parent e2698281c4
commit 5fa7e7bde9
2 changed files with 15 additions and 2 deletions

View File

@ -1,10 +1,17 @@
"""Module containing functionality to interact with the filesystem"""
import os
from pathlib import Path
from maildirclean.maildir import MailDir, TopSender
def delete_files(file_list: list[str | Path]):
def delete_all_from_selected_email(selected_senders: list[TopSender], maildir: MailDir):
for sender in selected_senders:
delete_files(maildir.get_paths_for_email(sender.email))
maildir.remove_email(sender.email)
def delete_files(file_list: list[str]):
"""Delete all files in the provided file list
Args:

View File

@ -119,3 +119,9 @@ class MailDir:
]
return senders
def get_paths_for_email(self, email: str) -> list[str]:
return self._df.loc[self._df == email, "path"].to_list()
def remove_email(self, email: str):
self._df.drop(self._df[self._df["email"] == email].index, inplace=True)