11<?php
2+
23class ispconfig3_spam extends rcube_plugin
34{
45 public $ task = 'settings ' ;
56 private $ rcmail ;
67 private $ rc ;
78 private $ soap ;
89
9- const content_filters = [
10+ const CONTENT_FILTERS = [
1011 'amavisd ' => [
1112 'policy_tag ' => 'spam_tag_level ' ,
1213 'policy_tag2 ' => 'spam_tag2_level ' ,
@@ -26,29 +27,25 @@ function init()
2627 $ this ->add_texts ('localization/ ' );
2728 $ this ->require_plugin ('ispconfig3_account ' );
2829
29- $ this ->register_action ('plugin.ispconfig3_spam ' , array ( $ this , 'init_html ' ) );
30- $ this ->register_action ('plugin.ispconfig3_spam.save ' , array ( $ this , 'save ' ) );
30+ $ this ->register_action ('plugin.ispconfig3_spam ' , [ $ this , 'init_html ' ] );
31+ $ this ->register_action ('plugin.ispconfig3_spam.save ' , [ $ this , 'save ' ] );
3132
3233 if (strpos ($ this ->rcmail ->action , 'plugin.ispconfig3_spam ' ) === 0 ) {
33- $ this ->api ->output ->add_handler ('spam_form ' , array ( $ this , 'gen_form ' ) );
34- $ this ->api ->output ->add_handler ('sectionname_spam ' , array ( $ this , 'prefs_section_name ' ) );
35- $ this ->api ->output ->add_handler ('spam_table ' , array ( $ this , 'gen_table ' ) );
34+ $ this ->api ->output ->add_handler ('spam_form ' , [ $ this , 'gen_form ' ] );
35+ $ this ->api ->output ->add_handler ('sectionname_spam ' , [ $ this , 'prefs_section_name ' ] );
36+ $ this ->api ->output ->add_handler ('spam_table ' , [ $ this , 'gen_table ' ] );
3637
3738 $ this ->include_script ('spam.js ' );
3839 $ this ->include_stylesheet ($ this ->local_skin_path () . '/spam.css ' );
3940
40- $ this ->soap = new SoapClient (null , array (
41+ $ this ->soap = new SoapClient (null , [
4142 'location ' => $ this ->rcmail ->config ->get ('soap_url ' ) . 'index.php ' ,
4243 'uri ' => $ this ->rcmail ->config ->get ('soap_url ' ),
4344 $ this ->rcmail ->config ->get ('soap_validate_cert ' ) ?:
44- 'stream_context ' => stream_context_create (
45- array ('ssl ' => array (
46- 'verify_peer ' => false ,
47- 'verify_peer_name ' => false ,
48- 'allow_self_signed ' => true
49- )
50- ))
51- ));
45+ 'stream_context ' => stream_context_create (['ssl ' => [
46+ 'verify_peer ' => false , 'verify_peer_name ' => false , 'allow_self_signed ' => true
47+ ]])
48+ ]);
5249 }
5350 }
5451
@@ -67,64 +64,66 @@ function save()
6764 {
6865 $ policy_id = rcube_utils::get_input_value ('_spampolicy_name ' , rcube_utils::INPUT_POST );
6966 $ move_junk = rcube_utils::get_input_value ('_spammove ' , rcube_utils::INPUT_POST );
70-
71- if (!$ move_junk )
72- $ move_junk = 'n ' ;
73- else
74- $ move_junk = 'y ' ;
67+ $ move_junk = (!$ move_junk ) ? 'n ' : 'y ' ;
7568
7669 try {
7770 $ session_id = $ this ->soap ->login ($ this ->rcmail ->config ->get ('remote_soap_user ' ), $ this ->rcmail ->config ->get ('remote_soap_pass ' ));
78- $ mail_user = $ this ->soap ->mail_user_get ($ session_id , array ( 'login ' => $ this ->rcmail ->user ->data ['username ' ]) );
71+ $ mail_user = $ this ->soap ->mail_user_get ($ session_id , [ 'login ' => $ this ->rcmail ->user ->data ['username ' ]] );
7972 // Alternatively also search the email field, this can differ from the login field for legacy reasons.
8073 if (empty ($ mail_user )) {
81- $ mail_user = $ this ->soap ->mail_user_get ($ session_id , array ( 'email ' => $ this ->rcmail ->user ->data ['username ' ]) );
74+ $ mail_user = $ this ->soap ->mail_user_get ($ session_id , [ 'email ' => $ this ->rcmail ->user ->data ['username ' ]] );
8275 }
8376
84- $ spam_user = $ this ->soap ->mail_spamfilter_user_get ($ session_id , array ( 'email ' => $ mail_user [0 ]['email ' ]) );
77+ $ spam_user = $ this ->soap ->mail_spamfilter_user_get ($ session_id , [ 'email ' => $ mail_user [0 ]['email ' ]] );
8578 $ uid = $ this ->soap ->client_get_id ($ session_id , $ mail_user [0 ]['sys_userid ' ]);
8679
8780 if ($ spam_user [0 ]['id ' ] == '' ) {
88- $ params = array ('server_id ' => $ mail_user [0 ]['server_id ' ],
89- 'priority ' => '5 ' ,
90- 'policy_id ' => $ policy_id ,
91- 'email ' => $ mail_user [0 ]['email ' ],
92- 'fullname ' => $ mail_user [0 ]['email ' ],
93- 'local ' => 'Y ' );
94-
95- $ add = $ this ->soap ->mail_spamfilter_user_add ($ session_id , $ uid , $ params );
81+ $ params = [
82+ 'server_id ' => $ mail_user [0 ]['server_id ' ],
83+ 'priority ' => '5 ' ,
84+ 'policy_id ' => $ policy_id ,
85+ 'email ' => $ mail_user [0 ]['email ' ],
86+ 'fullname ' => $ mail_user [0 ]['email ' ],
87+ 'local ' => 'Y '
88+ ];
89+
90+ $ this ->soap ->mail_spamfilter_user_add ($ session_id , $ uid , $ params );
9691 }
9792 else {
9893 $ params = $ spam_user [0 ];
9994 $ params ['policy_id ' ] = $ policy_id ;
10095
101- $ update = $ this ->soap ->mail_spamfilter_user_update ($ session_id , $ uid , $ spam_user [0 ]['id ' ], $ params );
96+ $ this ->soap ->mail_spamfilter_user_update ($ session_id , $ uid , $ spam_user [0 ]['id ' ], $ params );
10297 }
10398
10499 $ params = $ mail_user [0 ];
105100 unset($ params ['password ' ]);
106101
107102 $ ispconfig_version = $ this ->soap ->server_get_app_version ($ session_id );
108103 if (version_compare ($ ispconfig_version ['ispc_app_version ' ], '3.1dev ' , '< ' )) {
109- $ startdate = array ('year ' => substr ($ params ['autoresponder_start_date ' ], 0 , 4 ),
104+ $ startdate = [
105+ 'year ' => substr ($ params ['autoresponder_start_date ' ], 0 , 4 ),
110106 'month ' => substr ($ params ['autoresponder_start_date ' ], 5 , 2 ),
111107 'day ' => substr ($ params ['autoresponder_start_date ' ], 8 , 2 ),
112108 'hour ' => substr ($ params ['autoresponder_start_date ' ], 11 , 2 ),
113- 'minute ' => substr ($ params ['autoresponder_start_date ' ], 14 , 2 ));
109+ 'minute ' => substr ($ params ['autoresponder_start_date ' ], 14 , 2 )
110+ ];
114111
115- $ enddate = array ('year ' => substr ($ params ['autoresponder_end_date ' ], 0 , 4 ),
112+ $ enddate = [
113+ 'year ' => substr ($ params ['autoresponder_end_date ' ], 0 , 4 ),
116114 'month ' => substr ($ params ['autoresponder_end_date ' ], 5 , 2 ),
117115 'day ' => substr ($ params ['autoresponder_end_date ' ], 8 , 2 ),
118116 'hour ' => substr ($ params ['autoresponder_end_date ' ], 11 , 2 ),
119- 'minute ' => substr ($ params ['autoresponder_end_date ' ], 14 , 2 ));
117+ 'minute ' => substr ($ params ['autoresponder_end_date ' ], 14 , 2 )
118+ ];
120119
121120 $ params ['autoresponder_end_date ' ] = $ enddate ;
122121 $ params ['autoresponder_start_date ' ] = $ startdate ;
123122 }
124123
125124 $ params ['move_junk ' ] = $ move_junk ;
126125
127- $ update = $ this ->soap ->mail_user_update ($ session_id , $ uid , $ mail_user [0 ]['mailuser_id ' ], $ params );
126+ $ this ->soap ->mail_user_update ($ session_id , $ uid , $ mail_user [0 ]['mailuser_id ' ], $ params );
128127 $ this ->soap ->logout ($ session_id );
129128
130129 $ this ->rcmail ->output ->command ('display_message ' , $ this ->gettext ('successfullysaved ' ), 'confirmation ' );
@@ -139,59 +138,60 @@ function save()
139138
140139 function gen_form ($ attrib )
141140 {
142- $ policy_name = array () ;
143- $ policy_id = array () ;
141+ $ policy_name = [] ;
142+ $ policy_id = [] ;
144143 $ enabled = 0 ;
145144
146145 $ form_id = $ attrib ['id ' ] ?: 'form ' ;
147- $ out = $ this ->rcmail ->output ->request_form (array (
146+ $ out = $ this ->rcmail ->output ->request_form ([
148147 'id ' => $ form_id ,
149148 'name ' => $ form_id ,
150149 'method ' => 'post ' ,
151150 'task ' => 'settings ' ,
152151 'action ' => 'plugin.ispconfig3_spam.save ' ,
153152 'noclose ' => true
154- ) + $ attrib );
153+ ] + $ attrib );
155154
156155 $ out .= '<fieldset><legend> ' . $ this ->gettext ('acc_spam ' ) . '</legend> ' . "\n" ;
157156
158157 try {
159158 $ session_id = $ this ->soap ->login ($ this ->rcmail ->config ->get ('remote_soap_user ' ), $ this ->rcmail ->config ->get ('remote_soap_pass ' ));
160- $ mail_user = $ this ->soap ->mail_user_get ($ session_id , array ( 'login ' => $ this ->rcmail ->user ->data ['username ' ]) );
159+ $ mail_user = $ this ->soap ->mail_user_get ($ session_id , [ 'login ' => $ this ->rcmail ->user ->data ['username ' ]] );
161160 // Alternatively also search the email field, this can differ from the login field for legacy reasons.
162161 if (empty ($ mail_user )) {
163- $ mail_user = $ this ->soap ->mail_user_get ($ session_id , array ( 'email ' => $ this ->rcmail ->user ->data ['username ' ]) );
162+ $ mail_user = $ this ->soap ->mail_user_get ($ session_id , [ 'email ' => $ this ->rcmail ->user ->data ['username ' ]] );
164163 }
165164
166- $ spam_user = $ this ->soap ->mail_spamfilter_user_get ($ session_id , array ( 'email ' => $ mail_user [0 ]['email ' ]) );
167- $ policies = $ this ->soap ->mail_policy_get ($ session_id , array () );
168- $ policy_sel = $ this ->soap ->mail_policy_get ($ session_id , array ( 'id ' => $ spam_user [0 ]['policy_id ' ]) );
165+ $ spam_user = $ this ->soap ->mail_spamfilter_user_get ($ session_id , [ 'email ' => $ mail_user [0 ]['email ' ]] );
166+ $ policies = $ this ->soap ->mail_policy_get ($ session_id , [] );
167+ $ policy_sel = $ this ->soap ->mail_policy_get ($ session_id , [ 'id ' => $ spam_user [0 ]['policy_id ' ]] );
169168 $ this ->soap ->logout ($ session_id );
170169
171- foreach ($ policies as $ policy ) {
170+ foreach (( array ) $ policies as $ policy ) {
172171 $ policy_name [] = $ policy ['policy_name ' ];
173172 $ policy_id [] = $ policy ['id ' ];
174173 }
175174
176175 $ enabled = $ mail_user [0 ]['move_junk ' ];
177- if ($ enabled == 'y ' )
176+ if ($ enabled == 'y ' ) {
178177 $ enabled = 1 ;
178+ }
179179 }
180180 catch (SoapFault $ e ) {
181181 $ error = $ this ->rc ->text_exists ($ e ->getMessage (), $ this ->ID ) ? $ this ->gettext ($ e ->getMessage ()) : $ e ->getMessage ();
182182 $ this ->rcmail ->output ->command ('display_message ' , 'Soap Error: ' . $ error , 'error ' );
183183 }
184184
185- $ table = new html_table (array ( 'cols ' => 2 , 'class ' => 'propform ' ) );
185+ $ table = new html_table ([ 'cols ' => 2 , 'class ' => 'propform ' ] );
186186
187187 $ field_id = 'spampolicy_name ' ;
188- $ input_spampolicy_name = new html_select (array ( 'name ' => '_ ' . $ field_id , 'id ' => $ field_id) );
188+ $ input_spampolicy_name = new html_select ([ 'name ' => '_ ' . $ field_id , 'id ' => $ field_id] );
189189 $ input_spampolicy_name ->add ($ policy_name , $ policy_id );
190190 $ table ->add ('title ' , html::label ($ field_id , rcube::Q ($ this ->gettext ('policy_name ' ))));
191- $ table ->add ('' , $ input_spampolicy_name ->show ($ policy_sel [0 ]['policy_name ' ]));
191+ $ table ->add ('' , $ input_spampolicy_name ->show ($ policy_sel [0 ]['policy_name ' ] ?? '' ));
192192
193193 $ field_id = 'spammove ' ;
194- $ input_spammove = new html_checkbox (array ( 'name ' => '_ ' . $ field_id , 'id ' => $ field_id , 'value ' => '1 ' ) );
194+ $ input_spammove = new html_checkbox ([ 'name ' => '_ ' . $ field_id , 'id ' => $ field_id , 'value ' => '1 ' ] );
195195 $ table ->add ('title ' , html::label ($ field_id , rcube::Q ($ this ->gettext ('spammove ' ))));
196196 $ table ->add ('' , $ input_spammove ->show ($ enabled ));
197197 $ out .= $ table ->show ();
@@ -206,18 +206,18 @@ function gen_table($attrib)
206206 $ out = '<fieldset><legend> ' . $ this ->gettext ('policy_entries ' ) . '</legend> ' . "\n" ;
207207
208208 $ spam_table = new html_table ([ 'id ' => 'spam-table ' , 'class ' => 'records-table ' , 'cellspacing ' => '0 ' , 'cols ' => 4 ]);
209- $ spam_table ->add_header (array ( 'width ' => '220px ' ) , $ this ->gettext ('policy_name ' ));
209+ $ spam_table ->add_header ([ 'width ' => '220px ' ] , $ this ->gettext ('policy_name ' ));
210210
211211 try {
212212 $ session_id = $ this ->soap ->login ($ this ->rcmail ->config ->get ('remote_soap_user ' ), $ this ->rcmail ->config ->get ('remote_soap_pass ' ));
213- $ mail_user = $ this ->soap ->mail_user_get ($ session_id , array ( 'login ' => $ this ->rcmail ->user ->data ['username ' ]) );
213+ $ mail_user = $ this ->soap ->mail_user_get ($ session_id , [ 'login ' => $ this ->rcmail ->user ->data ['username ' ]] );
214214 // Alternatively also search the email field, this can differ from the login field for legacy reasons.
215215 if (empty ($ mail_user )) {
216- $ mail_user = $ this ->soap ->mail_user_get ($ session_id , array ( 'email ' => $ this ->rcmail ->user ->data ['username ' ]) );
216+ $ mail_user = $ this ->soap ->mail_user_get ($ session_id , [ 'email ' => $ this ->rcmail ->user ->data ['username ' ]] );
217217 }
218218
219- $ spam_user = $ this ->soap ->mail_spamfilter_user_get ($ session_id , array ( 'email ' => $ mail_user [0 ]['email ' ]) );
220- $ policies = $ this ->soap ->mail_policy_get ($ session_id , array () );
219+ $ spam_user = $ this ->soap ->mail_spamfilter_user_get ($ session_id , [ 'email ' => $ mail_user [0 ]['email ' ]] );
220+ $ policies = $ this ->soap ->mail_policy_get ($ session_id , [] );
221221 $ mail_server_config = $ this ->soap ->server_get ($ session_id , $ mail_user [0 ]['server_id ' ], 'mail ' );
222222 $ this ->soap ->logout ($ session_id );
223223
@@ -226,20 +226,20 @@ function gen_table($attrib)
226226 $ filter = 'rspamd ' ;
227227 }
228228
229- $ policy_titles = array_keys (self ::content_filters [$ filter ]);
230- $ policy_fields = array_values (self ::content_filters [$ filter ]);
229+ $ policy_titles = array_keys (self ::CONTENT_FILTERS [$ filter ]);
230+ $ policy_fields = array_values (self ::CONTENT_FILTERS [$ filter ]);
231231
232232 $ spam_table ->add_header ([ 'class ' => 'value ' , 'width ' => '150px ' ], $ this ->gettext ($ policy_titles [0 ]));
233233 $ spam_table ->add_header ([ 'class ' => 'value ' , 'width ' => '150px ' ], $ this ->gettext ($ policy_titles [1 ]));
234234 $ spam_table ->add_header ([ 'class ' => 'value ' , 'width ' => '130px ' ], $ this ->gettext ($ policy_titles [2 ]));
235235
236- foreach ($ policies as $ policy ) {
236+ foreach (( array ) $ policies as $ policy ) {
237237 if ($ policy ['id ' ] == $ spam_user [0 ]['policy_id ' ]) {
238238 $ spam_table ->set_row_attribs ([ 'class ' => 'selected ' ]);
239239 }
240240
241241 $ this ->_spam_row ($ spam_table , $ policy ['policy_name ' ], $ policy [$ policy_fields [0 ]],
242- $ policy [$ policy_fields [1 ]], $ policy [$ policy_fields [2 ]], $ attrib );
242+ $ policy [$ policy_fields [1 ]], $ policy [$ policy_fields [2 ]]);
243243 }
244244
245245 if (empty ($ policies )) {
@@ -259,13 +259,11 @@ function gen_table($attrib)
259259 return $ out ;
260260 }
261261
262- private function _spam_row ($ spam_table , $ name , $ tag , $ tag2 , $ kill, $ attrib )
262+ private function _spam_row ($ spam_table , $ name , $ tag , $ tag2 , $ kill )
263263 {
264- $ spam_table ->add (array ('class ' => 'policy ' ), $ name );
265- $ spam_table ->add (array ('class ' => 'value ' ), ' ' . $ tag );
266- $ spam_table ->add (array ('class ' => 'value ' ), ' ' . $ tag2 );
267- $ spam_table ->add (array ('class ' => 'value ' ), $ kill );
268-
269- return $ spam_table ;
264+ $ spam_table ->add (['class ' => 'policy ' ], $ name );
265+ $ spam_table ->add (['class ' => 'value ' ], ' ' . $ tag );
266+ $ spam_table ->add (['class ' => 'value ' ], ' ' . $ tag2 );
267+ $ spam_table ->add (['class ' => 'value ' ], $ kill );
270268 }
271269}
0 commit comments