|
|
@ -148,7 +148,7 @@ class rcube_sieve_forward extends rcube_sieve_engine
|
|
|
|
$action = 'copy';
|
|
|
|
$action = 'copy';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($act['type'] == 'stop') {
|
|
|
|
else if ($act['type'] == 'stop') {
|
|
|
|
// we might loose information if there rules after the stop
|
|
|
|
// we might loose information if there are rules after the stop
|
|
|
|
$stop_found = true;
|
|
|
|
$stop_found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($act['type'] == 'discard') {
|
|
|
|
else if ($act['type'] == 'discard') {
|
|
|
@ -207,10 +207,8 @@ class rcube_sieve_forward extends rcube_sieve_engine
|
|
|
|
$date_extension = in_array('date', $this->exts);
|
|
|
|
$date_extension = in_array('date', $this->exts);
|
|
|
|
$forward_tests = (array) $this->forward['tests'];
|
|
|
|
$forward_tests = (array) $this->forward['tests'];
|
|
|
|
|
|
|
|
|
|
|
|
if ($action == 'redirect' || $action == 'copy') {
|
|
|
|
if (empty($target) || !rcube_utils::check_email($target)) {
|
|
|
|
if (empty($target) || !rcube_utils::check_email($target)) {
|
|
|
|
$error = 'noemailwarning';
|
|
|
|
$error = 'noemailwarning';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($forward_tests)) {
|
|
|
|
if (empty($forward_tests)) {
|
|
|
@ -224,18 +222,13 @@ class rcube_sieve_forward extends rcube_sieve_engine
|
|
|
|
$rule['disabled'] = $status == 'off';
|
|
|
|
$rule['disabled'] = $status == 'off';
|
|
|
|
$rule['tests'] = $forward_tests;
|
|
|
|
$rule['tests'] = $forward_tests;
|
|
|
|
$rule['join'] = $date_extension ? count($forward_tests) > 1 : false;
|
|
|
|
$rule['join'] = $date_extension ? count($forward_tests) > 1 : false;
|
|
|
|
$rule['actions'] = array();
|
|
|
|
$rule['actions'] = array(array(
|
|
|
|
$rule['after'] = $after;
|
|
|
|
'type' => 'redirect',
|
|
|
|
|
|
|
|
|
|
|
|
if ($action && $action != 'keep') {
|
|
|
|
|
|
|
|
$rule['actions'][] = array(
|
|
|
|
|
|
|
|
'type' => $action == 'discard' ? 'discard' : 'redirect',
|
|
|
|
|
|
|
|
'copy' => $action == 'copy',
|
|
|
|
'copy' => $action == 'copy',
|
|
|
|
'target' => $action != 'discard' ? $target : '',
|
|
|
|
'target' => $target,
|
|
|
|
);
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->save_forward_script($rule)) {
|
|
|
|
if ($this->merge_rule($rule, $this->forward, $this->script_name)) {
|
|
|
|
$this->rc->output->show_message('managesieve.forwardsaved', 'confirmation');
|
|
|
|
$this->rc->output->show_message('managesieve.forwardsaved', 'confirmation');
|
|
|
|
$this->rc->output->send();
|
|
|
|
$this->rc->output->send();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -320,99 +313,6 @@ class rcube_sieve_forward extends rcube_sieve_engine
|
|
|
|
return $out;
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Saves forward script (adding some variables)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function save_forward_script($rule)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// if script does not exist create a new one
|
|
|
|
|
|
|
|
if ($this->script_name === null || $this->script_name === false) {
|
|
|
|
|
|
|
|
$this->script_name = $this->rc->config->get('managesieve_script_name');
|
|
|
|
|
|
|
|
if (empty($this->script_name)) {
|
|
|
|
|
|
|
|
$this->script_name = 'roundcube';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// use default script contents
|
|
|
|
|
|
|
|
if (!$this->rc->config->get('managesieve_kolab_master')) {
|
|
|
|
|
|
|
|
$script_file = $this->rc->config->get('managesieve_default');
|
|
|
|
|
|
|
|
if ($script_file && is_readable($script_file)) {
|
|
|
|
|
|
|
|
$content = file_get_contents($script_file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create and load script
|
|
|
|
|
|
|
|
if ($this->sieve->save_script($this->script_name, $content)) {
|
|
|
|
|
|
|
|
$this->sieve->load($this->script_name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$script_active = in_array($this->script_name, $this->active);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// re-order rules if needed
|
|
|
|
|
|
|
|
if (isset($rule['after']) && $rule['after'] !== '') {
|
|
|
|
|
|
|
|
// reset original forward rule
|
|
|
|
|
|
|
|
if (isset($this->forward['idx'])) {
|
|
|
|
|
|
|
|
$this->script[$this->forward['idx']] = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add at target position
|
|
|
|
|
|
|
|
if ($rule['after'] >= count($this->script) - 1) {
|
|
|
|
|
|
|
|
$this->script[] = $rule;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
$script = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->script as $idx => $r) {
|
|
|
|
|
|
|
|
if ($r) {
|
|
|
|
|
|
|
|
$script[] = $r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($idx == $rule['after']) {
|
|
|
|
|
|
|
|
$script[] = $rule;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->script = $script;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->script = array_values(array_filter($this->script));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// update original forward rule if it exists
|
|
|
|
|
|
|
|
else if (isset($this->forward['idx'])) {
|
|
|
|
|
|
|
|
$this->script[$this->forward['idx']] = $rule;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise put forward rule on top
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
array_unshift($this->script, $rule);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if the script was not active, we need to de-activate
|
|
|
|
|
|
|
|
// all rules except the forward rule, but only if it is not disabled
|
|
|
|
|
|
|
|
if (!$script_active && !$rule['disabled']) {
|
|
|
|
|
|
|
|
foreach ($this->script as $idx => $r) {
|
|
|
|
|
|
|
|
if (empty($r['actions']) || $r['actions'][0]['type'] != 'forward') {
|
|
|
|
|
|
|
|
$this->script[$idx]['disabled'] = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$this->sieve->script) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->sieve->script->content = $this->script;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// save the script
|
|
|
|
|
|
|
|
$saved = $this->save_script($this->script_name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// activate the script
|
|
|
|
|
|
|
|
if ($saved && !$script_active && !$rule['disabled']) {
|
|
|
|
|
|
|
|
$this->activate_script($this->script_name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* API: get forward rule
|
|
|
|
* API: get forward rule
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -472,17 +372,13 @@ class rcube_sieve_forward extends rcube_sieve_engine
|
|
|
|
$rule['disabled'] = isset($data['enabled']) && !$data['enabled'];
|
|
|
|
$rule['disabled'] = isset($data['enabled']) && !$data['enabled'];
|
|
|
|
$rule['tests'] = $forward_tests;
|
|
|
|
$rule['tests'] = $forward_tests;
|
|
|
|
$rule['join'] = $date_extension ? count($forward_tests) > 1 : false;
|
|
|
|
$rule['join'] = $date_extension ? count($forward_tests) > 1 : false;
|
|
|
|
$rule['actions'] = array();
|
|
|
|
$rule['actions'] = array(array(
|
|
|
|
|
|
|
|
'type' => 'redirect',
|
|
|
|
if ($data['action'] && $data['action'] != 'keep') {
|
|
|
|
|
|
|
|
$rule['actions'][] = array(
|
|
|
|
|
|
|
|
'type' => $data['action'] == 'discard' ? 'discard' : 'redirect',
|
|
|
|
|
|
|
|
'copy' => $data['action'] == 'copy',
|
|
|
|
'copy' => $data['action'] == 'copy',
|
|
|
|
'target' => $data['action'] != 'discard' ? $data['target'] : '',
|
|
|
|
'target' => $data['target'],
|
|
|
|
);
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->save_forward_script($rule);
|
|
|
|
return $this->merge_rule($rule, $this->forward, $this->script_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|