Email Rules as Code: Writing Deterministic Workflows for Your Inbox
As a developer, I have written enough email filters to know their ceiling: a checkbox here, a folder dropdown there, and no way to express anything more complex than "move everything from this sender." Real email workflows are not that simple. They are conditionals, combinations, and precedence — the domain of code, not checkboxes.
The good news: the rule engine in Wonder Mail thinks like code. Conditions combine, rules run in order, and the first match wins. If you can write a small if/then block, you can write an email workflow. This post translates the mental model.
Wonder Mail is an inbox cleaner that executes every rule on-device, so your "code" runs locally, instantly, and privately.
The Rule as a Conditional
Every rule is a conditional:
IF <conditions> THEN <actions>
Conditions (can combine):
-
sender.domain = "example.com"— match by sender domain -
keyword = "invoice"— match in subject or body -
date within = "7 days"— match by recency -
has_attachment = true— match by file presence
Actions:
move to foldermark Priorityadd tag
Combining Conditions: AND and OR
Conditions combine with AND and OR semantics:
# OR — catches receipts from anywhere
IF keyword = "receipt" OR keyword = "invoice"
THEN move to Receipts
# AND — only promotional receipts
IF keyword = "receipt" AND sender.domain = "store.com"
THEN move to Receipts, tag Promo
OR widens the net; AND narrows it. Most workflows are a mix of both.
Precedence: The First Match Wins
Rules evaluate in order, and the first matching rule wins. This is the most important design detail — it gives you deterministic behavior:
Rule 1: IF sender.domain = "client-a.com" THEN move to Priority # specific first
Rule 2: IF keyword = "invoice" THEN move to Receipts # general second
A client invoice matches Rule 1 and stops there — it goes to Priority, not Receipts. If Rule 2 came first, the same email would be filed to Receipts and never surface. Order matters exactly like code: specific cases before general cases.
Three Workflows, Written as Code
Workflow 1: The Contract Pipeline
IF keyword = "contract" OR keyword = "agreement"
THEN move to Contracts, mark Priority
Every legal document is filed and surfaced. Nothing unsigned slips through.
Workflow 2: The Document Intake
IF has_attachment = true AND keyword != "receipt"
THEN move to "Files to Review"
Attachments collect for a daily review pass — except receipts, which have their own pipeline. The != (negation) is the part checkboxes never offer.
Workflow 3: The Client Priority Lane
IF sender.domain = "client-a.com" OR sender.domain = "client-b.com"
THEN mark Priority, tag Client
Key clients always surface, even during floods.
The Local Execution Advantage
Here is where the "as code" framing pays off beyond ergonomics: the rules run on your device. No server-side evaluation, no vendor infrastructure in the path, no upload of your mail to make rules work. The semantics of your workflow are executed locally — deterministic, instant, offline-capable.
That means your rules behave identically on a plane, in a tunnel, or at 3 a.m. with the network down. The workflow is a property of your device, not a service.
Debugging Your Rules
Like code, rules need debugging:
- Is a rule over-matching? Narrow it with AND conditions.
- Is a rule never firing? Check precedence — an earlier rule may be swallowing the match.
- Is mail landing wrong? Move the message manually; the correction trains the local model, and the rule set stays inspectable.
Review your rules monthly. The stack compounds: every tuning session makes the next month lighter.
The Takeaway
Email rules are a programming language in miniature — conditionals, combination, precedence, negation. Once you think of them that way, building an automated inbox is like writing a small, well-ordered script: deterministic, testable, and permanently yours.
If your mail client's filter UI has been holding you back, switch to one with a real engine. An inbox cleaner whose rules run like code — locally, in order, on your device — turns inbox automation from a checkbox exercise into a system you can actually reason about.
Top comments (0)