diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-31 11:42:24 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-17 10:26:19 +0100 |
| commit | a7d12f9608d1105e5f3d6da6ad6c9f3fa4d9b458 (patch) | |
| tree | f5a3703c60090ed1cd67c7e7b0710e0868838e54 /assets/hooks/mailrules.py | |
| parent | 4161ac9a31e160c0dbdd8b1998a1895fe95dcf93 (diff) | |
| download | qtmaildir-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/mailrules.py')
| -rwxr-xr-x | assets/hooks/mailrules.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/assets/hooks/mailrules.py b/assets/hooks/mailrules.py index e96e0ad..2171c21 100755 --- a/assets/hooks/mailrules.py +++ b/assets/hooks/mailrules.py @@ -42,7 +42,7 @@ DEFAULT_STAGE = 50 # `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", - "move"} + "move", "allow_archive"} # What `move` may say. Mirrors qtmaildirconf.MOVE_ROLES and the C++ reader; # see "Changing the rule format" in AGENTS.md. @@ -63,6 +63,7 @@ class Rule: stage: int = DEFAULT_STAGE enabled: bool = True note: str = "" + allow_archive: bool = False unknown: dict = field(default_factory=dict) @@ -203,6 +204,10 @@ def _rule_to_dict(rule): # Only when set, so a file with no moves is byte-identical after a save. if rule.move: out["move"] = rule.move + # 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 @@ -275,5 +280,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}, ) |
