Enhancement: re-work mail rule dialog, support multiple include patterns (#7635)

This commit is contained in:
shamoon
2024-09-05 15:32:03 -07:00
committed by GitHub
parent e1ba1a1898
commit 4903e4290d
5 changed files with 143 additions and 100 deletions

View File

@@ -686,6 +686,25 @@ class MailAccountHandler(LoggingMixin):
return processed_elements
def filename_inclusion_matches(
self,
filter_attachment_filename_include: Optional[str],
filename: str,
) -> bool:
if filter_attachment_filename_include:
filter_attachment_filename_inclusions = (
filter_attachment_filename_include.split(",")
)
# Force the filename and pattern to the lowercase
# as this is system dependent otherwise
filename = filename.lower()
for filename_include in filter_attachment_filename_inclusions:
if filename_include and fnmatch(filename, filename_include.lower()):
return True
return False
return True
def filename_exclusion_matches(
self,
filter_attachment_filename_exclude: Optional[str],
@@ -728,9 +747,9 @@ class MailAccountHandler(LoggingMixin):
)
continue
if rule.filter_attachment_filename_include and not fnmatch(
att.filename.lower(),
rule.filter_attachment_filename_include.lower(),
if not self.filename_inclusion_matches(
rule.filter_attachment_filename_include,
att.filename,
):
# Force the filename and pattern to the lowercase
# as this is system dependent otherwise

View File

@@ -658,6 +658,12 @@ class TestMail(
exclude_pattern=None,
expected_matches=["f2.png"],
),
FilterTestCase(
"PDF Files with f2 and f3",
include_pattern="f2.pdf,f3*",
exclude_pattern=None,
expected_matches=["f2.pdf", "f3.pdf"],
),
FilterTestCase(
"PDF Files without f1",
include_pattern="*.pdf",