From b20dd5b0fbffd65958c36c8fb9d50975699fae9a Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 15 Aug 2024 17:32:54 +0200 Subject: [PATCH] fix: line ending for sieve scripts should be clrf Ref https://www.rfc-editor.org/rfc/rfc5228#section-2.2 Signed-off-by: Daniel Kesselberg --- .gitattributes | 1 + lib/Service/OutOfOffice/OutOfOfficeParser.php | 6 +-- .../OutOfOffice/OutOfOfficeParserTest.php | 40 +++++++++---------- ...eaned.txt => sieve-vacation-cleaned.sieve} | 0 ...ation-off.txt => sieve-vacation-off.sieve} | 0 ...xt => sieve-vacation-on-no-end-date.sieve} | 0 ...o-tz.txt => sieve-vacation-on-no-tz.sieve} | 0 ...e-vacation-on-special-chars-message.sieve} | 2 +- ...e-vacation-on-special-chars-subject.sieve} | 0 ...eve-vacation-on-subject-placeholder.sieve} | 0 ...acation-on.txt => sieve-vacation-on.sieve} | 0 11 files changed, 25 insertions(+), 24 deletions(-) rename tests/data/{sieve-vacation-cleaned.txt => sieve-vacation-cleaned.sieve} (100%) rename tests/data/{sieve-vacation-off.txt => sieve-vacation-off.sieve} (100%) rename tests/data/{sieve-vacation-on-no-end-date.txt => sieve-vacation-on-no-end-date.sieve} (100%) rename tests/data/{sieve-vacation-on-no-tz.txt => sieve-vacation-on-no-tz.sieve} (100%) rename tests/data/{sieve-vacation-on-special-chars-message.txt => sieve-vacation-on-special-chars-message.sieve} (86%) rename tests/data/{sieve-vacation-on-special-chars-subject.txt => sieve-vacation-on-special-chars-subject.sieve} (100%) rename tests/data/{sieve-vacation-on-subject-placeholder.txt => sieve-vacation-on-subject-placeholder.sieve} (100%) rename tests/data/{sieve-vacation-on.txt => sieve-vacation-on.sieve} (100%) diff --git a/.gitattributes b/.gitattributes index 033aac4bed..33116453d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,3 +3,4 @@ # SPDX-License-Identifier: AGPL-3.0-only /CHANGELOG.md merge=union /vendor-bin/**/composer.lock binary +/tests/data/*.sieve text eol=crlf diff --git a/lib/Service/OutOfOffice/OutOfOfficeParser.php b/lib/Service/OutOfOffice/OutOfOfficeParser.php index a879ca8eba..fdd2e0f1f6 100644 --- a/lib/Service/OutOfOffice/OutOfOfficeParser.php +++ b/lib/Service/OutOfOffice/OutOfOfficeParser.php @@ -73,7 +73,7 @@ public function parseOutOfOfficeState(string $sieveScript): OutOfOfficeParserRes $state = $nextState; } - return new OutOfOfficeParserResult($data, $sieveScript, implode("\n", $scriptOut)); + return new OutOfOfficeParserResult($data, $sieveScript, implode("\r\n", $scriptOut)); } /** @@ -99,7 +99,7 @@ public function buildSieveScript( if (!$state->isEnabled()) { //unset($jsonData['start'], $jsonString['end']); - return implode("\n", [ + return implode("\r\n", [ $untouchedScript, self::SEPARATOR, self::DATA_MARKER . $stateJsonString, @@ -173,7 +173,7 @@ public function buildSieveScript( self::SEPARATOR, ]); - return implode("\n", array_merge( + return implode("\r\n", array_merge( $requireSection, [$untouchedScript], $vacationSection, diff --git a/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php b/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php index aa1cd70d28..685c7bc98c 100644 --- a/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php +++ b/tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php @@ -24,8 +24,8 @@ protected function setUp(): void { } public function testParseEnabledResponder(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on.txt"); - $cleanedScript = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on.sieve"); + $cleanedScript = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); $actual = $this->outOfOfficeParser->parseOutOfOfficeState($script); self::assertEquals($script, $actual->getSieveScript()); @@ -39,8 +39,8 @@ public function testParseEnabledResponder(): void { } public function testParseDisabledResponder(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-off.txt"); - $cleanedScript = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-off.sieve"); + $cleanedScript = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); $actual = $this->outOfOfficeParser->parseOutOfOfficeState($script); self::assertEquals($script, $actual->getSieveScript()); @@ -54,7 +54,7 @@ public function testParseDisabledResponder(): void { } public function testParseLeaveForeignScriptUntouched(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); $actual = $this->outOfOfficeParser->parseOutOfOfficeState($script); self::assertEquals($script, $actual->getSieveScript()); @@ -63,8 +63,8 @@ public function testParseLeaveForeignScriptUntouched(): void { } public function testParseOldEnabledResponder(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-no-tz.txt"); - $cleanedScript = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-no-tz.sieve"); + $cleanedScript = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); $actual = $this->outOfOfficeParser->parseOutOfOfficeState($script); self::assertEquals($script, $actual->getSieveScript()); @@ -78,8 +78,8 @@ public function testParseOldEnabledResponder(): void { } public function testBuildEnabledResponder(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); - $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); + $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on.sieve"); $actual = $this->outOfOfficeParser->buildSieveScript( new OutOfOfficeState( @@ -96,8 +96,8 @@ public function testBuildEnabledResponder(): void { } public function testBuildEnabledResponderWithoutEndDate(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); - $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-no-end-date.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); + $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-no-end-date.sieve"); $actual = $this->outOfOfficeParser->buildSieveScript( new OutOfOfficeState( @@ -114,8 +114,8 @@ public function testBuildEnabledResponderWithoutEndDate(): void { } public function testBuildEnabledResponderWithSpecialCharsInMessage(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); - $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-special-chars-message.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); + $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-special-chars-message.sieve"); $actual = $this->outOfOfficeParser->buildSieveScript( new OutOfOfficeState( @@ -123,7 +123,7 @@ public function testBuildEnabledResponderWithSpecialCharsInMessage(): void { new DateTimeImmutable("2022-09-02T00:00:00+0100"), null, "On vacation", - "I'm on vacation.\n\"Hello, World!\"\n\\ escaped backslash", + "I'm on vacation.\r\n\"Hello, World!\"\r\n\\ escaped backslash", ), $script, ["Test Test ", "Test Alias "], @@ -132,8 +132,8 @@ public function testBuildEnabledResponderWithSpecialCharsInMessage(): void { } public function testBuildEnabledResponderWithSpecialCharsInSubject(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); - $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-special-chars-subject.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); + $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-special-chars-subject.sieve"); $actual = $this->outOfOfficeParser->buildSieveScript( new OutOfOfficeState( @@ -150,8 +150,8 @@ public function testBuildEnabledResponderWithSpecialCharsInSubject(): void { } public function testBuildEnabledResponderWithSubjectPlaceholder(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); - $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-subject-placeholder.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); + $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-on-subject-placeholder.sieve"); $actual = $this->outOfOfficeParser->buildSieveScript( new OutOfOfficeState( @@ -168,8 +168,8 @@ public function testBuildEnabledResponderWithSubjectPlaceholder(): void { } public function testBuildDisabledResponder(): void { - $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.txt"); - $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-off.txt"); + $script = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-cleaned.sieve"); + $expected = file_get_contents(__DIR__ . "/../../../data/sieve-vacation-off.sieve"); $actual = $this->outOfOfficeParser->buildSieveScript( new OutOfOfficeState( diff --git a/tests/data/sieve-vacation-cleaned.txt b/tests/data/sieve-vacation-cleaned.sieve similarity index 100% rename from tests/data/sieve-vacation-cleaned.txt rename to tests/data/sieve-vacation-cleaned.sieve diff --git a/tests/data/sieve-vacation-off.txt b/tests/data/sieve-vacation-off.sieve similarity index 100% rename from tests/data/sieve-vacation-off.txt rename to tests/data/sieve-vacation-off.sieve diff --git a/tests/data/sieve-vacation-on-no-end-date.txt b/tests/data/sieve-vacation-on-no-end-date.sieve similarity index 100% rename from tests/data/sieve-vacation-on-no-end-date.txt rename to tests/data/sieve-vacation-on-no-end-date.sieve diff --git a/tests/data/sieve-vacation-on-no-tz.txt b/tests/data/sieve-vacation-on-no-tz.sieve similarity index 100% rename from tests/data/sieve-vacation-on-no-tz.txt rename to tests/data/sieve-vacation-on-no-tz.sieve diff --git a/tests/data/sieve-vacation-on-special-chars-message.txt b/tests/data/sieve-vacation-on-special-chars-message.sieve similarity index 86% rename from tests/data/sieve-vacation-on-special-chars-message.txt rename to tests/data/sieve-vacation-on-special-chars-message.sieve index 6e1f51e61f..8131e1a3b4 100644 --- a/tests/data/sieve-vacation-on-special-chars-message.txt +++ b/tests/data/sieve-vacation-on-special-chars-message.sieve @@ -11,7 +11,7 @@ if address "From" "marketing@company.org" { } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### -# DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","subject":"On vacation","message":"I'm on vacation.\n\"Hello, World!\"\n\\ escaped backslash"} +# DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","subject":"On vacation","message":"I'm on vacation.\r\n\"Hello, World!\"\r\n\\ escaped backslash"} if currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z" { vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation. \"Hello, World!\" diff --git a/tests/data/sieve-vacation-on-special-chars-subject.txt b/tests/data/sieve-vacation-on-special-chars-subject.sieve similarity index 100% rename from tests/data/sieve-vacation-on-special-chars-subject.txt rename to tests/data/sieve-vacation-on-special-chars-subject.sieve diff --git a/tests/data/sieve-vacation-on-subject-placeholder.txt b/tests/data/sieve-vacation-on-subject-placeholder.sieve similarity index 100% rename from tests/data/sieve-vacation-on-subject-placeholder.txt rename to tests/data/sieve-vacation-on-subject-placeholder.sieve diff --git a/tests/data/sieve-vacation-on.txt b/tests/data/sieve-vacation-on.sieve similarity index 100% rename from tests/data/sieve-vacation-on.txt rename to tests/data/sieve-vacation-on.sieve