mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Enhancement: re-work mail rule dialog, support multiple include patterns (#7635)
This commit is contained in:
@@ -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
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user