Skip to content

Commit

Permalink
fixup! feat: mail filters
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Sep 13, 2024
1 parent 44c2e68 commit c8db6ba
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 10 deletions.
3 changes: 0 additions & 3 deletions lib/Service/MailFilter/FilterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Service/MailFilter/FilterBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/data/mail-filter/test1.sieve
Original file line number Diff line number Diff line change
@@ -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":["[email protected]","[email protected]"],"field":"from"}],"actions":[{"type":"addflag","flag":"Alice and Bob"}],"priority":10}]
# Filter: Test 1
Expand Down
2 changes: 0 additions & 2 deletions tests/data/mail-filter/test2.sieve
Original file line number Diff line number Diff line change
@@ -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":["[email protected]"],"field":"from"}],"actions":[{"type":"fileinto","flag":"","mailbox":"Test Data"}],"priority":"20"}]
# Filter: Test 2
Expand Down
2 changes: 0 additions & 2 deletions tests/data/mail-filter/test3.sieve
Original file line number Diff line number Diff line change
@@ -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":["[email protected]"],"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
Expand Down
1 change: 0 additions & 1 deletion tests/data/mail-filter/test4.sieve
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c8db6ba

Please sign in to comment.