|
5 | 5 | /** |
6 | 6 | * Please refer to https://datatracker.ietf.org/doc/html/rfc5293#section-5 |
7 | 7 | */ |
8 | | -class DeleteHeaderFilterAction implements FilterAction |
| 8 | +class DeleteHeaderFilterAction extends BaseSieveAction |
9 | 9 | { |
10 | | - private $index; |
11 | | - private $last; |
12 | | - private $comparator; |
13 | | - private $matchType; |
14 | | - private $fieldName; |
15 | | - private $valuePatterns; |
16 | | - |
17 | 10 | public $require = ['editheader']; |
18 | 11 |
|
19 | | - /** |
20 | | - * @param string $fieldName - The field name of the header to delete |
21 | | - * @param int|null $index - Index of the header to delete |
22 | | - * @param bool $last - Flag to indicate if the last occurrence should be deleted |
23 | | - * @param string|null $comparator - Comparator for matching |
24 | | - * @param string|null $matchType - Type of match |
25 | | - * @param array|null $valuePatterns - Patterns to match the header value |
26 | | - */ |
27 | | - public function __construct($fieldName, $index = null, $last = false, $comparator = null, $matchType = null, $valuePatterns = []) { |
28 | | - $this->index = $index; |
29 | | - $this->last = $last; |
30 | | - $this->comparator = $comparator; |
31 | | - $this->matchType = $matchType; |
32 | | - $this->fieldName = $fieldName; |
33 | | - $this->valuePatterns = $valuePatterns; |
| 12 | + protected function getRequiredParams() |
| 13 | + { |
| 14 | + return ['field-name']; |
| 15 | + } |
| 16 | + |
| 17 | + protected function getParamTypes() { |
| 18 | + return [ |
| 19 | + 'index' => 'bool', |
| 20 | + 'last' => 'bool', |
| 21 | + 'comparator' => 'string', |
| 22 | + 'match-type' => 'string', |
| 23 | + 'field-name' => 'string', |
| 24 | + 'value-patterns' => 'string-list' |
| 25 | + ]; |
34 | 26 | } |
35 | 27 |
|
36 | 28 | /** |
37 | 29 | * @return string |
38 | 30 | */ |
39 | 31 | public function parse() { |
40 | 32 | $script = "deleteheader"; |
41 | | - if ($this->index) { |
42 | | - $script .= " :index {$this->index}"; |
43 | | - if ($this->last) { |
| 33 | + if (!empty($this->params['index'])) { |
| 34 | + $script .= " :index {$this->params['index']}"; |
| 35 | + if (!empty($this->params['last'])) { |
44 | 36 | $script .= " :last"; |
45 | 37 | } |
46 | 38 | } |
47 | | - if ($this->comparator) { |
48 | | - $script .= " {$this->comparator}"; |
| 39 | + if (!empty($this->params['comparator'])) { |
| 40 | + $script .= " {$this->params['comparator']}"; |
49 | 41 | } |
50 | | - if ($this->matchType) { |
51 | | - $script .= " {$this->matchType}"; |
| 42 | + if (!empty($this->params['match-type'])) { |
| 43 | + $script .= " {$this->params['match-type']}"; |
52 | 44 | } |
53 | | - $script .= " \"{$this->fieldName}\""; |
54 | | - if ($this->valuePatterns) { |
55 | | - $script .= " [\"" . implode('", "', $this->valuePatterns) . "\"]"; |
| 45 | + $script .= " \"{$this->params['field-name']}\""; |
| 46 | + if (!empty($this->params['value-patterns'])) { |
| 47 | + $script .= " [\"" . implode('", "', $this->params['value-patterns']) . "\"]"; |
56 | 48 | } |
57 | 49 | $script .= ";\n"; |
58 | 50 | return $script; |
|
0 commit comments