aboutsummaryrefslogtreecommitdiffstats
path: root/assets/hooks/test_mailrules.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-31 11:42:24 +0100
committerDanilo M. <danix@danix.xyz>2026-11-17 10:26:19 +0100
commita7d12f9608d1105e5f3d6da6ad6c9f3fa4d9b458 (patch)
treef5a3703c60090ed1cd67c7e7b0710e0868838e54 /assets/hooks/test_mailrules.py
parent4161ac9a31e160c0dbdd8b1998a1895fe95dcf93 (diff)
downloadqtmaildir-a7d12f9608d1105e5f3d6da6ad6c9f3fa4d9b458.tar.gz
qtmaildir-a7d12f9608d1105e5f3d6da6ad6c9f3fa4d9b458.zip
feat: an optional allow_archive field on a tagging rule
Both readers learn it together, as the rule format requires. No version bump: the field is optional, and each writer emits it only on a rule that removes inbox, so a file without one saves unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'assets/hooks/test_mailrules.py')
-rwxr-xr-xassets/hooks/test_mailrules.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/assets/hooks/test_mailrules.py b/assets/hooks/test_mailrules.py
index 6613fc0..f467783 100755
--- a/assets/hooks/test_mailrules.py
+++ b/assets/hooks/test_mailrules.py
@@ -313,6 +313,41 @@ def test_a_rule_whose_only_action_is_a_bad_move_is_dropped():
assert len(store.warnings) == 2, store.warnings
+def test_allow_archive_round_trips_and_is_omitted_when_false():
+ """Item 213. Known, so not carried as unknown; written only when true."""
+ with tempfile.TemporaryDirectory() as tmp:
+ path = write_rules(tmp, {
+ "version": 1,
+ "rules": [
+ {"id": "promo", "add": ["promo"], "remove": ["inbox"],
+ "query": "from:a@example.com", "allow_archive": True},
+ {"id": "plain", "add": ["x"], "query": "from:b@example.com"},
+ ],
+ })
+ store = mailrules.load(path)
+ assert store.rules[0].allow_archive is True
+ assert store.rules[1].allow_archive is False
+ assert "allow_archive" not in store.rules[0].unknown
+
+ mailrules.save(store, path)
+ raw = json.loads(path.read_text())
+ assert raw["rules"][0]["allow_archive"] is True
+ assert "allow_archive" not in raw["rules"][1]
+
+
+def test_allow_archive_on_a_rule_keeping_inbox_is_accepted_and_ignored():
+ """Never a reason to drop a rule: the hook runs unattended."""
+ with tempfile.TemporaryDirectory() as tmp:
+ path = write_rules(tmp, {
+ "version": 1,
+ "rules": [{"id": "x", "add": ["x"], "query": "from:a@example.com",
+ "allow_archive": True}],
+ })
+ store = mailrules.load(path)
+ assert len(store.rules) == 1
+ assert store.warnings == []
+
+
def run_all():
for name, fn in sorted(globals().items()):
if name.startswith("test_") and callable(fn):