Skip to content

Commit

Permalink
fix: allow deleting even though the rule is not valid. Refs #1305
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Cederstrand committed May 2, 2024
1 parent 1371649 commit 6ed6617
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion exchangelib/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,8 +2302,13 @@ def save(self):

def delete(self):
if self.is_enabled is False:
# Cannot delete a disabled rule - server throws 'ErrorItemNotFound'
# Cannot delete a disabled rule - the server throws 'ErrorItemNotFound'. We need to enable it first.
self.is_enabled = True
# Make sure we can save the rule by wiping all possibly-misconfigured fields
self.priority = 10**6
self.conditions = None
self.exceptions = None
self.actions = Actions(stop_processing_rules=True)
self.save()
self.account.delete_rule(self)

Expand Down
13 changes: 13 additions & 0 deletions tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,19 @@ def test_basic_inbox_rule(self):
rule.delete()
self.assertNotIn(rule.display_name, {r.display_name for r in self.account.rules})

def test_disabled_inbox_rule(self):
# Make sure we can delete a disabled rule
rule = Rule(
account=self.account,
display_name=get_random_string(16),
priority=10**6,
is_enabled=False,
actions=Actions(stop_processing_rules=True),
)
rule.save()
rule.actions = Actions(forward_to_recipients=[[Address()]]) # Test with an invalid action
rule.delete()

def test_all_inbox_rule_actions(self):
for action_name, action in {
"assign_categories": ["foo", "bar"],
Expand Down

0 comments on commit 6ed6617

Please sign in to comment.