~ubuntu-branches/ubuntu/raring/roundcube-plugins-extra/raring

« back to all changes in this revision

Viewing changes to sieverules-1-11/sieverules.php

Tags: 0.5.4-20110919
* Bump version number for Roundcube to 0.5.4.
* Upgrade sieverules to version 1.11-20110813.
* Label jqueryui as version 1.8+dfsg instead of 1.8.12+dfsg.
* Upgrade sauserprefs to version 1.6-20110828.
* Upgrade markasjunk2 to version 1.3.
* Fix typo in debian/copyright.
* Use system-wide jQuery Mousewheel plugin in contextmenu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * SieveRules
5
 
 *
6
 
 * Plugin to allow the user to manage their Sieve filters using the managesieve protocol
7
 
 *
8
 
 * @version 1.11
9
 
 * @author Philip Weir
10
 
 * Based on the Managesieve plugin by Aleksander Machniak
11
 
 */
12
 
class sieverules extends rcube_plugin
13
 
{
14
 
        public $task = 'settings';
15
 
        private $sieve;
16
 
        private $sieve_error;
17
 
        private $script;
18
 
        private $action;
19
 
        private $examples = array();
20
 
        private $force_vacto = false;
21
 
        private $show_vacfrom = false;
22
 
        private $show_vachandle = false;
23
 
        private $current_ruleset;
24
 
 
25
 
        // default values: label => value
26
 
        private $headers = array('subject' => 'header::Subject',
27
 
                                        'from' => 'address::From',
28
 
                                        'to' => 'address::To',
29
 
                                        'cc' => 'address::Cc',
30
 
                                        'bcc' => 'address::Bcc',
31
 
                                        'envelopeto' => 'envelope::To',
32
 
                                        'envelopefrom' => 'envelope::From'
33
 
                                        );
34
 
 
35
 
        private $operators = array('filtercontains' => 'contains',
36
 
                                        'filternotcontains' => 'notcontains',
37
 
                                        'filteris' => 'is',
38
 
                                        'filterisnot' => 'notis',
39
 
                                        'filterexists' => 'exists',
40
 
                                        'filternotexists' => 'notexists'
41
 
                                        );
42
 
 
43
 
        private $flags = array('flagread' => '\\\\Seen',
44
 
                                        'flagdeleted' => '\\\\Deleted',
45
 
                                        'flaganswered' => '\\\\Answered',
46
 
                                        'flagdraft' => '\\\\Draft',
47
 
                                        'flagflagged' => '\\\\Flagged'
48
 
                                        );
49
 
 
50
 
        function init()
51
 
        {
52
 
                $rcmail = rcmail::get_instance();
53
 
                $this->load_config();
54
 
 
55
 
                if ($rcmail->config->get('sieverules_multiplerules') && get_input_value('_ruleset', RCUBE_INPUT_GET, true))
56
 
                        $this->current_ruleset = get_input_value('_ruleset', RCUBE_INPUT_GET, true);
57
 
                elseif ($rcmail->config->get('sieverules_multiplerules') && $_SESSION['sieverules_current_ruleset'])
58
 
                        $this->current_ruleset = $_SESSION['sieverules_current_ruleset'];
59
 
                elseif ($rcmail->config->get('sieverules_multiplerules'))
60
 
                        $this->current_ruleset = false;
61
 
                else
62
 
                        $this->current_ruleset = $rcmail->config->get('sieverules_ruleset_name');
63
 
 
64
 
                // override default values
65
 
                if ($rcmail->config->get('sieverules_default_headers'))
66
 
                        $this->headers = $rcmail->config->get('sieverules_default_headers');
67
 
 
68
 
                if ($rcmail->config->get('sieverules_default_operators'))
69
 
                        $this->operators = $rcmail->config->get('sieverules_default_operators');
70
 
 
71
 
                if ($rcmail->config->get('sieverules_default_flags'))
72
 
                        $this->flags = $rcmail->config->get('sieverules_default_flags');
73
 
 
74
 
                $this->action = $rcmail->action;
75
 
 
76
 
                $this->add_texts('localization/', array('filters'));
77
 
                $this->include_script('sieverules.js');
78
 
 
79
 
                $this->register_action('plugin.sieverules', array($this, 'init_html'));
80
 
                $this->register_action('plugin.sieverules.add', array($this, 'init_html'));
81
 
                $this->register_action('plugin.sieverules.edit', array($this, 'init_html'));
82
 
                $this->register_action('plugin.sieverules.setup', array($this, 'init_setup'));
83
 
                $this->register_action('plugin.sieverules.advanced', array($this, 'init_html'));
84
 
                $this->register_action('plugin.sieverules.move', array($this, 'move'));
85
 
                $this->register_action('plugin.sieverules.save', array($this, 'save'));
86
 
                $this->register_action('plugin.sieverules.delete', array($this, 'delete'));
87
 
                $this->register_action('plugin.sieverules.import', array($this, 'import'));
88
 
                $this->register_action('plugin.sieverules.update_list', array($this, 'gen_js_list'));
89
 
                $this->register_action('plugin.sieverules.del_ruleset', array($this, 'delete_ruleset'));
90
 
                $this->register_action('plugin.sieverules.rename_ruleset', array($this, 'rename_ruleset'));
91
 
                $this->register_action('plugin.sieverules.enable_ruleset', array($this, 'enable_ruleset'));
92
 
                $this->register_action('plugin.sieverules.copy_filter', array($this, 'copy_filter'));
93
 
        }
94
 
 
95
 
        function init_html()
96
 
        {
97
 
                $rcmail = rcmail::get_instance();
98
 
 
99
 
                // always include all identities when creating vacation messages
100
 
                if ($rcmail->config->get('sieverules_force_vacto'))
101
 
                        $this->force_vacto = $rcmail->config->get('sieverules_force_vacto');
102
 
 
103
 
                // include the 'from' option when creating vacation messages
104
 
                if ($rcmail->config->get('sieverules_show_vacfrom'))
105
 
                        $this->show_vacfrom = $rcmail->config->get('sieverules_show_vacfrom');
106
 
 
107
 
                // include the 'handle' option when creating vacation messages
108
 
                if ($rcmail->config->get('sieverules_show_vachandle'))
109
 
                        $this->show_vachandle = $rcmail->config->get('sieverules_show_vachandle');
110
 
 
111
 
                $this->_startup();
112
 
 
113
 
                if ($rcmail->config->get('sieverules_multiplerules') && $this->current_ruleset === false) {
114
 
                        if ($ruleset = $this->sieve->get_active()) {
115
 
                                $this->current_ruleset = $this->sieve->get_active();
116
 
                        }
117
 
                        else {
118
 
                                $this->current_ruleset = $rcmail->config->get('sieverules_ruleset_name');
119
 
                                $this->_startup();
120
 
                                rcmail_overwrite_action('plugin.sieverules.setup');
121
 
                                $this->action = 'plugin.sieverules.setup';
122
 
                        }
123
 
                }
124
 
 
125
 
                if ($rcmail->config->get('sieverules_multiplerules'))
126
 
                        $_SESSION['sieverules_current_ruleset'] = $this->current_ruleset;
127
 
 
128
 
                $this->api->output->set_env('ruleset', $this->current_ruleset);
129
 
                if ($rcmail->config->get('sieverules_adveditor') == 2 && get_input_value('_override', RCUBE_INPUT_GET) != '1' && $this->action == 'plugin.sieverules') {
130
 
                        rcmail_overwrite_action('plugin.sieverules.advanced');
131
 
                        $this->action = 'plugin.sieverules.advanced';
132
 
                }
133
 
 
134
 
                $this->api->output->add_handlers(array(
135
 
                'sieveruleslist' => array($this, 'gen_list'),
136
 
                'sieverulesexamplelist' => array($this, 'gen_examples'),
137
 
                'sieverulessetup' => array($this, 'gen_setup'),
138
 
                'sieveruleform' => array($this, 'gen_form'),
139
 
                'advancededitor' => array($this, 'gen_advanced'),
140
 
                'advswitch' => array($this, 'gen_advswitch'),
141
 
                'rulelist' => array($this, 'gen_rulelist'),
142
 
                'sieverulesframe' => array($this, 'sieverules_frame'),
143
 
                ));
144
 
 
145
 
                if ($this->action != 'plugin.sieverules.advanced')
146
 
                        $this->api->output->include_script('list.js');
147
 
 
148
 
                if (sizeof($this->examples) > 0)
149
 
                        $this->api->output->set_env('examples', 'true');
150
 
 
151
 
                if ($this->action == 'plugin.sieverules.add') {
152
 
                        $this->api->output->set_pagetitle($this->gettext('newfilter'));
153
 
                        $this->api->output->send('sieverules.editsieverule');
154
 
                }
155
 
                elseif ($this->action == 'plugin.sieverules.edit') {
156
 
                        $this->api->output->set_pagetitle($this->gettext('edititem'));
157
 
                        $this->api->output->send('sieverules.editsieverule');
158
 
                }
159
 
                elseif ($this->action == 'plugin.sieverules.setup') {
160
 
                        $this->api->output->set_pagetitle($this->gettext('filters'));
161
 
                        $this->api->output->add_script(JS_OBJECT_NAME .".add_onload('". JS_OBJECT_NAME .".sieverules_load_setup()');");
162
 
                        $this->api->output->send('sieverules.sieverules');
163
 
                }
164
 
                elseif ($this->action == 'plugin.sieverules.advanced') {
165
 
                        $this->api->output->set_pagetitle($this->gettext('filters'));
166
 
                        $this->api->output->send('sieverules.advancededitor');
167
 
                }
168
 
                else {
169
 
                        $this->api->output->set_pagetitle($this->gettext('filters'));
170
 
                        $this->api->output->send('sieverules.sieverules');
171
 
                }
172
 
        }
173
 
 
174
 
        function init_setup()
175
 
        {
176
 
                $this->_startup();
177
 
 
178
 
                $this->api->output->add_handlers(array(
179
 
                'sieverulessetup' => array($this, 'gen_setup'),
180
 
                ));
181
 
 
182
 
                $this->api->output->set_pagetitle($this->gettext('filters'));
183
 
                $this->api->output->send('sieverules.setupsieverules');
184
 
        }
185
 
 
186
 
        function sieverules_frame($attrib)
187
 
        {
188
 
                if (!$attrib['id'])
189
 
                        $attrib['id'] = 'rcmprefsframe';
190
 
 
191
 
                $attrib['name'] = $attrib['id'];
192
 
 
193
 
                $this->api->output->set_env('contentframe', $attrib['name']);
194
 
                $this->api->output->set_env('blankpage', $attrib['src'] ? $this->api->output->abs_url($attrib['src']) : 'program/blank.gif');
195
 
 
196
 
                return html::iframe($attrib);
197
 
        }
198
 
 
199
 
        function gen_advanced($attrib)
200
 
        {
201
 
                list($form_start, $form_end) = get_form_tags($attrib, 'plugin.sieverules.save');
202
 
                $out = $form_start;
203
 
 
204
 
                $input_script = new html_textarea(array('id' => 'sieverules_adv', 'name' => '_script'));
205
 
                $out .= $input_script->show(htmlspecialchars($this->sieve->script->raw));
206
 
 
207
 
                $out .= $form_end;
208
 
 
209
 
                return $out;
210
 
        }
211
 
 
212
 
        function gen_list($attrib)
213
 
        {
214
 
                $this->api->output->add_label('sieverules.movingfilter', 'loading', 'sieverules.switchtoadveditor');
215
 
                $this->api->output->add_gui_object('sieverules_list', 'sieverules-table');
216
 
 
217
 
                $table = new html_table(array('id' => 'sieverules-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 2));
218
 
                $table->add_header(array('colspan' => 2), $this->gettext('filters'));
219
 
 
220
 
                if (sizeof($this->script) == 0) {
221
 
                        $table->add(array('colspan' => '2'), rep_specialchars_output($this->gettext('nosieverules')));
222
 
                        $table->add_row();
223
 
                }
224
 
                else foreach($this->script as $idx => $filter) {
225
 
                        $table->set_row_attribs(array('id' => 'rcmrow' . $idx));
226
 
 
227
 
                        if ($filter['disabled'] == 1)
228
 
                                $table->add(null, Q($filter['name']) . ' (' . $this->gettext('disabled') . ')');
229
 
                        else
230
 
                                $table->add(null, Q($filter['name']));
231
 
 
232
 
                        $dst = $idx - 1;
233
 
                        $up_link = $this->api->output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'up_arrow', 'title' => 'sieverules.moveup', 'content' => ' '));
234
 
                        $dst = $idx + 2;
235
 
                        $down_link = $this->api->output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'down_arrow', 'title' => 'sieverules.movedown', 'content' => ' '));
236
 
 
237
 
                        $table->add('control', $down_link . $up_link);
238
 
                }
239
 
 
240
 
                return html::tag('div', array('id' => 'sieverules-list-filters'), $table->show());
241
 
        }
242
 
 
243
 
        function gen_js_list()
244
 
        {
245
 
                $this->_startup();
246
 
 
247
 
                if (sizeof($this->script) == 0) {
248
 
                        $this->api->output->command('sieverules_update_list', 'add-first', -1, rep_specialchars_output($this->gettext('nosieverules')));
249
 
                }
250
 
                else foreach($this->script as $idx => $filter) {
251
 
                        if ($filter['disabled'] == 1)
252
 
                                $filter_name = $filter['name'] . ' (' . $this->gettext('disabled') . ')';
253
 
                        else
254
 
                                $filter_name = $filter['name'];
255
 
 
256
 
                        $tmp_output = new rcube_template('settings');
257
 
                        $dst = $idx - 1;
258
 
                        $up_link = $tmp_output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'up_arrow', 'title' => 'sieverules.moveup', 'content' => ' '));
259
 
                        $up_link = str_replace("'", "\'", $up_link);
260
 
                        $dst = $idx + 2;
261
 
                        $down_link = $tmp_output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'down_arrow', 'title' => 'sieverules.movedown', 'content' => ' '));
262
 
                        $down_link = str_replace("'", "\'", $down_link);
263
 
 
264
 
                        $this->api->output->command('sieverules_update_list', $idx == 0 ? 'add-first' : 'add', 'rcmrow' . $idx, Q($filter_name), $down_link, $up_link);
265
 
                }
266
 
 
267
 
                $this->api->output->send();
268
 
        }
269
 
 
270
 
        function gen_examples()
271
 
        {
272
 
                if (sizeof($this->examples) > 0) {
273
 
                        $this->api->output->add_gui_object('sieverules_examples', 'sieverules-examples');
274
 
 
275
 
                        $examples = new html_table(array('id' => 'sieverules-examples', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 1));
276
 
                        $examples->add_header(null, $this->gettext('examplefilters'));
277
 
 
278
 
                        foreach($this->examples as $idx => $filter) {
279
 
                                $examples->set_row_attribs(array('id' => 'rcmrowex' . $idx));
280
 
                                $examples->add(null, Q($filter['name']));
281
 
                        }
282
 
 
283
 
                        return html::tag('div', array('id' => 'sieverules-list-examples'), $examples->show());
284
 
                }
285
 
                else {
286
 
                        return '';
287
 
                }
288
 
 
289
 
        }
290
 
 
291
 
        function gen_advswitch($attrib)
292
 
        {
293
 
                $input_adv = new html_checkbox(array('id' => 'adveditor', 'onclick' => JS_OBJECT_NAME . '.sieverules_adveditor(this);', 'value' => '1'));
294
 
                $out = html::label('adveditor', Q($this->gettext('adveditor'))) . $input_adv->show($this->action == 'plugin.sieverules.advanced' ? '1' : '');
295
 
                return html::tag('div', array('id' => 'advancedmode'), $out);
296
 
        }
297
 
 
298
 
        function gen_rulelist($attrib)
299
 
        {
300
 
                $this->api->output->add_label('sieverules.delrulesetconf', 'sieverules.rulesetexists');
301
 
 
302
 
                $rulesets = array();
303
 
                foreach ($this->sieve->list as $ruleset) {
304
 
                        array_push($rulesets, $ruleset);
305
 
                }
306
 
                sort($rulesets);
307
 
                $activeruleset = $this->sieve->get_active();
308
 
 
309
 
                $next_ruleset = '';
310
 
                for ($i = 0; $i < sizeof($rulesets); $i++) {
311
 
                        if ($rulesets[$i] == $this->current_ruleset) {
312
 
                                $i++;
313
 
 
314
 
                                if ($i == sizeof($rulesets))
315
 
                                        $i = sizeof($rulesets) - 2;
316
 
 
317
 
                                $next_ruleset = $rulesets[$i];
318
 
                                break;
319
 
                        }
320
 
                }
321
 
 
322
 
                $this->api->output->set_env('ruleset_total', sizeof($rulesets));
323
 
                $this->api->output->set_env('ruleset_active', $this->current_ruleset == $activeruleset ? True : False);
324
 
                $this->api->output->set_env('ruleset_next', $next_ruleset);
325
 
 
326
 
                // new/rename ruleset dialog
327
 
                $out = '';
328
 
                $table = new html_table(array('cols' => 2));
329
 
                $table->set_row_attribs(array('id' => 'sieverulesrsdialog_input'));
330
 
                $table->add('title', html::label('sieverulesrsdialog_name', Q($this->gettext('name'))));
331
 
                $table->add(null, html::tag('input', array('type' => 'text', 'id' => 'sieverulesrsdialog_name', 'name' => '_name', 'value' => '')));
332
 
 
333
 
                $select_ruleset = new html_select(array('id' => 'sieverulesrsdialog_ruleset'));
334
 
                if (sizeof($this->sieve->list) == 1) {
335
 
                        $select_ruleset->add(Q($this->gettext('nosieverulesets')), '');
336
 
                }
337
 
                else foreach ($rulesets as $ruleset) {
338
 
                        if ($ruleset !== $this->current_ruleset)
339
 
                                $select_ruleset->add(Q($ruleset), Q($ruleset));
340
 
                }
341
 
 
342
 
                $table->set_row_attribs(array('id' => 'sieverulesrsdialog_select'));
343
 
                $table->add('title', html::label('sieverulesrsdialog_ruleset', Q($this->gettext('selectruleset'))));
344
 
                $table->add(null, $select_ruleset->show());
345
 
 
346
 
                $buttons = html::tag('input', array('type' => 'hidden', 'id' => 'sieverulesrsdialog_action', 'value' => ''));
347
 
                $buttons .= html::tag('input', array('type' => 'button', 'class' => 'button mainaction', 'value' => $this->gettext('save'), 'onclick' => JS_OBJECT_NAME . '.sieverulesdialog_submit();')) . '&nbsp;';
348
 
                $buttons .= html::tag('input', array('type' => 'button', 'class' => 'button', 'value' => $this->gettext('cancel'), 'onclick' => 'rcube_find_object(\'sieverulesrsdialog\').style.display = \'none\';'));
349
 
 
350
 
                $out .= html::tag('h3', array('id' => 'sieverulesrsdialog_add'), Q($this->gettext('newruleset')));
351
 
                $out .= html::tag('h3', array('id' => 'sieverulesrsdialog_edit', 'style' => 'display: none;'), Q($this->gettext('renameruleset')));
352
 
                $out .= html::tag('h3', array('id' => 'sieverulesrsdialog_copyto', 'style' => 'display: none;'), Q($this->gettext('copytoruleset')));
353
 
                $out .= html::tag('h3', array('id' => 'sieverulesrsdialog_copyfrom', 'style' => 'display: none;'), Q($this->gettext('copyfromruleset')));
354
 
                $out .= $table->show();
355
 
                $out .= html::p(array('class' => 'formbuttons'), $buttons);
356
 
                $out = html::tag('form', array(), $out);
357
 
                $out = html::div(array('id' => 'sieverulesrsdialog', 'style' => 'display: none;'), $out);
358
 
 
359
 
                // add overlay input box to html page
360
 
                $this->api->output->add_footer($out);
361
 
 
362
 
                $action = ($this->action == 'plugin.sieverules.advanced') ? 'plugin.sieverules.advanced' : 'plugin.sieverules';
363
 
                if ($attrib['type'] == 'link') {
364
 
                        $lis = '';
365
 
 
366
 
                        if (sizeof($this->sieve->list) == 0) {
367
 
                                $href  = html::a(array('href' => "#", 'class' => 'active', 'onclick' => 'return false;'), Q($this->gettext('nosieverulesets')));
368
 
                                $lis .= html::tag('li', $href);
369
 
                        }
370
 
                        else foreach ($rulesets as $ruleset) {
371
 
                                $class = 'active';
372
 
                                if ($ruleset === $this->current_ruleset)
373
 
                                        $class .= ' selected';
374
 
 
375
 
                                $ruleset_text = $ruleset;
376
 
                                if ($ruleset === $activeruleset)
377
 
                                        $ruleset_text = str_replace('%s', $ruleset, $this->gettext('activeruleset'));
378
 
 
379
 
                                $href = html::a(array('href' => "#", 'class' => $class, 'onclick' => JS_OBJECT_NAME . '.sieverules_select_ruleset(\''. $ruleset .'\', \''. $action .'\');'), Q($ruleset_text));
380
 
                                $lis .= html::tag('li', null, $href);
381
 
                        }
382
 
 
383
 
                        return $lis;
384
 
                }
385
 
                elseif ($attrib['type'] == 'select') {
386
 
                        $select_ruleset = new html_select(array('id' => 'rulelist', 'onchange' => JS_OBJECT_NAME . '.sieverules_select_ruleset(this, \''. $action .'\');'));
387
 
 
388
 
                        if (sizeof($this->sieve->list) == 0) {
389
 
                                $select_ruleset->add(Q($this->gettext('nosieverulesets')), '');
390
 
                        }
391
 
                        else foreach ($rulesets as $ruleset) {
392
 
                                if ($ruleset === $activeruleset)
393
 
                                        $ruleset = str_replace('%s', $ruleset, $this->gettext('activeruleset'));
394
 
 
395
 
                                $select_ruleset->add(Q($ruleset), Q($ruleset));
396
 
                        }
397
 
 
398
 
                        return html::label('rulelist', Q($this->gettext('selectruleset'))) . $select_ruleset->show(Q($this->current_ruleset));
399
 
                }
400
 
        }
401
 
 
402
 
        function gen_setup()
403
 
        {
404
 
                $rcmail = rcmail::get_instance();
405
 
                $text = '';
406
 
                $buttons = '';
407
 
 
408
 
                if ($rcmail->config->get('sieverules_default_file', false) && is_readable($rcmail->config->get('sieverules_default_file'))) {
409
 
                        $text .= "<br /><br />" . $this->gettext('importdefault');
410
 
                        $buttons .= $this->api->output->button(array('command' => 'plugin.sieverules.import', 'prop' => '_import=_default_', 'type' => 'input', 'class' => 'button', 'label' => 'sieverules.usedefaultfilter'));
411
 
                }
412
 
                elseif ($rcmail->config->get('sieverules_default_file', false) && !is_readable($rcmail->config->get('sieverules_default_file'))) {
413
 
                        raise_error(array(
414
 
                                'code' => 600,
415
 
                                'type' => 'php',
416
 
                                'file' => __FILE__,
417
 
                                'line' => __LINE__,
418
 
                                'message' => "SieveRules plugin: Unable to open default rule file"
419
 
                                ), true, false);
420
 
                }
421
 
 
422
 
                $type = '';
423
 
                $ruleset = '';
424
 
                if (sizeof($this->sieve->list) > 0) {
425
 
                        if ($result = $this->sieve->check_import()) {
426
 
                                list($type, $name, $ruleset) = $result;
427
 
                                $text .= "<br /><br />" . str_replace('%s', $name, $this->gettext('importother'));
428
 
                                $buttons .= (strlen($buttons) > 0) ? '&nbsp;&nbsp;' : '';
429
 
                                $buttons .= $this->api->output->button(array('command' => 'plugin.sieverules.import', 'prop' => '_type=' . $type . '&_import=' . $ruleset, 'type' => 'input', 'class' => 'button', 'label' => 'sieverules.importfilter'));
430
 
                        }
431
 
 
432
 
                        if ($rcmail->config->get('sieverules_multiplerules', false)) {
433
 
                                $text .= "<br /><br />" . $this->gettext('copyexisting');
434
 
                                $buttons .= (strlen($buttons) > 0) ? '&nbsp;&nbsp;' : '';
435
 
                                $buttons .= $this->api->output->button(array('command' => 'plugin.sieverules.ruleset_dialog_setup', 'prop' => 'copyfrom_ruleset', 'type' => 'input', 'class' => 'button', 'label' => 'sieverules.copyexistingfilter'));
436
 
                        }
437
 
                }
438
 
 
439
 
                if ($rcmail->config->get('sieverules_auto_load_default') && !$rcmail->config->get('sieverules_multiplerules', false) && $type != '' && $ruleset != '' && $ruleset == $this->sieve->get_active()) {
440
 
                        $this->import($type, $ruleset, false);
441
 
 
442
 
                        if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
443
 
                                $this->api->output->add_script("parent.". JS_OBJECT_NAME .".goto_url('plugin.sieverules');");
444
 
                        }
445
 
                        else {
446
 
                                // go to sieverules page
447
 
                                rcmail_overwrite_action('plugin.sieverules');
448
 
                                $this->api->output->send('sieverules.sieverules');
449
 
                        }
450
 
                }
451
 
                else if ($rcmail->config->get('sieverules_auto_load_default') && is_readable($rcmail->config->get('sieverules_default_file')) && strlen($text) > 0 && strlen($buttons) > 0 && $type == '' && $ruleset == '') {
452
 
                        $this->import($type, '_default_', false);
453
 
 
454
 
                        if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
455
 
                                $this->api->output->add_script("parent.". JS_OBJECT_NAME .".goto_url('plugin.sieverules');");
456
 
                        }
457
 
                        else {
458
 
                                // go to sieverules page
459
 
                                rcmail_overwrite_action('plugin.sieverules');
460
 
                                $this->api->output->send('sieverules.sieverules');
461
 
                        }
462
 
                }
463
 
                else if (strlen($text) > 0 && strlen($buttons) > 0) {
464
 
                        $out = "<br />". $this->gettext('noexistingfilters') . $text . "<br /><br /><br />\n";
465
 
                        $out .= $buttons;
466
 
                        $out .= "&nbsp;&nbsp;" . $this->api->output->button(array('command' => 'plugin.sieverules.import', 'prop' => '_import=_none_', 'type' => 'input', 'class' => 'button', 'label' => 'cancel'));
467
 
 
468
 
                        $out = html::tag('p', array('style' => 'text-align: center; padding: 10px;'), "\n" . $out);
469
 
                        $out = html::tag('div', array('id' => 'prefs-title', 'class' => 'boxtitle'), Q($this->gettext('importfilters'))) . $out;
470
 
 
471
 
                        return $out;
472
 
                }
473
 
                else {
474
 
                        if ($rcmail->config->get('sieverules_auto_load_default') && !is_readable($rcmail->config->get('sieverules_default_file')))
475
 
                                raise_error(array(
476
 
                                        'code' => 600,
477
 
                                        'type' => 'php',
478
 
                                        'file' => __FILE__,
479
 
                                        'line' => __LINE__,
480
 
                                        'message' => "SieveRules plugin: Unable to open default rule file"
481
 
                                        ), true, false);
482
 
 
483
 
                        $this->sieve->save();
484
 
                        if (!$rcmail->config->get('sieverules_multiplerules', false)) $this->sieve->set_active($this->current_ruleset);
485
 
 
486
 
                        if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
487
 
                                $this->api->output->add_script("parent.". JS_OBJECT_NAME .".goto_url('plugin.sieverules');");
488
 
                        }
489
 
                        else {
490
 
                                // go to sieverules page
491
 
                                rcmail_overwrite_action('plugin.sieverules');
492
 
                                $this->api->output->send('sieverules.sieverules');
493
 
                        }
494
 
                }
495
 
        }
496
 
 
497
 
        function gen_form($attrib)
498
 
        {
499
 
                $rcmail = rcmail::get_instance();
500
 
                $this->include_script('jquery.maskedinput.js');
501
 
                $this->api->output->add_label(
502
 
                        'sieverules.norulename', 'sieverules.ruleexists', 'sieverules.noheader',
503
 
                        'sieverules.headerbadchars', 'sieverules.noheadervalue', 'sieverules.sizewrongformat',
504
 
                        'sieverules.noredirect', 'sieverules.redirectaddresserror', 'sieverules.noreject', 'sieverules.vacnodays',
505
 
                        'sieverules.vacdayswrongformat', 'sieverules.vacnomsg', 'sieverules.notifynomethod', 'sieverules.missingfoldername',
506
 
                        'sieverules.notifynomsg', 'sieverules.filterdeleteconfirm', 'sieverules.ruledeleteconfirm',
507
 
                        'sieverules.actiondeleteconfirm', 'sieverules.notifyinvalidmethod', 'sieverules.nobodycontentpart',
508
 
                        'sieverules.badoperator','sieverules.baddateformat','sieverules.badtimeformat','sieverules.vactoexp_err');
509
 
 
510
 
                $ext = $this->sieve->get_extensions();
511
 
                $iid = get_input_value('_iid', RCUBE_INPUT_GPC);
512
 
                if ($iid == '')
513
 
                        $iid = sizeof($this->script);
514
 
 
515
 
                if (substr($iid, 0, 2) == 'ex') {
516
 
                        $cur_script = $this->examples[substr($iid, 2)];
517
 
                        $this->api->output->set_env('eid', $iid);
518
 
                        $iid = sizeof($this->script);
519
 
                        $this->api->output->set_env('iid', $iid);
520
 
                        $example = true;
521
 
                }
522
 
                else {
523
 
                        $cur_script = $this->script[$iid];
524
 
                        $this->api->output->set_env('iid', $iid);
525
 
                        $example = false;
526
 
 
527
 
                        if (isset($this->script[$iid])) {
528
 
                                $this->api->output->add_script("if (parent.". JS_OBJECT_NAME .".sieverules_examples) parent.". JS_OBJECT_NAME .".sieverules_examples.clear_selection();");
529
 
                                $this->api->output->add_script("parent.". JS_OBJECT_NAME .".sieverules_list.highlight_row(".$iid.");");
530
 
                        }
531
 
                }
532
 
 
533
 
                if (sizeof($rcmail->config->get('sieverules_predefined_rules')) > 0) {
534
 
                        $predefined = array();
535
 
                        foreach($rcmail->config->get('sieverules_predefined_rules') as $idx => $data)
536
 
                                array_push($predefined, array($data['type'], $data['header'], $data['operator'], $data['extra'], $data['target']));
537
 
 
538
 
                        $this->api->output->set_env('predefined_rules', $predefined);
539
 
                }
540
 
 
541
 
                list($form_start, $form_end) = get_form_tags($attrib, 'plugin.sieverules.save');
542
 
 
543
 
                $out = $form_start;
544
 
 
545
 
                $hidden_iid = new html_hiddenfield(array('name' => '_iid', 'value' => $iid));
546
 
                $out .= $hidden_iid->show();
547
 
 
548
 
                // 'any' flag
549
 
                if (sizeof($cur_script['tests']) == 1 && $cur_script['tests'][0]['type'] == 'true' && !$cur_script['tests'][0]['not'])
550
 
                        $any = true;
551
 
 
552
 
                // filter disable
553
 
                $field_id = 'rcmfd_disable';
554
 
                $input_disable = new html_checkbox(array('name' => '_disable', 'id' => $field_id, 'value' => 1));
555
 
 
556
 
                $out .= html::span('disableLink', html::label($field_id, Q($this->gettext('disablerule')))
557
 
                                . "&nbsp;" . $input_disable->show($cur_script['disabled']));
558
 
 
559
 
                // filter name input
560
 
                $field_id = 'rcmfd_name';
561
 
                $input_name = new html_inputfield(array('name' => '_name', 'id' => $field_id));
562
 
 
563
 
                $out .= html::label($field_id, Q($this->gettext('filtername')));
564
 
                $out .= "&nbsp;" . $input_name->show($cur_script['name']);
565
 
 
566
 
                $out .= "<br /><br />";
567
 
 
568
 
                if (sizeof($cur_script['tests']) == 1 && $cur_script['tests'][0]['type'] == 'true' && !$cur_script['tests'][0]['not'])
569
 
                        $join_any = true;
570
 
 
571
 
                $field_id = 'rcmfd_join_all';
572
 
                $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'allof', 'onclick' => JS_OBJECT_NAME . '.sieverules_rule_join_radio(\'allof\')'));
573
 
                $join_type = $input_join->show($cur_script['join'] && !$join_any ? 'allof' : '');
574
 
                $join_type .= "&nbsp;" . html::label($field_id, Q($this->gettext('filterallof')));
575
 
 
576
 
                $field_id = 'rcmfd_join_anyof';
577
 
                $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'anyof', 'onclick' => JS_OBJECT_NAME . '.sieverules_rule_join_radio(\'anyof\')'));
578
 
                $join_type .= "&nbsp;" . $input_join->show($cur_script['join'] && !$join_any ? '' : 'anyof');
579
 
                $join_type .= "&nbsp;" . html::label($field_id, Q($this->gettext('filteranyof')));
580
 
 
581
 
                $field_id = 'rcmfd_join_any';
582
 
                $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'any', 'onclick' => JS_OBJECT_NAME . '.sieverules_rule_join_radio(\'any\')'));
583
 
                $join_type .= "&nbsp;" . $input_join->show($join_any ? 'any' : '');
584
 
                $join_type .= "&nbsp;" . html::label($field_id, Q($this->gettext('filterany')));
585
 
 
586
 
                $rules_table = new html_table(array('id' => 'rules-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 5));
587
 
                $rules_table = $this->_rule_row($ext, $rules_table, null, $rcmail->config->get('sieverules_predefined_rules'), $attrib);
588
 
 
589
 
                if (!$join_any) {
590
 
                        if (!isset($cur_script))
591
 
                                $rules_table = $this->_rule_row($ext, $rules_table, array(), $rcmail->config->get('sieverules_predefined_rules'), $attrib);
592
 
                        else foreach ($cur_script['tests'] as $rules)
593
 
                                $rules_table = $this->_rule_row($ext, $rules_table, $rules, $rcmail->config->get('sieverules_predefined_rules'), $attrib);
594
 
                }
595
 
 
596
 
                $out .= html::tag('fieldset', null, html::tag('legend', null, Q($this->gettext('messagesrules')))
597
 
                                . Q((!$rcmail->config->get('sieverules_use_elsif', true)) ? $this->gettext('sieveruleexp_stop'): $this->gettext('sieveruleexp')) . "<br /><br />"
598
 
                                . $join_type . "<br /><br />"
599
 
                                . $rules_table->show());
600
 
 
601
 
                rcmail::get_instance()->imap_connect();
602
 
                $actions_table = new html_table(array('id' => 'actions-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 3));
603
 
                $actions_table = $this->_action_row($ext, $actions_table, 'rowid', null, $attrib, $example);
604
 
 
605
 
                if (!isset($cur_script))
606
 
                        $actions_table = $this->_action_row($ext, $actions_table, 0, array(), $attrib, $example);
607
 
                else foreach ($cur_script['actions'] as $idx => $actions)
608
 
                        $actions_table = $this->_action_row($ext, $actions_table, $idx, $actions, $attrib, $example);
609
 
 
610
 
                $out .= html::tag('fieldset', null, html::tag('legend', null, Q($this->gettext('messagesactions')))
611
 
                                . Q($this->gettext('sieveactexp')). "<br /><br />"
612
 
                                . $actions_table->show());
613
 
 
614
 
                $out .= $form_end;
615
 
 
616
 
                return $out;
617
 
        }
618
 
 
619
 
        function move()
620
 
        {
621
 
                $this->_startup();
622
 
 
623
 
                $src = get_input_value('_src', RCUBE_INPUT_GET);
624
 
                $dst = get_input_value('_dst', RCUBE_INPUT_GET);
625
 
 
626
 
                $result = $this->sieve->script->move_rule($src, $dst);
627
 
                $result = $this->sieve->save();
628
 
 
629
 
                if ($result)
630
 
                        $this->api->output->command('sieverules_update_list', 'move', $src , $dst);
631
 
                else
632
 
                        $this->api->output->command('display_message', $this->gettext('filtersaveerror'), 'error');
633
 
 
634
 
                $this->api->output->send();
635
 
        }
636
 
 
637
 
        function save()
638
 
        {
639
 
                $rcmail = rcmail::get_instance();
640
 
                $this->_startup();
641
 
 
642
 
                $script = trim(get_input_value('_script', RCUBE_INPUT_POST, true));
643
 
                if ($script != '' && ($rcmail->config->get('sieverules_adveditor') == 1 || $rcmail->config->get('sieverules_adveditor') == 2)) {
644
 
                        $script = $this->_strip_val($script);
645
 
                        $save = $this->sieve->save($script);
646
 
 
647
 
                        if ($save) {
648
 
                                $this->api->output->command('display_message', $this->gettext('filtersaved'), 'confirmation');
649
 
                                $this->sieve->get_script();
650
 
                        }
651
 
                        else {
652
 
                                $this->api->output->command('display_message', $this->gettext('filtersaveerror'), 'error');
653
 
                        }
654
 
 
655
 
                        // go to next step
656
 
                        rcmail_overwrite_action('plugin.sieverules.advanced');
657
 
                        $this->action = 'plugin.sieverules.advanced';
658
 
                        $this->init_html();
659
 
                }
660
 
                else {
661
 
                        $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
662
 
                        $iid = trim(get_input_value('_iid', RCUBE_INPUT_POST));
663
 
                        $join = trim(get_input_value('_join', RCUBE_INPUT_POST));
664
 
                        $disabled = trim(get_input_value('_disable', RCUBE_INPUT_POST));
665
 
 
666
 
                        $tests = $_POST['_test'];
667
 
                        $headers = $_POST['_header'];
668
 
                        $bodyparts = $_POST['_bodypart'];
669
 
                        $ops = $_POST['_operator'];
670
 
                        $sizeops = $_POST['_size_operator'];
671
 
                        $dateops = $_POST['_date_operator'];
672
 
                        $spamtestops = $_POST['_spamtest_operator'];
673
 
                        $targets = $_POST['_target'];
674
 
                        $sizeunits = $_POST['_units'];
675
 
                        $contentparts = $_POST['_body_contentpart'];
676
 
                        $comparators = $_POST['_comparator'];
677
 
                        $advops = $_POST['_advoperator'];
678
 
                        $advtargets = $_POST['_advtarget'];
679
 
                        $actions = $_POST['_act'];
680
 
                        $folders = $_POST['_folder'];
681
 
                        $customfolders = $_POST['_customfolder'];
682
 
                        $addresses = $_POST['_redirect'];
683
 
                        $rejects = $_POST['_reject'];
684
 
                        $vacfroms = $_POST['_vacfrom'];
685
 
                        $vactos = $_POST['_vacto'];
686
 
                        $days = $_POST['_day'];
687
 
                        $handles = $_POST['_handle'];
688
 
                        $subjects = $_POST['_subject'];
689
 
                        $origsubjects = $_POST['_orig_subject'];
690
 
                        $msgs = $_POST['_msg'];
691
 
                        $charsets = $_POST['_charset'];
692
 
                        $flags = $_POST['_imapflags'];
693
 
                        $nfroms = $_POST['_nfrom'];
694
 
                        $nimpts = $_POST['_nimpt'];
695
 
                        $nmethods = $_POST['_nmethod'];
696
 
                        $noptions = $_POST['_noption'];
697
 
                        $nmsgs = $_POST['_nmsg'];
698
 
                        $dateparts = $_POST['_datepart'];
699
 
                        $weekdays = $_POST['_weekday'];
700
 
                        $advweekdays = $_POST['_advweekday'];
701
 
 
702
 
                        $script = array();
703
 
                        $script['join'] = ($join == 'allof') ? true : false;
704
 
                        $script['name'] = $name;
705
 
                        $script['disabled'] = $disabled;
706
 
                        $script['tests'] = array();
707
 
                        $script['actions'] = array();
708
 
 
709
 
                        // rules
710
 
                        $i = 0;
711
 
                        if ($join == 'any') {
712
 
                                $script['tests'][0]['type'] = 'true';
713
 
                        }
714
 
                        else foreach($tests as $idx => $type) {
715
 
                                // ignore the first (default) row
716
 
                                if ($idx == 0)
717
 
                                        continue;
718
 
 
719
 
                                $header = $this->_strip_val($headers[$idx]);
720
 
                                $op = $this->_strip_val($ops[$idx]);
721
 
                                $bodypart = $this->_strip_val($bodyparts[$idx]);
722
 
                                $advop = $this->_strip_val($advops[$idx]);
723
 
                                $contentpart = $this->_strip_val($contentparts[$idx]);
724
 
                                $target = $this->_strip_val($targets[$idx]);
725
 
                                $advtarget = $this->_strip_val($advtargets[$idx]);
726
 
                                $comparator = $this->_strip_val($comparators[$idx]);
727
 
                                $datepart = $this->_strip_val($dateparts[$idx]);
728
 
                                $weekday = $this->_strip_val($weekdays[$idx]);
729
 
                                $advweekday = $this->_strip_val($advweekdays[$idx]);
730
 
 
731
 
                                switch ($type) {
732
 
                                        case 'size':
733
 
                                                $sizeop = $this->_strip_val($sizeops[$idx]);
734
 
                                                $sizeunit = $this->_strip_val($sizeunits[$idx]);
735
 
 
736
 
                                                $script['tests'][$i]['type'] = 'size';
737
 
                                                $script['tests'][$i]['operator'] = $sizeop;
738
 
                                                $script['tests'][$i]['target'] = $target.$sizeunit;
739
 
                                                break;
740
 
                                        case 'spamtest':
741
 
                                                $spamtestop = $this->_strip_val($spamtestops[$idx]);
742
 
 
743
 
                                                $script['tests'][$i]['type'] = 'spamtest';
744
 
                                                $script['tests'][$i]['operator'] = $spamtestop;
745
 
                                                $script['tests'][$i]['target'] = $target;
746
 
                                                break;
747
 
                                        case 'date':
748
 
                                                $op = $this->_strip_val($dateops[$idx]);
749
 
 
750
 
                                                if ($datepart == 'weekday')
751
 
                                                        $target = $weekday;
752
 
 
753
 
                                                $script['tests'][$i]['datepart'] = $datepart;
754
 
                                        case 'body':
755
 
                                                $script['tests'][$i]['bodypart'] = $bodypart;
756
 
 
757
 
                                                if ($bodypart == 'content')
758
 
                                                        $script['tests'][$i]['contentpart'] = $contentpart;
759
 
                                                else
760
 
                                                        $script['tests'][$i]['contentpart'] = '';
761
 
                                        case 'exists':
762
 
                                        case 'header':
763
 
                                        case 'address':
764
 
                                        case 'envelope':
765
 
                                                if (preg_match('/^not/', $op) || preg_match('/^not/', $advop))
766
 
                                                        $script['tests'][$i]['not'] = true;
767
 
                                                else
768
 
                                                        $script['tests'][$i]['not'] = '';
769
 
 
770
 
                                                $op = preg_replace('/^not/', '', $op);
771
 
                                                $advop = preg_replace('/^not/', '', $advop);
772
 
                                                $header = preg_match('/[\s,]+/', $header) ? preg_split('/[\s,]+/', $header, -1, PREG_SPLIT_NO_EMPTY) : $header;
773
 
 
774
 
                                                if ($op == 'exists') {
775
 
                                                        $script['tests'][$i]['type'] = 'exists';
776
 
                                                        $script['tests'][$i]['operator'] = 'exists';
777
 
                                                        $script['tests'][$i]['header'] = $header;
778
 
                                                }
779
 
                                                elseif ($op == 'advoptions') {
780
 
                                                        $script['tests'][$i]['type'] = $type;
781
 
                                                        $script['tests'][$i]['operator'] = $advop;
782
 
                                                        $script['tests'][$i]['header'] = $header;
783
 
                                                        $script['tests'][$i]['target'] = $advtarget;
784
 
 
785
 
                                                        if (substr($advop, 0, 5) == 'count' || substr($advop, 0, 5) == 'value')
786
 
                                                                $script['tests'][$i]['comparator'] = $comparator;
787
 
                                                        else
788
 
                                                                $script['tests'][$i]['comparator'] = '';
789
 
                                                }
790
 
                                                else {
791
 
                                                        $script['tests'][$i]['type'] = $type;
792
 
                                                        $script['tests'][$i]['operator'] = $op;
793
 
                                                        $script['tests'][$i]['header'] = $header;
794
 
                                                        $script['tests'][$i]['target'] = $target;
795
 
                                                }
796
 
                                                break;
797
 
                                }
798
 
                                $i++;
799
 
                        }
800
 
 
801
 
                        // actions
802
 
                        $i = 0;
803
 
                        foreach($actions as $idx => $type) {
804
 
                                // ignore the first (default) row
805
 
                                if ($idx == 0)
806
 
                                        continue;
807
 
 
808
 
                                $type = $this->_strip_val($type);
809
 
 
810
 
                                $script['actions'][$i]['type'] = $type;
811
 
 
812
 
                                switch ($type) {
813
 
                                        case 'fileinto':
814
 
                                        case 'fileinto_copy':
815
 
                                                $folder = $this->_strip_val($folders[$idx]);
816
 
                                                $rcmail = rcmail::get_instance();
817
 
                                                $rcmail->imap_connect();
818
 
                                                $script['actions'][$i]['target'] = $rcmail->config->get('sieverules_include_imap_root', true) ? $rcmail->imap->mod_mailbox($folder) : $folder;
819
 
                                                if ($rcmail->config->get('sieverules_folder_delimiter', false))
820
 
                                                        $script['actions'][$i]['target'] = str_replace($rcmail->imap->get_hierarchy_delimiter(), $rcmail->config->get('sieverules_folder_delimiter'), $script['actions'][$i]['target']);
821
 
 
822
 
                                                if ($folder == '@@newfolder')
823
 
                                                        $script['actions'][$i]['target'] = $this->_strip_val($customfolders[$idx]);
824
 
                                                break;
825
 
                                        case 'redirect':
826
 
                                        case 'redirect_copy':
827
 
                                                $address = $this->_strip_val($addresses[$idx]);
828
 
                                                $script['actions'][$i]['target'] = $address;
829
 
                                                break;
830
 
                                        case 'reject':
831
 
                                        case 'ereject':
832
 
                                                $rejects = $this->_strip_val($rejects[$idx]);
833
 
                                                $script['actions'][$i]['target'] = $rejects;
834
 
                                                break;
835
 
                                        case 'vacation':
836
 
                                                $from = $this->_strip_val($vacfroms[$idx]);
837
 
                                                $to = $this->_strip_val($vactos[$idx]);
838
 
                                                $day = $this->_strip_val($days[$idx]);
839
 
                                                $handle = $this->_strip_val($handles[$idx]);
840
 
                                                $subject = $this->_strip_val($subjects[$idx]);
841
 
                                                $origsubject = $this->_strip_val($origsubjects[$idx]);
842
 
                                                $msg = $this->_strip_val($msgs[$idx]);
843
 
                                                $charset = $this->_strip_val($charsets[$idx]);
844
 
                                                $script['actions'][$i]['days'] = $day;
845
 
                                                $script['actions'][$i]['subject'] = $subject;
846
 
                                                $script['actions'][$i]['origsubject'] = $origsubject;
847
 
                                                $script['actions'][$i]['from'] = $from;
848
 
                                                $script['actions'][$i]['addresses'] = $to;
849
 
                                                $script['actions'][$i]['handle'] = $handle;
850
 
                                                $script['actions'][$i]['msg'] = $msg;
851
 
                                                $script['actions'][$i]['charset'] = $charset;
852
 
                                                break;
853
 
                                        case 'imapflags':
854
 
                                        case 'imap4flags':
855
 
                                                $flag = $this->_strip_val($flags[$idx]);
856
 
                                                $script['actions'][$i]['target'] = $flag;
857
 
                                                break;
858
 
                                        case 'notify':
859
 
                                        case 'enotify':
860
 
                                                $from = $this->_strip_val($nfroms[$idx]);
861
 
                                                $importance = $this->_strip_val($nimpts[$idx]);
862
 
                                                $method = $this->_strip_val($nmethods[$idx]);
863
 
                                                $option = $this->_strip_val($noptions[$idx]);
864
 
                                                $msg = $this->_strip_val($nmsgs[$idx]);
865
 
                                                $script['actions'][$i]['from'] = $from;
866
 
                                                $script['actions'][$i]['importance'] = $importance;
867
 
                                                $script['actions'][$i]['method'] = $method;
868
 
                                                $script['actions'][$i]['options'] = $option;
869
 
                                                $script['actions'][$i]['msg'] = $msg;
870
 
                                                break;
871
 
                                }
872
 
 
873
 
                                $i++;
874
 
                        }
875
 
 
876
 
                        if (!isset($this->script[$iid]))
877
 
                                $result = $this->sieve->script->add_rule($script);
878
 
                        else
879
 
                                $result = $this->sieve->script->update_rule($iid, $script);
880
 
 
881
 
                        if ($result === true)
882
 
                                $save = $this->sieve->save();
883
 
 
884
 
                        if ($save && $result === true && !$rcmail->config->get('sieverules_multiplerules', false))
885
 
                                $save = $this->sieve->set_active($this->current_ruleset);
886
 
 
887
 
                        if ($save && $result === true) {
888
 
                                $this->api->output->command('display_message', $this->gettext('filtersaved'), 'confirmation');
889
 
 
890
 
                                if ($script['disabled'] == 1)
891
 
                                        $filter_name = $script['name'] . ' (' . $this->gettext('disabled') . ')';
892
 
                                else
893
 
                                        $filter_name = $script['name'];
894
 
 
895
 
                                $dst = $iid - 1;
896
 
                                $up_link = $this->api->output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'up_arrow', 'title' => 'sieverules.moveup', 'content' => ' '));
897
 
                                $up_link = str_replace("'", "\'", $up_link);
898
 
                                $dst = $iid + 2;
899
 
                                $down_link = $this->api->output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'down_arrow', 'title' => 'sieverules.movedown', 'content' => ' '));
900
 
                                $down_link = str_replace("'", "\'", $down_link);
901
 
 
902
 
                                if (!isset($this->script[$iid]) && sizeof($this->script) == 0)
903
 
                                        $this->api->output->add_script("parent.". JS_OBJECT_NAME .".sieverules_update_list('add-first', 'rcmrow". $iid ."', '". Q($filter_name) ."', '". $down_link ."', '". $up_link ."');");
904
 
                                elseif (!isset($this->script[$iid]))
905
 
                                        $this->api->output->add_script("parent.". JS_OBJECT_NAME .".sieverules_update_list('add', 'rcmrow". $iid ."', '". Q($filter_name) ."', '". $down_link ."', '". $up_link ."');");
906
 
                                else
907
 
                                        $this->api->output->add_script("parent.". JS_OBJECT_NAME .".sieverules_update_list('update', ". $iid .", '". Q($filter_name) ."');");
908
 
                        }
909
 
                        else {
910
 
                                if ($result == SIEVE_ERROR_BAD_ACTION)
911
 
                                        $this->api->output->command('display_message', $this->gettext('filteractionerror'), 'error');
912
 
                                elseif ($result == SIEVE_ERROR_NOT_FOUND)
913
 
                                        $this->api->output->command('display_message', $this->gettext('filtermissingerror'), 'error');
914
 
                                else
915
 
                                        $this->api->output->command('display_message', $this->gettext('filtersaveerror'), 'error');
916
 
                        }
917
 
 
918
 
                        // update rule list
919
 
                        if ($this->sieve_error)
920
 
                                $this->script = array();
921
 
                        else
922
 
                                $this->script = $this->sieve->script->as_array();
923
 
 
924
 
                        // go to next step
925
 
                        rcmail_overwrite_action('plugin.sieverules.edit');
926
 
                        $this->action = 'plugin.sieverules.edit';
927
 
                        $this->init_html();
928
 
                }
929
 
        }
930
 
 
931
 
        function delete()
932
 
        {
933
 
                $this->_startup();
934
 
 
935
 
                $result = false;
936
 
                $ids = get_input_value('_iid', RCUBE_INPUT_GET);
937
 
                if (is_numeric($ids) && isset($this->script[$ids]) && !$this->sieve_error) {
938
 
                        $result = $this->sieve->script->delete_rule($ids);
939
 
                        if ($result === true)
940
 
                                $result = $this->sieve->save();
941
 
                }
942
 
 
943
 
                if ($result === true) {
944
 
                        $this->api->output->command('display_message', $this->gettext('filterdeleted'), 'confirmation');
945
 
                        $this->api->output->add_script("parent.". JS_OBJECT_NAME .".sieverules_update_list('delete', ". $ids .");");
946
 
                }
947
 
                elseif ($result == SIEVE_ERROR_NOT_FOUND)
948
 
                        $this->api->output->command('display_message', $this->gettext('filtermissingerror'), 'error');
949
 
                else
950
 
                        $this->api->output->command('display_message', $this->gettext('filterdeleteerror'), 'error');
951
 
 
952
 
                // update rule list
953
 
                if ($this->sieve_error)
954
 
                        $this->script = array();
955
 
                else
956
 
                        $this->script = $this->sieve->script->as_array();
957
 
 
958
 
                if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
959
 
                        $this->api->output->add_script("parent.". JS_OBJECT_NAME .".show_contentframe(false);");
960
 
                }
961
 
                else {
962
 
                        // go to sieverules page
963
 
                        rcmail_overwrite_action('plugin.sieverules.edit');
964
 
                        $this->action = 'plugin.sieverules.edit';
965
 
                        $this->init_html();
966
 
                }
967
 
        }
968
 
 
969
 
        function import($type = null, $ruleset = null, $redirect = true)
970
 
        {
971
 
                $rcmail = rcmail::get_instance();
972
 
                $this->_startup();
973
 
 
974
 
                if (!$type && !$ruleset) {
975
 
                        $type = get_input_value('_type', RCUBE_INPUT_GET);
976
 
                        $ruleset = get_input_value('_import', RCUBE_INPUT_GET);
977
 
                }
978
 
 
979
 
                if ($ruleset == '_default_') {
980
 
                        if ($rcmail->config->get('sieverules_default_file', false) && is_readable($rcmail->config->get('sieverules_default_file'))) {
981
 
                                $this->sieve->script->add_text(file_get_contents($rcmail->config->get('sieverules_default_file')));
982
 
                                $save = $this->sieve->save();
983
 
 
984
 
                                if ($save && !$rcmail->config->get('sieverules_multiplerules', false))
985
 
                                        $save = $this->sieve->set_active($this->current_ruleset);
986
 
 
987
 
                                if ($save)
988
 
                                        $this->api->output->command('display_message', $this->gettext('filterimported'), 'confirmation');
989
 
                                else
990
 
                                        $this->api->output->command('display_message', $this->gettext('filterimporterror'), 'error');
991
 
 
992
 
                                // update rule list
993
 
                                if ($this->sieve_error)
994
 
                                        $this->script = array();
995
 
                                else
996
 
                                        $this->script = $this->sieve->script->as_array();
997
 
                        }
998
 
                        elseif ($rcmail->config->get('sieverules_default_file', false) && !is_readable($rcmail->config->get('sieverules_default_file'))) {
999
 
                                raise_error(array(
1000
 
                                        'code' => 600,
1001
 
                                        'type' => 'php',
1002
 
                                        'file' => __FILE__,
1003
 
                                        'line' => __LINE__,
1004
 
                                        'message' => "SieveRules plugin: Unable to open default rule file"
1005
 
                                        ), true, false);
1006
 
                        }
1007
 
                }
1008
 
                elseif ($ruleset == '_example_') {
1009
 
                        if (get_input_value('_eids', RCUBE_INPUT_GET)) {
1010
 
                                $pos = get_input_value('_pos', RCUBE_INPUT_GET);
1011
 
                                $eids = explode(",", get_input_value('_eids', RCUBE_INPUT_GET));
1012
 
 
1013
 
                                if ($pos == 'end')
1014
 
                                        $pos = null;
1015
 
                                else
1016
 
                                        $pos = substr($pos, 6);
1017
 
 
1018
 
                                foreach ($eids as $eid) {
1019
 
                                        $this->sieve->script->add_rule($this->examples[substr($eid, 2)], $pos);
1020
 
                                        if ($pos) $pos++;
1021
 
                                }
1022
 
 
1023
 
                                $this->sieve->save();
1024
 
                                if (!$rcmail->config->get('sieverules_multiplerules', false)) $this->sieve->set_active($this->current_ruleset);
1025
 
 
1026
 
                                // update rule list
1027
 
                                if ($this->sieve_error)
1028
 
                                        $this->script = array();
1029
 
                                else
1030
 
                                        $this->script = $this->sieve->script->as_array();
1031
 
                        }
1032
 
                }
1033
 
                elseif ($ruleset == '_none_') {
1034
 
                        $this->sieve->save();
1035
 
                        if (!$rcmail->config->get('sieverules_multiplerules', false)) $this->sieve->set_active($this->current_ruleset);
1036
 
                }
1037
 
                elseif ($ruleset == '_copy_') {
1038
 
                        $this->rename_ruleset(true);
1039
 
                        return;
1040
 
                }
1041
 
                elseif ($type != '' && $ruleset != '') {
1042
 
                        $import = $this->sieve->do_import($type, $ruleset);
1043
 
 
1044
 
                        if ($import) {
1045
 
                                $this->script = $this->sieve->script->as_array();
1046
 
                                $this->sieve->save();
1047
 
                                if (!$rcmail->config->get('sieverules_multiplerules', false)) $this->sieve->set_active($this->current_ruleset);
1048
 
                                $this->api->output->command('display_message', $this->gettext('filterimported'), 'confirmation');
1049
 
                        }
1050
 
                        else {
1051
 
                                $this->script = array();
1052
 
                                if (!$redirect) $this->sieve->save();
1053
 
                                $this->api->output->command('display_message', $this->gettext('filterimporterror'), 'error');
1054
 
                        }
1055
 
                }
1056
 
 
1057
 
                if ($redirect) {
1058
 
                        // go to sieverules page
1059
 
                        rcmail_overwrite_action('plugin.sieverules');
1060
 
                        $this->action = 'plugin.sieverules';
1061
 
                        $this->init_html();
1062
 
                }
1063
 
        }
1064
 
 
1065
 
        function delete_ruleset()
1066
 
        {
1067
 
                $this->_startup();
1068
 
                $this->sieve->del_script($this->current_ruleset);
1069
 
 
1070
 
                $this->current_ruleset = get_input_value('_next', RCUBE_INPUT_GET);
1071
 
 
1072
 
                rcmail_overwrite_action('plugin.sieverules');
1073
 
                $this->action = 'plugin.sieverules';
1074
 
                $this->init_html();
1075
 
        }
1076
 
 
1077
 
        function rename_ruleset($makeCopy = false)
1078
 
        {
1079
 
                $this->_startup();
1080
 
                $script = $this->sieve->script->as_text();
1081
 
                $active = $this->sieve->get_active() == $this->current_ruleset ? true : false;
1082
 
 
1083
 
                $old_ruleset = $this->current_ruleset;
1084
 
                $this->current_ruleset = get_input_value('_new', RCUBE_INPUT_GET, true);
1085
 
                $this->sieve->set_ruleset($this->current_ruleset);
1086
 
                $this->sieve->save($script);
1087
 
 
1088
 
                if (!$makeCopy) {
1089
 
                        if ($active)
1090
 
                                $this->sieve->set_active($this->current_ruleset);
1091
 
 
1092
 
                        $this->sieve->del_script($old_ruleset);
1093
 
                }
1094
 
 
1095
 
                rcmail_overwrite_action('plugin.sieverules');
1096
 
                $this->action = 'plugin.sieverules';
1097
 
                $this->init_html();
1098
 
        }
1099
 
 
1100
 
        function enable_ruleset()
1101
 
        {
1102
 
                $this->_startup();
1103
 
                $activeruleset = get_input_value('_ruleset', RCUBE_INPUT_GET, true);
1104
 
                $this->sieve->set_active($activeruleset);
1105
 
 
1106
 
                if (get_input_value('_reload', RCUBE_INPUT_GET, true) == "1") {
1107
 
                        rcmail_overwrite_action('plugin.sieverules');
1108
 
                        $this->action = 'plugin.sieverules';
1109
 
                        $this->init_html();
1110
 
                }
1111
 
                else {
1112
 
                        $rulesets = array();
1113
 
                        foreach ($this->sieve->list as $ruleset)
1114
 
                                array_push($rulesets, $ruleset);
1115
 
 
1116
 
                        sort($rulesets);
1117
 
 
1118
 
                        foreach ($rulesets as $ruleset) {
1119
 
                                if ($ruleset === $activeruleset)
1120
 
                                        $this->api->output->command('sieverules_add_ruleset', Q($ruleset), Q(str_replace('%s', $ruleset, $this->gettext('activeruleset'))));
1121
 
                                else
1122
 
                                        $this->api->output->command('sieverules_add_ruleset', Q($ruleset), Q($ruleset));
1123
 
                        }
1124
 
 
1125
 
                        $this->api->output->send();
1126
 
                }
1127
 
        }
1128
 
 
1129
 
        function copy_filter()
1130
 
        {
1131
 
                $this->_startup();
1132
 
                $script = $this->script[get_input_value('_iid', RCUBE_INPUT_GET)];
1133
 
                $this->current_ruleset = get_input_value('_dest', RCUBE_INPUT_GET);
1134
 
                $this->_startup();
1135
 
                $this->sieve->script->add_rule($script);
1136
 
                $this->sieve->save();
1137
 
 
1138
 
                $this->api->output->command('display_message', $this->gettext('filtercopied'), 'confirmation');
1139
 
                $this->api->output->send();
1140
 
        }
1141
 
 
1142
 
        private function _startup()
1143
 
        {
1144
 
                $rcmail = rcmail::get_instance();
1145
 
 
1146
 
                if (!$this->sieve) {
1147
 
                        include('lib/Net/Sieve.php');
1148
 
                        include('include/rcube_sieve.php');
1149
 
                        include('include/rcube_sieve_script.php');
1150
 
                        $rcmail = rcmail::get_instance();
1151
 
 
1152
 
                        // try to connect to managesieve server and to fetch the script
1153
 
                        $this->sieve = new rcube_sieve($_SESSION['username'],
1154
 
                                                $rcmail->decrypt($_SESSION['password']),
1155
 
                                                rcube_idn_to_ascii(rcube_parse_host($rcmail->config->get('sieverules_host'))),
1156
 
                                                $rcmail->config->get('sieverules_port'), $rcmail->config->get('sieverules_auth_type', NULL),
1157
 
                                                $rcmail->config->get('sieverules_usetls'), $this->current_ruleset,
1158
 
                                                $this->home, $rcmail->config->get('sieverules_use_elsif', true),
1159
 
                                                $rcmail->config->get('sieverules_auth_cid', NULL), $rcmail->config->get('sieverules_auth_pw', NULL));
1160
 
 
1161
 
                        if ($rcmail->config->get('sieverules_debug', false))
1162
 
                                $this->sieve->set_debug(true);
1163
 
 
1164
 
                        $this->sieve_error = $this->sieve->error();
1165
 
 
1166
 
                        if ($this->sieve_error == SIEVE_ERROR_NOT_EXISTS) {
1167
 
                                // load default rule set
1168
 
                                if (($rcmail->config->get('sieverules_default_file', false) && is_readable($rcmail->config->get('sieverules_default_file'))) || sizeof($this->sieve->list) > 0) {
1169
 
                                        rcmail_overwrite_action('plugin.sieverules.setup');
1170
 
                                        $this->action = 'plugin.sieverules.setup';
1171
 
                                }
1172
 
                                elseif ($rcmail->config->get('sieverules_default_file', false) && !is_readable($rcmail->config->get('sieverules_default_file'))) {
1173
 
                                        raise_error(array(
1174
 
                                                'code' => 600,
1175
 
                                                'type' => 'php',
1176
 
                                                'file' => __FILE__,
1177
 
                                                'line' => __LINE__,
1178
 
                                                'message' => "SieveRules plugin: Unable to open default rule file"
1179
 
                                                ), true, false);
1180
 
                                }
1181
 
 
1182
 
                                // that's not exactly an error
1183
 
                                $this->sieve_error = false;
1184
 
                        }
1185
 
                        elseif ($this->sieve_error) {
1186
 
                                switch ($this->sieve_error) {
1187
 
                                        case SIEVE_ERROR_CONNECTION:
1188
 
                                        case SIEVE_ERROR_LOGIN:
1189
 
                                                $this->api->output->command('display_message', $this->gettext('filterconnerror'), 'error');
1190
 
                                        break;
1191
 
                                        default:
1192
 
                                                $this->api->output->command('display_message', $this->gettext('filterunknownerror'), 'error');
1193
 
                                        break;
1194
 
                                }
1195
 
 
1196
 
                                $this->api->output->set_env('sieveruleserror', true);
1197
 
                        }
1198
 
 
1199
 
                        // finally set script objects
1200
 
                        if ($this->sieve_error) {
1201
 
                                $this->script = array();
1202
 
                        }
1203
 
                        else {
1204
 
                                $this->script = $this->sieve->script->as_array();
1205
 
 
1206
 
                                // load example filters
1207
 
                                if ($rcmail->config->get('sieverules_example_file', false) && is_readable($rcmail->config->get('sieverules_example_file')))
1208
 
                                        $this->examples = $this->sieve->script->parse_text(file_get_contents($rcmail->config->get('sieverules_example_file')));
1209
 
                                elseif ($rcmail->config->get('sieverules_example_file', false) && !is_readable($rcmail->config->get('sieverules_example_file')))
1210
 
                                        raise_error(array(
1211
 
                                                'code' => 600,
1212
 
                                                'type' => 'php',
1213
 
                                                'file' => __FILE__,
1214
 
                                                'line' => __LINE__,
1215
 
                                                'message' => "SieveRules plugin: Unable to open example rule file"
1216
 
                                                ), true, false);
1217
 
                        }
1218
 
                }
1219
 
                else {
1220
 
                        $this->sieve->set_ruleset($this->current_ruleset);
1221
 
                        $this->script = $this->sieve->script->as_array();
1222
 
                }
1223
 
        }
1224
 
 
1225
 
        private function _rule_row($ext, $rules_table, $rule, $predefined_rules, $attrib)
1226
 
        {
1227
 
                $rcmail = rcmail::get_instance();
1228
 
                $imgclass = null;
1229
 
 
1230
 
                if (!isset($rule)) {
1231
 
                        $rules_table->set_row_attribs(array('style' => 'display: none;'));
1232
 
                        $imgclass = 'nohtc';
1233
 
                }
1234
 
 
1235
 
                if (in_array('regex', $ext) || in_array('relational', $ext) || in_array('subaddress', $ext))
1236
 
                        $this->operators['filteradvoptions'] = 'advoptions';
1237
 
 
1238
 
                $header_style = 'visibility: hidden;';
1239
 
                $op_style = '';
1240
 
                $sizeop_style = 'display: none;';
1241
 
                $dateop_style = 'display: none;';
1242
 
                $spamtestop_style = 'display: none;';
1243
 
                $target_style = '';
1244
 
                $units_style = 'display: none;';
1245
 
                $bodypart_style = 'display: none;';
1246
 
                $datepart_style = 'display: none;';
1247
 
                $advcontentpart_style = 'display: none;';
1248
 
                $spam_prob_style = 'display: none;';
1249
 
                $weekdays_style = 'display: none;';
1250
 
                $advweekdays_style = 'display: none;';
1251
 
                $advtarget_style = '';
1252
 
 
1253
 
                $test = 'header';
1254
 
                $selheader = 'Subject';
1255
 
                $header = 'Subject';
1256
 
                $op = 'contains';
1257
 
                $sizeop = 'under';
1258
 
                $spamtestop = 'ge';
1259
 
                $target = '';
1260
 
                $target_size = '';
1261
 
                $units = 'KB';
1262
 
                $bodypart = '';
1263
 
                $advcontentpart = '';
1264
 
 
1265
 
                $predefined = -1;
1266
 
                foreach($predefined_rules as $idx => $data) {
1267
 
                        if (($data['type'] == $rule['type'] || $rule['type'] == 'exists')
1268
 
                                && $data['header'] == $rule['header']
1269
 
                                && $data['operator'] == ($rule['not'] ? 'not' : '') . $rule['operator']
1270
 
                                && $data['target'] == $rule['target']) {
1271
 
                                        $predefined = $idx;
1272
 
                                        break;
1273
 
                        }
1274
 
                }
1275
 
 
1276
 
                if ($predefined > -1) {
1277
 
                        $op_style = 'display: none;';
1278
 
                        $target_style = 'display: none;';
1279
 
                        $selheader = $rule['type'] . '::predefined_' . $predefined;
1280
 
                        $test = $rule['type'];
1281
 
 
1282
 
                        if ($rule['type'] == 'size') {
1283
 
                                $header = 'size';
1284
 
                                $sizeop = $rule['operator'];
1285
 
                                preg_match('/^([0-9]+)(K|M|G)*$/', $rule['target'], $matches);
1286
 
                                $target = $matches[1];
1287
 
                                $target_size = 'short';
1288
 
                                $units = $matches[2];
1289
 
                        }
1290
 
                        elseif ($rule['type'] == 'spamtest') {
1291
 
                                $header = 'spamtest';
1292
 
                                $spamtestop = $rule['operator'];
1293
 
                                $target = $rule['target'];
1294
 
                        }
1295
 
                        elseif ($rule['type'] == 'exists') {
1296
 
                                $selheader = $predefined_rules[$predefined]['type'] . '::predefined_' . $predefined;
1297
 
                                $header = $rule['header'];
1298
 
                                $op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1299
 
                        }
1300
 
                        else {
1301
 
                                $header = $rule['header'];
1302
 
                                $op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1303
 
                                $target = htmlspecialchars($rule['target']);
1304
 
                        }
1305
 
                }
1306
 
                elseif ((isset($rule['type']) && $rule['type'] != 'exists') && in_array($rule['type'] . '::' . $rule['header'], $this->headers)) {
1307
 
                        $target_style = $rule['operator'] == 'exists' ? 'display: none;' : '';
1308
 
 
1309
 
                        $selheader = $rule['type'] . '::' . $rule['header'];
1310
 
                        $test = $rule['type'];
1311
 
                        $header = $rule['header'];
1312
 
                        $op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1313
 
                        $target = htmlspecialchars($rule['target']);
1314
 
                }
1315
 
                elseif ((isset($rule['type']) && $rule['type'] == 'exists') && $this->_in_headerarray($rule['header'], $this->headers) != false) {
1316
 
                        $target_style = $rule['operator'] == 'exists' ? 'display: none;' : '';
1317
 
 
1318
 
                        $selheader = $this->_in_headerarray($rule['header'], $this->headers) . '::' . $rule['header'];
1319
 
                        $test = $rule['type'];
1320
 
                        $header = $rule['header'];
1321
 
                        $op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1322
 
                }
1323
 
                elseif (isset($rule['type']) && $rule['type'] == 'size') {
1324
 
                        $op_style = 'display: none;';
1325
 
                        $sizeop_style = '';
1326
 
                        $units_style = '';
1327
 
 
1328
 
                        $selheader = 'size::size';
1329
 
                        $header = 'size';
1330
 
                        $test = 'size';
1331
 
                        $sizeop = $rule['operator'];
1332
 
                        preg_match('/^([0-9]+)(K|M|G)*$/', $rule['target'], $matches);
1333
 
                        $target = $matches[1];
1334
 
                        $target_size = 'short';
1335
 
                        $units = $matches[2];
1336
 
                }
1337
 
                elseif (isset($rule['type']) && $rule['type'] == 'body') {
1338
 
                        $bodypart_style = '';
1339
 
                        $header_style = 'display: none;';
1340
 
 
1341
 
                        $selheader = 'body::body';
1342
 
                        $header = 'body';
1343
 
                        $test = 'body';
1344
 
                        $bodypart = $rule['bodypart'];
1345
 
                        $op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1346
 
                        $target = htmlspecialchars($rule['target']);
1347
 
 
1348
 
                        if ($rule['contentpart'] != '') {
1349
 
                                $advcontentpart = $rule['contentpart'];
1350
 
                                $advcontentpart_style = '';
1351
 
                        }
1352
 
                }
1353
 
                elseif (isset($rule['type']) && $rule['type'] == 'spamtest') {
1354
 
                        $op_style = 'display: none;';
1355
 
                        $target_style = 'display: none;';
1356
 
                        $spamtestop_style = '';
1357
 
                        $spam_prob_style = '';
1358
 
 
1359
 
                        $test = $rule['type'];
1360
 
                        $selheader = 'spamtest::spamtest';
1361
 
                        $header = 'spamtest';
1362
 
                        $spamtestop = $rule['operator'];
1363
 
                        $target = $rule['target'];
1364
 
                        $spam_probability = $rule['target'];
1365
 
                }
1366
 
                elseif (isset($rule['type']) && $rule['type'] == 'date') {
1367
 
                        $op_style = 'display: none;';
1368
 
                        $dateop_style = '';
1369
 
                        $header_style = 'display: none;';
1370
 
                        $datepart_style = '';
1371
 
 
1372
 
                        if ($rule['datepart'] == 'weekday') {
1373
 
                                $target_style = 'display: none;';
1374
 
                                $advtarget_style = 'display: none;';
1375
 
                                $weekdays_style = '';
1376
 
                                $advweekdays_style = '';
1377
 
                        }
1378
 
 
1379
 
                        $test = $rule['type'];
1380
 
                        $selheader = 'date::' . $rule['header'];
1381
 
                        $header = $rule['header'];
1382
 
                        $datepart = $rule['datepart'];
1383
 
                        $dateop = ($rule['not'] ? 'not' : '') . $rule['operator'];
1384
 
                        $target = $rule['target'];
1385
 
                }
1386
 
                elseif (isset($rule['type']) && $rule['type'] != 'true') {
1387
 
                        $header_style = '';
1388
 
                        $target_style = $rule['operator'] == 'exists' ? 'display: none;' : '';
1389
 
 
1390
 
                        $selheader = 'header::other';
1391
 
                        $test = 'header';
1392
 
                        $header = is_array($rule['header']) ? join(', ', $rule['header']) : $rule['header'];
1393
 
                        $op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1394
 
                        $target = htmlspecialchars($rule['target']);
1395
 
                }
1396
 
 
1397
 
                // check for advanced options
1398
 
                $showadvanced = false;
1399
 
                if (!in_array($op, $this->operators) || $rule['comparator'] != '' || $rule['contentpart'] != '') {
1400
 
                        $showadvanced = true;
1401
 
                        $target_style = 'display: none;';
1402
 
                }
1403
 
 
1404
 
                $select_header = new html_select(array('name' => "_selheader[]", 'onchange' => JS_OBJECT_NAME . '.sieverules_header_select(this)'));
1405
 
                foreach($this->headers as $name => $val) {
1406
 
                        if (($val == 'envelope' && in_array('envelope', $ext)) || $val != 'envelope')
1407
 
                                $select_header->add(Q($this->gettext($name)), Q($val));
1408
 
                }
1409
 
 
1410
 
                if (in_array('body', $ext))
1411
 
                        $select_header->add(Q($this->gettext('body')), Q('body::body'));
1412
 
 
1413
 
                if (in_array('spamtest', $ext))
1414
 
                        $select_header->add(Q($this->gettext('spamtest')), Q('spamtest::spamtest'));
1415
 
 
1416
 
                foreach($predefined_rules as $idx => $data)
1417
 
                        $select_header->add(Q($data['name']), Q($data['type'] . '::predefined_' . $idx));
1418
 
 
1419
 
                if (in_array('date', $ext))
1420
 
                        $select_header->add(Q($this->gettext('arrival')), Q('date::currentdate'));
1421
 
 
1422
 
                $select_header->add(Q($this->gettext('size')), Q('size::size'));
1423
 
                $select_header->add(Q($this->gettext('otherheader')), Q('header::other'));
1424
 
                $input_test = new html_hiddenfield(array('name' => '_test[]', 'value' => $test));
1425
 
                $rules_table->add('selheader', $select_header->show($selheader) . $input_test->show());
1426
 
 
1427
 
                $help_button = html::img(array('class' => $imgclass, 'src' => $attrib['helpicon'], 'alt' => $this->gettext('sieveruleheaders'), 'border' => 0, 'style' => 'margin-left: 4px;'));
1428
 
                $help_button = html::a(array('name' => '_headerhlp', 'href' => "#", 'onclick' => 'return '. JS_OBJECT_NAME .'.sieverules_xheaders(this);', 'title' => $this->gettext('sieveruleheaders'), 'style' => $header_style), $help_button);
1429
 
 
1430
 
                $input_header = new html_inputfield(array('name' => '_header[]', 'style' => $header_style, 'class' => 'short'));
1431
 
                $select_bodypart = new html_select(array('name' => '_bodypart[]', 'onchange' => JS_OBJECT_NAME . '.sieverules_bodypart_select(this)', 'style' => $bodypart_style));
1432
 
                $select_bodypart->add(Q($this->gettext('auto')), Q(''));
1433
 
                $select_bodypart->add(Q($this->gettext('raw')), Q('raw'));
1434
 
                $select_bodypart->add(Q($this->gettext('text')), Q('text'));
1435
 
                $select_bodypart->add(Q($this->gettext('other')), Q('content'));
1436
 
                $select_datepart = new html_select(array('name' => '_datepart[]', 'onchange' => JS_OBJECT_NAME . '.sieverules_datepart_select(this)','style' => $datepart_style));
1437
 
                $select_datepart->add(Q($this->gettext('date')), Q('date'));
1438
 
                $select_datepart->add(Q($this->gettext('time')), Q('time'));
1439
 
                $select_datepart->add(Q($this->gettext('weekday')), Q('weekday'));
1440
 
                $rules_table->add('header', $input_header->show($header) . $help_button . $select_bodypart->show($bodypart) . $select_datepart->show($datepart));
1441
 
 
1442
 
                $select_op = new html_select(array('name' => "_operator[]", 'onchange' => JS_OBJECT_NAME . '.sieverules_rule_op_select(this)', 'style' => $op_style));
1443
 
                foreach($this->operators as $name => $val)
1444
 
                        $select_op->add(Q($this->gettext($name)), $val);
1445
 
 
1446
 
                $select_size_op = new html_select(array('name' => "_size_operator[]", 'style' => $sizeop_style));
1447
 
                $select_size_op->add(Q($this->gettext('filterunder')), 'under');
1448
 
                $select_size_op->add(Q($this->gettext('filterover')), 'over');
1449
 
 
1450
 
                $select_date_op = new html_select(array('name' => "_date_operator[]", 'style' => $dateop_style));
1451
 
                $select_date_op->add(Q($this->gettext('filteris')), 'is');
1452
 
                $select_date_op->add(Q($this->gettext('filterisnot')), 'notis');
1453
 
 
1454
 
                if (in_array('relational', $ext)) {
1455
 
                        $select_date_op->add(Q($this->gettext('filterbefore')), 'value "lt"');
1456
 
                        $select_date_op->add(Q($this->gettext('filterafter')), 'value "gt"');
1457
 
                }
1458
 
 
1459
 
                $select_spamtest_op = new html_select(array('name' => "_spamtest_operator[]", 'style' => $spamtestop_style));
1460
 
                $select_spamtest_op->add(Q($this->gettext('spamlevelequals')), 'eq');
1461
 
                $select_spamtest_op->add(Q($this->gettext('spamlevelislessthanequal')), 'le');
1462
 
                $select_spamtest_op->add(Q($this->gettext('spamlevelisgreaterthanequal')), 'ge');
1463
 
 
1464
 
                if ($showadvanced)
1465
 
                        $rules_table->add('op', $select_op->show('advoptions') . $select_size_op->show($sizeop) . $select_date_op->show($dateop) . $select_spamtest_op->show($spamtestop));
1466
 
                else
1467
 
                        $rules_table->add('op', $select_op->show($op) . $select_size_op->show($sizeop) . $select_date_op->show($dateop) . $select_spamtest_op->show($spamtestop));
1468
 
 
1469
 
                $input_target = new html_inputfield(array('name' => '_target[]', 'style' => $target_style, 'class' => $target_size));
1470
 
 
1471
 
                $select_units = new html_select(array('name' => "_units[]", 'style' => $units_style, 'class' => 'short'));
1472
 
                $select_units->add(Q($this->gettext('B')), '');
1473
 
                $select_units->add(Q($this->gettext('KB')), 'K');
1474
 
                $select_units->add(Q($this->gettext('MB')), 'M');
1475
 
 
1476
 
                $select_spam_probability = new html_select(array('name' => "_spam_probability[]", 'style' => $spam_prob_style, 'class' => 'long'));
1477
 
                $select_spam_probability->add(Q($this->gettext('spamnotchecked')), '0');
1478
 
                $select_spam_probability->add(Q("0%"), '1');
1479
 
                $select_spam_probability->add(Q("5%"), '2');
1480
 
                $select_spam_probability->add(Q("20%"), '3');
1481
 
                $select_spam_probability->add(Q("40%"), '4');
1482
 
                $select_spam_probability->add(Q("50%"), '5');
1483
 
                $select_spam_probability->add(Q("60%"), '6');
1484
 
                $select_spam_probability->add(Q("70%"), '7');
1485
 
                $select_spam_probability->add(Q("80%"), '8');
1486
 
                $select_spam_probability->add(Q("90%"), '9');
1487
 
                $select_spam_probability->add(Q("100%"), '10');
1488
 
 
1489
 
                $select_weekdays = new html_select(array('name' => "_weekday[]", 'style' => $weekdays_style, 'class' => 'long'));
1490
 
                $select_weekdays->add(Q($this->gettext('sunday')), '0');
1491
 
                $select_weekdays->add(Q($this->gettext('monday')), '1');
1492
 
                $select_weekdays->add(Q($this->gettext('tuesday')), '2');
1493
 
                $select_weekdays->add(Q($this->gettext('wednesday')), '3');
1494
 
                $select_weekdays->add(Q($this->gettext('thursday')), '4');
1495
 
                $select_weekdays->add(Q($this->gettext('friday')), '5');
1496
 
                $select_weekdays->add(Q($this->gettext('saturday')), '6');
1497
 
 
1498
 
                $rules_table->add('target', $select_weekdays->show($target) . $select_spam_probability->show($spam_probability) . $input_target->show($target) . "&nbsp;" . $select_units->show($units));
1499
 
 
1500
 
                $add_button = $this->api->output->button(array('command' => 'plugin.sieverules.add_rule', 'type' => 'link', 'class' => 'add', 'title' => 'sieverules.addsieverule', 'content' => ' '));
1501
 
                $delete_button = $this->api->output->button(array('command' => 'plugin.sieverules.del_rule', 'type' => 'link', 'class' => 'delete', 'classact' => 'delete_act', 'title' => 'sieverules.deletesieverule', 'content' => ' '));
1502
 
                $rules_table->add('control', $delete_button . $add_button);
1503
 
 
1504
 
                if (isset($rule))
1505
 
                        $rowid = $rules_table->size();
1506
 
                else
1507
 
                        $rowid = 'rowid';
1508
 
 
1509
 
                $headers_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 4));
1510
 
                $headers_table->add(array('colspan' => 4, 'style' => 'white-space: normal;'), Q($this->gettext('sieveheadershlp')));
1511
 
                $headers_table->add_row();
1512
 
 
1513
 
                $col1 = '';
1514
 
                $col2 = '';
1515
 
                $col3 = '';
1516
 
                $col4 = '';
1517
 
                $other_headers = $rcmail->config->get('sieverules_other_headers');
1518
 
                sort($other_headers);
1519
 
                $col_length = sizeof($other_headers) / 4;
1520
 
                $col_length = ceil($col_length);
1521
 
                foreach ($other_headers as $idx => $xheader) {
1522
 
                        $input_xheader = new html_radiobutton(array('id' => $xheader . '_' . $rowid, 'name' => '_xheaders_' . $rowid . '[]', 'value' => $xheader, 'onclick' => JS_OBJECT_NAME . '.sieverules_set_xheader(this)', 'class' => 'radio'));
1523
 
                        $xheader_show = $input_xheader->show($header) . "&nbsp;" . html::label($xheader . '_' . $rowid, Q($xheader));
1524
 
 
1525
 
                        if ($idx < $col_length)
1526
 
                                $col1 .= $xheader_show . "<br />";
1527
 
                        elseif ($idx < $col_length * 2)
1528
 
                                $col2 .= $xheader_show . "<br />";
1529
 
                        elseif ($idx < $col_length * 3)
1530
 
                                $col3 .= $xheader_show . "<br />";
1531
 
                        elseif ($idx < $col_length * 4)
1532
 
                                $col4 .= $xheader_show . "<br />";
1533
 
                }
1534
 
 
1535
 
                $headers_table->add(array('style' => 'vertical-align: top; width: 25%;'), $col1);
1536
 
                $headers_table->add(array('style' => 'vertical-align: top; width: 25%;'), $col2);
1537
 
                $headers_table->add(array('style' => 'vertical-align: top; width: 25%;'), $col3);
1538
 
                $headers_table->add(array('style' => 'vertical-align: top; width: 25%;'), $col4);
1539
 
 
1540
 
                $rules_table->set_row_attribs(array('style' => 'display: none;'));
1541
 
                $rules_table->add(array('colspan' => 5), $headers_table->show());
1542
 
                $rules_table->add_row();
1543
 
 
1544
 
                $advanced_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 2));
1545
 
                $advanced_table->add(array('colspan' => 2, 'style' => 'white-space: normal;'), Q($this->gettext('advancedoptions')));
1546
 
                $advanced_table->add_row();
1547
 
 
1548
 
                $help_button = html::img(array('class' => $imgclass, 'src' => $attrib['helpicon'], 'alt' => $this->gettext('contentpart'), 'border' => 0, 'style' => 'margin-left: 4px;'));
1549
 
                $help_button = html::a(array('href' => "#", 'onclick' => 'return '. JS_OBJECT_NAME .'.sieverules_help(this, ' . $advanced_table->size() . ');', 'title' => $this->gettext('contentpart')), $help_button);
1550
 
 
1551
 
                $field_id = 'rcmfd_advcontentpart_'. $rowid;
1552
 
                $advanced_table->set_row_attribs(array('style' => $advcontentpart_style));
1553
 
                $input_advcontentpart = new html_inputfield(array('id' => $field_id, 'name' => '_body_contentpart[]', 'class' => 'short'));
1554
 
                $advanced_table->add(array('style' => 'white-space: normal;', 'class' => 'selheader'), html::label($field_id, Q($this->gettext('bodycontentpart'))));
1555
 
                $advanced_table->add(array('style' => 'white-space: normal;'), $input_advcontentpart->show($advcontentpart) . $help_button);
1556
 
 
1557
 
                $advanced_table->set_row_attribs(array('class' => 'advhelp', 'style' => 'display: none;'));
1558
 
                $advanced_table->add(array('colspan' => 2, 'class' => 'vacdaysexp'), $this->gettext('contentpartexp'));
1559
 
                $advanced_table->add_row();
1560
 
 
1561
 
                $field_id = 'rcmfd_advoperator_'. $rowid;
1562
 
                $select_advop = new html_select(array('id' => $field_id, 'name' => "_advoperator[]", 'onchange' => JS_OBJECT_NAME . '.sieverules_rule_advop_select(this)'));
1563
 
 
1564
 
                if (in_array('regex', $ext)) {
1565
 
                        $select_advop->add(Q($this->gettext('filterregex')), 'regex');
1566
 
                        $select_advop->add(Q($this->gettext('filternotregex')), 'notregex');
1567
 
                }
1568
 
 
1569
 
                if (in_array('relational', $ext)) {
1570
 
                        $select_advop->add(Q($this->gettext('countisgreaterthan')), 'count "gt"');
1571
 
                        $select_advop->add(Q($this->gettext('countisgreaterthanequal')), 'count "ge"');
1572
 
                        $select_advop->add(Q($this->gettext('countislessthan')), 'count "lt"');
1573
 
                        $select_advop->add(Q($this->gettext('countislessthanequal')), 'count "le"');
1574
 
                        $select_advop->add(Q($this->gettext('countequals')), 'count "eq"');
1575
 
                        $select_advop->add(Q($this->gettext('countnotequals')), 'count "ne"');
1576
 
                        $select_advop->add(Q($this->gettext('valueisgreaterthan')), 'value "gt"');
1577
 
                        $select_advop->add(Q($this->gettext('valueisgreaterthanequal')), 'value "ge"');
1578
 
                        $select_advop->add(Q($this->gettext('valueislessthan')), 'value "lt"');
1579
 
                        $select_advop->add(Q($this->gettext('valueislessthanequal')), 'value "le"');
1580
 
                        $select_advop->add(Q($this->gettext('valueequals')), 'value "eq"');
1581
 
                        $select_advop->add(Q($this->gettext('valuenotequals')), 'value "ne"');
1582
 
                }
1583
 
 
1584
 
                if (in_array('subaddress', $ext)) {
1585
 
                        $select_advop->add(Q($this->gettext('userpart')), 'user');
1586
 
                        $select_advop->add(Q($this->gettext('notuserpart')), 'notuser');
1587
 
                        $select_advop->add(Q($this->gettext('detailpart')), 'detail');
1588
 
                        $select_advop->add(Q($this->gettext('notdetailpart')), 'notdetail');
1589
 
                        $select_advop->add(Q($this->gettext('domainpart')), 'domain');
1590
 
                        $select_advop->add(Q($this->gettext('notdomainpart')), 'notdomain');
1591
 
                }
1592
 
 
1593
 
                $advanced_table->add(array('style' => 'white-space: normal;', 'class' => 'selheader'), html::label($field_id, Q($this->gettext('operator'))));
1594
 
                $advanced_table->add(array('style' => 'white-space: normal;'), $select_advop->show($op));
1595
 
 
1596
 
                $field_id = 'rcmfd_comparator_'. $rowid;
1597
 
                if (substr($op, 0, 5) == 'count' || substr($op, 0, 5) == 'value')
1598
 
                        $select_comparator = new html_select(array('id' => $field_id, 'name' => "_comparator[]"));
1599
 
                else
1600
 
                        $select_comparator = new html_select(array('id' => $field_id, 'name' => "_comparator[]", 'disabled' => 'disabled'));
1601
 
 
1602
 
                $select_comparator->add(Q($this->gettext('i;ascii-casemap')), '');
1603
 
                $select_comparator->add(Q($this->gettext('i;octet')), 'i;octet');
1604
 
 
1605
 
                foreach ($ext as $extension) {
1606
 
                        if (substr($extension, 0, 11) == 'comparator-' && $extension != 'comparator-i;ascii-casemap' && $extension != 'comparator-i;octet')
1607
 
                                $select_comparator->add(Q($this->gettext(substr($extension, 11))), substr($extension, 11));
1608
 
                }
1609
 
 
1610
 
                $advanced_table->add(array('style' => 'white-space: normal;', 'class' => 'selheader'), html::label($field_id, Q($this->gettext('comparator'))));
1611
 
                $advanced_table->add(array('style' => 'white-space: normal;'), $select_comparator->show($rule['comparator']));
1612
 
 
1613
 
                $select_advweekdays = new html_select(array('name' => "_advweekday[]", 'style' => $advweekdays_style));
1614
 
                $select_advweekdays->add(Q($this->gettext('sunday')), '0');
1615
 
                $select_advweekdays->add(Q($this->gettext('monday')), '1');
1616
 
                $select_advweekdays->add(Q($this->gettext('tuesday')), '2');
1617
 
                $select_advweekdays->add(Q($this->gettext('wednesday')), '3');
1618
 
                $select_advweekdays->add(Q($this->gettext('thursday')), '4');
1619
 
                $select_advweekdays->add(Q($this->gettext('friday')), '5');
1620
 
                $select_advweekdays->add(Q($this->gettext('saturday')), '6');
1621
 
 
1622
 
                $field_id = 'rcmfd_advtarget_'. $rowid;
1623
 
                $input_advtarget = new html_inputfield(array('id' => $field_id, 'name' => '_advtarget[]', 'style' => $advtarget_style));
1624
 
                $advanced_table->add(array('style' => 'white-space: normal;', 'class' => 'selheader'), html::label($field_id, Q($this->gettext('teststring'))));
1625
 
                $advanced_table->add(array('style' => 'white-space: normal;'), $input_advtarget->show($target) . $select_advweekdays->show($target));
1626
 
 
1627
 
                if (!($showadvanced && $predefined == -1))
1628
 
                        $rules_table->set_row_attribs(array('style' => 'display: none;'));
1629
 
                $rules_table->add(array('colspan' => 5), $advanced_table->show());
1630
 
                $rules_table->add_row();
1631
 
 
1632
 
                return $rules_table;
1633
 
        }
1634
 
 
1635
 
        private function _action_row($ext, $actions_table, $rowid, $action, $attrib, $example)
1636
 
        {
1637
 
                $rcmail = rcmail::get_instance();
1638
 
                static $a_mailboxes;
1639
 
                $imgclass = null;
1640
 
 
1641
 
                if (!isset($action)) {
1642
 
                        $actions_table->set_row_attribs(array('style' => 'display: none;'));
1643
 
                        $imgclass = 'nohtc';
1644
 
                }
1645
 
 
1646
 
                $help_icon = html::img(array('src' => $attrib['helpicon'], 'alt' => $this->gettext('messagehelp'), 'border' => 0));
1647
 
 
1648
 
                $vacadvstyle = ($action['type'] != 'vacation' && $this->force_vacto) ? '' : 'display: none;';
1649
 
                $vacadvstyle_from = ($this->show_vacfrom) ? $vacadvstyle : 'display: none;';
1650
 
                $vacadvstyle_handle = ($this->show_vachandle) ? $vacadvstyle : 'display: none;';
1651
 
                $vacadvclass_from = ($this->show_vacfrom) ? 'advanced' : 'disabled';
1652
 
                $vacadvclass_handle = ($this->show_vachandle) ? 'advanced' : 'disabled';
1653
 
                $vacshowadv = ($action['type'] != 'vacation' && $this->force_vacto) ? '1' : '';
1654
 
                $noteadvstyle = 'display: none;';
1655
 
                $noteshowadv = '';
1656
 
 
1657
 
                // setup allowed actions
1658
 
                $allowed_actions = array();
1659
 
                $config_actions = $rcmail->config->get('sieverules_allowed_actions', array());
1660
 
                if (in_array('fileinto', $ext) && ($config_actions['fileinto'] || $action['type'] == 'fileinto'))
1661
 
                        $allowed_actions['fileinto'] = $this->gettext('messagemoveto');
1662
 
                if (in_array('fileinto', $ext) && in_array('copy', $ext) && ($config_actions['fileinto'] || $action['type'] == 'fileinto'))
1663
 
                        $allowed_actions['fileinto_copy'] = $this->gettext('messagecopyto');
1664
 
                if (in_array('vacation', $ext) && ($config_actions['vacation'] || $action['type'] == 'vacation'))
1665
 
                        $allowed_actions['vacation'] = $this->gettext('messagevacation');
1666
 
                if (in_array('reject', $ext) && ($config_actions['reject'] || $action['type'] == 'reject'))
1667
 
                        $allowed_actions['reject'] =  $this->gettext('messagereject');
1668
 
                elseif (in_array('ereject', $ext) && ($config_actions['reject'] || $action['type'] == 'ereject'))
1669
 
                        $allowed_actions['ereject'] = $this->gettext('messagereject');
1670
 
                if (in_array('imapflags', $ext) && ($config_actions['imapflags'] || $action['type'] == 'imapflags'))
1671
 
                        $allowed_actions['imapflags'] = $this->gettext('messageimapflags');
1672
 
                elseif (in_array('imap4flags', $ext) && ($config_actions['imapflags'] || $action['type'] == 'imap4flags'))
1673
 
                        $allowed_actions['imap4flags'] = $this->gettext('messageimapflags');
1674
 
                if (in_array('notify', $ext) && ($config_actions['notify'] || $action['type'] == 'notify'))
1675
 
                        $allowed_actions['notify'] = $this->gettext('messagenotify');
1676
 
                elseif (in_array('enotify', $ext) && ($config_actions['notify'] || $action['type'] == 'enotify'))
1677
 
                        $allowed_actions['enotify'] = $this->gettext('messagenotify');
1678
 
                if ($config_actions['redirect'] || $action['type'] == 'redirect')
1679
 
                        $allowed_actions['redirect'] = $this->gettext('messageredirect');
1680
 
                if (in_array('copy', $ext) && ($config_actions['redirect'] || $action['type'] == 'redirect_copy'))
1681
 
                        $allowed_actions['redirect_copy'] = $this->gettext('messageredirectcopy');
1682
 
                if ($config_actions['keep'] || $action['type'] == 'keep')
1683
 
                        $allowed_actions['keep'] = $this->gettext('messagekeep');
1684
 
                if ($config_actions['discard'] || $action['type'] == 'discard')
1685
 
                        $allowed_actions['discard'] = $this->gettext('messagediscard');
1686
 
                if ($config_actions['stop'] || $action['type'] == 'stop')
1687
 
                        $allowed_actions['stop'] = $this->gettext('messagestop');
1688
 
 
1689
 
                // set the default action
1690
 
                reset($allowed_actions);
1691
 
                $method = key($allowed_actions);
1692
 
 
1693
 
                $folder = 'INBOX';
1694
 
                $reject = '';
1695
 
 
1696
 
                $identity = $rcmail->user->get_identity();
1697
 
                if ($this->show_vacfrom)
1698
 
                        $vacfrom = (in_array('variables', $ext)) ? 'auto' : $identity['email'];
1699
 
                else
1700
 
                        $vacfrom = null;
1701
 
 
1702
 
                $vacto = null;
1703
 
                $address = '';
1704
 
                $days = '';
1705
 
                $handle = '';
1706
 
                $subject = '';
1707
 
                $origsubject = '';
1708
 
                $msg = '';
1709
 
                $charset = RCMAIL_CHARSET;
1710
 
                $flags = '';
1711
 
                $nfrom = '';
1712
 
                $nimpt = '';
1713
 
                $nmethod = '';
1714
 
                $noptions = '';
1715
 
                $nmsg = '';
1716
 
 
1717
 
                if ($action['type'] == 'fileinto' || $action['type'] == 'fileinto_copy') {
1718
 
                        $method = $action['type'];
1719
 
                        $folder = $rcmail->config->get('sieverules_include_imap_root', true) ? $rcmail->imap->mod_mailbox($action['target'], 'out') : $action['target'];
1720
 
 
1721
 
                        if ($rcmail->config->get('sieverules_folder_delimiter', false))
1722
 
                                $folder = str_replace($rcmail->imap->get_hierarchy_delimiter(), $rcmail->config->get('sieverules_folder_delimiter'), $folder);
1723
 
                }
1724
 
                elseif ($action['type'] == 'reject' || $action['type'] == 'ereject') {
1725
 
                        $method = $action['type'];
1726
 
                        $reject = htmlspecialchars($action['target']);
1727
 
                }
1728
 
                elseif ($action['type'] == 'vacation') {
1729
 
                        $method = 'vacation';
1730
 
                        $days = $action['days'];
1731
 
                        $vacfrom_default = $vacfrom;
1732
 
                        $vacfrom = $action['from'];
1733
 
                        $vacto = $action['addresses'];
1734
 
                        $handle = htmlspecialchars($action['handle']);
1735
 
                        $subject = htmlspecialchars($action['subject']);
1736
 
                        $origsubject = $action['origsubject'];
1737
 
                        $msg = htmlspecialchars($action['msg']);
1738
 
                        $charset = $action['charset'];
1739
 
                        if (!$example)
1740
 
                                $this->force_vacto = false;
1741
 
 
1742
 
                        // check advanced enabled
1743
 
                        if ((!empty($vacfrom) && $vacfrom != $vacfrom_default) || !empty($vacto) || !empty($handle) || $charset != RCMAIL_CHARSET || $this->force_vacto) {
1744
 
                                $vacadvstyle = '';
1745
 
                                $vacadvstyle_from = ($this->show_vacfrom) ? '' : 'display: none;';
1746
 
                                $vacadvstyle_handle = ($this->show_vachandle) ? '' : 'display: none;';
1747
 
                                $vacshowadv = '1';
1748
 
                        }
1749
 
                }
1750
 
                elseif ($action['type'] == 'redirect' || $action['type'] == 'redirect_copy') {
1751
 
                        $method = $action['type'];
1752
 
                        $address = $action['target'];
1753
 
                }
1754
 
                elseif ($action['type'] == 'imapflags' || $action['type'] == 'imap4flags') {
1755
 
                        $method = $action['type'];
1756
 
                        $flags = $action['target'];
1757
 
                }
1758
 
                elseif ($action['type'] == 'notify' || $action['type'] == 'enotify') {
1759
 
                        $method = $action['type'];
1760
 
                        $nfrom = htmlspecialchars($action['from']);
1761
 
                        $nimpt = htmlspecialchars($action['importance']);
1762
 
                        $nmethod = $action['method'];
1763
 
                        $noptions = $action['options'];
1764
 
                        $nmsg = $action['msg'];
1765
 
 
1766
 
                        // check advanced enabled
1767
 
                        if (!empty($nfrom) || !empty($nimpt)) {
1768
 
                                $noteadvstyle = '';
1769
 
                                $noteshowadv = '1';
1770
 
                        }
1771
 
                }
1772
 
                elseif ($action['type'] == 'discard' || $action['type'] == 'keep' || $action['type'] == 'stop') {
1773
 
                        $method = $action['type'];
1774
 
                }
1775
 
 
1776
 
                $select_action = new html_select(array('name' => "_act[]", 'onchange' => JS_OBJECT_NAME . '.sieverules_action_select(this)'));
1777
 
                foreach ($allowed_actions as $value => $text)
1778
 
                        $select_action->add(Q($text), $value);
1779
 
 
1780
 
                $actions_table->add('action', $select_action->show($method));
1781
 
 
1782
 
                $vacs_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 3, 'style' => ($method == 'vacation') ? '' : 'display: none;'));
1783
 
 
1784
 
                $to_addresses = "";
1785
 
                $vacto_arr = explode(",", $vacto);
1786
 
                $user_identities = $rcmail->user->list_identities();
1787
 
                if (count($user_identities)) {
1788
 
                        $field_id = 'rcmfd_sievevacfrom_'. $rowid;
1789
 
                        $select_id = new html_select(array('id' => $field_id, 'name' => "_vacfrom[]"));
1790
 
 
1791
 
                        if ($this->show_vacfrom && in_array('variables', $ext))
1792
 
                                $select_id->add(Q($this->gettext('autodetect')), "auto");
1793
 
                        elseif (!$this->show_vacfrom)
1794
 
                                $select_id->add(Q($this->gettext('autodetect')), "");
1795
 
 
1796
 
                        foreach ($user_identities as $sql_arr) {
1797
 
                                $select_id->add($sql_arr['email'], $sql_arr['email']);
1798
 
 
1799
 
                                $ffield_id = 'rcmfd_vac_' . $rowid . '_' . $sql_arr['identity_id'];
1800
 
 
1801
 
                                if ($this->force_vacto) {
1802
 
                                        $curaddress = $sql_arr['email'];
1803
 
                                        $vacto .= (!empty($vacto) ? ',' : '') . $sql_arr['email'];
1804
 
                                }
1805
 
                                else {
1806
 
                                        $curaddress = in_array($sql_arr['email'], $vacto_arr) ? $sql_arr['email'] : "";
1807
 
                                }
1808
 
 
1809
 
                                $input_address = new html_checkbox(array('id' => $ffield_id, 'name' => '_vacto_check_' . $rowid . '[]', 'value' => $sql_arr['email'], 'onclick' => JS_OBJECT_NAME . '.sieverules_toggle_vac_to(this, '. $rowid .')', 'class' => 'checkbox'));
1810
 
                                $to_addresses .= $input_address->show($curaddress) . "&nbsp;" . html::label($ffield_id, Q($sql_arr['email'])) . "<br />";
1811
 
                        }
1812
 
                }
1813
 
 
1814
 
                if ($rcmail->config->get('sieverules_limit_vacto', true) && strlen($to_addresses) > 0) {
1815
 
                        $vacs_table->set_row_attribs(array('class' => $vacadvclass_from, 'style' => $vacadvstyle_from));
1816
 
                        $vacs_table->add(null, html::label($field_id, Q($this->gettext('from'))));
1817
 
                        $vacs_table->add(array('colspan' => 2), $select_id->show($vacfrom));
1818
 
                        $vacs_table->add_row();
1819
 
 
1820
 
                        $field_id = 'rcmfd_sievevacto_'. $rowid;
1821
 
                        $input_vacto = new html_hiddenfield(array('id' => $field_id, 'name' => '_vacto[]', 'value' => $vacto));
1822
 
                        $vacs_table->set_row_attribs(array('class' => 'advanced', 'style' => $vacadvstyle));
1823
 
                        $vacs_table->add(array('style' => 'vertical-align: top;'), Q($this->gettext('sieveto')));
1824
 
                        $vacs_table->add(null, $to_addresses . $input_vacto->show());
1825
 
                        $help_button = html::a(array('href' => "#", 'onclick' => 'return ' . JS_OBJECT_NAME . '.sieverules_help(this, ' . $vacs_table->size() . ');', 'title' => $this->gettext('messagehelp')), $help_icon);
1826
 
                        $vacs_table->add(array('style' => 'vertical-align: top;'), $help_button);
1827
 
 
1828
 
                        $vacs_table->set_row_attribs(array('class' => 'advhelp', 'style' => 'display: none;'));
1829
 
                        $vacs_table->add(array('colspan' => 3, 'class' => 'vacdaysexp'), $this->gettext('vactoexp'));
1830
 
                        $vacs_table->add_row();
1831
 
                }
1832
 
                else {
1833
 
                        $field_id = 'rcmfd_sievevacfrom_'. $rowid;
1834
 
                        $input_vacfrom = new html_inputfield(array('id' => $field_id, 'name' => '_vacfrom[]'));
1835
 
                        $vacs_table->set_row_attribs(array('class' => $vacadvclass_from, 'style' => $vacadvstyle_from));
1836
 
                        $vacs_table->add(null, html::label($field_id, Q($this->gettext('from'))));
1837
 
                        $vacs_table->add(array('colspan' => 2), $input_vacfrom->show($vacfrom));
1838
 
                        $vacs_table->add_row();
1839
 
 
1840
 
                        $field_id = 'rcmfd_sievevacto_'. $rowid;
1841
 
                        $input_vacto = new html_inputfield(array('id' => $field_id, 'name' => '_vacto[]', 'class' => 'short'));
1842
 
                        $vacs_table->set_row_attribs(array('class' => 'advanced', 'style' => $vacadvstyle));
1843
 
                        $vacs_table->add(null, html::label($field_id, Q($this->gettext('sieveto'))));
1844
 
                        $vacs_table->add(null, $input_vacto->show($vacto));
1845
 
 
1846
 
                        $help_button = html::a(array('href' => "#", 'onclick' => 'return ' . JS_OBJECT_NAME . '.sieverules_help(this, ' . $vacs_table->size() . ');', 'title' => $this->gettext('messagehelp')), $help_icon);
1847
 
                        $vacs_table->add(null, $help_button);
1848
 
                        $vacs_table->set_row_attribs(array('class' => 'advhelp', 'style' => 'display: none;'));
1849
 
                        $vacs_table->add(array('colspan' => 3, 'class' => 'vacdaysexp'), $this->gettext('vactoexp') . '<br /><br />' . $this->gettext('vactoexp_adv'));
1850
 
                        $vacs_table->add_row();
1851
 
                }
1852
 
 
1853
 
                $field_id = 'rcmfd_sievevacdays_'. $rowid;
1854
 
                $input_day = new html_inputfield(array('id' => $field_id, 'name' => '_day[]', 'class' => 'short'));
1855
 
                $vacs_table->add(null, html::label($field_id, Q($this->gettext('days'))));
1856
 
                $vacs_table->add(null, $input_day->show($days));
1857
 
                $help_button = html::a(array('href' => "#", 'onclick' => 'return ' . JS_OBJECT_NAME . '.sieverules_help(this, ' . $vacs_table->size() . ');', 'title' => $this->gettext('messagehelp')), $help_icon);
1858
 
                $vacs_table->add(null, $help_button);
1859
 
 
1860
 
                $vacs_table->set_row_attribs(array('style' => 'display: none;'));
1861
 
                $vacs_table->add(array('colspan' => 3, 'class' => 'vacdaysexp'), $this->gettext('vacdaysexp'));
1862
 
                $vacs_table->add_row();
1863
 
 
1864
 
                $field_id = 'rcmfd_sievevachandle_'. $rowid;
1865
 
                $input_handle = new html_inputfield(array('id' => $field_id, 'name' => '_handle[]', 'class' => 'short'));
1866
 
                $vacs_table->set_row_attribs(array('class' => $vacadvclass_handle, 'style' => $vacadvstyle_handle));
1867
 
                $vacs_table->add(null, html::label($field_id, Q($this->gettext('sievevachandle'))));
1868
 
                $vacs_table->add(null, $input_handle->show($handle));
1869
 
                $help_button = html::a(array('href' => "#", 'onclick' => 'return ' . JS_OBJECT_NAME . '.sieverules_help(this, ' . $vacs_table->size() . ');', 'title' => $this->gettext('messagehelp')), $help_icon);
1870
 
                $vacs_table->add(null, $help_button);
1871
 
 
1872
 
                $vacs_table->set_row_attribs(array('class' => 'advhelp', 'style' => 'display: none;'));
1873
 
                $vacs_table->add(array('colspan' => 3, 'class' => 'vacdaysexp'), $this->gettext('vachandleexp'));
1874
 
                $vacs_table->add_row();
1875
 
 
1876
 
                $field_id = 'rcmfd_sievevacsubject_'. $rowid;
1877
 
                $input_subject = new html_inputfield(array('id' => $field_id, 'name' => '_subject[]'));
1878
 
                $vacs_table->add(null, html::label($field_id, Q($this->gettext('subject'))));
1879
 
                $vacs_table->add(array('colspan' => 2), $input_subject->show($subject));
1880
 
                $vacs_table->add_row();
1881
 
 
1882
 
                if (in_array('variables', $ext)) {
1883
 
                        $field_id = 'rcmfd_sievevacsubject_orig_'. $rowid;
1884
 
                        $input_origsubject = new html_checkbox(array('id' => $field_id, 'value' => '1', 'onclick' => JS_OBJECT_NAME . '.sieverules_toggle_vac_osubj(this, '. $rowid .')', 'class' => 'checkbox'));
1885
 
                        $input_vacosubj = new html_hiddenfield(array('id' => 'rcmfd_sievevactoh_'. $rowid, 'name' => '_orig_subject[]', 'value' => $origsubject));
1886
 
                        $vacs_table->add(null, '&nbsp;');
1887
 
                        $vacs_table->add(array('colspan' => 2), $input_origsubject->show($origsubject) . "&nbsp;" . html::label($field_id, Q($this->gettext('sieveorigsubj'))) . $input_vacosubj->show());
1888
 
                        $vacs_table->add_row();
1889
 
                }
1890
 
 
1891
 
                $field_id = 'rcmfd_sievevacmag_'. $rowid;
1892
 
                $input_msg = new html_textarea(array('id' => $field_id, 'name' => '_msg[]', 'rows' => '5', 'cols' => '40'));
1893
 
                $vacs_table->add('msg', html::label($field_id, Q($this->gettext('message'))));
1894
 
                $vacs_table->add(array('colspan' => 2), $input_msg->show($msg));
1895
 
                $vacs_table->add_row();
1896
 
 
1897
 
                $field_id = 'rcmfd_sievecharset_'. $rowid;
1898
 
                $vacs_table->set_row_attribs(array('class' => 'advanced', 'style' => $vacadvstyle));
1899
 
                $vacs_table->add(null, html::label($field_id, Q($this->gettext('charset'))));
1900
 
                $vacs_table->add(array('colspan' => 2), $this->_charset_selector(array('id' => $field_id, 'name' => '_charset[]'), $charset));
1901
 
                $vacs_table->add_row();
1902
 
 
1903
 
                $input_advopts = new html_checkbox(array('id' => 'vadvopts' . $rowid, 'name' => '_vadv_opts[]', 'onclick' => JS_OBJECT_NAME . '.sieverules_show_adv(this);', 'value' => '1', 'class' => 'checkbox'));
1904
 
                $vacs_table->add(array('colspan' => '3', 'style' => 'text-align: right'), html::label('vadvopts' . $rowid, Q($this->gettext('advancedoptions'))) . $input_advopts->show($vacshowadv));
1905
 
 
1906
 
                $notify_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 3, 'style' => ($method == 'notify' || $method == 'enotify') ? '' : 'display: none;'));
1907
 
 
1908
 
                $user_identities = $rcmail->user->list_identities();
1909
 
                if (count($user_identities)) {
1910
 
                        $field_id = 'rcmfd_sievenotifyfrom_'. $rowid;
1911
 
                        $select_id = new html_select(array('id' => $field_id, 'name' => "_nfrom[]"));
1912
 
                        $select_id->add(Q($this->gettext('autodetect')), "");
1913
 
 
1914
 
                        foreach ($user_identities as $sql_arr)
1915
 
                                $select_id->add($sql_arr['email'], $sql_arr['email']);
1916
 
 
1917
 
                        $notify_table->set_row_attribs(array('class' => 'advanced', 'style' => $noteadvstyle));
1918
 
                        $notify_table->add(null, html::label($field_id, Q($this->gettext('sievefrom'))));
1919
 
                        $notify_table->add(array('colspan' => 2), $select_id->show($nfrom));
1920
 
                        $notify_table->add_row();
1921
 
                }
1922
 
 
1923
 
                $field_id = 'rcmfd_nmethod_'. $rowid;
1924
 
                $input_method = new html_inputfield(array('id' => $field_id, 'name' => '_nmethod[]'));
1925
 
                $notify_table->add(null, html::label($field_id, Q($this->gettext('method'))));
1926
 
                $notify_table->add(array('colspan' => 2), $input_method->show($nmethod));
1927
 
                $notify_table->add_row();
1928
 
 
1929
 
                $field_id = 'rcmfd_noption_'. $rowid;
1930
 
                $input_method = new html_inputfield(array('id' => $field_id, 'name' => '_noption[]'));
1931
 
                $notify_table->add(null, html::label($field_id, Q($this->gettext('options'))));
1932
 
                $notify_table->add(array('colspan' => 2), $input_method->show($noptions));
1933
 
                $notify_table->add_row();
1934
 
 
1935
 
                $notify_table->set_row_attribs(array('style' => 'display: none;'));
1936
 
                $notify_table->add(array('colspan' => 3, 'class' => 'vacdaysexp'), $this->gettext('nmethodexp'));
1937
 
                $notify_table->add_row();
1938
 
 
1939
 
                $field_id = 'rcmfd_nimpt_'. $rowid;
1940
 
                $input_importance = new html_radiobutton(array('id' => $field_id . '_none', 'name' => '_notify_radio_' . $rowid, 'value' => 'none', 'onclick' => JS_OBJECT_NAME . '.sieverules_notify_impt(this, '. $rowid .')'));
1941
 
                $importance_show = $input_importance->show($nimpt) . "&nbsp;" . html::label($field_id . '_none', Q($this->gettext('importancen')));
1942
 
                $input_importance = new html_radiobutton(array('id' => $field_id . '_1', 'name' => '_notify_radio_' . $rowid, 'value' => '1', 'onclick' => JS_OBJECT_NAME . '.sieverules_notify_impt(this, '. $rowid .')'));
1943
 
                $importance_show .= '&nbsp;&nbsp;' . $input_importance->show($nimpt) . "&nbsp;" . html::label($field_id . '_1', Q($this->gettext('importance1')));
1944
 
                $input_importance = new html_radiobutton(array('id' => $field_id . '_2', 'name' => '_notify_radio_' . $rowid, 'value' => '2', 'onclick' => JS_OBJECT_NAME . '.sieverules_notify_impt(this, '. $rowid .')'));
1945
 
                $importance_show .= '&nbsp;&nbsp;' . $input_importance->show($nimpt) . "&nbsp;" . html::label($field_id . '_2', Q($this->gettext('importance2')));
1946
 
                $input_importance = new html_radiobutton(array('id' => $field_id . '_3', 'name' => '_notify_radio_' . $rowid, 'value' => '3', 'onclick' => JS_OBJECT_NAME . '.sieverules_notify_impt(this, '. $rowid .')'));
1947
 
                $importance_show .= '&nbsp;&nbsp;' . $input_importance->show($nimpt) . "&nbsp;" . html::label($field_id . '_3', Q($this->gettext('importance3')));
1948
 
                $input_importance = new html_hiddenfield(array('id' => 'rcmfd_sievenimpt_'. $rowid, 'name' => '_nimpt[]'));
1949
 
 
1950
 
                $notify_table->set_row_attribs(array('class' => 'advanced', 'style' => $noteadvstyle));
1951
 
                $notify_table->add(null, Q($this->gettext('flag')));
1952
 
                $notify_table->add(array('colspan' => 2), $importance_show . $input_importance->show($nimpt));
1953
 
                $notify_table->add_row();
1954
 
 
1955
 
                $field_id = 'rcmfd_nmsg_'. $rowid;
1956
 
                $input_msg = new html_inputfield(array('id' => $field_id, 'name' => '_nmsg[]'));
1957
 
                $notify_table->add(null, html::label($field_id, Q($this->gettext('message'))));
1958
 
                $notify_table->add(array('colspan' => 2), $input_msg->show($nmsg));
1959
 
                $notify_table->add_row();
1960
 
 
1961
 
                if (in_array('enotify', $ext)) {
1962
 
                        $input_advopts = new html_checkbox(array('id' => 'nadvopts' . $rowid, 'name' => '_nadv_opts[]', 'onclick' => JS_OBJECT_NAME . '.sieverules_show_adv(this);', 'value' => '1'));
1963
 
                        $notify_table->add(array('colspan' => '3', 'style' => 'text-align: right'), html::label('nadvopts' . $rowid, Q($this->gettext('advancedoptions'))) . $input_advopts->show($noteshowadv));
1964
 
                }
1965
 
 
1966
 
                // get mailbox list
1967
 
                $mbox_name = $rcmail->imap->get_mailbox_name();
1968
 
 
1969
 
                // build the folders tree
1970
 
                if (empty($a_mailboxes)) {
1971
 
                        // get mailbox list
1972
 
                        if ($rcmail->config->get('sieverules_fileinto_options', 0) > 0)
1973
 
                                $a_folders = $rcmail->imap->list_unsubscribed();
1974
 
                        else
1975
 
                                $a_folders = $rcmail->imap->list_mailboxes();
1976
 
 
1977
 
                        $delimiter = $rcmail->imap->get_hierarchy_delimiter();
1978
 
                        $a_mailboxes = array();
1979
 
 
1980
 
                        foreach ($a_folders as $ifolder) {
1981
 
                                if ($rcmail->config->get('sieverules_folder_encoding'))
1982
 
                                        $ifolder = $this->_mbox_encode($ifolder, $rcmail->config->get('sieverules_folder_encoding'));
1983
 
 
1984
 
                                if ($rcmail->config->get('sieverules_folder_delimiter', false))
1985
 
                                        rcmail_build_folder_tree($a_mailboxes, str_replace($delimiter, $rcmail->config->get('sieverules_folder_delimiter'), $ifolder), $rcmail->config->get('sieverules_folder_delimiter'));
1986
 
                                else
1987
 
                                        rcmail_build_folder_tree($a_mailboxes, $ifolder, $delimiter);
1988
 
                        }
1989
 
 
1990
 
                        if ($rcmail->config->get('sieverules_fileinto_options', 0) == 2)
1991
 
                                array_push($a_mailboxes, array('id' => '@@newfolder', 'name' => $this->gettext('createfolder'), 'virtual' => '', 'folders' => array()));
1992
 
                }
1993
 
 
1994
 
                $input_folderlist = new html_select(array('name' => '_folder[]', 'onchange' => JS_OBJECT_NAME . '.sieverules_select_folder(this);', 'style' => ($method == 'fileinto' || $method == 'fileinto_copy') ? '' : 'display: none;'));
1995
 
                rcmail_render_folder_tree_select($a_mailboxes, $mbox_name, 100, $input_folderlist, false);
1996
 
 
1997
 
                $show_customfolder = 'display: none;';
1998
 
                if ($rcmail->config->get('sieverules_fileinto_options', 0) == 2 && !$rcmail->imap->mailbox_exists($folder)) {
1999
 
                        $customfolder = $folder;
2000
 
                        $folder = '@@newfolder';
2001
 
                        $show_customfolder = '';
2002
 
                }
2003
 
 
2004
 
                $input_customfolder = new html_inputfield(array('name' => '_customfolder[]'));
2005
 
                $otherfolders = html::span(array('id' => 'customfolder_rowid', 'style' => $show_customfolder), '<br />' . $input_customfolder->show($customfolder));
2006
 
 
2007
 
                $input_address = new html_inputfield(array('name' => '_redirect[]', 'style' => ($method == 'redirect' || $method == 'redirect_copy') ? '' : 'display: none;'));
2008
 
                $input_reject = new html_textarea(array('name' => '_reject[]', 'rows' => '5', 'cols' => '40', 'style' => ($method == 'reject' || $method == 'ereject') ? '' : 'display: none;'));
2009
 
                $input_imapflags = new html_select(array('name' => '_imapflags[]', 'style' => ($method == 'imapflags' || $method == 'imap4flags') ? '' : 'display: none;'));
2010
 
                foreach($this->flags as $name => $val)
2011
 
                        $input_imapflags->add(Q($this->gettext($name)), Q($val));
2012
 
 
2013
 
                $actions_table->add('folder', $input_folderlist->show($folder) . $otherfolders . $input_address->show($address) . $vacs_table->show() . $notify_table->show() . $input_imapflags->show($flags) . $input_reject->show($reject));
2014
 
 
2015
 
                $add_button = $this->api->output->button(array('command' => 'plugin.sieverules.add_action', 'type' => 'link', 'class' => 'add', 'title' => 'sieverules.addsieveact', 'content' => ' '));
2016
 
                $delete_button = $this->api->output->button(array('command' => 'plugin.sieverules.del_action', 'type' => 'link', 'class' => 'delete', 'classact' => 'delete_act', 'title' => 'sieverules.deletesieveact', 'content' => ' '));
2017
 
 
2018
 
                if ($rcmail->config->get('sieverules_multiple_actions'))
2019
 
                        $actions_table->add('control', $delete_button . $add_button);
2020
 
                else
2021
 
                        $actions_table->add('control', "&nbsp;");
2022
 
 
2023
 
                return $actions_table;
2024
 
        }
2025
 
 
2026
 
        private function _in_headerarray($needle, $haystack)
2027
 
        {
2028
 
                foreach ($haystack as $data) {
2029
 
                        $args = explode("::", $data);
2030
 
                        if ($args[1] == $needle)
2031
 
                                return $args[0];
2032
 
                }
2033
 
 
2034
 
                return false;
2035
 
        }
2036
 
 
2037
 
        // coppied from rcube_template.php
2038
 
        private function _charset_selector($attrib, $charset)
2039
 
        {
2040
 
                $charsets = array(
2041
 
                        'US-ASCII'              => 'ASCII (English)',
2042
 
                        'EUC-JP'                => 'EUC-JP (Japanese)',
2043
 
                        'EUC-KR'                => 'EUC-KR (Korean)',
2044
 
                        'BIG5'                  => 'BIG5 (Chinese)',
2045
 
                        'GB2312'                => 'GB2312 (Chinese)',
2046
 
                        'ISO-2022-JP'   => 'ISO-2022-JP (Japanese)',
2047
 
                        'ISO-8859-1'    => 'ISO-8859-1 (Latin-1)',
2048
 
                        'ISO-8859-2'    => 'ISO-8859-2 (Central European)',
2049
 
                        'ISO-8859-7'    => 'ISO-8859-7 (Greek)',
2050
 
                        'ISO-8859-9'    => 'ISO-8859-9 (Turkish)',
2051
 
                        'Windows-1251'  => 'Windows-1251 (Cyrillic)',
2052
 
                        'Windows-1252'  => 'Windows-1252 (Western)',
2053
 
                        'Windows-1255'  => 'Windows-1255 (Hebrew)',
2054
 
                        'Windows-1256'  => 'Windows-1256 (Arabic)',
2055
 
                        'Windows-1257'  => 'Windows-1257 (Baltic)',
2056
 
                        'UTF-8'                 => 'UTF-8'
2057
 
                        );
2058
 
 
2059
 
                $select = new html_select($attrib);
2060
 
                $select->add(array_values($charsets), array_keys($charsets));
2061
 
 
2062
 
                return $select->show($charset);
2063
 
        }
2064
 
 
2065
 
        private function _strip_val($str)
2066
 
        {
2067
 
                return trim(htmlspecialchars_decode($str));
2068
 
        }
2069
 
 
2070
 
        private function _mbox_encode($text, $encoding)
2071
 
        {
2072
 
                return rcube_charset_convert($text, 'UTF7-IMAP', $encoding);
2073
 
        }
2074
 
}
2075
 
 
2076
 
?>
 
 
b'\\ No newline at end of file'