Skip to content

Commit

Permalink
Merge pull request #13 from josaphatim/added-actions
Browse files Browse the repository at this point in the history
Added missing actions
  • Loading branch information
kroky authored May 17, 2024
2 parents dbed4e5 + 9262e35 commit f6cf3f9
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Filters/Actions/AddHeaderFilterAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PhpSieveManager\Filters\Actions;

use PhpSieveManager\Exceptions\FilterActionParamException;

/**
* Please refer to https://datatracker.ietf.org/doc/html/rfc5293#section-4
*/
class AddHeaderFilterAction implements FilterAction
{
private $params;

/**
* @param array $params
* @throws FilterActionParamException
*/
public function __construct(array $params = []) {
if (count($params) != 2) {
throw new FilterActionParamException("AddHeaderFilterAction expect two parameters");
}
$this->params = $params;
}

/**
* @return string
*/
public function parse() {
return 'addheader "'.$this->params[0].'" "'.$this->params[1].'";'."\n";
}
}
31 changes: 31 additions & 0 deletions src/Filters/Actions/ConvertFilterAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PhpSieveManager\Filters\Actions;

use PhpSieveManager\Exceptions\FilterActionParamException;

/**
* Please refer to https://www.rfc-editor.org/rfc/rfc6558.html
*/
class ConvertFilterAction implements FilterAction
{
private $params;

/**
* @param array $params
* @throws FilterActionParamException
*/
public function __construct(array $params = []) {
if (count($params) != 3) {
throw new FilterActionParamException("ConvertFilterAction expect three parameters");
}
$this->params = $params;
}

/**
* @return string
*/
public function parse() {
return 'convert "'.$this->params[0].'" "'.$this->params[1].'" ["'.implode('","', $this->params[2]).'"];'."\n";
}
}
31 changes: 31 additions & 0 deletions src/Filters/Actions/DeleteHeaderFilterAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PhpSieveManager\Filters\Actions;

use PhpSieveManager\Exceptions\FilterActionParamException;

/**
* Please refer to https://datatracker.ietf.org/doc/html/rfc5293#section-5
*/
class DeleteHeaderFilterAction implements FilterAction
{
private $params;

/**
* @param array $params
* @throws FilterActionParamException
*/
public function __construct(array $params = []) {
if (count($params) != 1) {
throw new FilterActionParamException("DeleteHeaderFilterAction expect one parameters");
}
$this->params = $params;
}

/**
* @return string
*/
public function parse() {
return 'deleteheader "'.$this->params[0].'";'."\n";
}
}
31 changes: 31 additions & 0 deletions src/Filters/Actions/EncloseFilterAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PhpSieveManager\Filters\Actions;

use PhpSieveManager\Exceptions\FilterActionParamException;

/**
* Please refer to https://www.rfc-editor.org/rfc/rfc5703.html#section-6
*/
class EncloseFilterAction implements FilterAction
{
private $params;

/**
* @param array $params
* @throws FilterActionParamException
*/
public function __construct(array $params = []) {
if (count($params) != 1) {
throw new FilterActionParamException("EncloseFilterAction expect one parameters");
}
$this->params = $params;
}

/**
* @return string
*/
public function parse() {
return 'enclose "'.$this->params[0].'";'."\n";
}
}
34 changes: 34 additions & 0 deletions src/Filters/Actions/ExtractTextFilterAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace PhpSieveManager\Filters\Actions;

use PhpSieveManager\Exceptions\FilterActionParamException;

/**
* Please refer to https://www.rfc-editor.org/rfc/rfc5703.html#page-11
*/
class ExtractTextFilterAction implements FilterAction
{
private $params;

/**
* @param array $params
* @throws FilterActionParamException
*/
public function __construct(array $params = []) {
if ($params && count($params) > 2) {
throw new FilterActionParamException("ExtractTextFilterAction expect one or two parameters");
}
$this->params = $params;
}

/**
* @return string
*/
public function parse() {
if (count($this->params) == 1) {
return 'extracttext "'.$this->params[0].'";'."\n";
}
return 'extracttext :first '.$this->params[0].' "'.$this->params[1].'";'."\n";
}
}
31 changes: 31 additions & 0 deletions src/Filters/Actions/NotifyFilterAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PhpSieveManager\Filters\Actions;

use PhpSieveManager\Exceptions\FilterActionParamException;

/**
* Please refer to https://datatracker.ietf.org/doc/rfc5435/
*/
class NotifyFilterAction implements FilterAction
{
private $params;

/**
* @param array $params
* @throws FilterActionParamException
*/
public function __construct(array $params = []) {
if (count($params) != 3) {
throw new FilterActionParamException("NotifyFilterAction expect three parameters");
}
$this->params = $params;
}

/**
* @return string
*/
public function parse() {
return 'notify :importance "'.$this->params[0].'" :text "'.$this->params[1].'" "'.$this->params[2].'";'."\n";
}
}
31 changes: 31 additions & 0 deletions src/Filters/Actions/SetFilterAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PhpSieveManager\Filters\Actions;

use PhpSieveManager\Exceptions\FilterActionParamException;

/**
* Please refer to https://www.rfc-editor.org/rfc/rfc5229.html
*/
class SetFilterAction implements FilterAction
{
private $params;

/**
* @param array $params
* @throws FilterActionParamException
*/
public function __construct(array $params = []) {
if (count($params) != 2) {
throw new FilterActionParamException("SetFilterAction expect two parameters");
}
$this->params = $params;
}

/**
* @return string
*/
public function parse() {
return 'set "'.$this->params[0].'" "'.$this->params[1].'";'."\n";
}
}

0 comments on commit f6cf3f9

Please sign in to comment.