diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py index d792b5a97..a4a25fa0a 100644 --- a/src/paperless_mail/mail.py +++ b/src/paperless_mail/mail.py @@ -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) != 0 or len(criterias) != 0: + return AND(**rule_query, **criterias) else: return AND(rule_query, **criterias) diff --git a/src/paperless_mail/tests/test_mail.py b/src/paperless_mail/tests/test_mail.py index 1f482f336..4ad79563b 100644 --- a/src/paperless_mail/tests/test_mail.py +++ b/src/paperless_mail/tests/test_mail.py @@ -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",