6
* Plugin to allow the user to manage their Sieve filters using the managesieve protocol
10
* Based on the Managesieve plugin by Aleksander Machniak
12
class sieverules extends rcube_plugin
14
public $task = 'settings';
19
private $examples = array();
20
private $force_vacto = false;
21
private $show_vacfrom = false;
22
private $show_vachandle = false;
23
private $current_ruleset;
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'
35
private $operators = array('filtercontains' => 'contains',
36
'filternotcontains' => 'notcontains',
38
'filterisnot' => 'notis',
39
'filterexists' => 'exists',
40
'filternotexists' => 'notexists'
43
private $flags = array('flagread' => '\\\\Seen',
44
'flagdeleted' => '\\\\Deleted',
45
'flaganswered' => '\\\\Answered',
46
'flagdraft' => '\\\\Draft',
47
'flagflagged' => '\\\\Flagged'
52
$rcmail = rcmail::get_instance();
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;
62
$this->current_ruleset = $rcmail->config->get('sieverules_ruleset_name');
64
// override default values
65
if ($rcmail->config->get('sieverules_default_headers'))
66
$this->headers = $rcmail->config->get('sieverules_default_headers');
68
if ($rcmail->config->get('sieverules_default_operators'))
69
$this->operators = $rcmail->config->get('sieverules_default_operators');
71
if ($rcmail->config->get('sieverules_default_flags'))
72
$this->flags = $rcmail->config->get('sieverules_default_flags');
74
$this->action = $rcmail->action;
76
$this->add_texts('localization/', array('filters'));
77
$this->include_script('sieverules.js');
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'));
97
$rcmail = rcmail::get_instance();
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');
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');
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');
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();
118
$this->current_ruleset = $rcmail->config->get('sieverules_ruleset_name');
120
rcmail_overwrite_action('plugin.sieverules.setup');
121
$this->action = 'plugin.sieverules.setup';
125
if ($rcmail->config->get('sieverules_multiplerules'))
126
$_SESSION['sieverules_current_ruleset'] = $this->current_ruleset;
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';
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'),
145
if ($this->action != 'plugin.sieverules.advanced')
146
$this->api->output->include_script('list.js');
148
if (sizeof($this->examples) > 0)
149
$this->api->output->set_env('examples', 'true');
151
if ($this->action == 'plugin.sieverules.add') {
152
$this->api->output->set_pagetitle($this->gettext('newfilter'));
153
$this->api->output->send('sieverules.editsieverule');
155
elseif ($this->action == 'plugin.sieverules.edit') {
156
$this->api->output->set_pagetitle($this->gettext('edititem'));
157
$this->api->output->send('sieverules.editsieverule');
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');
164
elseif ($this->action == 'plugin.sieverules.advanced') {
165
$this->api->output->set_pagetitle($this->gettext('filters'));
166
$this->api->output->send('sieverules.advancededitor');
169
$this->api->output->set_pagetitle($this->gettext('filters'));
170
$this->api->output->send('sieverules.sieverules');
174
function init_setup()
178
$this->api->output->add_handlers(array(
179
'sieverulessetup' => array($this, 'gen_setup'),
182
$this->api->output->set_pagetitle($this->gettext('filters'));
183
$this->api->output->send('sieverules.setupsieverules');
186
function sieverules_frame($attrib)
189
$attrib['id'] = 'rcmprefsframe';
191
$attrib['name'] = $attrib['id'];
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');
196
return html::iframe($attrib);
199
function gen_advanced($attrib)
201
list($form_start, $form_end) = get_form_tags($attrib, 'plugin.sieverules.save');
204
$input_script = new html_textarea(array('id' => 'sieverules_adv', 'name' => '_script'));
205
$out .= $input_script->show(htmlspecialchars($this->sieve->script->raw));
212
function gen_list($attrib)
214
$this->api->output->add_label('sieverules.movingfilter', 'loading', 'sieverules.switchtoadveditor');
215
$this->api->output->add_gui_object('sieverules_list', 'sieverules-table');
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'));
220
if (sizeof($this->script) == 0) {
221
$table->add(array('colspan' => '2'), rep_specialchars_output($this->gettext('nosieverules')));
224
else foreach($this->script as $idx => $filter) {
225
$table->set_row_attribs(array('id' => 'rcmrow' . $idx));
227
if ($filter['disabled'] == 1)
228
$table->add(null, Q($filter['name']) . ' (' . $this->gettext('disabled') . ')');
230
$table->add(null, Q($filter['name']));
233
$up_link = $this->api->output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'up_arrow', 'title' => 'sieverules.moveup', 'content' => ' '));
235
$down_link = $this->api->output->button(array('command' => 'plugin.sieverules.move', 'prop' => $dst, 'type' => 'link', 'class' => 'down_arrow', 'title' => 'sieverules.movedown', 'content' => ' '));
237
$table->add('control', $down_link . $up_link);
240
return html::tag('div', array('id' => 'sieverules-list-filters'), $table->show());
243
function gen_js_list()
247
if (sizeof($this->script) == 0) {
248
$this->api->output->command('sieverules_update_list', 'add-first', -1, rep_specialchars_output($this->gettext('nosieverules')));
250
else foreach($this->script as $idx => $filter) {
251
if ($filter['disabled'] == 1)
252
$filter_name = $filter['name'] . ' (' . $this->gettext('disabled') . ')';
254
$filter_name = $filter['name'];
256
$tmp_output = new rcube_template('settings');
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);
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);
264
$this->api->output->command('sieverules_update_list', $idx == 0 ? 'add-first' : 'add', 'rcmrow' . $idx, Q($filter_name), $down_link, $up_link);
267
$this->api->output->send();
270
function gen_examples()
272
if (sizeof($this->examples) > 0) {
273
$this->api->output->add_gui_object('sieverules_examples', 'sieverules-examples');
275
$examples = new html_table(array('id' => 'sieverules-examples', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 1));
276
$examples->add_header(null, $this->gettext('examplefilters'));
278
foreach($this->examples as $idx => $filter) {
279
$examples->set_row_attribs(array('id' => 'rcmrowex' . $idx));
280
$examples->add(null, Q($filter['name']));
283
return html::tag('div', array('id' => 'sieverules-list-examples'), $examples->show());
291
function gen_advswitch($attrib)
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);
298
function gen_rulelist($attrib)
300
$this->api->output->add_label('sieverules.delrulesetconf', 'sieverules.rulesetexists');
303
foreach ($this->sieve->list as $ruleset) {
304
array_push($rulesets, $ruleset);
307
$activeruleset = $this->sieve->get_active();
310
for ($i = 0; $i < sizeof($rulesets); $i++) {
311
if ($rulesets[$i] == $this->current_ruleset) {
314
if ($i == sizeof($rulesets))
315
$i = sizeof($rulesets) - 2;
317
$next_ruleset = $rulesets[$i];
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);
326
// new/rename ruleset dialog
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' => '')));
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')), '');
337
else foreach ($rulesets as $ruleset) {
338
if ($ruleset !== $this->current_ruleset)
339
$select_ruleset->add(Q($ruleset), Q($ruleset));
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());
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();')) . ' ';
348
$buttons .= html::tag('input', array('type' => 'button', 'class' => 'button', 'value' => $this->gettext('cancel'), 'onclick' => 'rcube_find_object(\'sieverulesrsdialog\').style.display = \'none\';'));
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);
359
// add overlay input box to html page
360
$this->api->output->add_footer($out);
362
$action = ($this->action == 'plugin.sieverules.advanced') ? 'plugin.sieverules.advanced' : 'plugin.sieverules';
363
if ($attrib['type'] == 'link') {
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);
370
else foreach ($rulesets as $ruleset) {
372
if ($ruleset === $this->current_ruleset)
373
$class .= ' selected';
375
$ruleset_text = $ruleset;
376
if ($ruleset === $activeruleset)
377
$ruleset_text = str_replace('%s', $ruleset, $this->gettext('activeruleset'));
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);
385
elseif ($attrib['type'] == 'select') {
386
$select_ruleset = new html_select(array('id' => 'rulelist', 'onchange' => JS_OBJECT_NAME . '.sieverules_select_ruleset(this, \''. $action .'\');'));
388
if (sizeof($this->sieve->list) == 0) {
389
$select_ruleset->add(Q($this->gettext('nosieverulesets')), '');
391
else foreach ($rulesets as $ruleset) {
392
if ($ruleset === $activeruleset)
393
$ruleset = str_replace('%s', $ruleset, $this->gettext('activeruleset'));
395
$select_ruleset->add(Q($ruleset), Q($ruleset));
398
return html::label('rulelist', Q($this->gettext('selectruleset'))) . $select_ruleset->show(Q($this->current_ruleset));
404
$rcmail = rcmail::get_instance();
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'));
412
elseif ($rcmail->config->get('sieverules_default_file', false) && !is_readable($rcmail->config->get('sieverules_default_file'))) {
418
'message' => "SieveRules plugin: Unable to open default rule file"
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) ? ' ' : '';
429
$buttons .= $this->api->output->button(array('command' => 'plugin.sieverules.import', 'prop' => '_type=' . $type . '&_import=' . $ruleset, 'type' => 'input', 'class' => 'button', 'label' => 'sieverules.importfilter'));
432
if ($rcmail->config->get('sieverules_multiplerules', false)) {
433
$text .= "<br /><br />" . $this->gettext('copyexisting');
434
$buttons .= (strlen($buttons) > 0) ? ' ' : '';
435
$buttons .= $this->api->output->button(array('command' => 'plugin.sieverules.ruleset_dialog_setup', 'prop' => 'copyfrom_ruleset', 'type' => 'input', 'class' => 'button', 'label' => 'sieverules.copyexistingfilter'));
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);
442
if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
443
$this->api->output->add_script("parent.". JS_OBJECT_NAME .".goto_url('plugin.sieverules');");
446
// go to sieverules page
447
rcmail_overwrite_action('plugin.sieverules');
448
$this->api->output->send('sieverules.sieverules');
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);
454
if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
455
$this->api->output->add_script("parent.". JS_OBJECT_NAME .".goto_url('plugin.sieverules');");
458
// go to sieverules page
459
rcmail_overwrite_action('plugin.sieverules');
460
$this->api->output->send('sieverules.sieverules');
463
else if (strlen($text) > 0 && strlen($buttons) > 0) {
464
$out = "<br />". $this->gettext('noexistingfilters') . $text . "<br /><br /><br />\n";
466
$out .= " " . $this->api->output->button(array('command' => 'plugin.sieverules.import', 'prop' => '_import=_none_', 'type' => 'input', 'class' => 'button', 'label' => 'cancel'));
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;
474
if ($rcmail->config->get('sieverules_auto_load_default') && !is_readable($rcmail->config->get('sieverules_default_file')))
480
'message' => "SieveRules plugin: Unable to open default rule file"
483
$this->sieve->save();
484
if (!$rcmail->config->get('sieverules_multiplerules', false)) $this->sieve->set_active($this->current_ruleset);
486
if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
487
$this->api->output->add_script("parent.". JS_OBJECT_NAME .".goto_url('plugin.sieverules');");
490
// go to sieverules page
491
rcmail_overwrite_action('plugin.sieverules');
492
$this->api->output->send('sieverules.sieverules');
497
function gen_form($attrib)
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');
510
$ext = $this->sieve->get_extensions();
511
$iid = get_input_value('_iid', RCUBE_INPUT_GPC);
513
$iid = sizeof($this->script);
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);
523
$cur_script = $this->script[$iid];
524
$this->api->output->set_env('iid', $iid);
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.");");
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']));
538
$this->api->output->set_env('predefined_rules', $predefined);
541
list($form_start, $form_end) = get_form_tags($attrib, 'plugin.sieverules.save');
545
$hidden_iid = new html_hiddenfield(array('name' => '_iid', 'value' => $iid));
546
$out .= $hidden_iid->show();
549
if (sizeof($cur_script['tests']) == 1 && $cur_script['tests'][0]['type'] == 'true' && !$cur_script['tests'][0]['not'])
553
$field_id = 'rcmfd_disable';
554
$input_disable = new html_checkbox(array('name' => '_disable', 'id' => $field_id, 'value' => 1));
556
$out .= html::span('disableLink', html::label($field_id, Q($this->gettext('disablerule')))
557
. " " . $input_disable->show($cur_script['disabled']));
560
$field_id = 'rcmfd_name';
561
$input_name = new html_inputfield(array('name' => '_name', 'id' => $field_id));
563
$out .= html::label($field_id, Q($this->gettext('filtername')));
564
$out .= " " . $input_name->show($cur_script['name']);
566
$out .= "<br /><br />";
568
if (sizeof($cur_script['tests']) == 1 && $cur_script['tests'][0]['type'] == 'true' && !$cur_script['tests'][0]['not'])
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 .= " " . html::label($field_id, Q($this->gettext('filterallof')));
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 .= " " . $input_join->show($cur_script['join'] && !$join_any ? '' : 'anyof');
579
$join_type .= " " . html::label($field_id, Q($this->gettext('filteranyof')));
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 .= " " . $input_join->show($join_any ? 'any' : '');
584
$join_type .= " " . html::label($field_id, Q($this->gettext('filterany')));
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);
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);
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());
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);
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);
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());
623
$src = get_input_value('_src', RCUBE_INPUT_GET);
624
$dst = get_input_value('_dst', RCUBE_INPUT_GET);
626
$result = $this->sieve->script->move_rule($src, $dst);
627
$result = $this->sieve->save();
630
$this->api->output->command('sieverules_update_list', 'move', $src , $dst);
632
$this->api->output->command('display_message', $this->gettext('filtersaveerror'), 'error');
634
$this->api->output->send();
639
$rcmail = rcmail::get_instance();
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);
648
$this->api->output->command('display_message', $this->gettext('filtersaved'), 'confirmation');
649
$this->sieve->get_script();
652
$this->api->output->command('display_message', $this->gettext('filtersaveerror'), 'error');
656
rcmail_overwrite_action('plugin.sieverules.advanced');
657
$this->action = 'plugin.sieverules.advanced';
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));
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'];
703
$script['join'] = ($join == 'allof') ? true : false;
704
$script['name'] = $name;
705
$script['disabled'] = $disabled;
706
$script['tests'] = array();
707
$script['actions'] = array();
711
if ($join == 'any') {
712
$script['tests'][0]['type'] = 'true';
714
else foreach($tests as $idx => $type) {
715
// ignore the first (default) row
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]);
733
$sizeop = $this->_strip_val($sizeops[$idx]);
734
$sizeunit = $this->_strip_val($sizeunits[$idx]);
736
$script['tests'][$i]['type'] = 'size';
737
$script['tests'][$i]['operator'] = $sizeop;
738
$script['tests'][$i]['target'] = $target.$sizeunit;
741
$spamtestop = $this->_strip_val($spamtestops[$idx]);
743
$script['tests'][$i]['type'] = 'spamtest';
744
$script['tests'][$i]['operator'] = $spamtestop;
745
$script['tests'][$i]['target'] = $target;
748
$op = $this->_strip_val($dateops[$idx]);
750
if ($datepart == 'weekday')
753
$script['tests'][$i]['datepart'] = $datepart;
755
$script['tests'][$i]['bodypart'] = $bodypart;
757
if ($bodypart == 'content')
758
$script['tests'][$i]['contentpart'] = $contentpart;
760
$script['tests'][$i]['contentpart'] = '';
765
if (preg_match('/^not/', $op) || preg_match('/^not/', $advop))
766
$script['tests'][$i]['not'] = true;
768
$script['tests'][$i]['not'] = '';
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;
774
if ($op == 'exists') {
775
$script['tests'][$i]['type'] = 'exists';
776
$script['tests'][$i]['operator'] = 'exists';
777
$script['tests'][$i]['header'] = $header;
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;
785
if (substr($advop, 0, 5) == 'count' || substr($advop, 0, 5) == 'value')
786
$script['tests'][$i]['comparator'] = $comparator;
788
$script['tests'][$i]['comparator'] = '';
791
$script['tests'][$i]['type'] = $type;
792
$script['tests'][$i]['operator'] = $op;
793
$script['tests'][$i]['header'] = $header;
794
$script['tests'][$i]['target'] = $target;
803
foreach($actions as $idx => $type) {
804
// ignore the first (default) row
808
$type = $this->_strip_val($type);
810
$script['actions'][$i]['type'] = $type;
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']);
822
if ($folder == '@@newfolder')
823
$script['actions'][$i]['target'] = $this->_strip_val($customfolders[$idx]);
826
case 'redirect_copy':
827
$address = $this->_strip_val($addresses[$idx]);
828
$script['actions'][$i]['target'] = $address;
832
$rejects = $this->_strip_val($rejects[$idx]);
833
$script['actions'][$i]['target'] = $rejects;
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;
855
$flag = $this->_strip_val($flags[$idx]);
856
$script['actions'][$i]['target'] = $flag;
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;
876
if (!isset($this->script[$iid]))
877
$result = $this->sieve->script->add_rule($script);
879
$result = $this->sieve->script->update_rule($iid, $script);
881
if ($result === true)
882
$save = $this->sieve->save();
884
if ($save && $result === true && !$rcmail->config->get('sieverules_multiplerules', false))
885
$save = $this->sieve->set_active($this->current_ruleset);
887
if ($save && $result === true) {
888
$this->api->output->command('display_message', $this->gettext('filtersaved'), 'confirmation');
890
if ($script['disabled'] == 1)
891
$filter_name = $script['name'] . ' (' . $this->gettext('disabled') . ')';
893
$filter_name = $script['name'];
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);
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);
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 ."');");
907
$this->api->output->add_script("parent.". JS_OBJECT_NAME .".sieverules_update_list('update', ". $iid .", '". Q($filter_name) ."');");
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');
915
$this->api->output->command('display_message', $this->gettext('filtersaveerror'), 'error');
919
if ($this->sieve_error)
920
$this->script = array();
922
$this->script = $this->sieve->script->as_array();
925
rcmail_overwrite_action('plugin.sieverules.edit');
926
$this->action = 'plugin.sieverules.edit';
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();
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 .");");
947
elseif ($result == SIEVE_ERROR_NOT_FOUND)
948
$this->api->output->command('display_message', $this->gettext('filtermissingerror'), 'error');
950
$this->api->output->command('display_message', $this->gettext('filterdeleteerror'), 'error');
953
if ($this->sieve_error)
954
$this->script = array();
956
$this->script = $this->sieve->script->as_array();
958
if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
959
$this->api->output->add_script("parent.". JS_OBJECT_NAME .".show_contentframe(false);");
962
// go to sieverules page
963
rcmail_overwrite_action('plugin.sieverules.edit');
964
$this->action = 'plugin.sieverules.edit';
969
function import($type = null, $ruleset = null, $redirect = true)
971
$rcmail = rcmail::get_instance();
974
if (!$type && !$ruleset) {
975
$type = get_input_value('_type', RCUBE_INPUT_GET);
976
$ruleset = get_input_value('_import', RCUBE_INPUT_GET);
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();
984
if ($save && !$rcmail->config->get('sieverules_multiplerules', false))
985
$save = $this->sieve->set_active($this->current_ruleset);
988
$this->api->output->command('display_message', $this->gettext('filterimported'), 'confirmation');
990
$this->api->output->command('display_message', $this->gettext('filterimporterror'), 'error');
993
if ($this->sieve_error)
994
$this->script = array();
996
$this->script = $this->sieve->script->as_array();
998
elseif ($rcmail->config->get('sieverules_default_file', false) && !is_readable($rcmail->config->get('sieverules_default_file'))) {
1004
'message' => "SieveRules plugin: Unable to open default rule file"
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));
1016
$pos = substr($pos, 6);
1018
foreach ($eids as $eid) {
1019
$this->sieve->script->add_rule($this->examples[substr($eid, 2)], $pos);
1023
$this->sieve->save();
1024
if (!$rcmail->config->get('sieverules_multiplerules', false)) $this->sieve->set_active($this->current_ruleset);
1027
if ($this->sieve_error)
1028
$this->script = array();
1030
$this->script = $this->sieve->script->as_array();
1033
elseif ($ruleset == '_none_') {
1034
$this->sieve->save();
1035
if (!$rcmail->config->get('sieverules_multiplerules', false)) $this->sieve->set_active($this->current_ruleset);
1037
elseif ($ruleset == '_copy_') {
1038
$this->rename_ruleset(true);
1041
elseif ($type != '' && $ruleset != '') {
1042
$import = $this->sieve->do_import($type, $ruleset);
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');
1051
$this->script = array();
1052
if (!$redirect) $this->sieve->save();
1053
$this->api->output->command('display_message', $this->gettext('filterimporterror'), 'error');
1058
// go to sieverules page
1059
rcmail_overwrite_action('plugin.sieverules');
1060
$this->action = 'plugin.sieverules';
1065
function delete_ruleset()
1068
$this->sieve->del_script($this->current_ruleset);
1070
$this->current_ruleset = get_input_value('_next', RCUBE_INPUT_GET);
1072
rcmail_overwrite_action('plugin.sieverules');
1073
$this->action = 'plugin.sieverules';
1077
function rename_ruleset($makeCopy = false)
1080
$script = $this->sieve->script->as_text();
1081
$active = $this->sieve->get_active() == $this->current_ruleset ? true : false;
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);
1090
$this->sieve->set_active($this->current_ruleset);
1092
$this->sieve->del_script($old_ruleset);
1095
rcmail_overwrite_action('plugin.sieverules');
1096
$this->action = 'plugin.sieverules';
1100
function enable_ruleset()
1103
$activeruleset = get_input_value('_ruleset', RCUBE_INPUT_GET, true);
1104
$this->sieve->set_active($activeruleset);
1106
if (get_input_value('_reload', RCUBE_INPUT_GET, true) == "1") {
1107
rcmail_overwrite_action('plugin.sieverules');
1108
$this->action = 'plugin.sieverules';
1112
$rulesets = array();
1113
foreach ($this->sieve->list as $ruleset)
1114
array_push($rulesets, $ruleset);
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'))));
1122
$this->api->output->command('sieverules_add_ruleset', Q($ruleset), Q($ruleset));
1125
$this->api->output->send();
1129
function copy_filter()
1132
$script = $this->script[get_input_value('_iid', RCUBE_INPUT_GET)];
1133
$this->current_ruleset = get_input_value('_dest', RCUBE_INPUT_GET);
1135
$this->sieve->script->add_rule($script);
1136
$this->sieve->save();
1138
$this->api->output->command('display_message', $this->gettext('filtercopied'), 'confirmation');
1139
$this->api->output->send();
1142
private function _startup()
1144
$rcmail = rcmail::get_instance();
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();
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));
1161
if ($rcmail->config->get('sieverules_debug', false))
1162
$this->sieve->set_debug(true);
1164
$this->sieve_error = $this->sieve->error();
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';
1172
elseif ($rcmail->config->get('sieverules_default_file', false) && !is_readable($rcmail->config->get('sieverules_default_file'))) {
1178
'message' => "SieveRules plugin: Unable to open default rule file"
1182
// that's not exactly an error
1183
$this->sieve_error = false;
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');
1192
$this->api->output->command('display_message', $this->gettext('filterunknownerror'), 'error');
1196
$this->api->output->set_env('sieveruleserror', true);
1199
// finally set script objects
1200
if ($this->sieve_error) {
1201
$this->script = array();
1204
$this->script = $this->sieve->script->as_array();
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')))
1215
'message' => "SieveRules plugin: Unable to open example rule file"
1220
$this->sieve->set_ruleset($this->current_ruleset);
1221
$this->script = $this->sieve->script->as_array();
1225
private function _rule_row($ext, $rules_table, $rule, $predefined_rules, $attrib)
1227
$rcmail = rcmail::get_instance();
1230
if (!isset($rule)) {
1231
$rules_table->set_row_attribs(array('style' => 'display: none;'));
1232
$imgclass = 'nohtc';
1235
if (in_array('regex', $ext) || in_array('relational', $ext) || in_array('subaddress', $ext))
1236
$this->operators['filteradvoptions'] = 'advoptions';
1238
$header_style = 'visibility: hidden;';
1240
$sizeop_style = 'display: none;';
1241
$dateop_style = 'display: none;';
1242
$spamtestop_style = 'display: none;';
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 = '';
1254
$selheader = 'Subject';
1255
$header = 'Subject';
1263
$advcontentpart = '';
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']) {
1276
if ($predefined > -1) {
1277
$op_style = 'display: none;';
1278
$target_style = 'display: none;';
1279
$selheader = $rule['type'] . '::predefined_' . $predefined;
1280
$test = $rule['type'];
1282
if ($rule['type'] == '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];
1290
elseif ($rule['type'] == 'spamtest') {
1291
$header = 'spamtest';
1292
$spamtestop = $rule['operator'];
1293
$target = $rule['target'];
1295
elseif ($rule['type'] == 'exists') {
1296
$selheader = $predefined_rules[$predefined]['type'] . '::predefined_' . $predefined;
1297
$header = $rule['header'];
1298
$op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1301
$header = $rule['header'];
1302
$op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1303
$target = htmlspecialchars($rule['target']);
1306
elseif ((isset($rule['type']) && $rule['type'] != 'exists') && in_array($rule['type'] . '::' . $rule['header'], $this->headers)) {
1307
$target_style = $rule['operator'] == 'exists' ? 'display: none;' : '';
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']);
1315
elseif ((isset($rule['type']) && $rule['type'] == 'exists') && $this->_in_headerarray($rule['header'], $this->headers) != false) {
1316
$target_style = $rule['operator'] == 'exists' ? 'display: none;' : '';
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'];
1323
elseif (isset($rule['type']) && $rule['type'] == 'size') {
1324
$op_style = 'display: none;';
1328
$selheader = 'size::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];
1337
elseif (isset($rule['type']) && $rule['type'] == 'body') {
1338
$bodypart_style = '';
1339
$header_style = 'display: none;';
1341
$selheader = 'body::body';
1344
$bodypart = $rule['bodypart'];
1345
$op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1346
$target = htmlspecialchars($rule['target']);
1348
if ($rule['contentpart'] != '') {
1349
$advcontentpart = $rule['contentpart'];
1350
$advcontentpart_style = '';
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 = '';
1359
$test = $rule['type'];
1360
$selheader = 'spamtest::spamtest';
1361
$header = 'spamtest';
1362
$spamtestop = $rule['operator'];
1363
$target = $rule['target'];
1364
$spam_probability = $rule['target'];
1366
elseif (isset($rule['type']) && $rule['type'] == 'date') {
1367
$op_style = 'display: none;';
1369
$header_style = 'display: none;';
1370
$datepart_style = '';
1372
if ($rule['datepart'] == 'weekday') {
1373
$target_style = 'display: none;';
1374
$advtarget_style = 'display: none;';
1375
$weekdays_style = '';
1376
$advweekdays_style = '';
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'];
1386
elseif (isset($rule['type']) && $rule['type'] != 'true') {
1388
$target_style = $rule['operator'] == 'exists' ? 'display: none;' : '';
1390
$selheader = 'header::other';
1392
$header = is_array($rule['header']) ? join(', ', $rule['header']) : $rule['header'];
1393
$op = ($rule['not'] ? 'not' : '') . $rule['operator'];
1394
$target = htmlspecialchars($rule['target']);
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;';
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));
1410
if (in_array('body', $ext))
1411
$select_header->add(Q($this->gettext('body')), Q('body::body'));
1413
if (in_array('spamtest', $ext))
1414
$select_header->add(Q($this->gettext('spamtest')), Q('spamtest::spamtest'));
1416
foreach($predefined_rules as $idx => $data)
1417
$select_header->add(Q($data['name']), Q($data['type'] . '::predefined_' . $idx));
1419
if (in_array('date', $ext))
1420
$select_header->add(Q($this->gettext('arrival')), Q('date::currentdate'));
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());
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);
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));
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);
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');
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');
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"');
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');
1465
$rules_table->add('op', $select_op->show('advoptions') . $select_size_op->show($sizeop) . $select_date_op->show($dateop) . $select_spamtest_op->show($spamtestop));
1467
$rules_table->add('op', $select_op->show($op) . $select_size_op->show($sizeop) . $select_date_op->show($dateop) . $select_spamtest_op->show($spamtestop));
1469
$input_target = new html_inputfield(array('name' => '_target[]', 'style' => $target_style, 'class' => $target_size));
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');
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');
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');
1498
$rules_table->add('target', $select_weekdays->show($target) . $select_spam_probability->show($spam_probability) . $input_target->show($target) . " " . $select_units->show($units));
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);
1505
$rowid = $rules_table->size();
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();
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) . " " . html::label($xheader . '_' . $rowid, Q($xheader));
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 />";
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);
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();
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();
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);
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);
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();
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)'));
1564
if (in_array('regex', $ext)) {
1565
$select_advop->add(Q($this->gettext('filterregex')), 'regex');
1566
$select_advop->add(Q($this->gettext('filternotregex')), 'notregex');
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"');
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');
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));
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[]"));
1600
$select_comparator = new html_select(array('id' => $field_id, 'name' => "_comparator[]", 'disabled' => 'disabled'));
1602
$select_comparator->add(Q($this->gettext('i;ascii-casemap')), '');
1603
$select_comparator->add(Q($this->gettext('i;octet')), 'i;octet');
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));
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']));
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');
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));
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();
1632
return $rules_table;
1635
private function _action_row($ext, $actions_table, $rowid, $action, $attrib, $example)
1637
$rcmail = rcmail::get_instance();
1638
static $a_mailboxes;
1641
if (!isset($action)) {
1642
$actions_table->set_row_attribs(array('style' => 'display: none;'));
1643
$imgclass = 'nohtc';
1646
$help_icon = html::img(array('src' => $attrib['helpicon'], 'alt' => $this->gettext('messagehelp'), 'border' => 0));
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;';
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');
1689
// set the default action
1690
reset($allowed_actions);
1691
$method = key($allowed_actions);
1696
$identity = $rcmail->user->get_identity();
1697
if ($this->show_vacfrom)
1698
$vacfrom = (in_array('variables', $ext)) ? 'auto' : $identity['email'];
1709
$charset = RCMAIL_CHARSET;
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'];
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);
1724
elseif ($action['type'] == 'reject' || $action['type'] == 'ereject') {
1725
$method = $action['type'];
1726
$reject = htmlspecialchars($action['target']);
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'];
1740
$this->force_vacto = false;
1742
// check advanced enabled
1743
if ((!empty($vacfrom) && $vacfrom != $vacfrom_default) || !empty($vacto) || !empty($handle) || $charset != RCMAIL_CHARSET || $this->force_vacto) {
1745
$vacadvstyle_from = ($this->show_vacfrom) ? '' : 'display: none;';
1746
$vacadvstyle_handle = ($this->show_vachandle) ? '' : 'display: none;';
1750
elseif ($action['type'] == 'redirect' || $action['type'] == 'redirect_copy') {
1751
$method = $action['type'];
1752
$address = $action['target'];
1754
elseif ($action['type'] == 'imapflags' || $action['type'] == 'imap4flags') {
1755
$method = $action['type'];
1756
$flags = $action['target'];
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'];
1766
// check advanced enabled
1767
if (!empty($nfrom) || !empty($nimpt)) {
1772
elseif ($action['type'] == 'discard' || $action['type'] == 'keep' || $action['type'] == 'stop') {
1773
$method = $action['type'];
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);
1780
$actions_table->add('action', $select_action->show($method));
1782
$vacs_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 3, 'style' => ($method == 'vacation') ? '' : 'display: none;'));
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[]"));
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')), "");
1796
foreach ($user_identities as $sql_arr) {
1797
$select_id->add($sql_arr['email'], $sql_arr['email']);
1799
$ffield_id = 'rcmfd_vac_' . $rowid . '_' . $sql_arr['identity_id'];
1801
if ($this->force_vacto) {
1802
$curaddress = $sql_arr['email'];
1803
$vacto .= (!empty($vacto) ? ',' : '') . $sql_arr['email'];
1806
$curaddress = in_array($sql_arr['email'], $vacto_arr) ? $sql_arr['email'] : "";
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) . " " . html::label($ffield_id, Q($sql_arr['email'])) . "<br />";
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();
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);
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();
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();
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));
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();
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);
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();
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);
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();
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();
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, ' ');
1887
$vacs_table->add(array('colspan' => 2), $input_origsubject->show($origsubject) . " " . html::label($field_id, Q($this->gettext('sieveorigsubj'))) . $input_vacosubj->show());
1888
$vacs_table->add_row();
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();
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();
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));
1906
$notify_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 3, 'style' => ($method == 'notify' || $method == 'enotify') ? '' : 'display: none;'));
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')), "");
1914
foreach ($user_identities as $sql_arr)
1915
$select_id->add($sql_arr['email'], $sql_arr['email']);
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();
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();
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();
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();
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) . " " . 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 .= ' ' . $input_importance->show($nimpt) . " " . 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 .= ' ' . $input_importance->show($nimpt) . " " . 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 .= ' ' . $input_importance->show($nimpt) . " " . html::label($field_id . '_3', Q($this->gettext('importance3')));
1948
$input_importance = new html_hiddenfield(array('id' => 'rcmfd_sievenimpt_'. $rowid, 'name' => '_nimpt[]'));
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();
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();
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));
1967
$mbox_name = $rcmail->imap->get_mailbox_name();
1969
// build the folders tree
1970
if (empty($a_mailboxes)) {
1972
if ($rcmail->config->get('sieverules_fileinto_options', 0) > 0)
1973
$a_folders = $rcmail->imap->list_unsubscribed();
1975
$a_folders = $rcmail->imap->list_mailboxes();
1977
$delimiter = $rcmail->imap->get_hierarchy_delimiter();
1978
$a_mailboxes = array();
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'));
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'));
1987
rcmail_build_folder_tree($a_mailboxes, $ifolder, $delimiter);
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()));
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);
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 = '';
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));
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));
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));
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' => ' '));
2018
if ($rcmail->config->get('sieverules_multiple_actions'))
2019
$actions_table->add('control', $delete_button . $add_button);
2021
$actions_table->add('control', " ");
2023
return $actions_table;
2026
private function _in_headerarray($needle, $haystack)
2028
foreach ($haystack as $data) {
2029
$args = explode("::", $data);
2030
if ($args[1] == $needle)
2037
// coppied from rcube_template.php
2038
private function _charset_selector($attrib, $charset)
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)',
2059
$select = new html_select($attrib);
2060
$select->add(array_values($charsets), array_keys($charsets));
2062
return $select->show($charset);
2065
private function _strip_val($str)
2067
return trim(htmlspecialchars_decode($str));
2070
private function _mbox_encode($text, $encoding)
2072
return rcube_charset_convert($text, 'UTF7-IMAP', $encoding);
b'\\ No newline at end of file'