| | |
| | | "x-beenthere", |
| | | ); |
| | | |
| | | const VERSION = '7.0'; |
| | | const VERSION = '7.2'; |
| | | const PROGNAME = 'Roundcube (Managesieve)'; |
| | | const PORT = 4190; |
| | | |
| | |
| | | // Get list of scripts |
| | | $list = $this->list_scripts(); |
| | | |
| | | // reset current script when entering filters UI (#1489412) |
| | | if ($this->rc->action == 'plugin.managesieve') { |
| | | $this->rc->session->remove('managesieve_current'); |
| | | } |
| | | |
| | | if (!empty($_GET['_set']) || !empty($_POST['_set'])) { |
| | | $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true); |
| | | } |
| | |
| | | case SIEVE_ERROR_CONNECTION: |
| | | case SIEVE_ERROR_LOGIN: |
| | | $this->rc->output->show_message('managesieve.filterconnerror', 'error'); |
| | | rcube::raise_error(array('code' => 403, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Unable to connect to managesieve on $host:$port"), true, false); |
| | | break; |
| | | |
| | | default: |
| | | $this->rc->output->show_message('managesieve.filterunknownerror', 'error'); |
| | | break; |
| | | } |
| | | |
| | | rcube::raise_error(array('code' => 403, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Unable to connect to managesieve on $host:$port"), true, false); |
| | | // reload interface in case of possible error when specified script wasn't found (#1489412) |
| | | if ($script_name !== null && !empty($list) && !in_array($script_name, $list)) { |
| | | $this->rc->output->command('reload', 500); |
| | | } |
| | | |
| | | // to disable 'Add filter' button set env variable |
| | | $this->rc->output->set_env('filterconnerror', true); |
| | |
| | | } |
| | | else { |
| | | $this->exts = $this->sieve->get_extensions(); |
| | | $this->script = $this->sieve->script->as_array(); |
| | | $this->init_script(); |
| | | $this->rc->output->set_env('currentset', $this->sieve->current); |
| | | $_SESSION['managesieve_current'] = $this->sieve->current; |
| | | } |
| | |
| | | $act_types = rcube_utils::get_input_value('_action_type', rcube_utils::INPUT_POST, true); |
| | | $mailboxes = rcube_utils::get_input_value('_action_mailbox', rcube_utils::INPUT_POST, true); |
| | | $act_targets = rcube_utils::get_input_value('_action_target', rcube_utils::INPUT_POST, true); |
| | | $domain_targets = rcube_utils::get_input_value('_action_target_domain', rcube_utils::INPUT_POST); |
| | | $area_targets = rcube_utils::get_input_value('_action_target_area', rcube_utils::INPUT_POST, true); |
| | | $reasons = rcube_utils::get_input_value('_action_reason', rcube_utils::INPUT_POST, true); |
| | | $addresses = rcube_utils::get_input_value('_action_addresses', rcube_utils::INPUT_POST, true); |
| | |
| | | if (!count($target)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); |
| | | } |
| | | else if ($type != 'regex' && $type != 'matches') { |
| | | else if (strpos($type, 'count-') === 0) { |
| | | foreach ($target as $arg) { |
| | | if (preg_match('/[^0-9]/', $arg)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); |
| | | } |
| | | } |
| | | } |
| | | else if (strpos($type, 'value-') === 0) { |
| | | // Some date/time formats do not support i;ascii-numeric comparator |
| | | if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) { |
| | | $comparator = ''; |
| | | } |
| | | } |
| | | |
| | | if (!preg_match('/^(regex|matches|count-)/', $type) && count($target)) { |
| | | foreach ($target as $arg) { |
| | | if (!$this->validate_date_part($datepart, $arg)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat'); |
| | |
| | | if (!count($target)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); |
| | | } |
| | | else if ($type != 'regex' && $type != 'matches') { |
| | | else if (strpos($type, 'count-') === 0) { |
| | | foreach ($target as $arg) { |
| | | if (preg_match('/[^0-9]/', $arg)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); |
| | | } |
| | | } |
| | | } |
| | | else if (strpos($type, 'value-') === 0) { |
| | | // Some date/time formats do not support i;ascii-numeric comparator |
| | | if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) { |
| | | $comparator = ''; |
| | | } |
| | | } |
| | | |
| | | if (count($target) && !preg_match('/^(regex|matches|count-)/', $type)) { |
| | | foreach ($target as $arg) { |
| | | if (!$this->validate_date_part($datepart, $arg)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat'); |
| | |
| | | } |
| | | else if (preg_match('/^(value|count)-/', $type)) { |
| | | foreach ($target as $target_value) { |
| | | if (!preg_match('/[0-9]+/', $target_value)) { |
| | | if (preg_match('/[^0-9]/', $target_value)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); |
| | | } |
| | | } |
| | |
| | | $cust_header = (is_array($headers) && count($headers) == 1) ? $headers[0] : $headers; |
| | | } |
| | | |
| | | $header = $header == '...' ? $cust_header : $header; |
| | | |
| | | if (is_array($header)) { |
| | | foreach ($header as $h_index => $val) { |
| | | if (isset($this->headers[$val])) { |
| | | $header[$h_index] = $this->headers[$val]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if ($type == 'exists') { |
| | | $this->form['tests'][$i]['test'] = 'exists'; |
| | | $this->form['tests'][$i]['arg'] = $header == '...' ? $cust_header : $header; |
| | | $this->form['tests'][$i]['arg'] = $header; |
| | | } |
| | | else { |
| | | $test = 'header'; |
| | | $header = $header == '...' ? $cust_header : $header; |
| | | $test = 'header'; |
| | | |
| | | if ($mod == 'address' || $mod == 'envelope') { |
| | | $found = false; |
| | |
| | | } |
| | | else if (preg_match('/^(value|count)-/', $type)) { |
| | | foreach ($target as $target_value) { |
| | | if (!preg_match('/[0-9]+/', $target_value)) { |
| | | if (preg_match('/[^0-9]/', $target_value)) { |
| | | $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | if ($header != 'size' && $comparator) { |
| | | if (preg_match('/^(value|count)/', $this->form['tests'][$i]['type'])) |
| | | $comparator = 'i;ascii-numeric'; |
| | | |
| | | $this->form['tests'][$i]['comparator'] = $comparator; |
| | | } |
| | | |
| | |
| | | |
| | | $i = 0; |
| | | // actions |
| | | foreach($act_types as $idx => $type) { |
| | | $type = $this->strip_value($type); |
| | | $target = $this->strip_value($act_targets[$idx]); |
| | | foreach ($act_types as $idx => $type) { |
| | | $type = $this->strip_value($type); |
| | | |
| | | switch ($type) { |
| | | |
| | | case 'fileinto': |
| | | case 'fileinto_copy': |
| | | $mailbox = $this->strip_value($mailboxes[$idx], false, false); |
| | | $this->form['actions'][$i]['target'] = $this->mod_mailbox($mailbox, 'in'); |
| | | |
| | | if ($type == 'fileinto_copy') { |
| | | $type = 'fileinto'; |
| | | $this->form['actions'][$i]['copy'] = true; |
| | |
| | | |
| | | case 'redirect': |
| | | case 'redirect_copy': |
| | | $target = $this->strip_value($act_targets[$idx]); |
| | | $domain = $this->strip_value($domain_targets[$idx]); |
| | | |
| | | // force one of the configured domains |
| | | $domains = (array) $this->rc->config->get('managesieve_domains'); |
| | | if (!empty($domains) && !empty($target)) { |
| | | if (!$domain || !in_array($domain, $domains)) { |
| | | $domain = $domains[0]; |
| | | } |
| | | |
| | | $target .= '@' . $domain; |
| | | } |
| | | |
| | | $this->form['actions'][$i]['target'] = $target; |
| | | |
| | | if ($this->form['actions'][$i]['target'] == '') |
| | | if ($target == '') |
| | | $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); |
| | | else if (!rcube_utils::check_email($this->form['actions'][$i]['target'])) |
| | | $this->errors['actions'][$i]['target'] = $this->plugin->gettext('noemailwarning'); |
| | | else if (!rcube_utils::check_email($target)) |
| | | $this->errors['actions'][$i]['target'] = $this->plugin->gettext(!empty($domains) ? 'forbiddenchars' : 'noemailwarning'); |
| | | |
| | | if ($type == 'redirect_copy') { |
| | | $type = 'redirect'; |
| | | $this->form['actions'][$i]['copy'] = true; |
| | | } |
| | | |
| | | break; |
| | | |
| | | case 'addflag': |
| | |
| | | case 'vacation': |
| | | $reason = $this->strip_value($reasons[$idx]); |
| | | $interval_type = $interval_types[$idx] == 'seconds' ? 'seconds' : 'days'; |
| | | |
| | | $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); |
| | | $this->form['actions'][$i]['subject'] = $subject[$idx]; |
| | | $this->form['actions'][$i]['addresses'] = array_shift($addresses); |
| | |
| | | // @TODO: vacation :mime, :from, :handle |
| | | |
| | | foreach ((array)$this->form['actions'][$i]['addresses'] as $aidx => $address) { |
| | | if (!rcube_utils::check_email($address)) { |
| | | $this->form['actions'][$i]['addresses'][$aidx] = $address = trim($address); |
| | | |
| | | if (empty($address)) { |
| | | unset($this->form['actions'][$i]['addresses'][$aidx]); |
| | | } |
| | | else if (!rcube_utils::check_email($address)) { |
| | | $this->errors['actions'][$i]['addresses'] = $this->plugin->gettext('noemailwarning'); |
| | | break; |
| | | } |
| | |
| | | $select_header = new html_select(array('name' => "_header[]", 'id' => 'header'.$id, |
| | | 'onchange' => 'rule_header_select(' .$id .')')); |
| | | |
| | | foreach ($this->headers as $name => $val) |
| | | $select_header->add(rcube::Q($this->plugin->gettext($name)), Q($val)); |
| | | $select_header->add(rcube::Q($this->plugin->gettext('...')), '...'); |
| | | foreach ($this->headers as $index => $header) { |
| | | $header = $this->rc->text_exists($index) ? $this->plugin->gettext($index) : $header; |
| | | $select_header->add($header, $index); |
| | | } |
| | | $select_header->add($this->plugin->gettext('...'), '...'); |
| | | if (in_array('body', $this->exts)) |
| | | $select_header->add(rcube::Q($this->plugin->gettext('body')), 'body'); |
| | | $select_header->add(rcube::Q($this->plugin->gettext('size')), 'size'); |
| | | $select_header->add($this->plugin->gettext('body'), 'body'); |
| | | $select_header->add($this->plugin->gettext('size'), 'size'); |
| | | if (in_array('date', $this->exts)) { |
| | | $select_header->add(rcube::Q($this->plugin->gettext('datetest')), 'date'); |
| | | $select_header->add(rcube::Q($this->plugin->gettext('currdate')), 'currentdate'); |
| | | $select_header->add($this->plugin->gettext('datetest'), 'date'); |
| | | $select_header->add($this->plugin->gettext('currdate'), 'currentdate'); |
| | | } |
| | | |
| | | if (isset($rule['test'])) { |
| | | if (in_array($rule['test'], array('header', 'address', 'envelope')) |
| | | && !is_array($rule['arg1']) && in_array($rule['arg1'], $this->headers) |
| | | && !is_array($rule['arg1']) |
| | | && ($header = strtolower($rule['arg1'])) |
| | | && isset($this->headers[$header]) |
| | | ) { |
| | | $test = $rule['arg1']; |
| | | $test = $header; |
| | | } |
| | | else if ($rule['test'] == 'exists' |
| | | && !is_array($rule['arg']) && in_array($rule['arg'], $this->headers) |
| | | && !is_array($rule['arg']) |
| | | && ($header = strtolower($rule['arg'])) |
| | | && isset($this->headers[$header]) |
| | | ) { |
| | | $test = $rule['arg']; |
| | | $test = $header; |
| | | } |
| | | else if (in_array($rule['test'], array('size', 'body', 'date', 'currentdate'))) { |
| | | $test = $rule['test']; |
| | |
| | | $select_op->add(rcube::Q($this->plugin->gettext('valuenotequals')), 'value-ne'); |
| | | } |
| | | |
| | | // (current)date part select |
| | | if (in_array('date', $this->exts) || in_array('currentdate', $this->exts)) { |
| | | $date_parts = array('date', 'iso8601', 'std11', 'julian', 'time', |
| | | 'year', 'month', 'day', 'hour', 'minute', 'second', 'weekday', 'zone'); |
| | | $select_dp = new html_select(array('name' => "_rule_date_part[]", 'id' => 'rule_date_part'.$id, |
| | | 'style' => $rule['test'] == 'currentdate' || $rule['test'] == 'date' ? '' : 'display:none', |
| | | 'class' => 'datepart_selector', |
| | | )); |
| | | |
| | | foreach ($date_parts as $part) { |
| | | $select_dp->add(rcube::Q($this->plugin->gettext($part)), $part); |
| | | } |
| | | |
| | | $tout .= $select_dp->show($rule['test'] == 'currentdate' || $rule['test'] == 'date' ? $rule['part'] : ''); |
| | | } |
| | | |
| | | // target(s) input |
| | | if (in_array($rule['test'], array('header', 'address', 'envelope'))) { |
| | | $test = ($rule['not'] ? 'not' : '').($rule['type'] ? $rule['type'] : 'is'); |
| | |
| | | else { |
| | | $test = ($rule['not'] ? 'not' : '').$rule['test']; |
| | | $target = ''; |
| | | } |
| | | |
| | | // (current)date part select |
| | | if (in_array('date', $this->exts) || in_array('currentdate', $this->exts)) { |
| | | $date_parts = array('date', 'iso8601', 'std11', 'julian', 'time', |
| | | 'year', 'month', 'day', 'hour', 'minute', 'second', 'weekday', 'zone'); |
| | | $select_dp = new html_select(array('name' => "_rule_date_part[]", 'id' => 'rule_date_part'.$id, |
| | | 'style' => in_array($rule['test'], array('currentdate', 'date')) && !preg_match('/^(notcount|count)-/', $test) ? '' : 'display:none', |
| | | 'class' => 'datepart_selector', |
| | | )); |
| | | |
| | | foreach ($date_parts as $part) { |
| | | $select_dp->add(rcube::Q($this->plugin->gettext($part)), $part); |
| | | } |
| | | |
| | | $tout .= $select_dp->show($rule['test'] == 'currentdate' || $rule['test'] == 'date' ? $rule['part'] : ''); |
| | | } |
| | | |
| | | $tout .= $select_op->show($test); |
| | |
| | | $select_type->add(rcube::Q($this->plugin->gettext('detail')), 'detail'); |
| | | } |
| | | |
| | | $need_mod = $rule['test'] != 'size' && $rule['test'] != 'body'; |
| | | $need_mod = !in_array($rule['test'], array('size', 'body', 'date', 'currentdate')); |
| | | $mout = '<div id="rule_mod' .$id. '" class="adv"' . (!$need_mod ? ' style="display:none"' : '') . '>'; |
| | | $mout .= ' <span class="label">' . rcube::Q($this->plugin->gettext('modifier')) . ' </span>'; |
| | | $mout .= $select_mod->show($rule['test']); |
| | |
| | | |
| | | // actions target inputs |
| | | $out .= '<td class="rowtargets">'; |
| | | // shared targets |
| | | $out .= '<input type="text" name="_action_target['.$id.']" id="action_target' .$id. '" ' |
| | | .'value="' .($action['type']=='redirect' ? rcube::Q($action['target'], 'strict', false) : ''). '" size="35" ' |
| | | .'style="display:' .($action['type']=='redirect' ? 'inline' : 'none') .'" ' |
| | | . $this->error_class($id, 'action', 'target', 'action_target') .' />'; |
| | | |
| | | // force domain selection in redirect email input |
| | | $domains = (array) $this->rc->config->get('managesieve_domains'); |
| | | if (!empty($domains)) { |
| | | sort($domains); |
| | | |
| | | $domain_select = new html_select(array('name' => "_action_target_domain[$id]", 'id' => 'action_target_domain'.$id)); |
| | | $domain_select->add(array_combine($domains, $domains)); |
| | | |
| | | if ($action['type'] == 'redirect') { |
| | | $parts = explode('@', $action['target']); |
| | | if (!empty($parts)) { |
| | | $action['domain'] = array_pop($parts); |
| | | $action['target'] = implode('@', $parts); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // redirect target |
| | | $out .= '<span id="redirect_target' . $id . '" style="white-space:nowrap;' |
| | | . ' display:' . ($action['type'] == 'redirect' ? 'inline' : 'none') . '">' |
| | | . '<input type="text" name="_action_target['.$id.']" id="action_target' .$id. '"' |
| | | . ' value="' .($action['type'] == 'redirect' ? rcube::Q($action['target'], 'strict', false) : '') . '"' |
| | | . (!empty($domains) ? ' size="20"' : ' size="35"') |
| | | . $this->error_class($id, 'action', 'target', 'action_target') .' />' |
| | | . (!empty($domains) ? ' @ ' . $domain_select->show($action['domain']) : '') |
| | | . '</span>'; |
| | | |
| | | // (e)reject target |
| | | $out .= '<textarea name="_action_target_area['.$id.']" id="action_target_area' .$id. '" ' |
| | | .'rows="3" cols="35" '. $this->error_class($id, 'action', 'targetarea', 'action_target_area') |
| | | .'style="display:' .(in_array($action['type'], array('reject', 'ereject')) ? 'inline' : 'none') .'">' |
| | |
| | | 'maxlength' => 100, |
| | | 'id' => 'action_mailbox' . $id, |
| | | 'name' => "_action_mailbox[$id]", |
| | | 'style' => 'display:'.(!isset($action) || $action['type']=='fileinto' ? 'inline' : 'none') |
| | | 'style' => 'display:'.(empty($action['type']) || $action['type'] == 'fileinto' ? 'inline' : 'none') |
| | | )); |
| | | $out .= $select->show($mailbox); |
| | | $out .= '</td>'; |
| | |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | /** |
| | | * Initializes internal script data |
| | | */ |
| | | private function init_script() |
| | | { |
| | | $this->script = $this->sieve->script->as_array(); |
| | | |
| | | if (!$this->script) { |
| | | return; |
| | | } |
| | | |
| | | $headers = array(); |
| | | $exceptions = array('date', 'currentdate', 'size', 'body'); |
| | | |
| | | // find common headers used in script, will be added to the list |
| | | // of available (predefined) headers (#1489271) |
| | | foreach ($this->script as $rule) { |
| | | foreach ((array) $rule['tests'] as $test) { |
| | | if ($test['test'] == 'header') { |
| | | foreach ((array) $test['arg1'] as $header) { |
| | | $lc_header = strtolower($header); |
| | | |
| | | // skip special names to not confuse UI |
| | | if (in_array($lc_header, $exceptions)) { |
| | | continue; |
| | | } |
| | | |
| | | if (!isset($this->headers[$lc_header]) && !isset($headers[$lc_header])) { |
| | | $headers[$lc_header] = $header; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | ksort($headers); |
| | | |
| | | $this->headers += $headers; |
| | | } |
| | | } |