{ "about": "MAIL PREDICATE phase 2 (27 Nov 2026; NEXT-PHASE2-RULES): the cases both readers of mail cuts run, the SQL in Rust (cotton-rules mail/cuts.rs, against SQLite) and the Worker's TypeScript mirror (apps/business src/mail/predicate.ts, vitest). A cut covers mail from its normalised key (an address, @domain, or * for a read cut) sent at or before `before` and landed on the server (landed_at, by the server's clock) at or before `at`, unless its id is in `except`; a deleted cut row (Undo) covers nothing; a mail with no landing time is never covered. Precedence: a newer act on one mail (its id in every covering cut's except) > bin cut > archive cut > read cut. A conversation is live when any of its mails is live; waiting when none is opened. A sealed row not yet opened is waiting. Invented addresses only.", "cases": [ { "name": "a bin cut covers its sender's mail landed on the server up to the cut, and not mail arriving one second after", "bin": [ { "id": "cut-1", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "made_at": "2026-11-20T10:00:00.000Z" } ], "read": [], "archive": [], "mails": [ { "id": "m-old", "thread_id": "t-1", "from_email": " Ada@Example.TEST ", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:05.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "binned", "unread": true, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } }, { "id": "m-at-the-cut", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-20T10:00:00.000Z", "landed_at": "2026-11-20T10:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } }, { "id": "m-one-second-after", "thread_id": "t-2", "from_email": "ada@example.test", "sent_at": "2026-11-20T10:00:01.000Z", "landed_at": "2026-11-20T10:00:01.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "live", "unread": true, "binned_at": null, "archived": false } }, { "id": "m-sent-before-landed-after", "thread_id": "t-2", "from_email": "ada@example.test", "sent_at": "2026-11-19T09:00:00.000Z", "landed_at": "2026-11-20T10:00:01.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "live", "unread": true, "binned_at": null, "archived": false } }, { "id": "m-other-sender", "thread_id": "t-3", "from_email": "bo@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } } ], "threads": [ { "id": "t-1", "state": "binned" }, { "id": "t-2", "state": "live" }, { "id": "t-3", "state": "live" } ] }, { "name": "a domain cut covers that exact domain only; +tag is not folded; a mail brought back stays out", "bin": [ { "id": "cut-2", "key": "@shop.example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": "[\"m-brought-back\"]", "made_at": "2026-11-20T10:00:00.000Z" }, { "id": "cut-2b", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "made_at": "2026-11-20T10:00:00.000Z" } ], "read": [], "archive": [], "mails": [ { "id": "m-domain", "thread_id": "t-1", "from_email": "offers@shop.example.test", "sent_at": "2026-11-18T08:00:00.000Z", "landed_at": "2026-11-18T08:00:00.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "binned", "unread": true, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } }, { "id": "m-brought-back", "thread_id": "t-1", "from_email": "news@shop.example.test", "sent_at": "2026-11-18T08:00:00.000Z", "landed_at": "2026-11-18T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } }, { "id": "m-subdomain", "thread_id": "t-2", "from_email": "news@mail.shop.example.test", "sent_at": "2026-11-18T08:00:00.000Z", "landed_at": "2026-11-18T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } }, { "id": "m-lookalike", "thread_id": "t-3", "from_email": "news@notshop.example.test", "sent_at": "2026-11-18T08:00:00.000Z", "landed_at": "2026-11-18T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } }, { "id": "m-plus-tag", "thread_id": "t-4", "from_email": "ada+news@example.test", "sent_at": "2026-11-18T08:00:00.000Z", "landed_at": "2026-11-18T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } } ], "threads": [ { "id": "t-1", "state": "live" } ] }, { "name": "a cut then undo: the deleted row covers nothing", "bin": [ { "id": "cut-3", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "deleted_at": "2026-11-20T10:00:04.000Z", "made_at": "2026-11-20T10:00:00.000Z" } ], "read": [ { "id": "cut-4", "key": "*", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "deleted_at": "2026-11-20T10:00:04.000Z", "made_at": "2026-11-20T10:00:00.000Z" } ], "archive": [ { "id": "cut-4b", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "deleted_at": "2026-11-20T10:00:04.000Z", "made_at": "2026-11-20T10:00:00.000Z" } ], "mails": [ { "id": "m-undone", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "live", "unread": true, "binned_at": null, "archived": false } } ], "threads": [ { "id": "t-1", "state": "live" } ] }, { "name": "a read cut overlapping a bin cut: binned and read; unread after a read cut stays unread; mail landed after the read is not read", "bin": [ { "id": "cut-5", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-21T09:00:00.000Z", "except": null, "made_at": "2026-11-21T09:00:00.000Z" } ], "read": [ { "id": "cut-6", "key": "*", "before": "2026-11-20T12:00:00.000Z", "at": "2026-11-20T12:00:00.000Z", "except": "[\"m-marked-unread\"]", "made_at": "2026-11-20T12:00:00.000Z" }, { "id": "cut-7", "key": "ada@example.test", "before": "2026-11-19T00:00:00.000Z", "at": "2026-11-19T00:00:00.000Z", "except": null, "made_at": "2026-11-19T00:00:00.000Z" } ], "archive": [], "mails": [ { "id": "m-both", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-18T08:00:00.000Z", "landed_at": "2026-11-18T08:00:00.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-21T09:00:00.000Z", "archived": false } }, { "id": "m-read-by-star", "thread_id": "t-2", "from_email": "bo@example.test", "sent_at": "2026-11-20T11:00:00.000Z", "landed_at": "2026-11-20T11:00:00.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } }, { "id": "m-marked-unread", "thread_id": "t-2", "from_email": "bo@example.test", "sent_at": "2026-11-20T11:00:00.000Z", "landed_at": "2026-11-20T11:00:00.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "live", "unread": true, "binned_at": null, "archived": false } }, { "id": "m-landed-after-the-read", "thread_id": "t-2", "from_email": "bo@example.test", "sent_at": "2026-11-20T11:00:00.000Z", "landed_at": "2026-11-20T12:00:00.001Z", "trashed_at": null, "unread": 1, "expect": { "state": "live", "unread": true, "binned_at": null, "archived": false } } ] }, { "name": "a mail edited after the cut stays covered; its own earlier Bin date wins; a mail with no landing time is never covered; a mail restored after the cut is live", "bin": [ { "id": "cut-8", "key": "@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": "[\"m-restored\"]", "made_at": "2026-11-20T10:00:00.000Z" } ], "read": [], "archive": [], "mails": [ { "id": "m-edited", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 0, "updated_at": "2026-11-22T08:00:00.000Z", "subject": "changed after the cut", "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } }, { "id": "m-binned-before", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": "2026-11-19T20:00:00.000Z", "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-19T20:00:00.000Z", "archived": false } }, { "id": "m-no-landing-time", "thread_id": "t-2", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": null, "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } }, { "id": "m-restored", "thread_id": "t-3", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } } ], "threads": [ { "id": "t-1", "state": "binned" }, { "id": "t-2", "state": "live" } ] }, { "name": "two overlapping bin cuts with the mail excepted from one: the other still bins it", "bin": [ { "id": "cut-9", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": "[\"m-overlap\"]", "made_at": "2026-11-20T10:00:00.000Z" }, { "id": "cut-10", "key": "@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T11:00:00.000Z", "except": null, "made_at": "2026-11-20T11:00:00.000Z" } ], "read": [], "archive": [], "mails": [ { "id": "m-overlap", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T11:00:00.000Z", "archived": false } } ] }, { "name": "archive with bin: a bin cut wins over an archive cut; an archive cut alone archives", "bin": [ { "id": "cut-11", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "made_at": "2026-11-20T10:00:00.000Z" } ], "read": [], "archive": [ { "id": "cut-12", "key": "@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "made_at": "2026-11-20T10:00:00.000Z" } ], "mails": [ { "id": "m-archive-and-bin", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } }, { "id": "m-archive-only", "thread_id": "t-2", "from_email": "bo@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": true } }, { "id": "m-archive-landed-after", "thread_id": "t-3", "from_email": "bo@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-20T10:00:00.001Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } } ], "threads": [ { "id": "t-1", "state": "binned" }, { "id": "t-2", "state": "live" } ] }, { "name": "an upper-case cut key, never written so, covers nothing (its writer normalises)", "bin": [ { "id": "cut-13", "key": "ADA@EXAMPLE.TEST", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "made_at": "2026-11-20T10:00:00.000Z" } ], "read": [], "archive": [], "mails": [ { "id": "m-upper", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } } ] }, { "name": "a sealed row not yet opened is waiting, never live or binned; once opened the cut covers it; a conversation of sealed mail only waits", "bin": [ { "id": "cut-14", "key": "ada@example.test", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "made_at": "2026-11-20T10:00:00.000Z" } ], "read": [ { "id": "cut-15", "key": "*", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "except": null, "made_at": "2026-11-20T10:00:00.000Z" } ], "archive": [], "mails": [ { "id": "m-sealed", "thread_id": "t-sealed", "sealed": true, "data": { "sealed_enc": "s1:invented", "dek_enc": "d1:invented", "seal_v": 1 }, "landed_at": "2026-11-19T08:00:00.000Z", "expect": { "state": "waiting", "unread": null, "binned_at": null, "archived": false } }, { "id": "m-opened", "thread_id": "t-1", "from_email": "ada@example.test", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:00.000Z", "trashed_at": null, "unread": 1, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } } ], "threads": [ { "id": "t-sealed", "state": "waiting" }, { "id": "t-1", "state": "binned" } ] }, { "name": "a Delete's Bin date is when he tapped (made_at), never the newest arrival it covers (at); its 30 days run from made_at", "bin": [ { "id": "cut-q", "key": "quiet@kitebox.example", "before": "2026-10-01T08:00:00.000Z", "at": "2026-10-01T08:00:05.000Z", "made_at": "2026-11-20T10:00:00.000Z", "except": null, "state": "live" } ], "read": [], "archive": [], "mails": [ { "id": "m-quiet", "thread_id": "t-m-quiet", "from_email": "quiet@kitebox.example", "sent_at": "2026-10-01T08:00:00.000Z", "landed_at": "2026-10-01T08:00:05.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } } ] }, { "name": "an undone Delete covers nothing (its state, not its row, says so); an erasing or erased one still covers what it covered", "bin": [ { "id": "cut-u", "key": "undone@kitebox.example", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "made_at": "2026-11-20T10:00:00.000Z", "except": null, "state": "undone" }, { "id": "cut-e", "key": "erased@kitebox.example", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "made_at": "2026-11-20T10:00:00.000Z", "except": null, "state": "erased" }, { "id": "cut-g", "key": "erasing@kitebox.example", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "made_at": "2026-11-20T10:00:00.000Z", "except": null, "state": "erasing" } ], "read": [], "archive": [], "mails": [ { "id": "m-undone", "thread_id": "t-m-undone", "from_email": "undone@kitebox.example", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:05.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } }, { "id": "m-erased", "thread_id": "t-m-erased", "from_email": "erased@kitebox.example", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:05.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } }, { "id": "m-erasing", "thread_id": "t-m-erasing", "from_email": "erasing@kitebox.example", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:05.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } } ] }, { "name": "his own address is never covered: a domain Delete on his work domain leaves his own mail", "own": [ "me@kitebox.example" ], "bin": [ { "id": "cut-d", "key": "@kitebox.example", "before": "2026-11-20T10:00:00.000Z", "at": "2026-11-20T10:00:00.000Z", "made_at": "2026-11-20T10:00:00.000Z", "except": null, "state": "live" } ], "read": [], "archive": [], "mails": [ { "id": "m-mine", "thread_id": "t-m-mine", "from_email": " Me@Kitebox.example", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:05.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": false } }, { "id": "m-theirs", "thread_id": "t-m-theirs", "from_email": "news@kitebox.example", "sent_at": "2026-11-19T08:00:00.000Z", "landed_at": "2026-11-19T08:00:05.000Z", "trashed_at": null, "unread": 0, "expect": { "state": "binned", "unread": false, "binned_at": "2026-11-20T10:00:00.000Z", "archived": false } } ] }, { "name": "times in other shapes are one moment: a cut's at stored as …:00Z and a mail landed at +05:30 are compared normalised", "bin": [], "read": [], "archive": [ { "id": "cut-s", "key": "shapes@kitebox.example", "before": "2026-11-20T10:00:00Z", "at": "2026-11-20T10:00:00Z", "made_at": "2026-11-20T10:00:00Z", "except": null, "state": "live" } ], "mails": [ { "id": "m-shape", "thread_id": "t-m-shape", "from_email": "shapes@kitebox.example", "sent_at": "2026-11-20T15:30:00+05:30", "landed_at": "2026-11-20T15:30:00.000+05:30", "trashed_at": null, "unread": 0, "expect": { "state": "live", "unread": false, "binned_at": null, "archived": true } } ] } ], "keys": [ [ " ADA@Example.TEST ", "ada@example.test" ], [ "bo@example.test ", "bo@example.test" ], [ "ÅSA@EXAMPLE.TEST", "åsa@example.test" ], [ "@Shop.Example.TEST", "@shop.example.test" ], [ "Ada+News@example.test", "ada+news@example.test" ], [ "\t\n", "" ] ], "refused_keys": [ [ "ada@example.test", null ], [ "@shop.example.test", null ], [ "*", null ], [ "@gmail.com", "public_domain" ], [ "@googlemail.com", "public_domain" ], [ "@GMAIL.COM", "not_normal" ], [ " ada@example.test", "not_normal" ], [ "@", "empty" ], [ "@localhost", "not_a_domain" ], [ "@mail.yahoo.co.uk", "public_domain" ], [ "@privaterelay.appleid.com", "public_domain" ], [ "@notgmail.com", null ] ], "times": [ [ "2026-11-20T10:00:00Z", "2026-11-20T10:00:00.000Z" ], [ "2026-11-20T10:00:00.5Z", "2026-11-20T10:00:00.500Z" ], [ "2026-11-20T15:30:00.123456+05:30", "2026-11-20T10:00:00.123Z" ], [ "2026-11-20T10:00:00.999999Z", "2026-11-20T10:00:00.999Z" ], [ "2026-11-20T05:00:00-05:00", "2026-11-20T10:00:00.000Z" ], [ "2026-11-20T10:00:00.000Z", "2026-11-20T10:00:00.000Z" ], [ "2026-11-20T10:00:00", null ], [ "2026-11-20", null ], [ "20 Nov 2026 10:00:00 +0000", null ], [ "2026-11-20 10:00:00Z", null ], [ "2026-11-20T23:59:60Z", null ] ], "cut_at": [ { "shown_landed": [ "2026-11-19T08:00:00.000Z", "2026-11-20T10:00:00Z", null ], "at": "2026-11-20T10:00:00.000Z" }, { "shown_landed": [ null ], "at": null }, { "shown_landed": [], "at": null } ], "check_cut_at": [ { "at": "2026-11-20T10:00:00.000Z", "newest_known": "2026-11-20T10:00:00.000Z", "refused": null }, { "at": "2026-11-20T10:00:00.001Z", "newest_known": "2026-11-20T10:00:00.000Z", "refused": "later_than_known" }, { "at": "2030-01-01T00:00:00.000Z", "newest_known": "2026-11-20T10:00:00.000Z", "refused": "later_than_known" }, { "at": "2026-11-20T10:00:00.000Z", "newest_known": null, "refused": "later_than_known" }, { "at": "2026-11-20T10:00:00Z", "newest_known": "2026-11-21T10:00:00.000Z", "refused": "not_pinned" } ] }