Merge pull request #3554 from paperless-ngx/fix/issue-3553

Fix: handle mail rules with no filters on some imap servers
This commit is contained in:
shamoon 2023-06-07 13:00:38 -07:00 committed by GitHub
commit 714b2ecd9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -384,6 +384,8 @@ def make_criterias(rule: MailRule, supports_gmail_labels: bool):
if isinstance(rule_query, dict):
if len(rule_query) or len(criterias):
return AND(**rule_query, **criterias)
else:
return "ALL"
else:
return AND(rule_query, **criterias)

View File

@ -721,6 +721,31 @@ class TestMail(
self.assertEqual(len(self.bogus_mailbox.messages), 2)
self.assertEqual(len(self.bogus_mailbox.messages_spam), 1)
def test_handle_mail_account_move_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.MOVE,
action_parameter="spam",
maximum_age=0,
)
self.assertEqual(len(self.bogus_mailbox.messages), 3)
self.assertEqual(len(self.bogus_mailbox.messages_spam), 0)
self.mail_account_handler.handle_mail_account(account)
self.apply_mail_actions()
self.assertEqual(len(self.bogus_mailbox.messages), 0)
self.assertEqual(len(self.bogus_mailbox.messages_spam), 3)
def test_handle_mail_account_tag(self):
account = MailAccount.objects.create(
name="test",