1
1
<?php
2
+
2
3
class ispconfig3_spam extends rcube_plugin
3
4
{
4
5
public $ task = 'settings ' ;
5
6
private $ rcmail ;
6
7
private $ rc ;
7
8
private $ soap ;
8
9
9
- const content_filters = [
10
+ const CONTENT_FILTERS = [
10
11
'amavisd ' => [
11
12
'policy_tag ' => 'spam_tag_level ' ,
12
13
'policy_tag2 ' => 'spam_tag2_level ' ,
@@ -26,29 +27,25 @@ function init()
26
27
$ this ->add_texts ('localization/ ' );
27
28
$ this ->require_plugin ('ispconfig3_account ' );
28
29
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 ' ] );
31
32
32
33
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 ' ] );
36
37
37
38
$ this ->include_script ('spam.js ' );
38
39
$ this ->include_stylesheet ($ this ->local_skin_path () . '/spam.css ' );
39
40
40
- $ this ->soap = new SoapClient (null , array (
41
+ $ this ->soap = new SoapClient (null , [
41
42
'location ' => $ this ->rcmail ->config ->get ('soap_url ' ) . 'index.php ' ,
42
43
'uri ' => $ this ->rcmail ->config ->get ('soap_url ' ),
43
44
$ 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
+ ]);
52
49
}
53
50
}
54
51
@@ -67,64 +64,66 @@ function save()
67
64
{
68
65
$ policy_id = rcube_utils::get_input_value ('_spampolicy_name ' , rcube_utils::INPUT_POST );
69
66
$ 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 ' ;
75
68
76
69
try {
77
70
$ 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 ' ]] );
79
72
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
80
73
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 ' ]] );
82
75
}
83
76
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 ' ]] );
85
78
$ uid = $ this ->soap ->client_get_id ($ session_id , $ mail_user [0 ]['sys_userid ' ]);
86
79
87
80
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 );
96
91
}
97
92
else {
98
93
$ params = $ spam_user [0 ];
99
94
$ params ['policy_id ' ] = $ policy_id ;
100
95
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 );
102
97
}
103
98
104
99
$ params = $ mail_user [0 ];
105
100
unset($ params ['password ' ]);
106
101
107
102
$ ispconfig_version = $ this ->soap ->server_get_app_version ($ session_id );
108
103
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 ),
110
106
'month ' => substr ($ params ['autoresponder_start_date ' ], 5 , 2 ),
111
107
'day ' => substr ($ params ['autoresponder_start_date ' ], 8 , 2 ),
112
108
'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
+ ];
114
111
115
- $ enddate = array ('year ' => substr ($ params ['autoresponder_end_date ' ], 0 , 4 ),
112
+ $ enddate = [
113
+ 'year ' => substr ($ params ['autoresponder_end_date ' ], 0 , 4 ),
116
114
'month ' => substr ($ params ['autoresponder_end_date ' ], 5 , 2 ),
117
115
'day ' => substr ($ params ['autoresponder_end_date ' ], 8 , 2 ),
118
116
'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
+ ];
120
119
121
120
$ params ['autoresponder_end_date ' ] = $ enddate ;
122
121
$ params ['autoresponder_start_date ' ] = $ startdate ;
123
122
}
124
123
125
124
$ params ['move_junk ' ] = $ move_junk ;
126
125
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 );
128
127
$ this ->soap ->logout ($ session_id );
129
128
130
129
$ this ->rcmail ->output ->command ('display_message ' , $ this ->gettext ('successfullysaved ' ), 'confirmation ' );
@@ -139,59 +138,60 @@ function save()
139
138
140
139
function gen_form ($ attrib )
141
140
{
142
- $ policy_name = array () ;
143
- $ policy_id = array () ;
141
+ $ policy_name = [] ;
142
+ $ policy_id = [] ;
144
143
$ enabled = 0 ;
145
144
146
145
$ form_id = $ attrib ['id ' ] ?: 'form ' ;
147
- $ out = $ this ->rcmail ->output ->request_form (array (
146
+ $ out = $ this ->rcmail ->output ->request_form ([
148
147
'id ' => $ form_id ,
149
148
'name ' => $ form_id ,
150
149
'method ' => 'post ' ,
151
150
'task ' => 'settings ' ,
152
151
'action ' => 'plugin.ispconfig3_spam.save ' ,
153
152
'noclose ' => true
154
- ) + $ attrib );
153
+ ] + $ attrib );
155
154
156
155
$ out .= '<fieldset><legend> ' . $ this ->gettext ('acc_spam ' ) . '</legend> ' . "\n" ;
157
156
158
157
try {
159
158
$ 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 ' ]] );
161
160
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
162
161
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 ' ]] );
164
163
}
165
164
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 ' ]] );
169
168
$ this ->soap ->logout ($ session_id );
170
169
171
- foreach ($ policies as $ policy ) {
170
+ foreach (( array ) $ policies as $ policy ) {
172
171
$ policy_name [] = $ policy ['policy_name ' ];
173
172
$ policy_id [] = $ policy ['id ' ];
174
173
}
175
174
176
175
$ enabled = $ mail_user [0 ]['move_junk ' ];
177
- if ($ enabled == 'y ' )
176
+ if ($ enabled == 'y ' ) {
178
177
$ enabled = 1 ;
178
+ }
179
179
}
180
180
catch (SoapFault $ e ) {
181
181
$ error = $ this ->rc ->text_exists ($ e ->getMessage (), $ this ->ID ) ? $ this ->gettext ($ e ->getMessage ()) : $ e ->getMessage ();
182
182
$ this ->rcmail ->output ->command ('display_message ' , 'Soap Error: ' . $ error , 'error ' );
183
183
}
184
184
185
- $ table = new html_table (array ( 'cols ' => 2 , 'class ' => 'propform ' ) );
185
+ $ table = new html_table ([ 'cols ' => 2 , 'class ' => 'propform ' ] );
186
186
187
187
$ 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] );
189
189
$ input_spampolicy_name ->add ($ policy_name , $ policy_id );
190
190
$ 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 ' ] ?? '' ));
192
192
193
193
$ 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 ' ] );
195
195
$ table ->add ('title ' , html::label ($ field_id , rcube::Q ($ this ->gettext ('spammove ' ))));
196
196
$ table ->add ('' , $ input_spammove ->show ($ enabled ));
197
197
$ out .= $ table ->show ();
@@ -206,18 +206,18 @@ function gen_table($attrib)
206
206
$ out = '<fieldset><legend> ' . $ this ->gettext ('policy_entries ' ) . '</legend> ' . "\n" ;
207
207
208
208
$ 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 ' ));
210
210
211
211
try {
212
212
$ 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 ' ]] );
214
214
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
215
215
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 ' ]] );
217
217
}
218
218
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 , [] );
221
221
$ mail_server_config = $ this ->soap ->server_get ($ session_id , $ mail_user [0 ]['server_id ' ], 'mail ' );
222
222
$ this ->soap ->logout ($ session_id );
223
223
@@ -226,20 +226,20 @@ function gen_table($attrib)
226
226
$ filter = 'rspamd ' ;
227
227
}
228
228
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 ]);
231
231
232
232
$ spam_table ->add_header ([ 'class ' => 'value ' , 'width ' => '150px ' ], $ this ->gettext ($ policy_titles [0 ]));
233
233
$ spam_table ->add_header ([ 'class ' => 'value ' , 'width ' => '150px ' ], $ this ->gettext ($ policy_titles [1 ]));
234
234
$ spam_table ->add_header ([ 'class ' => 'value ' , 'width ' => '130px ' ], $ this ->gettext ($ policy_titles [2 ]));
235
235
236
- foreach ($ policies as $ policy ) {
236
+ foreach (( array ) $ policies as $ policy ) {
237
237
if ($ policy ['id ' ] == $ spam_user [0 ]['policy_id ' ]) {
238
238
$ spam_table ->set_row_attribs ([ 'class ' => 'selected ' ]);
239
239
}
240
240
241
241
$ 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 ]]);
243
243
}
244
244
245
245
if (empty ($ policies )) {
@@ -259,13 +259,11 @@ function gen_table($attrib)
259
259
return $ out ;
260
260
}
261
261
262
- private function _spam_row ($ spam_table , $ name , $ tag , $ tag2 , $ kill, $ attrib )
262
+ private function _spam_row ($ spam_table , $ name , $ tag , $ tag2 , $ kill )
263
263
{
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 );
270
268
}
271
269
}
0 commit comments