From 61f65b6f8700d248c6632848063a25beb6777a0f Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Thu, 5 Sep 2024 13:59:33 -0700
Subject: [PATCH] Support include multiple
---
docs/usage.md | 2 +-
src-ui/messages.xlf | 11 +++-----
.../mail-rule-edit-dialog.component.html | 2 +-
src/paperless_mail/mail.py | 25 ++++++++++++++++---
src/paperless_mail/tests/test_mail.py | 6 +++++
5 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/docs/usage.md b/docs/usage.md
index bf45d4982..4a34c95f1 100644
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -137,7 +137,7 @@ These rules perform the following:
Paperless will check all emails only once and completely ignore messages
that do not match your filters. It will also only perform the rule action
on e-mails that it has consumed documents from. The filename attachment
-exclusion pattern can include multiple patterns separated by a comma.
+patterns can include wildcards and multiple patterns separated by a comma.
The actions all ensure that the same mail is not consumed twice by
different means. These are as follows:
diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf
index dfec48f2f..99831c7e4 100644
--- a/src-ui/messages.xlf
+++ b/src-ui/messages.xlf
@@ -3752,22 +3752,19 @@
43
-
- Optional. Wildcards e.g. *.pdf or *invoice* allowed. Case insensitive.
+
+ Optional. Wildcards e.g. *.pdf or *invoice* allowed. Can be comma-separated list. Case insensitive.src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html43
-
-
- Exclude files matchingsrc/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html44
-
- Optional. Wildcards e.g. *.pdf or *invoice* allowed. Can be comma-separated list. Case insensitive.
+
+ Exclude files matchingsrc/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html44
diff --git a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html
index f9c71f5da..a7c0617b0 100644
--- a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html
+++ b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html
@@ -40,7 +40,7 @@
-
+
diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py
index 92c471845..4ecd44659 100644
--- a/src/paperless_mail/mail.py
+++ b/src/paperless_mail/mail.py
@@ -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
diff --git a/src/paperless_mail/tests/test_mail.py b/src/paperless_mail/tests/test_mail.py
index d671021bf..ef359db75 100644
--- a/src/paperless_mail/tests/test_mail.py
+++ b/src/paperless_mail/tests/test_mail.py
@@ -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",