22
33namespace PhpSieveManager \Filters \Actions ;
44
5- use PhpSieveManager \Exceptions \FilterActionParamException ;
6-
75/**
86 * Please refer to https://datatracker.ietf.org/doc/html/rfc5293#section-5
97 */
10- class DeleteHeaderFilterAction implements FilterAction
8+ class DeleteHeaderFilterAction extends BaseSieveAction
119{
12- private $ params ;
10+ public $ require = [ ' editheader ' ] ;
1311
14- /**
15- * @param array $params
16- * @throws FilterActionParamException
17- */
18- public function __construct (array $ params = []) {
19- if (count ($ params ) != 1 ) {
20- throw new FilterActionParamException ("DeleteHeaderFilterAction expect one parameters " );
21- }
22- $ this ->params = $ params ;
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+ ];
2326 }
2427
2528 /**
2629 * @return string
2730 */
2831 public function parse () {
29- return 'deleteheader " ' .$ this ->params [0 ].'"; ' ."\n" ;
32+ $ script = "deleteheader " ;
33+ if (!empty ($ this ->params ['index ' ])) {
34+ $ script .= " :index {$ this ->params ['index ' ]}" ;
35+ if (!empty ($ this ->params ['last ' ])) {
36+ $ script .= " :last " ;
37+ }
38+ }
39+ if (!empty ($ this ->params ['comparator ' ])) {
40+ $ script .= " {$ this ->params ['comparator ' ]}" ;
41+ }
42+ if (!empty ($ this ->params ['match-type ' ])) {
43+ $ script .= " {$ this ->params ['match-type ' ]}" ;
44+ }
45+ $ script .= " \"{$ this ->params ['field-name ' ]}\"" ;
46+ if (!empty ($ this ->params ['value-patterns ' ])) {
47+ $ script .= " [ \"" . implode ('", " ' , $ this ->params ['value-patterns ' ]) . "\"] " ;
48+ }
49+ $ script .= "; \n" ;
50+ return $ script ;
3051 }
3152}
0 commit comments