Skip to content

Rules: a Mark as junk action - #2249

Open
marian001 wants to merge 4 commits into
UCSLabs:mainfrom
marian001:feat/rule-mark-junk
Open

marian001 wants to merge 4 commits into
UCSLabs:mainfrom
marian001:feat/rule-mark-junk

Conversation

@marian001

@marian001 marian001 commented Dec 1, 2026 •

Copy link
Copy Markdown

Split out of #1845, as asked in #1845 (comment). There is no issue of its own for it; say so if you want one opened first.

What changes for the person using MailCraft

  • The Rules dialog has one more action, Mark as junk: the mail a rule finds goes to its account's Junk Email folder, as Home › Junk does.
  • For the control channel and agents: {"type": "markJunk"} among rules.add's actions. It takes no value.
  • It moves with the rule's other moves, after the marks, so a rule can mark mail as read and junk it. Mail in Junk Email already, or in a folder under it, or in an account with no such folder, stays where it is, and Run Rules Now doesn't count it.
  • A Microsoft account's server has no such rule action. The rule is kept on this computer; asking for it on the server ("server": true) is refused with "the server can't mark mail as junk". A server's rule that claims the action is read as a part not known here, like the other actions no server takes.

Nothing else from #1845 is in here: no rules.edit, no contact conditions, no contacts folders.

How it was checked

  • New tests: a_rule_marks_mail_as_junk (model), a_rule_that_marks_as_junk_is_made_and_moves_mail_to_junk_email (engine).

  • Extended tests: the server refusals in rules_remote_tests.rs and graph/rules_tests.rs, and the Rules form's keep_tests.rs (every action the builder offers is one rules.add takes).

  • The three new interface texts are translated in every catalogue and marked #, fuzzy.

  • cargo xtask ci on Rust 1.98.1, Linux: all 15 steps passed. Not run on macOS or Windows.

  • cargo xtask ci passes

  • A crash or data-loss fix has its regression test (not one)

  • "Allow edits by maintainers" is ticked (the box beside Create pull request)

  • I have signed the CLA, or will by commenting on this pull request

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

Summary by CodeRabbit

  • New Features
    • Added a Mark as junk action to the Rules builder. Matching messages move to the account’s Junk folder, and rules can still apply other actions, such as marking messages as read.
    • Rules using this action stay on your computer because Microsoft account servers don’t support it.

A rule can move the mail it finds to its account's Junk Email folder, as
Home › Junk does: `{"type": "markJunk"}` in `rules.add`, "Mark as junk" in
the Rules dialog.

- It moves with the rule's other moves, after the marks. Mail in Junk Email
  already, or under it, or in an account with no such folder, stays where it
  is and isn't counted by Run Rules Now.
- A Microsoft account's server has no such action: the rule is kept on this
  computer, `"server": true` is refused with the reason, and a server's rule
  that claims it is read as a part not known here.

Split out of UCSLabs#1845.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@marian001
marian001 requested a review from benandez as a code owner December 1, 2026 23:01
Human-reviewed, AI-assisted, nobody's mailbox harmed.
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The change adds a MarkJunk rule action to the model, command interface, and rules builder. When a rule runs, eligible matching mail moves to the account’s Junk folder. Server-rule handling rejects or omits this action because servers do not support it.

Changes: Junk rule action

Layer / File(s) Summary
Define and expose the junk action
crates/model/src/rule.rs, crates/engine/src/cmd/rules.rs, crates/ui-egui/src/forms.rs, crates/ui-egui/src/forms/rules/*, crates/i18n/po/*, packaging/release-notes.d/new/2249.md
The rule model, command parser, and rules builder add MarkJunk as a value-free action. Localization catalogs and the release note include text for the action and server limitation.
Apply the action to matching mail
crates/model/src/mailbox.rs, crates/model/src/mailbox_tests.rs, crates/engine/src/cmd/rules_parts_tests.rs
Mailbox::act moves eligible mail to the account’s Junk folder. Tests cover matching and nonmatching mail, existing Junk locations, action ordering, and command execution.
Handle server-rule limitations
crates/engine/src/cmd/rules.rs, crates/engine/src/cmd/rules_remote_tests.rs, crates/model/src/remote_rules.rs, crates/net/src/graph/rules*
Server-rule checks and downloaded-rule handling identify MarkJunk as unsupported. Tests cover local storage by default and rejection of an explicit request for server storage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant RulesForm
  participant RulesAddCommand
  participant RulesRunCommand
  participant MailboxAct
  participant JunkFolder
  RulesForm->>RulesAddCommand: Submit markJunk action
  RulesAddCommand->>RulesAddCommand: Parse as MarkJunk
  RulesRunCommand->>MailboxAct: Apply matching rule
  MailboxAct->>JunkFolder: Move eligible message
Loading

Possibly related PRs

  • UCSLabs/mailcraft#1177: Adds the rule-edit flow that opens a MarkJunk rule for editing and supports saving it unchanged.

Suggested reviewers: kartas39

Merge Risk: Low · up to 808ae

Mark as junk works as described for ordinary rules. A rule that lists Mark as junk twice around another move may file mail in a different folder than expected, which is a narrow edge case and does not block merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Rules: a Mark as junk action" names the main change: a new Mark as junk action for mail rules. It matches the rules.rs, mailbox.rs, rule.rs, and UI changes, and it is short and specific.
Description check Passed The description follows the repository template. It has the Closes line (left blank with a note that there is no issue), the user-facing changes section, the how-it-was-checked section, and the checkl…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description follows the repository template. It has the Closes line (left blank with a note that there is no issue), the user-facing changes section, the how-it-was-checked section, and the checklist. The author ticked the CI, maintainer-edit, and CLA boxes and left the regression-test box unticked with a note. The Closes line is empty, but the author explains there is no linked issue. The description is mostly complete and clearly states the behavior, server limits, and test coverage.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

@vangel76 vangel76 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the rule builder and editor, command validation, saved rule encoding, incoming-mail and manual execution paths, Graph refusal and import paths, translation catalogs, and merged source against current main.

Source review only. I did not build the project, run tests, or check CI.

Comment thread crates/model/src/rule.rs
ClearCategories,
/// Junk it, as Home › Junk does: move it to its account's Junk E-mail. Mail there already, or
/// of an account with no such folder, stays where it is.
MarkJunk,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1. Handle MarkJunk in the rule editor added on main

The merge with current main produces a non-exhaustive match in crates/ui-egui/src/forms.rs at Act::of. Main added rule editing after this branch split off, and Act::of explicitly matches every previous Action variant. The new MarkJunk variant makes mailcraft-ui-egui fail to compile after a clean merge. Add A::MarkJunk => Act { kind: Do::Junk, ..base } to the editor conversion and check that opening and saving an existing junk rule preserves its action.

@benandez benandez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Mark as junk uses the same move path as Delete and MoveTo; every exhaustive Action match is updated; Graph export refuses it with a clear reason; stage ordering (last move wins, marks first) and stop-processing are consistent and tested; all 16 catalogues are filled and marked fuzzy.

Non-blocking:

  • The params help and two comments say "Junk E-mail"; the folder is "Junk Email".
  • No test for an account without a Junk folder (the _ => false arm); rules.add could say when a single-account rule's account has none.
  • As with earlier new actions, an older build refuses a mailbox file containing markJunk (no data lost). A lenient Unknown action variant would be a separate, project-wide change.

@benandez
benandez added this pull request to the merge queue Dec 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 3, 2026
…as junk rule

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@benandez
benandez enabled auto-merge December 3, 2026 10:11
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

crates/engine/src/cmd/rules.rs: 1

473-476: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Preserve the last occurrence of folder-changing actions.

For [markJunk, moveTo Archive, markJunk], once_each removes the final MarkJunk. The stage-sorted executor then leaves the message in Archive instead of Junk. This contradicts the documented “last listed move wins” behavior.

Retain the last identical folder-changing action rather than the first. Keep duplicate-copy suppression unchanged.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ee6df7c and 808ae84.

Files selected for processing: 23

  • crates/engine/src/cmd/rules.rs
  • crates/engine/src/cmd/rules_remote_tests.rs
  • crates/i18n/po/cs.po
  • crates/i18n/po/de.po
  • crates/i18n/po/es.po
  • crates/i18n/po/fr.po
  • crates/i18n/po/he.po
  • crates/i18n/po/hu.po
  • crates/i18n/po/it.po
  • crates/i18n/po/ja.po
  • crates/i18n/po/ka.po
  • crates/i18n/po/messages.pot
  • crates/i18n/po/nl.po
  • crates/i18n/po/pl.po
  • crates/i18n/po/pt_BR.po
  • crates/i18n/po/pt_PT.po
  • crates/i18n/po/ro.po
  • crates/i18n/po/sl.po
  • crates/i18n/po/zh_CN.po
  • crates/model/src/mailbox.rs
  • crates/net/src/graph/rules.rs
  • crates/ui-egui/src/forms.rs
  • crates/ui-egui/src/forms/rules/tests.rs
Files skipped from review as they are similar to previous changes: 17

  • crates/i18n/po/cs.po
  • crates/i18n/po/de.po
  • crates/i18n/po/es.po
  • crates/i18n/po/fr.po
  • crates/i18n/po/he.po
  • crates/i18n/po/hu.po
  • crates/i18n/po/it.po
  • crates/i18n/po/ja.po
  • crates/i18n/po/ka.po
  • crates/i18n/po/messages.pot
  • crates/i18n/po/nl.po
  • crates/i18n/po/pl.po
  • crates/i18n/po/pt_BR.po
  • crates/i18n/po/pt_PT.po
  • crates/i18n/po/ro.po
  • crates/i18n/po/sl.po
  • crates/i18n/po/zh_CN.po

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@benandez

benandez commented Dec 3, 2026

Copy link
Copy Markdown
Member

Merged main and added the Mark as junk case to the rules form's new edit path from #1177 (plus a test that a junk rule opens and saves back unchanged), so it builds with main; re-queued.

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.

3 participants