Skip to content

Commit

Permalink
Merge pull request #10002 from nextcloud/chore/noid/newlines-for-siev…
Browse files Browse the repository at this point in the history
…e-ooo

fix: line ending for sieve scripts should be clrf
  • Loading branch information
st3iny authored Aug 16, 2024
2 parents 3fad97e + 1f54a38 commit 6b32ffc
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SPDX-FileCopyrightText = "2022 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["src/tests/data/[email protected]", "src/tests/data/[email protected]", "src/tests/data/[email protected]", "src/tests/data/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/imap.localhost.ca.crt", "tests/data/smime-certs/domain.tld.ca.crt", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/decrypted-message-body.txt", "tests/data/decrypted-signed-opaque-message-body.txt", "tests/data/encrypted-message.txt", "tests/data/encrypted-signed-opaque-message.txt", "tests/data/sieve-vacation-cleaned.txt", "tests/data/sieve-vacation-off.txt", "tests/data/sieve-vacation-on-no-end-date.txt", "tests/data/sieve-vacation-on-no-tz.txt", "tests/data/sieve-vacation-on-special-chars-message.txt", "tests/data/sieve-vacation-on-special-chars-subject.txt", "tests/data/sieve-vacation-on-subject-placeholder.txt", "tests/data/sieve-vacation-on.txt", "tests/data/signed-message.txt", "tests/data/signed-opaque-message.txt"]
path = ["src/tests/data/[email protected]", "src/tests/data/[email protected]", "src/tests/data/[email protected]", "src/tests/data/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/imap.localhost.ca.crt", "tests/data/smime-certs/domain.tld.ca.crt", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/smime-certs/[email protected]", "tests/data/decrypted-message-body.txt", "tests/data/decrypted-signed-opaque-message-body.txt", "tests/data/encrypted-message.txt", "tests/data/encrypted-signed-opaque-message.txt", "tests/data/sieve-vacation-cleaned.sieve", "tests/data/sieve-vacation-off.sieve", "tests/data/sieve-vacation-on-no-end-date.sieve", "tests/data/sieve-vacation-on-no-tz.sieve", "tests/data/sieve-vacation-on-special-chars-message.sieve", "tests/data/sieve-vacation-on-special-chars-subject.sieve", "tests/data/sieve-vacation-on-subject-placeholder.sieve", "tests/data/sieve-vacation-on.sieve", "tests/data/signed-message.txt", "tests/data/signed-opaque-message.txt"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2023 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/OutOfOffice/OutOfOfficeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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,
Expand Down Expand Up @@ -173,7 +173,7 @@ public function buildSieveScript(
self::SEPARATOR,
]);

return implode("\n", array_merge(
return implode("\r\n", array_merge(
$requireSection,
[$untouchedScript],
$vacationSection,
Expand Down
40 changes: 20 additions & 20 deletions tests/Unit/Service/OutOfOffice/OutOfOfficeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -114,16 +114,16 @@ 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(
true,
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 <[email protected]>", "Test Alias <[email protected]>"],
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if address "From" "[email protected]" {
}

### 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 <[email protected]>", "Test Alias <[email protected]>"] "I'm on vacation.
\"Hello, World!\"
Expand Down
File renamed without changes.

0 comments on commit 6b32ffc

Please sign in to comment.