Filters on a shared mailbox: its own rules, sort-only for members #156

Merged
jcoffey-dev merged 1 commits from feat/155-shared-mailbox-filters into main 2026-11-25 21:03:23 +00:00
Owner

Summary

Webmail side of shared-mailbox filters. The server side is inbuxa/inbuxa-server#643.

With a shared mailbox in view, Settings › Filters now edits that mailbox's own Sieve script. Before this, the sieve store followed accountId, and the switcher never changes it (it sets viewing). So the page always showed the reader's own filters, with the shared mailbox's folders in the picker. store/sieve.ts now picks its account with filtersTarget(): the shared mailbox when one from sharedMail is in view, the reader's own otherwise. A locked account (AL-7) still keeps the reader's own filters. App.tsx re-inits the sieve store when the view changes.

  1. Whose filters. On a shared mailbox the heading reads "Filters for [email protected]".
  2. Forbidden, explained. With Read or Organize access (from the delegation, so no request is sent), or when the server answers forbidden on SieveScript/get or /set, the page says "You need full access to this mailbox to change its filters." It shows no tabs, no editor and no New rule button. "Filter messages like this" shows the same line.
  3. Sort only for members. On a shared mailbox, unless the session's permissions include impersonate (the server's admin test in #643):
    • The rule editor drops Forward and Reject. It still offers move to folder, mark read, star, add label, keep, delete and stop.
    • A rule that forwards, rejects or uses an action this version doesn't know is shown read-only with "Saved by an administrator; only an administrator can change it": no toggle, edit, move or delete.
    • Saving writes such a rule back unchanged. Its # rule: line and its Sieve block come out byte for byte, and there's a test for it.
    • A refused save shows the server's SetError description in the toast.
  4. Personal hint. On the reader's own Filters page, when they have shared mailboxes: "Rules here only apply to mail delivered to you. To sort a shared mailbox's mail, switch to it first."

The store also drops one account's scripts when it switches to another, and throws away a SieveScript/get answer for a mailbox that's no longer in view.

Depends on the server's exact shape

  • Forbidden is read as a method-level error of type forbidden on SieveScript/get or /set, or on the upload.
  • The admin-only refusal is read as a SetError in notCreated or notUpdated, and its description is shown as it is. A bare forbidden SetError with no description on a shared mailbox shows the no-access line.
  • Admin means impersonate in session.ihasmail.permissions. An installation with administration turned off sends no permissions, so an admin there gets the sort-only editor. The server still accepts their save.
  • A Full member has to be able to upload a blob to the shared account before SieveScript/set.

Open question

#643 checks the whole compiled script. So while an administrator's forwarding rule is in the script, any save by a member is refused, even one that only changes another rule. That's the documented behavior ("a member then editing it must remove those actions or ask an admin"). This PR keeps the admin's rule and shows the server's refusal. If members should be able to save around it, the server would have to compare against the stored script.

Related issues

Fixes #155. Server: inbuxa/inbuxa-server#643.

Translations

Adds 5 keys:

  • "Filters for {name}"
  • "You need full access to this mailbox to change its filters."
  • "Rules here only apply to mail delivered to you. To sort a shared mailbox's mail, switch to it first."
  • "Saved by an administrator; only an administrator can change it"
  • "Create a rule to move newsletters to a folder or flag important senders." (the empty state when forwarding isn't offered)

They're translated in all ten catalogs. The translations are AI-made and not yet read by a native speaker, and the catalogs say so. The fallback count is 0 in every language before (1763/1763) and after (1768/1768).

Testing

Ran locally, step for step as in .gitea/workflows/ci.yml:

  • npm ci --ignore-scripts
  • npm run typecheck
  • npm test: web 1681 tests, server 321
  • sh scripts/release-version.test.sh
  • npm run build
  • npm run i18n:check

New tests:

  • store/__tests__/sieve-shared-mailbox.test.ts: the target account, Forbidden handling, the server's refusal text, and a stale answer.
  • views/settings/__tests__/filters-shared-mailbox.test.tsx: the heading, the no-access page, the read-only rule, the editor's choices, and the personal hint.
  • lib/sieve/__tests__/sieve.test.ts: the round trip of an admin's rule.

Not driven in the built app: the mock server has no shared-mailbox accounts or per-account Sieve, so it can't show any of this yet. It needs a server with #643 to try end to end.

## Summary Webmail side of shared-mailbox filters. The server side is inbuxa/inbuxa-server#643. With a shared mailbox in view, Settings › Filters now edits that mailbox's own Sieve script. Before this, the sieve store followed `accountId`, and the switcher never changes it (it sets `viewing`). So the page always showed the reader's own filters, with the shared mailbox's folders in the picker. `store/sieve.ts` now picks its account with `filtersTarget()`: the shared mailbox when one from `sharedMail` is in view, the reader's own otherwise. A locked account (AL-7) still keeps the reader's own filters. `App.tsx` re-inits the sieve store when the view changes. 1. **Whose filters.** On a shared mailbox the heading reads "Filters for [email protected]". 2. **Forbidden, explained.** With Read or Organize access (from the delegation, so no request is sent), or when the server answers `forbidden` on `SieveScript/get` or `/set`, the page says "You need full access to this mailbox to change its filters." It shows no tabs, no editor and no New rule button. "Filter messages like this" shows the same line. 3. **Sort only for members.** On a shared mailbox, unless the session's permissions include `impersonate` (the server's admin test in #643): - The rule editor drops Forward and Reject. It still offers move to folder, mark read, star, add label, keep, delete and stop. - A rule that forwards, rejects or uses an action this version doesn't know is shown read-only with "Saved by an administrator; only an administrator can change it": no toggle, edit, move or delete. - Saving writes such a rule back unchanged. Its `# rule:` line and its Sieve block come out byte for byte, and there's a test for it. - A refused save shows the server's `SetError` description in the toast. 4. **Personal hint.** On the reader's own Filters page, when they have shared mailboxes: "Rules here only apply to mail delivered to you. To sort a shared mailbox's mail, switch to it first." The store also drops one account's scripts when it switches to another, and throws away a `SieveScript/get` answer for a mailbox that's no longer in view. ### Depends on the server's exact shape - Forbidden is read as a method-level error of type `forbidden` on `SieveScript/get` or `/set`, or on the upload. - The admin-only refusal is read as a `SetError` in `notCreated` or `notUpdated`, and its `description` is shown as it is. A bare `forbidden` SetError with no description on a shared mailbox shows the no-access line. - Admin means `impersonate` in `session.ihasmail.permissions`. An installation with administration turned off sends no permissions, so an admin there gets the sort-only editor. The server still accepts their save. - A Full member has to be able to upload a blob to the shared account before `SieveScript/set`. ### Open question #643 checks the whole compiled script. So while an administrator's forwarding rule is in the script, any save by a member is refused, even one that only changes another rule. That's the documented behavior ("a member then editing it must remove those actions or ask an admin"). This PR keeps the admin's rule and shows the server's refusal. If members should be able to save around it, the server would have to compare against the stored script. ## Related issues Fixes #155. Server: inbuxa/inbuxa-server#643. ## Translations Adds 5 keys: - "Filters for {name}" - "You need full access to this mailbox to change its filters." - "Rules here only apply to mail delivered to you. To sort a shared mailbox's mail, switch to it first." - "Saved by an administrator; only an administrator can change it" - "Create a rule to move newsletters to a folder or flag important senders." (the empty state when forwarding isn't offered) They're translated in all ten catalogs. The translations are AI-made and not yet read by a native speaker, and the catalogs say so. The fallback count is 0 in every language before (1763/1763) and after (1768/1768). ## Testing Ran locally, step for step as in `.gitea/workflows/ci.yml`: - `npm ci --ignore-scripts` - `npm run typecheck` - `npm test`: web 1681 tests, server 321 - `sh scripts/release-version.test.sh` - `npm run build` - `npm run i18n:check` New tests: - `store/__tests__/sieve-shared-mailbox.test.ts`: the target account, Forbidden handling, the server's refusal text, and a stale answer. - `views/settings/__tests__/filters-shared-mailbox.test.tsx`: the heading, the no-access page, the read-only rule, the editor's choices, and the personal hint. - `lib/sieve/__tests__/sieve.test.ts`: the round trip of an admin's rule. Not driven in the built app: the mock server has no shared-mailbox accounts or per-account Sieve, so it can't show any of this yet. It needs a server with #643 to try end to end.
jcoffey-dev added 1 commit 2026-11-25 20:31:46 +00:00
Filters on a shared mailbox: its own rules, sort-only for members
ci / node (pull_request) Skipped
ci / version (pull_request) Skipped
ci / docker-build (pull_request) Skipped
ci / publish (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 1m44s
ci / announce (pull_request) Skipped
1b1eada098
With a shared mailbox in view, Settings > Filters now edits that
mailbox's Sieve script instead of the reader's own, and says so in the
heading ("Filters for [email protected]"). Rules written into the reader's
own script for a shared address never ran on its mail.

- Read and Organize members, or a server that answers Forbidden, get
  "You need full access to this mailbox to change its filters." with no
  editor and no New rule button. The same goes for "Filter messages
  like this".
- A member who isn't an administrator (no impersonate permission) is
  offered only actions that sort: file, star, label, mark read, keep,
  delete and stop. Forward and reject are not offered.
- A rule an administrator saved that forwards, rejects or uses an action
  this version doesn't know is shown read-only, "Saved by an
  administrator; only an administrator can change it", and is written
  back unchanged when the other rules are saved.
- A refused save shows the server's own description.
- The reader's own Filters page, when they have shared mailboxes, says
  its rules only apply to mail delivered to them.

Five new strings, translated in all ten catalogs (AI-made, unreviewed);
nothing falls back to English before or after.

Fixes #155
jcoffey-dev merged commit f7fcd10a33 into main 2026-11-25 21:03:23 +00:00
jcoffey-dev deleted branch feat/155-shared-mailbox-filters 2026-11-25 21:03:24 +00:00
Sign in to join this conversation.