Skip to content

Commit

Permalink
docs: Upodate Inbox Rules docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecederstrand committed Mar 3, 2024
1 parent 3f7ead2 commit a7527dd
Showing 1 changed file with 23 additions and 48 deletions.
71 changes: 23 additions & 48 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1902,9 +1902,10 @@ a = Account(...)
print(a.delegates)
```

## InboxRules
## Inbox Rules

An account can have several inbox-rules, which are used to trigger the rule actions for a rule based on the corresponding conditions in the mailbox. Here's how to fetch information about those rules:
An account can have several inbox rules, which are used to trigger the rule actions for a rule based on the corresponding
conditions in the mailbox. Here's how to fetch information about those rules:

```python
from exchangelib import Account
Expand All @@ -1915,7 +1916,7 @@ print(a.rules)

The `InboxRules` element represents an array of rules in the user's mailbox. Each `Rule` is structured as follows:

* `rule_id`: Specifies the rule identifier.
* `id`: Specifies the rule identifier.
* `display_name`: Contains the display name of a rule.
* `priority`: Indicates the order in which a rule is to be run.
* `is_enabled`: Indicates whether the rule is enabled.
Expand All @@ -1928,69 +1929,43 @@ The `InboxRules` element represents an array of rules in the user's mailbox. Eac
Here are examples of operations for adding, deleting, modifying, and querying InboxRules.

```python
from exchangelib import IMPERSONATION, Account

from exchangelib import Account
from exchangelib.properties import Actions, Conditions, Exceptions, Rule

ACCESS_TYPE = IMPERSONATION # Choose one from (IMPERSONATION, DELEGATE)

# Create Account object, set email address, access type and configuration
account = Account(
primary_smtp_address='[email protected]',
access_type=ACCESS_TYPE,
...
)

print("Rules of account before creation:", account.rules, '\n')

# Create rule conditions, sender contains 'sender_example'
conditions = Conditions(
contains_sender_strings=[
"sender_example",
],
)
a = Account(...)

# Create rule actions, automatically delete emails
actions = Actions(
delete=True
)
print("Rules before creation:", a.rules, "\n")

# Create Rule instance
rule = Rule(
display_name='test_exchangelib_rule',
display_name="test_exchangelib_rule",
priority=1,
is_enabled=True,
conditions=conditions,
conditions=Conditions(contains_sender_strings=["sender_example"]),
exceptions=Exceptions(),
actions=actions,
actions=Actions(delete=True),
)

# Create rule
rule_id = account.create_rule(rule)
a.create_rule(rule)
print("Rule:", rule)
print("Created rule with ID:", rule_id, '\n')
print("Created rule with ID:", rule.id, "\n")

if rule_id:
# Get rule list
print("Get Rules of account after creation:", account.rules, '\n')
# Get rule list
print("Rules after creation:", a.rules, "\n")

# Modify rule
rule.rule_id = rule_id
rule.display_name = 'test_exchangelib_rule(modified)'
res = account.set_rule(rule)
print("Modified rule with ID:", rule.rule_id)
print("Response:", res.text if hasattr(res, 'text') else res)
print("Rules of account after modification:", account.rules, '\n')
# Modify rule
print("Modifying rule with ID:", rule.id)
rule.display_name = "test_exchangelib_rule(modified)"
a.set_rule(rule)
print("Rules after modification:", a.rules, "\n")

# Delete rule
res = account.delete_rule(rule=rule)
print("Deleted rule with ID:", rule.rule_id)
print("Response:", res.text if hasattr(res, 'text') else res)
print("Rules of account after deletion:", account.rules)
# Delete rule
print("Deleting rule with ID:", rule.id)
a.delete_rule(rule=rule)
print("Rules after deletion:", a.rules)
```

Please note that the response for creating/modifying/deleting rules does not contain the corresponding `rule_id`.

## Export and upload

Exchange supports backup and restore of folder contents using special
Expand Down

0 comments on commit a7527dd

Please sign in to comment.