aboutsummaryrefslogtreecommitdiffstats
path: root/assets/hooks/mailrules.py
diff options
context:
space:
mode:
Diffstat (limited to 'assets/hooks/mailrules.py')
-rwxr-xr-xassets/hooks/mailrules.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/assets/hooks/mailrules.py b/assets/hooks/mailrules.py
index dbb80a5..fbd615b 100755
--- a/assets/hooks/mailrules.py
+++ b/assets/hooks/mailrules.py
@@ -41,7 +41,8 @@ DEFAULT_STAGE = 50
# Fields this version understands. Anything else in a rule object is kept in
# `unknown` and written back untouched, which is what makes the file neutral
# rather than this tool's file that another program may read.
-KNOWN_KEYS = {"id", "stage", "enabled", "add", "remove", "query", "note"}
+KNOWN_KEYS = {"id", "stage", "enabled", "add", "remove", "query", "note",
+ "allow_archive"}
# An id is a handle, not a display name: a UI selects on it and a diff tracks
# it. Tags may contain '/' and may be renamed; ids may not.
@@ -57,6 +58,7 @@ class Rule:
stage: int = DEFAULT_STAGE
enabled: bool = True
note: str = ""
+ allow_archive: bool = False
unknown: dict = field(default_factory=dict)
@@ -194,6 +196,10 @@ def _rule_to_dict(rule):
"query": rule.query,
"note": rule.note,
}
+ # Written only where it does something, matching src/tagrules.cpp, so a
+ # file without an archiving rule round-trips unchanged (item 213).
+ if rule.allow_archive and "inbox" in rule.remove:
+ out["allow_archive"] = True
out.update(rule.unknown)
return out
@@ -257,5 +263,6 @@ def _parse_rule(obj, index, seen, warnings):
stage=stage,
enabled=bool(obj.get("enabled", True)),
note=obj.get("note", "") if isinstance(obj.get("note", ""), str) else "",
+ allow_archive=obj.get("allow_archive") is True,
unknown={k: v for k, v in obj.items() if k not in KNOWN_KEYS},
)