-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f7ead2
commit a7527dd
Showing
1 changed file
with
23 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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. | ||
|
@@ -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 | ||
|