Skip to content

feat(sieve): implement redirecting action in filter UI#13095

Open
hazveg wants to merge 1 commit into
nextcloud:mainfrom
hazveg:feat/filter-forward-action
Open

feat(sieve): implement redirecting action in filter UI#13095
hazveg wants to merge 1 commit into
nextcloud:mainfrom
hazveg:feat/filter-forward-action

Conversation

@hazveg

@hazveg hazveg commented Jun 17, 2026

Copy link
Copy Markdown

This patch implements an action for redirecting via the Sieve 'redirect' directive.

form to create forward

I've attempted to include a corresponding test case, but was unfortunately unable to figure out how the tests are run - thus being unable to test my test. Sorry about that.

Summary by CodeRabbit

  • New Features

    • Added a "Forward to" mail filter action, enabling users to automatically forward emails matching filter rules to a specified recipient address.
  • Tests

    • Added test fixtures to validate forward mail filter action functionality and Sieve script generation.

@hazveg hazveg force-pushed the feat/filter-forward-action branch from 50a9524 to 286e1bf Compare June 17, 2026 07:53
This patch implements an action for redirecting via the Sieve
'redirect' directive.

Signed-off-by: hazveg <aaron.jaeger06@gmail.com>
@ChristophWurst

Copy link
Copy Markdown
Member

Very nice. Thank you! We will check it out soon

@ChristophWurst

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a forward action type to the mail filter system. A new MailFilterActions.Forward enum member and MailFilterActionForward class are added in TypeScript. A new ActionForward.vue component renders a recipient text input and is wired into the existing Action.vue selector. FilterBuilder::buildSieveScript() maps the forward action to a Sieve redirect command. Test fixtures cover the new rule.

Changes

Forward Mail Filter Action

Layer / File(s) Summary
MailFilterActions.Forward model and class
src/models/mailFilter.ts
Adds Forward = 'forward' to the MailFilterActions enum and a new MailFilterActionForward class implementing MailFilterAction with a generated id.
ActionForward component and Action.vue wiring
src/components/mailFilter/ActionForward.vue, src/components/mailFilter/Action.vue
New ActionForward component renders an NcTextField bound to action.recipient and emits update-action on change. Action.vue imports, registers, exposes a "Forward to" option, and returns ActionForward from componentInstance.
FilterBuilder: forward → Sieve redirect
lib/Service/MailFilter/FilterBuilder.php
Adds a case in buildSieveScript() that escapes recipient and appends a Sieve redirect command for the forward action type.
Test fixtures for forward rule
tests/data/mail-filter/builder9.json, tests/data/mail-filter/builder9.sieve
Adds input JSON rule matching to = bob@example.org with a forward action to alice@example.org and the expected Sieve output with the redirect command.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, a letter takes flight,
Redirected to Alice, just right!
A new enum declared,
A component prepared,
Sieve catches and forwards the mail overnight. ✉️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing a forward/redirect action in the filter UI using Sieve.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@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.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 22b34a44-9e72-4848-9bc2-e03653412729

📥 Commits

Reviewing files that changed from the base of the PR and between b133d88 and 286e1bf.

📒 Files selected for processing (6)
  • lib/Service/MailFilter/FilterBuilder.php
  • src/components/mailFilter/Action.vue
  • src/components/mailFilter/ActionForward.vue
  • src/models/mailFilter.ts
  • tests/data/mail-filter/builder9.json
  • tests/data/mail-filter/builder9.sieve

Comment on lines +90 to +93
{
id: MailFilterActions.Forward,
label: this.t('mail', 'Forward to'),
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Forward action objects in JSON fixtures =="
fd -e json . tests src | while read -r file; do
  jq -c --arg file "$file" '
    .. | objects
    | select(.type? == "forward")
    | {file: $file, hasRecipient: has("recipient"), hasFlag: has("flag"), object: .}
  ' "$file" 2>/dev/null || true
done

echo
echo "== Forward key usage in code paths =="
rg -n -C2 'forward|recipient|flag' src/components/mailFilter src/models lib/Service/MailFilter tests/data/mail-filter

Repository: nextcloud/mail

Length of output: 24829


🏁 Script executed:

# Get the MailFilterActionForward class definition from models
ast-grep outline src/models/mailFilter.ts --match MailFilterActionForward --view expanded

Repository: nextcloud/mail

Length of output: 320


🏁 Script executed:

# Read the MailFilterActionForward class definition more fully
sed -n '89,100p' src/models/mailFilter.ts

Repository: nextcloud/mail

Length of output: 395


🏁 Script executed:

# Verify there are no other forward actions in fixtures with the same issue
fd -e json tests src | while read -r file; do
  jq -c --arg file "$file" '
    .. | objects
    | select(.type? == "forward")
    | {file: $file, keys: keys}
  ' "$file" 2>/dev/null || true
done

Repository: nextcloud/mail

Length of output: 152


🏁 Script executed:

# Search for all forward action objects in JSON files
rg -A2 '"type":\s*"forward"' tests/data/mail-filter --type json

Repository: nextcloud/mail

Length of output: 323


Fix fixture data integrity: forward action should use recipient key, not flag.

The test fixture at tests/data/mail-filter/builder9.json contains a forward action with "flag": "alice@example.org", but the backend FilterBuilder consumes action['recipient'] (lib/Service/MailFilter/FilterBuilder.php:94) and the frontend ActionForward component emits { recipient: value }.

Additionally, the MailFilterActionForward model class (src/models/mailFilter.ts) lacks a recipient property definition.

Fixture inconsistency
{
  "type": "forward",
  "flag": "alice@example.org"
}

Should be:

{
  "type": "forward",
  "recipient": "alice@example.org"
}

Comment on lines +1 to +4
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use the repository-required SPDX header block format in this new Vue file.

The new file uses an HTML comment SPDX banner, but the guideline requires the C-style SPDX block format.

💡 Suggested fix
-<!--
-  - SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
-  - SPDX-License-Identifier: AGPL-3.0-or-later
--->
+/* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */

As per coding guidelines "**/*.{php,js,ts,tsx,vue}: Every file must include an SPDX license header... Header format: /* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
/* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

Source: Coding guidelines

Comment thread src/models/mailFilter.ts
Comment on lines +89 to +95
export class MailFilterActionForward implements MailFilterAction {
public id: number
public type: string
constructor() {
this.id = randomId()
this.type = 'forward'
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Initialize recipient in the forward action model to preserve the frontend↔backend contract.

MailFilterActionForward currently creates { id, type } only, but the Sieve builder reads action['recipient'] directly for type === 'forward'. A newly-added forward action saved before input can therefore serialize without recipient and break redirect generation.

💡 Suggested fix
 export class MailFilterActionForward implements MailFilterAction {
 	public id: number
 	public type: string
+	public recipient: string
 	constructor() {
 		this.id = randomId()
 		this.type = 'forward'
+		this.recipient = ''
 	}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export class MailFilterActionForward implements MailFilterAction {
public id: number
public type: string
constructor() {
this.id = randomId()
this.type = 'forward'
}
export class MailFilterActionForward implements MailFilterAction {
public id: number
public type: string
public recipient: string
constructor() {
this.id = randomId()
this.type = 'forward'
this.recipient = ''
}
}

Comment on lines +15 to +20
"actions": [
{
"type": "forward",
"flag": "alice@example.org"
}
],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: Field name mismatch between test fixture and implementation.

Line 18 uses "flag" as the field name, but FilterBuilder.php line 94 expects "recipient":

$recipient = SieveUtils::escapeString($action['recipient'])

This will cause the forward action to fail at runtime because the expected field does not exist. The expected Sieve output in builder9.sieve line 3 confirms the correct field name should be "recipient".

[functional_correctness, data_integrity_and_integration]

🐛 Proposed fix for test fixture field name
 		"actions": [
 			{
 				"type": "forward",
-				"flag": "alice@example.org"
+				"recipient": "alice@example.org"
 			}
 		],

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants