Merge pull request #3161 from paperless-ngx/fix/issue-3160

Fix: Handle delete mail action with no filters
This commit is contained in:
shamoon 2023-04-25 08:11:23 -07:00 committed by GitHub
commit 08ac40dd48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -381,7 +381,8 @@ def make_criterias(rule):
rule_query = get_rule_action(rule).get_criteria()
if isinstance(rule_query, dict):
return AND(**rule_query, **criterias)
if len(rule_query) or len(criterias):
return AND(**rule_query, **criterias)
else:
return AND(rule_query, **criterias)

View File

@ -612,6 +612,29 @@ class TestMail(
self.assertEqual(len(self.bogus_mailbox.messages), 1)
def test_handle_mail_account_delete_no_filters(self):
account = MailAccount.objects.create(
name="test",
imap_server="",
username="admin",
password="secret",
)
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.MailAction.DELETE,
maximum_age=0,
)
self.assertEqual(len(self.bogus_mailbox.messages), 3)
self.mail_account_handler.handle_mail_account(account)
self.apply_mail_actions()
self.assertEqual(len(self.bogus_mailbox.messages), 0)
def test_handle_mail_account_flag(self):
account = MailAccount.objects.create(
name="test",