From c8db6baa4c3c85ef3294ecf31b1a1de2c24cf66e Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 13 Sep 2024 13:24:27 +0200 Subject: [PATCH] fixup! feat: mail filters Signed-off-by: Daniel Kesselberg --- lib/Service/MailFilter/FilterBuilder.php | 3 --- tests/Unit/Service/MailFilter/FilterBuilderTest.php | 3 +++ tests/data/mail-filter/test1.sieve | 2 -- tests/data/mail-filter/test2.sieve | 2 -- tests/data/mail-filter/test3.sieve | 2 -- tests/data/mail-filter/test4.sieve | 1 - 6 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/Service/MailFilter/FilterBuilder.php b/lib/Service/MailFilter/FilterBuilder.php index 9a63aeabe3..7b58ad37eb 100644 --- a/lib/Service/MailFilter/FilterBuilder.php +++ b/lib/Service/MailFilter/FilterBuilder.php @@ -110,18 +110,15 @@ public function buildSieveScript(array $filters, string $untouchedScript): strin $requireSection[] = self::SEPARATOR; $requireSection[] = 'require ' . SieveUtils::stringList($extensions) . ';'; $requireSection[] = self::SEPARATOR; - $requireSection[] = ''; } $stateJsonString = json_encode($this->sanitizeDefinition($filters), JSON_THROW_ON_ERROR); $filterSection = [ - '', self::SEPARATOR, self::DATA_MARKER . $stateJsonString, ...$commands, self::SEPARATOR, - '', ]; return implode(self::SIEVE_NEWLINE, array_merge( diff --git a/tests/Unit/Service/MailFilter/FilterBuilderTest.php b/tests/Unit/Service/MailFilter/FilterBuilderTest.php index e346570fb5..aa7b99fe8d 100644 --- a/tests/Unit/Service/MailFilter/FilterBuilderTest.php +++ b/tests/Unit/Service/MailFilter/FilterBuilderTest.php @@ -42,6 +42,9 @@ public function testBuild(string $testName): void { $script = $this->builder->buildSieveScript($filters, $untouchedScript); + // the .sieve files have \r\n line endings + $script .= "\r\n"; + $this->assertStringEqualsFile( $this->testFolder . $testName . '.sieve', $script diff --git a/tests/data/mail-filter/test1.sieve b/tests/data/mail-filter/test1.sieve index 09739e786e..5147a3f2b7 100644 --- a/tests/data/mail-filter/test1.sieve +++ b/tests/data/mail-filter/test1.sieve @@ -1,9 +1,7 @@ ### Nextcloud Mail: Filters ### DON'T EDIT ### require ["imap4flags"]; ### Nextcloud Mail: Filters ### DON'T EDIT ### - # Hello, this is a test - ### Nextcloud Mail: Filters ### DON'T EDIT ### # DATA: [{"name":"Test 1","enable":true,"operator":"allof","tests":[{"operator":"is","values":["alice@example.org","bob@example.org"],"field":"from"}],"actions":[{"type":"addflag","flag":"Alice and Bob"}],"priority":10}] # Filter: Test 1 diff --git a/tests/data/mail-filter/test2.sieve b/tests/data/mail-filter/test2.sieve index 545d93ecdb..fcbb516c67 100644 --- a/tests/data/mail-filter/test2.sieve +++ b/tests/data/mail-filter/test2.sieve @@ -1,9 +1,7 @@ ### Nextcloud Mail: Filters ### DON'T EDIT ### require ["fileinto"]; ### Nextcloud Mail: Filters ### DON'T EDIT ### - # Hello, this is a test - ### Nextcloud Mail: Filters ### DON'T EDIT ### # DATA: [{"name":"Test 2","enable":true,"operator":"anyof","tests":[{"operator":"contains","values":["Project-A","Project-B"],"field":"subject"},{"operator":"is","values":["john@example.org"],"field":"from"}],"actions":[{"type":"fileinto","flag":"","mailbox":"Test Data"}],"priority":"20"}] # Filter: Test 2 diff --git a/tests/data/mail-filter/test3.sieve b/tests/data/mail-filter/test3.sieve index 292e06f42b..1b279a0b57 100644 --- a/tests/data/mail-filter/test3.sieve +++ b/tests/data/mail-filter/test3.sieve @@ -1,9 +1,7 @@ ### Nextcloud Mail: Filters ### DON'T EDIT ### require ["fileinto", "imap4flags"]; ### Nextcloud Mail: Filters ### DON'T EDIT ### - # Hello, this is a test - ### Nextcloud Mail: Filters ### DON'T EDIT ### # DATA: [{"name":"Test 3.1","enable":true,"operator":"anyof","tests":[{"operator":"contains","values":["Project-A","Project-B"],"field":"subject"},{"operator":"is","values":["john@example.org"],"field":"from"}],"actions":[{"type":"fileinto","flag":"","mailbox":"Test Data"},{"type":"stop"}],"priority":"20"},{"name":"Test 3.2","enable":true,"operator":"allof","tests":[{"operator":"contains","values":["@example.org"],"field":"to"}],"actions":[{"type":"addflag","flag":"Test A"}],"priority":30}] # Filter: Test 3.1 diff --git a/tests/data/mail-filter/test4.sieve b/tests/data/mail-filter/test4.sieve index 28e18b4a08..22432c66c7 100644 --- a/tests/data/mail-filter/test4.sieve +++ b/tests/data/mail-filter/test4.sieve @@ -1,5 +1,4 @@ # Hello, this is a test - ### Nextcloud Mail: Filters ### DON'T EDIT ### # DATA: [{"actions":[{"flag":"Flag 123","type":"addflag"}],"enable":true,"name":"Test 4","operator":"allof","priority":60,"tests":[]}] # Filter: Test 4