Skip to content

#2110: rules kept on an Exchange server (EWS) - #2256

Draft
linuxrrze wants to merge 22 commits into
UCSLabs:mainfrom
linuxrrze:feat/ews-server-rules
Draft

linuxrrze wants to merge 22 commits into
UCSLabs:mainfrom
linuxrrze:feat/ews-server-rules

Conversation

@linuxrrze

@linuxrrze linuxrrze commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #2255

Closes #2110 (part 2 of 2). Until the part before it is merged, this pull request also shows its commits; the rules are the commits after #2110: merge part 1.

What it does for the owner

An Exchange server account (on-premises Exchange reached over EWS) keeps its rules on its server, as a Microsoft account already does through Graph:

  • The rules made in Outlook are shown in Rules and Alerts. Parts MailCraft doesn't know are shown by name, never dropped or rewritten.
  • A rule made in MailCraft goes to the server when Exchange can run it there; one it can't stays on this computer and runs here, and the Rules window says why.
  • Switching a rule on or off, moving it up or down, deleting it, and changing it (its name, conditions, exceptions or actions) changes that one rule on the server.
  • People of the organisation that an on-premises server names by directory name (/o=…/cn=…) in a rule's senders or recipients are shown by their address, looked up in the address list.

How it behaves

  • Outlook is the reference: the same Rules and Alerts window and the same model of rules kept on the server, read and written through EWS GetInboxRules / UpdateInboxRules ([MS-OXWSRULES]).
  • Changes to a rule follow main's rules.edit model (Reules edit #1177), the same as for a Microsoft account: the engine sends only the parts changed here (RuleOp::Update with parts: name, conditions, exceptions, actions), plus a switch or a move. This pull request has no edit path of its own.
  • EWS can't change one part alone (SetRuleOperation replaces the whole rule). So each change goes by rule id, one at a time, and is written on the server's own copy of that rule, read just before. Only the parts the change names are written anew; every other part goes back byte for byte as the server gave it. Within a part that changed, a condition, exception, move or copy that is the same as on the server also goes back as the server gave it (a person's display name, a folder's change key). An Outlook rule with parts unknown here survives a change of another rule byte for byte.
  • A rule that couldn't be read whole, has a part not known here, or that the service marks as not changeable (IsNotSupported) is never rewritten. A rule with unknown parts can still be switched, moved and deleted. An IsNotSupported rule is shown read-only.
  • The host gives back what went, so main's outcome handling covers EWS too. If the server refuses a change (Exchange's own validation code is shown), the parts that went go back to what the server has. A change of a rule deleted on the server meanwhile (RuleNotFound, or missing from a complete read) deletes it here too, and says so.
  • Outlook's own copy of the rules. While the mailbox holds it (OutlookRuleBlobExists), the server takes no change unless that copy is removed. MailCraft then sends nothing and asks the owner first ("Outlook's Copy of the Rules"). The rules on the server stay and keep running either way. Only on a yes is the copy removed (RemoveOutlookRuleBlob), once, with the next change that goes. A question closed unanswered is a no; File › Info's rules line says where it stands and offers Ask again. Until then new rules and changes stay on this computer and run here.
    • Departure from Outlook, named: Outlook rewrites the server's rules and its own copy whenever it saves them, without asking. MailCraft never removes Outlook's copy without the owner's yes, because whatever only that copy held (such as rules that run only on one computer) is lost, and Outlook may then say the rules on the server have changed.
  • Agents: ui.removeOutlookRules is classed as Delete, so an agent needs the owner's yes; changes to the server's rules need the owner as they do for a Microsoft account.
  • Not offered for an online archive or a shared mailbox, nor for an account whose server isn't usable.

Privacy

  • Requests go only to the account's own server, with its own sign-in, pinned certificate and caps; the password is never sent anywhere else, and never to Microsoft 365 hosts. With no password at hand nothing is sent; a password the server turns down is forgotten, as for Send/Receive.
  • Outlook's own copy of the rules is removed only on the owner's yes.
  • Directory names are looked up in the account's own address list (ResolveNames, at most 50 a job), on the same server.
  • Server answers are read by a bounded reader (sizes capped, hostile answers turned into errors, never a panic).

How it was tested

Fakes only, never a real mailbox:

  • mailcraft-ews: the reader and writer (hostile answers, a rule too long to read whole, validation errors); the in-process EWS stand-in answers both operations, held to the schema, with round trips of creating, switching, moving, deleting and changing a rule; a change of one part written with every other part byte for byte; a switch and a move with it; a part the server's rules can't hold refused and given back; a rule gone; an Outlook rule with unknown parts unchanged through a change of another; refusals (unknown parts, IsNotSupported, not read whole, Outlook's copy); a sender named by directory name, resolved and not, kept through changes; the readers in the ews fuzz target and the crate's property tests.
  • engine: rules.edit on such an account sends its changes part by part, a refused part comes back as the server has it, a gone rule goes, a rule taken off the server is deleted there, an Outlook rule or a read-only one is never rewritten; main's rules tests pass unchanged; agent classes.
  • window and app: the job, the question about Outlook's copy in a kittest, the host runner against the stand-in.
  • cargo xtask ci passes.

Catalogues refreshed with cargo xtask i18n; the new texts have fuzzy drafts in all 16 languages. Docs: gap 17, docs/ui-parity.md, docs/exchange-servers.md (not yet tried against a real server), ROADMAP step 11, with their fragments (packaging/release-notes.d/new/2110-rules.md, docs/log.d/…/2110-rules.md).

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

File › Info › Automatic Replies, its line and the status bar now work for an
Exchange server account, through EWS GetUserOofSettings and SetUserOofSettings
([MS-OXWOOF]), at the account's own server with its password.

- mailcraft-ews: `oof`, the two requests and a bounded reader (state,
  audience, UTC time range, the two replies, capped; a reply too long to read
  makes the answer unreadable, never empty), carried in Graph's names so the
  existing commands and dialog serve both kinds of account; and
  `automatic_replies`, which reads, changes what was read and writes it whole,
  then reads again, so what the owner left alone goes back as the server had
  it. The stand-in answers both operations, held to the schema.
- engine: `can_reply` takes Exchange server accounts (not an online archive or
  one without a usable server); `ews_request` says what the host asks with.
  Nothing is changed before the first read or while offline, as for Graph.
- window and app: `Services::ews_auto_replies`, the host job in
  `ews_runner`, a password the server turns down forgotten as for Send/Receive.
- tests: reader and writer (hostile, oversize, faults), stand-in round trip,
  engine commands, the window's job and a kittest of the dialog, the reader
  in the `ews` fuzz target and the crate's proptests.
- docs: gap 17, ui-parity, step 11, fragments 2110.md; catalogues refreshed,
  the two new texts as fuzzy drafts in every language.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
An Exchange server account's rules are kept on its server through EWS
GetInboxRules and UpdateInboxRules ([MS-OXWSRULES]), in the model a
Microsoft account's already use, so the engine's merge, the Rules and Alerts
window and the agent classes serve both.

- mailcraft-ews: `rules`, the requests and a bounded reader. Conditions,
  exceptions and actions MailCraft knows become its own; any other is named
  among the rule's unknown parts, so the rule is shown, never run here and
  never made again from what was kept; `IsNotSupported` is read-only. Changes
  go by RuleId, one operation a request: a MailCraft rule is created whole
  (its id, which the answer doesn't give, found by reading again), a deletion
  by id, and a switch or a move is written on the server's own copy of the
  rule, read just before, with only IsEnabled or Priority changed, so an
  Outlook rule keeps every part; one that couldn't be read whole is never
  written back. RemoveOutlookRuleBlob is sent only with the owner's yes, and
  without it nothing is sent while Outlook's copy is there. The stand-in
  answers both operations, held to the schema.
- engine: `keeps_rules` takes Exchange server accounts (not an online
  archive or one without a usable server); `ews_rules_request`; the owner's
  one-shot yes for removing Outlook's copy in the rules driver.
- window and app: `Services::ews_rules`, `ews_runner::run_rules`; the question
  about Outlook's copy (`ui.removeOutlookRules`, classed Delete for agents),
  closed unanswered is a no; File › Info's rules line with Ask again; a
  password the server turns down forgotten.
- tests: reader and writer (hostile answers, a rule too long to read whole,
  validation errors), stand-in round trips, an Outlook rule with unknown parts
  that survives a change of another rule unchanged, engine merge and agent
  classes, the window's job and question with a kittest, the reader in the
  `ews` fuzz target and the crate's proptests.
- docs: gap 17, ui-parity, step 11, fragments 2110-rules.md; catalogues
  refreshed, the new texts as fuzzy drafts in every language.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
…named by directory name

A change of a rule's name, conditions, exceptions or actions goes to the
Exchange server by RuleId (SetRuleOperation), written on the server's own copy
of the rule read just before, as a switch or a move already is.

- mailcraft-ews: `ServerRules::edited`: the rule as MailCraft has it now, on
  the server's copy; each condition, exception and move or copy the change
  leaves as it was goes back as the server gave it (a person's name, a
  folder's change key). Refused, with why, for a rule with a part not known
  here, one the service may not change (IsNotSupported), one not read whole,
  and a change the server's rules can't hold; Outlook's copy keeps it from
  going without the owner's yes, as every change.
- People of the organisation an on-premises server names by directory name
  (RoutingType EX, /o=…/cn=…) in FromAddresses or SentToAddresses are read:
  by the SMTP address the address list gives (ResolveNames, at most 50 a job),
  else by the name as given; an unchanged list goes back as the server wrote
  it, and a new directory name is written routed EX. Such rules were read-only
  for their "unknown" senders before.
- model: `ServerRule::edited` (which change, so an answer for an earlier one
  doesn't count for a later one), `Rule::mark_edited`; `RuleOp::body` and
  `edit` for an Update, `RuleOutcome::edit`.
- engine: `rule_upload` sends a change whole to an Exchange server alone, of
  a rule every part of which is known; a read keeps the change until the
  server takes it; refused, the rule is as the server has it again; one whose
  server copy now has unknown parts lets the change go.
  `edited_on_exchange` for the command that changes a rule: marks the change,
  or (kept on this computer now) has the server delete its copy.
- tests: stand-in round trip of a change (name, conditions, actions), an
  Outlook rule with unknown parts byte-identical through a change of another,
  refusals (unknown parts, IsNotSupported, not read whole, a flag, Outlook's
  copy), an EX sender read resolved and not, kept through a change of its rule
  and of another; engine upload, merge, answers and keeping here; the new
  readers in the proptests and the `ews` fuzz target.
- catalogues re-wrapped by `cargo xtask i18n` (no text changed).

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Conflicts and how they were resolved:
- crates/ews/src/reply.rs: both sides added a method to `Reply` at the
  same place; both kept (`response` from this branch, for Automatic
  Replies' answers that are not response-message lists, and main's
  `busy_with_nothing_done`).
- docs/gaps.md: rows 16 to 18 conflicted only because neighbours moved.
  Main's rows 16 (encrypting and signing) and 18 (releases), this
  branch's row 17 (Automatic Replies for Exchange server accounts, UCSLabs#2110),
  which main had not changed.
- crates/i18n/po/{cs,es,fr,he,hu,it,ja,ka,nl,pl,pt_BR,pt_PT,ro,sl,zh_CN}.po:
  main's catalogues taken, `cargo xtask i18n` run, then this branch's two
  new texts given their fuzzy drafts again in all 16 languages. Checked:
  no translation of main's is lost or changed, none of the branch's is
  lost (hu and ka have main's newer wording).
- docs/gaps.md row 17 also names Zimbra accounts (new on main) among those
  without automatic replies.
- docs/parity-checklist.md regenerated with `cargo xtask parity`.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Brings in feat/ews-auto-replies as it is after `UCSLabs#2110: merge main`, so this
part is current with main too.

Conflicts and how they were resolved:
- crates/engine/src/cmd/mod.rs: main added `rules_budget_tests` where this
  branch added `rules_ews_tests`; both kept, in order.
- docs/gaps.md: rows 16 to 18 conflicted only because neighbours moved.
  Main's rows 16 (encrypting and signing) and 18 (releases), and this
  branch's row 17, which is part 1's row 17 (unchanged by main) with the
  rules kept on an Exchange server added; it also names Zimbra accounts
  (new on main) among those without automatic replies, as part 1 does.
- crates/i18n/po/*.po merged without conflicts; `cargo xtask i18n` run,
  then the new texts of both parts given their fuzzy drafts in all 16
  languages. Checked: no translation of main's is lost or changed, none of
  the branch's is lost (hu and ka have main's newer wording).
- docs/parity-checklist.md regenerated with `cargo xtask parity`.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Main's `cargo xtask text-part` (new since this branch began) counts every
`.body` read whole as a message's text part read as it is. In
crates/ews/src/rules.rs the three it found are a rule change's rule
(`RuleOp::body`, as in crates/net/src/graph/rules.rs), not a message's:
listed with that reason in xtask/text-part-readers.txt.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Main's `graphs_delete_past_the_retention_period_is_used_in_one_place_only`
(apps/mailcraft-cli/tests/graph_changes.rs, UCSLabs#30 part 7) allows the name of
that delete in one call site alone. A comment in crates/ews/src/rules.rs
named EWS's rule action of the same name, to say it is not known here: it
now says "deleting it for good" instead. No code changed.

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

coderabbitai Bot commented Dec 2, 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

Main's new Turkish catalogue (UCSLabs#1711) came after this branch's last merge of
main, so the texts of Automatic Replies for Exchange server accounts, and
four of main's own (saved searches in Favorites, UCSLabs#1306), had no Turkish
entry and `cargo xtask i18n` failed on the merged state. They are drafts,
marked fuzzy, as in the other catalogues.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Main's new Turkish catalogue (UCSLabs#1711) has no entry for the texts of rules kept
on an Exchange server, so `cargo xtask i18n` failed on the merged state.
They are drafts, marked fuzzy, as in the other catalogues.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
SonarCloud read `let _ = set.element().write();` in oof_tests.rs as a
lock guard dropped at once and rated the new code's reliability C. It
is a false positive: `soap::Element::write` turns a SOAP XML element
into its text, there is no lock. The text now has a name (`_xml`),
still unused, so the rule no longer fires; behaviour is unchanged.
The same in the proptest that writes GetUserOofSettings.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Conflicts:
- docs/ui-parity.md, the Backstage (File) row: main added Print and
  Save as PDF and its "No print preview"; this branch added Automatic
  Replies for an Exchange server account (UCSLabs#2110). Main's row with this
  branch's words about Automatic Replies.
- crates/i18n/po/{cs,es,fr,he,hu,it,ja,ka,nl,pl,pt_BR,pt_PT,ro,sl,tr,zh_CN}.po:
  entries both sides added next to each other. Main's translation where
  both have one, this branch's entries and drafts added, then
  `cargo xtask i18n`. No translation of main's or of this branch's is
  lost; every catalogue is 100%.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
SonarCloud read `let _ = e.write();` in rules_tests.rs as a lock guard
dropped at once and rated the new code's reliability C. It is a false
positive: `soap::Element::write` turns a SOAP XML element into its
text, there is no lock. The text now has a name (`_xml`), still unused,
so the rule no longer fires; behaviour is unchanged. The same for the
two lines after it that write a rule's element.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Brings part 1's merge of main (Print and Save as PDF, UCSLabs#32, and the rest)
and its SonarCloud fix.

Conflict:
- docs/ui-parity.md, the Backstage (File) row: part 1 brought main's
  Print and Save as PDF and "No print preview"; this branch added where
  an Exchange server account's rules on the server stand, with Ask
  again. Part 1's row with this branch's clause about the rules.

Catalogues merged without conflict; after `cargo xtask i18n` no
translation of main's, part 1's or this branch's is lost, and every
catalogue (tr included) is 100%.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Conflicts and how they were resolved:
- crates/ews/src/lib.rs: main added the calendar module docs and standin_userconfig beside this
  branch's oof and standin_oof; both kept (standin_userconfig keeps its cfg line).
- crates/ews/src/xml.rs: main added MAX_DICTIONARY_TEXT and the Value/Body/TextBody text caps
  beside this branch's MAX_MESSAGE_TEXT and its Message arm; both kept.
- apps/mailcraft/src/ews_runner.rs: main's run_calendar and run_calendar_with, then this branch's
  run_auto_replies and run_auto_replies_with; imports of both.
- apps/mailcraft/src/main.rs: main's calendar and JMAP host contexts and hooks, then this
  branch's automatic replies one.
- crates/ui-egui/src/lib.rs: Services keeps main's ews_calendar and this branch's
  ews_auto_replies.
- docs/gaps.md, docs/ui-parity.md: main's rows, with this branch's words for Exchange server
  accounts' automatic replies put into them.
- crates/i18n/po/*.po: main's catalogues, `cargo xtask i18n`, then this branch's two texts'
  drafts put back; no translation of main's lost, and the five Turkish saved-search entries are
  now main's own.

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

- A change the server took is said as made when the read after it fails: the EWS host
  chooses its line by whether the change went (auto_replies_result), as the Microsoft host
  does, so the trouble kept is a read's, never "Couldn't change"; and the status line says
  what was set, from the change, instead of what was known before it (both hosts).
- A reply too long for a server is refused with the reason, never cut: MAX_REPLY_HTML is
  the 128 000 bytes the schema advises; account.setAutomaticReplies refuses a reply whose
  HTML is longer (REPLY_TOO_LONG), and so does OofSettings::with_change (Error::TooLarge,
  OofRun::refused). A server's plain reply written as HTML for showing stops before the
  character that would not fit, never inside a <br> or a reference.
- The text cap of an automatic reply's Message applies inside InternalReply and
  ExternalReply only; any other element of that name keeps the cap every element has.
- OofRun's Debug shows how the run went, never the replies.
- The proptest of a change has times that can be read, so it reaches its body, and checks
  that the reply reads back as written and became no element.
- A read that waits for the password says so in File › Info and in the dialog.
- An online archive and an account without a usable server address get refusals of their
  own (ARCHIVE; the account's own "has no Exchange server address that can be used"), not
  the text for IMAP accounts, renamed NOT_SUPPORTED.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
`cargo xtask i18n`, and fuzzy drafts in all 17 catalogues of the refusal for an online
archive and of the one for a reply too long for the server.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Brings in Automatic Replies for Exchange server accounts with the review's
fixes (NOT_SUPPORTED, the scoped Message cap, MAX_REPLY_HTML 128 000) and
main up to 5df5365, which has UCSLabs#1177 (rules.edit, a change sent part by
part). Where the rules model clashed, main's is taken: this branch's own
change counter (ServerRule::edited, RuleOp::edit, RuleOutcome::edit, the
edit helper and the merge's keeping of an edit) is dropped; the EWS writer
is moved onto RuleOp::parts in the next commit. Catalogues refreshed, the
branch's translations kept.

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

The EWS host now takes main's RuleOp::Update with its parts (UCSLabs#1177): the
server's copy of the rule, read just before, is written back whole with
SetRuleOperation (EWS has no change of a part alone), the parts the change
names taken from its body, IsEnabled and Priority where given, and every
other part as the server gave it, byte for byte. A rule not read whole,
with parts not known here, or IsNotSupported is still never rewritten; a
part the server's rules can't hold is refused before anything is sent.
Each outcome gives back the op's body and parts, so the engine's outcomes
take what went, put a refused part back as the server has it, and drop a
rule gone from the server. Outlook's own copy, directory names and
Exchange's validation errors are as they were.

Tests: one part written with the rest byte for byte, a switch and a move
with it, a refused part given back, a rule gone; rules.edit on such an
account sends its parts, a refusal and a gone rule come back through main's
outcomes, a rule taken off the server is deleted there. Docs and fragments
say a change goes part by part; exchange-servers.md lists the rules among
what is not yet tried against a real server.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
Up to 95bee53. Only tr.po clashed: main's taken, the catalogues refreshed
with cargo xtask i18n, and this branch's Turkish drafts put back (none of
main's translations lost, none of the branch's).

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

The change written part by part reads its body's parts once more; that body
is the rule a change carries (RuleOp::body), never a message's text part.

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 PR no longer has its own edit path. ServerRule::edited, RuleOp::edit / RuleOutcome::edit and the edit helper in rules_remote.rs are gone. Edits come from rules.edit and Rule::changed_parts(), as they do for a Microsoft account. The engine sends an RuleOp::Update with parts (name, conditions, exceptions, actions), plus a switch or a move.
  • The EWS host takes that op as it is. EWS has no change of one part alone (SetRuleOperation replaces the rule), so the host reads the server's copy of the rule just before writing. It writes only the listed parts from the op's body, changes IsEnabled / Priority where given, and writes the rest back as the server gave it. Parts MailCraft doesn't model (a display name beside an address, a folder's change key) stay byte for byte.
  • The host gives back the op's body and parts in each outcome, as Graph's host does. So main's Sent::of / went handling covers EWS answers too: a part Exchange refuses (with its validation code) is put back as the server has it, and RuleNotFound is a gone rule.
  • These refusals stay as before: a rule not read whole, a rule with parts unknown here, and IsNotSupported. The EWS-specific parts also stay: the question about Outlook's own copy (RemoveOutlookRuleBlob, only on the owner's yes), resolving directory names (EX) through ResolveNames, and Exchange's validation errors.
  • Merged #2110: Automatic Replies for Exchange server accounts (EWS) #2255 (part 1) and main. Tests are adapted to the new path. Main's rules tests pass unchanged.

@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

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.

Exchange server accounts: Automatic Replies and rules kept on the server (EWS)

1 participant