Handle delete mail action with no filters

This commit is contained in:
shamoon 2023-04-24 20:55:01 -07:00
parent 405769dc97
commit 434d1fe225
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() rule_query = get_rule_action(rule).get_criteria()
if isinstance(rule_query, dict): 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: else:
return AND(rule_query, **criterias) return AND(rule_query, **criterias)

View File

@ -612,6 +612,29 @@ class TestMail(
self.assertEqual(len(self.bogus_mailbox.messages), 1) 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): def test_handle_mail_account_flag(self):
account = MailAccount.objects.create( account = MailAccount.objects.create(
name="test", name="test",