mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Merge pull request #680 from paperless-ngx/bug-fix-fnmatch
[bug] - Fixes attachment filename matching during mail fetching
This commit is contained in:
commit
00287b27ab
@ -253,7 +253,7 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
|
|
||||||
return total_processed_files
|
return total_processed_files
|
||||||
|
|
||||||
def handle_message(self, message, rule):
|
def handle_message(self, message, rule) -> int:
|
||||||
if not message.attachments:
|
if not message.attachments:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -285,7 +285,12 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if rule.filter_attachment_filename:
|
if rule.filter_attachment_filename:
|
||||||
if not fnmatch(att.filename, rule.filter_attachment_filename):
|
# Force the filename and pattern to the lowercase
|
||||||
|
# as this is system dependent otherwise
|
||||||
|
if not fnmatch(
|
||||||
|
att.filename.lower(),
|
||||||
|
rule.filter_attachment_filename.lower(),
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
title = self.get_title(message, att, rule)
|
title = self.get_title(message, att, rule)
|
||||||
|
@ -409,18 +409,21 @@ class TestMail(DirectoriesMixin, TestCase):
|
|||||||
_AttachmentDef(filename="f2.pdf"),
|
_AttachmentDef(filename="f2.pdf"),
|
||||||
_AttachmentDef(filename="f3.pdf"),
|
_AttachmentDef(filename="f3.pdf"),
|
||||||
_AttachmentDef(filename="f2.png"),
|
_AttachmentDef(filename="f2.png"),
|
||||||
|
_AttachmentDef(filename="file.PDf"),
|
||||||
|
_AttachmentDef(filename="f1.Pdf"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
("*.pdf", ["f1.pdf", "f2.pdf", "f3.pdf"]),
|
("*.pdf", ["f1.pdf", "f1.Pdf", "f2.pdf", "f3.pdf", "file.PDf"]),
|
||||||
("f1.pdf", ["f1.pdf"]),
|
("f1.pdf", ["f1.pdf", "f1.Pdf"]),
|
||||||
("f1", []),
|
("f1", []),
|
||||||
("*", ["f1.pdf", "f2.pdf", "f3.pdf", "f2.png"]),
|
("*", ["f1.pdf", "f2.pdf", "f3.pdf", "f2.png", "f1.Pdf", "file.PDf"]),
|
||||||
("*.png", ["f2.png"]),
|
("*.png", ["f2.png"]),
|
||||||
]
|
]
|
||||||
|
|
||||||
for (pattern, matches) in tests:
|
for (pattern, matches) in tests:
|
||||||
|
matches.sort()
|
||||||
self.async_task.reset_mock()
|
self.async_task.reset_mock()
|
||||||
account = MailAccount()
|
account = MailAccount()
|
||||||
rule = MailRule(
|
rule = MailRule(
|
||||||
@ -431,11 +434,11 @@ class TestMail(DirectoriesMixin, TestCase):
|
|||||||
|
|
||||||
result = self.mail_account_handler.handle_message(message, rule)
|
result = self.mail_account_handler.handle_message(message, rule)
|
||||||
|
|
||||||
self.assertEqual(result, len(matches))
|
self.assertEqual(result, len(matches), f"Error with pattern: {pattern}")
|
||||||
filenames = [
|
filenames = sorted(
|
||||||
a[1]["override_filename"] for a in self.async_task.call_args_list
|
[a[1]["override_filename"] for a in self.async_task.call_args_list],
|
||||||
]
|
)
|
||||||
self.assertCountEqual(filenames, matches)
|
self.assertListEqual(filenames, matches)
|
||||||
|
|
||||||
def test_handle_mail_account_mark_read(self):
|
def test_handle_mail_account_mark_read(self):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user