Skip to content

#2057: rules kept on an IMAP server in Sieve: MailCraft's script, the owner's own, webmail filters, Change Rule - #2108

Draft
linuxrrze wants to merge 56 commits into
UCSLabs:mainfrom
linuxrrze:sieve/3-rules
Draft

linuxrrze wants to merge 56 commits into
UCSLabs:mainfrom
linuxrrze:sieve/3-rules

Conversation

@linuxrrze

@linuxrrze linuxrrze commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #2106, #2107

Part 3 of 4 of #2057: rules kept on an IMAP account's server, in Sieve. It builds on part 2
(sieve/2-replies, #2107), which builds on part 1 (#2106). Until those are merged, this
diff against main includes them too. This part's own changes are the commits after part 2's head.
Rules and Alerts keeps its current layout here. The relayout comes last, in #2058.

Part of #2057, which the last part (#2058) closes.

What it does for the person using MailCraft

  • Rules kept on the server for IMAP accounts whose server keeps Sieve scripts, as for Microsoft
    accounts. A rule goes into MailCraft's script, after the Automatic Replies, when Sieve can do all
    of it:

    • conditions: the sender's and recipients' words and addresses, words in the subject or body, mail
      to you, size;
    • actions: move, copy, delete, mark as read, flag, clear the flag, stop processing.

    It then runs while MailCraft is closed. Any other rule stays on this computer, and Rules and
    Alerts says which part keeps it there. Two rules that move mail to different folders, the first
    not stopping processing, both stay on this computer (the server would file a message both match
    into both folders), and each names the other rule and both folders; asked for the server
    explicitly, they are refused with that text. A rule kept in MailCraft's script looks for the sender's
    and recipients' words in their addresses, as on Microsoft accounts.

  • Rules and Alerts says what keeps them off the server. No ManageSieve; no fileinto; the
    owner's own script runs instead; or MailCraft's script was changed elsewhere, then with
    Replace with MailCraft's (the owner's click only, bound to the script the owner saw).

  • The rules of the owner's own Sieve script (made in webmail or another program) are listed under
    the script's name:

    • with their names (Roundcube's # rule:[…], RainLoop's and SnappyMail's filter names);
    • header tests shown as words in the message header (an exact one as "exactly");
    • a rule the script switches off shown off;
    • what MailCraft has no name for named by its Sieve command.

    File › Info says when that script sends the automatic replies itself.

  • Change Rule (rules.edit) follows main's rule-editing model from Reules edit #1177. There is one edit
    path: main's rules.edit, rule_for_edit and the editor's "send only what changed" Save. A change
    names only the parts it changes (name, conditions, exceptions, actions); every other part stays as
    it was. The pencil beside a rule, or a double click, opens the rule builder filled in. Save changes
    the rule in place, keeping its place in the order and whether it is on. On a Sieve account:

    • a rule of MailCraft's script is written again in that script. Sieve rewrites the whole script,
      so the rule is checked whole, as a new one is (what Sieve can't say keeps it on this computer,
      with why);
    • a rule of the owner's own script (made in webmail or another program) is written part by part.
      A new name alone rewrites only its # rule:[…] comment and leaves its if byte for byte. A
      changed condition, exception or action rewrites its if, with the parts the change didn't name
      taken from the script as read;
    • a RainLoop / SnappyMail filter is written part by part too. Its name, condition and folder each
      come from the change only when the change names them, and otherwise from the filter's settings as
      read (" YES " and all). A filter with settings MailCraft doesn't know is still read-only.

    A rule a Microsoft account's server keeps is changed as main changes it. This part's earlier own
    edit path, which refused those rules and replaced a rule whole, is gone.

  • Sieve rules (rules.addSieve, rules.editSieve): a rule written in Sieve itself, for what the
    builder can't say. It is kept in its place in MailCraft's script, and its requires are joined
    into the script's one require. It is checked first with part 1's local check and never run here.

  • The Sieve editor (Rules and Alerts › Advanced… › New Sieve rule…, or the pencil on a Sieve
    rule) has line numbers. Mistakes are marked and listed as you type, and a click on one goes there.
    Check asks the server's CHECKSCRIPT inside MailCraft's whole script and gives the line numbers
    as the rule's own. Save waits while there is a mistake.

  • The owner's own active script, edited whole (Advanced… › Edit your Sieve script…,
    sieve.ownScript / sieve.putOwnScript). It is written back exactly as typed (CRLF kept), only
    while the server's script is still the one read and still active, and where HAVESPACE says there
    is room. Otherwise nothing is written, and Reload reads it again.

  • RainLoop / SnappyMail filters changed in place. Each filter is a rule you can change, switch
    on or off, move or delete, and New Filter… adds one. The filter's settings (base64 JSON) and its
    Sieve are written together in the webmail's own shape, and the rest of the script is left byte for
    byte. A filter with settings MailCraft doesn't know, or one changed by hand, is shown read-only
    with why.

  • Every rule of a Sieve account can be changed. The builder is used when it loses nothing, and
    otherwise the rule's own Sieve text (sieve.ownBlock, sieve.putOwnBlock). Only that rule's bytes
    are replaced, in the text whose digest was read, and an extension it needs joins require. Edit
    as Sieve… is in a row's menu. One of MailCraft's own rules that the builder can't show is edited
    as Sieve and kept as a Sieve rule from then on (rules.toSieve).

  • Agents. Every new command has an approval class, read from part 1's table. An agent's Sieve
    rule, or a change of the owner's script, is asked about as a send when it can send mail or
    answer a sender (redirect, vacation, reject, ereject, notify, report, include), when
    it hands mail to a program (pipe, filter, execute), when it uses a command not known, or when
    it can't be read. A word in a string or a comment is no command. Sieve that only changes messages
    (addheader, deleteheader, replace, enclose) is asked as settings, and the question says so.
    The question shows the agent's Sieve as its own text, never as an instruction. A change to a
    webmail filter that files into Deleted Items is asked as a delete. A builder or editor with an
    unsaved draft in Rules and Alerts is reported to the agent gate as unsaved.

Specs it follows

  • Sieve: RFC 5228 (address, header, size, fileinto, stop, allof/anyof, comments),
    copy (RFC 3894), imap4flags (RFC 5232), body (RFC 5173), and the other extensions of part 1's
    table for Sieve rules and the owner's script.
  • ManageSieve: RFC 5804, CHECKSCRIPT and HAVESPACE, through part 1's client.
  • The RainLoop / SnappyMail filter shape (a # RAINLOOP:SIEVE line, each filter's settings as base64
    JSON in a comment before its Sieve) is the shape those webmails write. The tests use synthetic
    scripts in that shape.

How it was tested

  • Never against a real mailbox. Host flow tests drive the window through the desktop app's Sieve job
    to the fake ManageSieve server on loopback, with invented rules, scripts and a synthetic
    SnappyMail-shaped script.
  • Engine unit and property tests: sieve_rules, sieve_elsewhere, sieve_own, sieve_blocks,
    rules_sieve, rules_webmail, rules_edit_sieve (the stack's Change Rule tests, moved beside main's rules_edit tests, which pass unchanged), sieve_effects, sieve_rainloop. New: one part of a webmail filter or of a rule of the owner's own script changed with every other part kept byte for byte, a part a filter can't have refused, an edit that names nothing writing nothing.
    hostile_params_never_panic runs the new commands with junk Sieve, digests and ids. Model tests
    cover the header condition.
  • kittest UI tests for Rules and Alerts, the builder, the Sieve editor (inline, in the current
    layout) and the webmail filters.
  • It has not yet been tried against a real ManageSieve server, nor against a real webmail's
    script.
  • cargo xtask ci passes on this branch: all 14 steps (fmt, assets, spdx, test-files, workflows, layers, wasm-clock, i18n, release-notes, docs-log, clippy, test, wasm, deny).

Known limits (this part's share)

  • Only rules Sieve can say exactly go to the server. Outlook's other conditions and actions stay on
    this computer, with why.
  • A rule of the owner's own script is changed in the builder only when the Sieve it writes is the
    same tests, match types, comparators and actions. Otherwise it is changed as its Sieve text.
    Deleting, moving and switching off such a rule are left to the script's text.
  • A RainLoop/SnappyMail filter with settings MailCraft doesn't know is changed as its Sieve alone.
    The webmail may put its own version back, and the editor warns about that.
  • RFC 5804 has no conditional PUTSCRIPT: every write of MailCraft's or the owner's script is checked
    just before it is made. That narrows, but can't close, the moment in which a change made elsewhere
    is written over.
  • A word with a semicolon in it isn't shown in the rule builder, as on main (Reules edit #1177), so such a rule
    is changed as its Sieve text on a Sieve account. JMAP's Sieve is still to come (Full Stalwart support: shared mailboxes, Sieve, and two-way calendars and contacts over JMAP #1722).

Docs

docs/mcp.md (approval classes), docs/mail-privacy-rules.md, docs/gaps.md, ROADMAP.md,
docs/ui-parity.md (Rules and Alerts as it is laid out here) and docs/parity-checklist.md.
Progress, revision and release-note fragments, and the translation catalogues (cargo xtask i18n;
new texts as fuzzy drafts).

Human-reviewed, AI-assisted, nobody's mailbox harmed.

The groundwork of Rules and Automatic Replies kept on an IMAP server in
Sieve; nothing in the window uses it yet.

- proto::managesieve: a ManageSieve client (RFC 5804) over any Read + Write
  stream: capabilities, STARTTLS, SASL PLAIN (RFC 4616) or XOAUTH2 /
  OAUTHBEARER (RFC 7628), LISTSCRIPTS, GETSCRIPT, PUTSCRIPT, CHECKSCRIPT,
  SETACTIVE, DELETESCRIPT, HAVESPACE, LOGOUT. A referral is never followed;
  a script's name is quoted and its text sent as a counted literal; every
  line, string, response and count is bounded, a listing that can't be kept
  whole is refused and one command keeps at most a megabyte.
- net::sieve: an IMAP account's Sieve scripts on its IMAP host, port 4190,
  or on the host and port named for it (Account::sieve_host, sieve_port),
  over STARTTLS only (plain only to loopback, for the tests); the sign-in
  goes to those hosts alone. write replaces MailCraft's script only while
  it is still what MailCraft last wrote there (SHA-256 digest) and never
  makes another script inactive; write_own writes the owner's own script
  back only while it is still the one read and active, after HAVESPACE.
  When no session can be had it says what it found (Reach), naming the
  host and port, telling a port that expects TLS from the first byte by a
  TLS hello on a connection of its own. A fake ManageSieve server for the
  tests (fake_sieve.rs).
- engine::sieve: the bounded Sieve reader (RFC 5228 tokens and comments,
  with where each is and why a text stops being Sieve) and quoting;
  engine::sieve_check: a whole script, or a block for MailCraft's script,
  checked with a line and column for each problem, from one table of the
  commands, tests and tags of RFC 5228 and its extensions, with what each
  needs and what it can do.
- Fuzz targets managesieve and sieve_check, in fuzz.yml; property tests.
- Docs: architecture (proto, net), mail privacy rules (where Sieve scripts
  go); progress and revision fragments; translation catalogues.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
- engine::sieve: MailCraft's own script, "mailcraft", written from the
  replies (vacation, RFC 5230; a time range as currentdate, RFC 5260, with
  relational's :value, RFC 5231; inside the organisation by the address's
  domain) and read back; every value one quoted string, so no reply,
  address or domain changes the script's shape (property tests).
- Account::sieve_written keeps the digest of what MailCraft last wrote,
  never the text (sha2, in the browser too). account.automaticReplies and
  account.setAutomaticReplies take IMAP accounts; sync.applySieve (host
  only) takes in what the server has. A script changed elsewhere is never
  written over unless the owner chooses Replace with MailCraft's, bound to
  the script as seen; the owner's own active script stays active;
  contactsOnly and, without date tests, a time range are refused.
- account.edit's sieve: another ManageSieve host or port (Account
  Settings › Sieve server); what was known of the server before is
  forgotten when it changes.
- The window: File › Info's line and Try again, the Automatic Replies
  dialog in its Sieve shape, the status bar only while MailCraft's script
  is the one running; what was found where the server was looked for is
  said, naming the host and port. The desktop app's Sieve job runs on a
  background thread (sieve_job.rs); flow tests through it to the fake
  server.
- Docs: ROADMAP item 11, gap 17, ui-parity Backstage, mail privacy rules;
  fragments and release note; translation catalogues.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
In the current Rules and Alerts layout; the relayout comes in UCSLabs#2058.

- Rules an IMAP account's server can keep go into MailCraft's script after
  the replies, one block each, when Sieve says them exactly (sender's,
  recipients', subject's and body's words and addresses, mail to me, size;
  move, copy, delete, mark as read, flag, clear the flag, stop); the others
  stay on this computer, saying which part. sync.sieveScript says what the
  script is to become; Rules and Alerts says what keeps them off the server,
  with Replace with MailCraft's.
- The owner's own active script (and MailCraft's once changed elsewhere)
  read with a bounded parser and its rules listed under its name, with
  webmail names, header tests and switched-off rules (sieve_elsewhere,
  sieve_rainloop; Condition::Header in the model).
- Change Rule (rules.edit), Sieve rules (rules.addSieve, rules.editSieve),
  the Sieve editor with the local check and the server's CHECKSCRIPT, the
  owner's script edited whole (sieve.ownScript, sieve.putOwnScript),
  RainLoop/SnappyMail filters changed in place (rules_webmail), every rule
  changed in the builder when that loses nothing, else as its Sieve
  (sieve.ownBlock, sieve.putOwnBlock, rules.toSieve).
- Agents: every new command has a class; Sieve that sends, answers, runs a
  program, is unknown or unreadable asks as send, from sieve_check's table.
- Tests: engine, model, flow tests to the fake server, kittest tests of the
  builder and the Sieve editor inline; hostile_params_never_panic covers
  the new commands.
- Docs: mcp, mail privacy rules, gaps, ROADMAP, ui-parity, parity
  checklist (Change Rule); fragments and release notes; translations.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
…r and its tests tightened

From CodeRabbit's review of UCSLabs#2058:
- The probe that tells a silent server reads on until it has the two
  bytes a TLS record begins with, within the same wait, when the first
  read brings one.
- The fake server keeps the first bytes across reads before answering a
  TLS hello, says the same capabilities in its greeting and on
  CAPABILITY (SASL and STARTTLS only before sign-in, VERSION only when
  set), refuses a literal larger than any script before allocating, and
  answers PUTSCRIPT with its configured warnings.
- It keeps what each connection that isn't greeted received, and the
  tests of servers that don't greet assert that the first connection got
  nothing and a second one only a TLS hello, without the password.
- The password test asserts that nothing was sent to a server offering
  no password mechanism.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
…es need variables, exact server names

From CodeRabbit's review of UCSLabs#2058:
- `:last` without `:index` is an error (RFC 5260).
- setflag, addflag, removeflag and hasflag with their variable need
  `variables` (RFC 5232); with the flags alone `imap4flags` is enough.
- Every required extension, known here or not, is looked for on the
  server by its exact name; one rule says what gives what (spamtestplus
  gives spamtest, vacation-seconds gives vacation), and a block needing
  spamtestplus no longer needs spamtest too.
- What each `ihave` in an `allof` names counts in its block (not in
  `anyof`, nor under `not`).
- After a tag not known here, in a whole script requiring an extension
  MailCraft doesn't know, the positional count is left to the server.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 1 with main merged in, and its fixes after CodeRabbit's review.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 1 with main merged in, and its fixes after CodeRabbit's review.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
…aren't kept on the server

As the maintainer suggested on UCSLabs#2058, and as the owner decided: two rules
of an IMAP account meant for the server (switched on, made in the form,
each one Sieve can say) that move mail to different folders, the first
of them not stopping the rules after it, are not written to the server's
script. There a message both match would be filed into both folders,
where MailCraft ends with it in one. Both run on this computer.

- `sieve_rules::folder_clash` says which other rule and which folders;
  `server_cannot` gives NotOnServer::FolderClash, and
  `not_on_server_said` the full text, naming both rules and both folders.
- Rules and Alerts says it under each rule, and the builder of a new one;
  `rules.list` and `rules.edit` say it as "why" for agents.
- Asked for the server explicitly (`rules.add`/`rules.edit` with
  "server": true, `rules.keepOnServer`), the command fails with the same
  text. Otherwise the rule stays meant for the server, and goes there
  once the other one stops, moves into the same folder, is switched off
  or deleted.
- Delete counts as a move to Deleted Items; copies, and Sieve rules the
  owner wrote, are left out.

Tests: two_rules_moving_one_message_to_different_folders_both_run_here_and_say_which
(engine) and each_rule_says_which_other_rule_and_folders_keep_both_off_the_server
(kittest). Gap 17, its revision row and the release note say so.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
…the Sieve editor and their tests

From CodeRabbit's review of UCSLabs#2058:
- An agent's question shows Sieve text as it is: each line with its
  spaces at both ends, blank lines too, joined by ⏎.
- The builder lets go of a rule deleted by another command on the next
  frame, not only after a command of its own.
- A filter of a webmail's script is offered only its own account's
  folders, and another can't be saved.
- The Sieve editor paints the gutter for the rows in view only.
- Tests: a property over canonical webmail filters that requires the
  save to succeed and the bytes to stay; Edit as Sieve… reached through
  the row's right-click menu; the no-owner-script case on a server with
  MailCraft's script alone; the cursor at the problem's line and column.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 1 with main merged in, and its fixes after CodeRabbit's review.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 2 with part 1 and main merged in.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
…the owner's script

Part 1's check now looks for every required extension on the server, known
here or not. The owner's whole script still refuses only a known extension
the server lacks: one MailCraft doesn't know stays a warning, as its contract
says (sieve_own_tests covers both).

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…nse codes, a broken session sends nothing

CodeRabbit on UCSLabs#2106:
- A listing with more than one ACTIVE script is refused (RFC 5804 has at most one).
- An unknown response code's arguments are passed over whole, lists nested in them and all
  (RFC 5804 §4 extension-data); unbalanced parentheses are still an error.
- After an answer that wasn't read to its end (too many lines, too long, unreadable, BYE), or a
  command that couldn't be sent, the session is broken and sends nothing more: a later command
  would take the leftover OK for its own. A whole NO, or a name refused before sending, leaves it
  usable.
- LOGOUT: a NO or a garbled answer is an error, and so is a LOGOUT that couldn't be sent; BYE or a
  hang-up after it is a goodbye.
- HAVESPACE: only QUOTA and QUOTA/... say there is no room.
- A quoted string counts its escapes towards the 1024-octet limit; longer goes as a literal.
- U+061C is taken out of a server's words like the other direction marks.
- The session's Debug output shows counts, never the server's IMPLEMENTATION text.
- The invalid-UTF-8 fixture declares its literal's real length.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
…e script read last, stops seen while waiting

CodeRabbit on UCSLabs#2106:
- read: the capabilities are asked for again once signed in (they may change then, RFC 5804
  §1.7); a server that refuses CAPABILITY keeps what it said before.
- write: the listing is read again after PUTSCRIPT, just before SETACTIVE; a script another
  program made active meanwhile stays active (AnotherActive). The window that remains is said.
- write_own: the script's text first, then the listing, last before PUTSCRIPT: one switched off
  while its text was read isn't written.
- The greeting's first words are waited for when they come in pieces (a line, or the 16 bytes
  looked at, within the same wait), so what answered is told the same either way.
- A stop is seen while the greeting is waited for and while the TLS hello's answer is, in slices
  of 100 ms, and no reason is made of a probe that was stopped.
- The fake refuses DELETESCRIPT of a script it doesn't have (RFC 5804 §2.10).
- Tests: the stop test waits on the fake's connection instead of a sleep; the silent cases require
  the TLS hello on the second connection; the split-alert reading is tested without a socket, and
  the socket peer's waits are bounded; the oversized-literal test fails on a timeout.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
…t to right in allof, unknown guards

CodeRabbit on UCSLabs#2106:
- `:last` needs `:index` only where the command has one (the index tests, deleteheader);
  `addheader :last` and `duplicate :last` stand on their own (RFC 5293, RFC 7352).
- In an `allof`, the tests after an `ihave` may use what it names (RFC 5463 §3: left to
  right, once it held); not before it, not in `anyof`.
- One predicate says when what isn't known here is a warning (an unknown require, or an
  unknown `ihave` guard, never in a block); the positional count and the order of arguments
  after an unknown tag follow it.
- Required extensions are looked up in a set, for the server check and for `declared`: a
  require list of tens of thousands of names is checked in linear time.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
CodeRabbit on UCSLabs#2106: the five ManageSieve texts left empty in cs, de, es, fr, hu, it, ka, nl,
pl, ro and zh_CN, and the 84 Sieve texts in he, ja, pt_BR, pt_PT and sl, as drafts marked fuzzy;
with the new text of a session that can't go on. No translation of main changed.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
… them

CI on UCSLabs#2108: a_canonical_filter_saved_unchanged_is_written_back_byte_for_byte generated names
with a Hangul filler (U+115F, U+3164), which mailcraft_names takes out of every name on purpose;
the code is right. The generator keeps only names mailcraft_names::incoming leaves as they are,
through the crate's own function, so it can't drift from it. The RainLoop and elsewhere name
properties check names the same way instead of a hand-made list. The two CI seeds are in
proptest-regressions, and a plain test pins both cases: read without the filler, saved
unchanged with that name and the rest byte for byte.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
he, ja, pt_BR, pt_PT and sl had none of Automatic Replies' texts; the other catalogues one. Drafts, marked fuzzy, for review by native speakers.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
With part 3's texts as fuzzy drafts in every catalogue (he, ja, pt_BR, pt_PT and sl had none of them, the others 11), for review by native speakers.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
…script after a write, stops in the handshake, quieter probe and Debug

- A BYE (REFERRAL) to CAPABILITY or HAVESPACE after signing in is said as a
  referral: only a refusal that leaves the session usable falls back
  (ManageSieve::is_broken).
- write: the listing after the write says whether the script is active,
  whether or not it is to be made active.
- write_own: a plain NO to GETSCRIPT for a script the listing no longer has
  is a change (the script is gone), RFC 5804 §2.9 having NONEXISTENT as a
  SHOULD; a listed one keeps the refusal.
- check: the server's words are capped again after the secret is blanked out.
- The TLS handshake after STARTTLS watches the stop flag; a stop is said as
  one, not as a failed secure connection.
- The probe's TLS hello resumes no earlier session.
- Capabilities' Debug shows counts and flags, none of the server's words.
- LOGOUT: a timeout with the connection open is an error; OK, BYE and a
  hang-up are goodbyes.
- A cancelled sign-in reads one response; data in place of NO ends the
  session.
- Tests: the fake's CAPABILITY must be accepted; the redaction test uses a
  real literal and checks the exact refusal.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
No conflicts. `cargo xtask i18n` re-sorted the catalogues (the branch's
entry for "A name must follow the colon." moves after main's new
"A message to somebody who has no Public key …"), and `cargo xtask
parity` counts main's new command (405).

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 1 brings in main. Conflicts:
- crates/i18n/po/*.po (15 catalogues): both sides added entries next to
  each other. Merged entry by entry against the merge base: every entry
  of either side kept with its translation, none blank where either side
  had one, no translation changed on both sides; then `cargo xtask i18n`.
  Checked: 0 of main's translations lost or changed, 0 of this branch's.
  Main's "Automatic replies are kept on the mail server, and MailCraft can
  set them only for accounts that sign in with Microsoft so far …" stays
  gone: this part replaced it with the ManageSieve wording.
- docs/gaps.md: row 16 (encryption) takes main's new text, which this
  part hadn't touched; row 17 keeps this part's Sieve automatic replies.
docs/parity-checklist.md regenerated with `cargo xtask parity`.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 2 brings in part 1 and main. Conflicts:
- crates/i18n/po/*.po and messages.pot: both sides added entries next to
  each other. Merged entry by entry against the merge base (every entry of
  either side kept with its translation, none blank where either side had
  one, none changed on both sides), then `cargo xtask i18n`. Checked:
  0 of main's translations lost or changed, 0 of part 2's, 0 of this
  branch's.
- docs/gaps.md: row 16 (encryption) takes main's new text, which this
  part hadn't touched; row 17 keeps this part's text (part 2's row 17 is
  unchanged since the merge base).
docs/parity-checklist.md regenerated with `cargo xtask parity`.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Conflicts:
- .github/workflows/fuzz.yml: the list of fuzz targets keeps both sides' (this branch's managesieve and sieve_check, main's zimbra).
- fuzz/Cargo.toml: both [[bin]] entries kept (sieve_check, then main's zimbra).
- docs/parity-checklist.md: regenerated with `cargo xtask parity`.

Catalogues: refreshed with `cargo xtask i18n`; no translation of main's or of this branch's was lost. Main added Turkish (tr.po): fuzzy drafts for this branch's 85 texts.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 1 now has main in it. Conflicts:
- crates/engine/src/cmd/account.rs: servers_text keeps main's Zimbra account line and this part's Sieve server in the IMAP line.
- crates/ui-egui/src/auto_replies.rs: main lays the dialog's rows out with crate::rtl::line (right-to-left languages); this part's time range that the server can't keep and its "everyone outside, or nobody" for a Sieve server are kept, their rows laid out the same way.
- docs/ui-parity.md: Backstage keeps this part's Automatic Replies for a Sieve server and main's Print and Save as PDF.
- docs/parity-checklist.md: regenerated with `cargo xtask parity`.
- Catalogues: merged entry by entry and refreshed with `cargo xtask i18n`; no translation of main's, of part 1's or of this branch's was lost. Turkish: fuzzy drafts for this part's 31 texts.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 2 now has main in it. Conflicts:
- docs/parity-checklist.md: regenerated with `cargo xtask parity`.
- Catalogues: merged entry by entry and refreshed with `cargo xtask i18n`; no translation of main's, of part 2's or of this branch's was lost. Turkish: fuzzy drafts for this part's 209 texts.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Catalogues merged entry by entry (main's new entries and translations
kept, none of either side's lost; 17 catalogues).

Main's new guard test (every host an account sends a secret to is shown
and fingerprinted) names every Account field: the ManageSieve server an
IMAP account names in Account Settings (sieve_host, sieve_port) is one
its sign-in goes to, so it is now in Confirm Servers' text and in the
fingerprint here already, as part 2 had it, and the test changes it
like the IMAP and SMTP hosts.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 1 with main merged. Account Settings' ManageSieve server meets
main's GNOME accounts (account.edit's text says both), Zimbra and
calendar homes in the fingerprint and Confirm Servers; the last
written script's digest is named in main's every-field guard test as
no place anything goes. Docs take main's text with the Sieve lines
kept; catalogues merged entry by entry, none lost (17).

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Part 2 brings main, and with it UCSLabs#1177's rule editing: rules.edit,
rule_for_edit, Rule::changed_parts and the editor's Save that sends only
the parts changed. This part had an edit path of its own; the two are
one now, main's:

- rules.edit runs main's rule_for_edit for every rule; what isn't given
  stays. This part's own rule_edited is a thin wrapper over it, and its
  whole-rule replacement and refusal of a rule a Microsoft account's
  server keeps are gone (cannot_edit has no Microsoft reason; main's
  "not read yet" and "no answer yet" are reasons of it instead).
- On an IMAP account whose server keeps MailCraft's Sieve script, the
  script is written again whole, so the edited rule is placed as this
  part placed it (checked whole, a folder clash, kept here by choice);
  main's checks of a server's own copy are for other servers.
- A rule or filter of the owner's own script takes the change part by
  part (edited_parts): what the change doesn't make differ is kept as
  the script has it.
- The agent's questions about rules.edit are main's; the Sieve and
  webmail ones are kept. The Rules dialog keeps this part's builder,
  with main's can_edit, saved() and "New Rule" button; a word with a
  semicolon isn't shown in the builder, as on main.
- This part's Change Rule tests move to rules_edit_sieve_tests.rs, next
  to main's rules_edit_tests.rs, which is main's unchanged.
- The every-field guard test names sieve_offers too.

Catalogues merged entry by entry, none lost (17).

Human-reviewed, AI-assisted, nobody's mailbox harmed.
… rules.edit takes it

Tests: one part of a webmail filter changed (its name, then its folder)
with the others kept from its settings as read, " YES " and all, the
other filter byte for byte, a part a filter can't have refused, a change
that makes nothing differ writing the script as it was; a new name alone
for a rule of the owner's own script rewriting only its comment, a new
condition rewriting its `if` with the script's own actions and stop. The
tests that wrote a whole rule again now say what the parts left out
keep (a filler in a filter's name stays until it is renamed; a rule's
stop stays when the change doesn't name it).

Docs and fragments: Change Rule follows rules.edit as it is since
UCSLabs#1177, and changing a rule a Microsoft account's server keeps is no
longer named as a gap.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Main's Edit button had come into each rule's row beside this part's
Change pencil, which opens every kind of rule; it goes, and the held-key
test tabs past the same buttons again. A borrow clippy finds needless.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@linuxrrze

Copy link
Copy Markdown
Contributor Author

Reworked onto main's rule-editing model from #1177, now that it's merged.

What changed:

  • This part no longer has its own edit path. Its rules.edit (which replaced a rule whole and refused a rule a Microsoft account's server keeps) and its duplicate checks are gone. Main's rules.edit, rule_for_edit and the editor's Save, which sends only the parts changed in the builder, are the one path for every account. A change names only the parts it changes (name, conditions, exceptions, actions), and every other part stays as it was. Main's rules tests pass unchanged.
  • On a Sieve account, the Sieve writers take the change part by part:
    • A rule of MailCraft's own script: Sieve has no change of one rule alone, so MailCraft's script is written again with the rule as the edit leaves it. The rule is checked whole, as a new one is. What Sieve can't say keeps it on this computer, with why.
    • A rule of the owner's own script (made in webmail or another program): only the parts the change names are written. A new name alone rewrites the # rule:[…] comment and leaves the if byte for byte. A changed condition, exception or action rewrites the if, with the parts the change didn't name taken from the script as read. Every other byte of the script stays as it was.
    • A RainLoop / SnappyMail filter: its name, condition and folder each come from the change only when the change names them, and otherwise from the filter's settings as read (" YES " and all). An edit that changes nothing writes nothing.
  • These stay as before: refusals for rules with parts MailCraft doesn't know and for filters with settings it doesn't know, digest-guarded writes of the owner's script (OWN_CHANGED when the server's script moved on), the agent approval classes, rules.addSieve / rules.editSieve, rules.toSieve and sieve.putOwnBlock.
  • Two behaviour points now follow main. A word with a semicolon in it isn't shown in the rule builder, so such a rule is changed as its Sieve text. The agent's question about rules.edit is main's ("change the rule …, to: …").
  • Main's every-field guard test for account hosts now lists the ManageSieve server (sieve_host, sieve_port), which is shown and fingerprinted from part 1 on, plus the two Sieve fields that are no host (sieve_written, sieve_offers).
  • Main merged into part 1 and carried up the stack. Tests are adapted, and there are new ones: one part of a filter or of an owner's-script rule changed with the rest kept byte for byte, a part a filter can't have refused, an edit that names nothing writing nothing, and a Microsoft-server rule changed through main's path.

@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@inluck

inluck commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Tried at 45af231, with tests at that head and Pigeonhole's sieve-test on a real Dovecot server (it runs a script against a message and says what would happen; nothing is delivered or sent). Three things where the rules and Automatic Replies meet.

1. A rule change takes the place of a replies change that is still waiting

sieve_queue keeps one waiting write per account (crates/ui-egui/src/sieve_replies.rs:284), and a rules write is built by script_due from the replies as last read from the server (crates/engine/src/cmd/sieve_replies.rs:257), not from a replies change that is queued and not yet written. So if the owner turns Automatic Replies on while another Sieve job is under way (one at a time, for every account), and a rule is added or changed before the replies write starts, the rules write replaces it. The rule reaches the server, the replies never do, and the status line says "Your rules are kept on the server".

A test for crates/ui-egui/src/sieve_replies_tests.rs that fails at 45af231:

#[test]
fn a_rule_change_keeps_a_waiting_replies_change() {
    let (mut app, account, answers, jobs) = window();
    read(&mut app, account, &answers, SieveResult { state: Some(state(&RULES, None, None)), ..Default::default() });
    let inbox = app.session.mailbox.folder_of_kind(account, mailcraft_model::FolderKind::Inbox).unwrap();
    app.session.mailbox.folder_mut(inbox).unwrap().remote = "INBOX".into();
    // A read under way, its answer not taken in yet: the replies change waits behind it.
    app.sieve.read.clear();
    answers.lock().unwrap().push_back(SieveResult { account, state: Some(state(&RULES, None, None)), ..Default::default() });
    app.execute("account.automaticReplies", json!({"account": account})).unwrap();
    app.execute("account.setAutomaticReplies", json!({"account": account, "status": "alwaysEnabled", "internal": "Away."})).unwrap();
    // Before it starts, a rule kept on the server is added.
    app.execute(
        "rules.add",
        json!({"name": "Lists", "account": account, "conditions": [{"type": "fromContains", "value": "list"}], "actions": [{"type": "moveTo", "value": inbox}]}),
    )
    .unwrap();
    for _ in 0..4 {
        app.poll_sieve();
    }
    let writes: Vec<String> = jobs.lock().unwrap().iter().filter_map(|(_, w, _)| w.as_ref().map(|w| w.text.clone())).collect();
    assert!(writes.last().is_some_and(|t| t.contains("Away.") && t.contains("fileinto")), "last write: {:?}", writes.last());
}

One write goes out, with # Automatic replies are off. and the rule; afterwards said() is "Your rules are kept on the server" and auto_replies_on() is empty.

2. Rules and Alerts' Replace with MailCraft's turns Automatic Replies off

With replies on, once MailCraft's script is changed elsewhere (a webmail adding a filter to the active script, say), the replies are no longer known, and the Rules window's Replace with MailCraft's writes the script with them off (script_due: None if replace && sieve.changed_elsewhere => &blank). The doc comment says that's meant, but the window doesn't say it. Before the click, the note is "MailCraft's Sieve script on the server was changed elsewhere, so MailCraft leaves it as it is, and these rules run on this computer. Replace it with MailCraft's to keep them on the server: what was changed in it elsewhere is lost." After it, File › Info says "Automatic replies: off", and the reply text is gone from the server, with no copy here. In this case the webmail only appended a filter, so the replies section MailCraft wrote was still in the changed script.

A test that fails on its last line at 45af231 (sieve_rules_write(account, true) is what the button calls):

#[test]
fn replace_from_the_rules_window_keeps_the_replies() {
    let (mut app, account, answers, jobs) = window();
    let (_, rule) = with_rule(&mut app, account, &answers);
    app.poll_sieve();
    app.execute("account.setAutomaticReplies", json!({"account": account, "status": "alwaysEnabled", "internal": "Away."})).unwrap();
    app.poll_sieve();
    assert_eq!(app.auto_replies_on(), vec![account]);
    let ours = jobs.lock().unwrap().iter().rev().find_map(|(_, w, _)| w.clone()).unwrap().text;
    let edited = format!("{ours}if header :contains \"subject\" \"invoice\" {{ fileinto \"INBOX/Lists\"; }}\r\n");
    read(&mut app, account, &answers, SieveResult { state: Some(state(&RULES, Some(SCRIPT_NAME), Some(&edited))), ..Default::default() });
    assert!(app.sieve_rules_note(account).is_some_and(|(_, replace)| replace));
    app.sieve_rules_write(account, true);
    app.poll_sieve();
    let written = jobs.lock().unwrap().iter().rev().find_map(|(_, w, _)| w.clone()).unwrap().text;
    assert!(written.contains(&format!("# rule {rule}")));
    assert!(written.contains("Away."), "the replies aren't in what was written");
}

3. A Sieve rule that replies or refuses stops the whole script while Automatic Replies are on

script() (crates/engine/src/sieve.rs:427) puts MailCraft's vacation first and every rule after it. A Sieve rule with a vacation of its own, or a reject, then conflicts with it at run time, for every message the replies reach (RFC 5230 §4.7, RFC 5429 §2.4). Neither the local check nor the server's check of the script can catch that: it only happens when a message comes. I generated the scripts at 45af231 with rules.addSieve, rules.add and account.setAutomaticReplies (replies for inside and outside), and ran each through sieve-test:

Rules Replies Message from The server's answer
a Sieve rule with its own vacation for boss@example.org, then a rule filing boss@'s mail in INBOX/Lists on boss@example.org duplicate vacation action not allowed (previously triggered one was here: … line 4), then final result: failed; resolved with successful implicit keep
the same off boss@example.org the rule's reply, and the message filed in INBOX/Lists
a Sieve rule reject "No thanks."; for spam@example.net on spam@example.net reject/ereject action conflicts with other action: the vacation action (… line 5) also sends a response to the sender, then final result: failed; resolved with successful implicit keep
the same off spam@example.net rejected

So while replies are on, such a message gets no reply at all, neither MailCraft's nor the rule's. No later rule files it, and the refused sender's mail lands in the Inbox. (sieve-test needed -x +reject to know reject; the server's ManageSieve offers it.)

The first script, as MailCraft wrote it
# MailCraft: automatic replies kept on this server. Changed elsewhere, MailCraft leaves it as it is.
require ["vacation", "fileinto"];
if address :domain :is "from" "example.org" {
    vacation :days 7 :addresses ["ada@example.org"] :handle "mailcraft-internal" "Away until Monday.";
} else {
    vacation :days 7 :addresses ["ada@example.org"] :handle "mailcraft-external" "Away until Monday.";
}
# rule 19
# Sieve rule: Boss
if address :is "from" "boss@example.org" {
  vacation :days 1 "At the airport: call me.";
}
# rule 20
if address :all :contains "from" ["boss@"] {
    fileinto "INBOX/Lists";
}

Human-reviewed, AI-assisted, nobody's mailbox harmed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants