Managesieve: sieve string implement

pull/5248/head
pulcov 9 years ago
parent 5b3a86da57
commit b312dc6c88

@ -595,6 +595,7 @@ class rcube_sieve_engine
// and arrays // and arrays
$headers = rcube_utils::get_input_value('_header', rcube_utils::INPUT_POST); $headers = rcube_utils::get_input_value('_header', rcube_utils::INPUT_POST);
$cust_headers = rcube_utils::get_input_value('_custom_header', rcube_utils::INPUT_POST); $cust_headers = rcube_utils::get_input_value('_custom_header', rcube_utils::INPUT_POST);
$cust_vars = rcube_utils::get_input_value('_custom_var', rcube_utils::INPUT_POST);
$ops = rcube_utils::get_input_value('_rule_op', rcube_utils::INPUT_POST); $ops = rcube_utils::get_input_value('_rule_op', rcube_utils::INPUT_POST);
$sizeops = rcube_utils::get_input_value('_rule_size_op', rcube_utils::INPUT_POST); $sizeops = rcube_utils::get_input_value('_rule_size_op', rcube_utils::INPUT_POST);
$sizeitems = rcube_utils::get_input_value('_rule_size_item', rcube_utils::INPUT_POST); $sizeitems = rcube_utils::get_input_value('_rule_size_item', rcube_utils::INPUT_POST);
@ -854,6 +855,7 @@ class rcube_sieve_engine
} }
else { else {
$cust_header = $headers = $this->strip_value(array_shift($cust_headers)); $cust_header = $headers = $this->strip_value(array_shift($cust_headers));
$cust_var = $headers = $this->strip_value(array_shift($cust_vars));
$mod = $this->strip_value($mods[$idx]); $mod = $this->strip_value($mods[$idx]);
$mod_type = $this->strip_value($mod_types[$idx]); $mod_type = $this->strip_value($mod_types[$idx]);
$index = $this->strip_value($indexes[$idx]); $index = $this->strip_value($indexes[$idx]);
@ -868,10 +870,10 @@ class rcube_sieve_engine
$this->form['tests'][$i]['last'] = !empty($indexlast); $this->form['tests'][$i]['last'] = !empty($indexlast);
} }
if ($header == '...') { if ($header == '...' || $header == 'string') {
if (!count($headers)) if (!count($headers))
$this->errors['tests'][$i]['header'] = $this->plugin->gettext('cannotbeempty'); $this->errors['tests'][$i]['header'] = $this->plugin->gettext('cannotbeempty');
else { else if ($header == '...') {
foreach ($headers as $hr) { foreach ($headers as $hr) {
// RFC2822: printable ASCII except colon // RFC2822: printable ASCII except colon
if (!preg_match('/^[\x21-\x39\x41-\x7E]+$/i', $hr)) { if (!preg_match('/^[\x21-\x39\x41-\x7E]+$/i', $hr)) {
@ -881,9 +883,11 @@ class rcube_sieve_engine
} }
if (empty($this->errors['tests'][$i]['header'])) if (empty($this->errors['tests'][$i]['header']))
$cust_header = (is_array($headers) && count($headers) == 1) ? $headers[0] : $headers; $cust_header = $cust_var = (is_array($headers) && count($headers) == 1) ? $headers[0] : $headers;
} }
$test = $header == 'string' ? 'string' : 'header';
$header = $header == 'string' ? $cust_var : $header;
$header = $header == '...' ? $cust_header : $header; $header = $header == '...' ? $cust_header : $header;
if (is_array($header)) { if (is_array($header)) {
@ -899,8 +903,6 @@ class rcube_sieve_engine
$this->form['tests'][$i]['arg'] = $header; $this->form['tests'][$i]['arg'] = $header;
} }
else { else {
$test = 'header';
if ($mod == 'address' || $mod == 'envelope') { if ($mod == 'address' || $mod == 'envelope') {
$found = false; $found = false;
if (empty($this->errors['tests'][$i]['header'])) { if (empty($this->errors['tests'][$i]['header'])) {
@ -1446,6 +1448,9 @@ class rcube_sieve_engine
if (in_array('body', $this->exts)) { if (in_array('body', $this->exts)) {
$select_header->add($this->plugin->gettext('body'), 'body'); $select_header->add($this->plugin->gettext('body'), 'body');
} }
if (in_array('variables', $this->exts)) {
$select_header->add($this->plugin->gettext('string'), 'string');
}
$select_header->add($this->plugin->gettext('size'), 'size'); $select_header->add($this->plugin->gettext('size'), 'size');
if (in_array('date', $this->exts)) { if (in_array('date', $this->exts)) {
$select_header->add($this->plugin->gettext('datetest'), 'date'); $select_header->add($this->plugin->gettext('datetest'), 'date');
@ -1472,7 +1477,7 @@ class rcube_sieve_engine
$matches = ($header = strtolower($rule['arg'])) && isset($this->headers[$header]); $matches = ($header = strtolower($rule['arg'])) && isset($this->headers[$header]);
$test = $matches ? $header : '...'; $test = $matches ? $header : '...';
} }
else if (in_array($rule['test'], array('size', 'body', 'date', 'currentdate'))) { else if (in_array($rule['test'], array('size', 'body', 'date', 'currentdate', 'string'))) {
$test = $rule['test']; $test = $rule['test'];
} }
else if (in_array($rule['test'], array('duplicate'))) { else if (in_array($rule['test'], array('duplicate'))) {
@ -1492,6 +1497,12 @@ class rcube_sieve_engine
unset($custom); unset($custom);
} }
} }
else if (isset($rule['test']) && $rule['test'] == 'string') {
$customv = (array) $rule['arg1'];
if (count($customv) == 1 && isset($this->headers[strtolower($customv[0])])) {
unset($customv);
}
}
else if (isset($rule['test']) && $rule['test'] == 'exists') { else if (isset($rule['test']) && $rule['test'] == 'exists') {
$custom = (array) $rule['arg']; $custom = (array) $rule['arg'];
if (count($custom) == 1 && isset($this->headers[strtolower($custom[0])])) { if (count($custom) == 1 && isset($this->headers[strtolower($custom[0])])) {
@ -1499,9 +1510,13 @@ class rcube_sieve_engine
} }
} }
// custom variable input
$tout = $this->list_input($id, 'custom_header', $custom, isset($custom), $tout = $this->list_input($id, 'custom_header', $custom, isset($custom),
$this->error_class($id, 'test', 'header', 'custom_header'), 15) . "\n"; $this->error_class($id, 'test', 'header', 'custom_header'), 15) . "\n";
$tout .= $this->list_input($id, 'custom_var', $customv, isset($customv),
$this->error_class($id, 'test', 'header', 'custom_var'), 15) . "\n";
// matching type select (operator) // matching type select (operator)
$select_op = new html_select(array('name' => "_rule_op[]", 'id' => 'rule_op'.$id, $select_op = new html_select(array('name' => "_rule_op[]", 'id' => 'rule_op'.$id,
'style' => 'display:' .(!in_array($rule['test'], array('size', 'duplicate')) ? 'inline' : 'none'), 'style' => 'display:' .(!in_array($rule['test'], array('size', 'duplicate')) ? 'inline' : 'none'),
@ -1538,7 +1553,7 @@ class rcube_sieve_engine
$target = ''; $target = '';
// target(s) input // target(s) input
if (in_array($rule['test'], array('header', 'address', 'envelope'))) { if (in_array($rule['test'], array('header', 'address', 'envelope','string'))) {
$target = $rule['arg2']; $target = $rule['arg2'];
} }
else if (in_array($rule['test'], array('body', 'date', 'currentdate'))) { else if (in_array($rule['test'], array('body', 'date', 'currentdate'))) {
@ -1625,7 +1640,7 @@ class rcube_sieve_engine
$select_type->add(rcube::Q($this->plugin->gettext('detail')), 'detail'); $select_type->add(rcube::Q($this->plugin->gettext('detail')), 'detail');
} }
$need_mod = !in_array($rule['test'], array('size', 'body', 'date', 'currentdate', 'duplicate')); $need_mod = !in_array($rule['test'], array('size', 'body', 'date', 'currentdate', 'duplicate', 'string'));
$mout = '<div id="rule_mod' .$id. '" class="adv"' . (!$need_mod ? ' style="display:none"' : '') . '>'; $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 .= ' <span class="label">' . rcube::Q($this->plugin->gettext('modifier')) . ' </span>';
$mout .= $select_mod->show($rule['test']); $mout .= $select_mod->show($rule['test']);
@ -1765,7 +1780,7 @@ class rcube_sieve_engine
$rule['type'] = $rule['type'] == 'over' ? 'under' : 'over'; $rule['type'] = $rule['type'] == 'over' ? 'under' : 'over';
} }
$set = array('header', 'address', 'envelope', 'body', 'date', 'currentdate'); $set = array('header', 'address', 'envelope', 'body', 'date', 'currentdate', 'string');
// build test string supported by select element // build test string supported by select element
if ($rule['size']) { if ($rule['size']) {

@ -238,8 +238,13 @@ class rcube_sieve_script
break; break;
case 'header': case 'header':
case 'string':
if ($test['test'] == 'string') {
array_push($exts, 'variables');
}
$tests[$i] .= ($test['not'] ? 'not ' : ''); $tests[$i] .= ($test['not'] ? 'not ' : '');
$tests[$i] .= 'header'; $tests[$i] .= $test['test'];
$this->add_index($test, $tests[$i], $exts); $this->add_index($test, $tests[$i], $exts);
$this->add_operator($test, $tests[$i], $exts); $this->add_operator($test, $tests[$i], $exts);
@ -707,6 +712,7 @@ class rcube_sieve_script
break; break;
case 'header': case 'header':
case 'string':
case 'address': case 'address':
case 'envelope': case 'envelope':
$test = array('test' => $token, 'not' => $not); $test = array('test' => $token, 'not' => $not);
@ -716,7 +722,7 @@ class rcube_sieve_script
$test += $this->test_tokens($tokens); $test += $this->test_tokens($tokens);
if ($token != 'header' && !empty($tokens)) { if ($token != 'header' && $token != 'string' && !empty($tokens)) {
for ($i=0, $len=count($tokens); $i<$len; $i++) { for ($i=0, $len=count($tokens); $i<$len; $i++) {
if (!is_array($tokens[$i]) && preg_match('/^:(localpart|domain|all|user|detail)$/i', $tokens[$i])) { if (!is_array($tokens[$i]) && preg_match('/^:(localpart|domain|all|user|detail)$/i', $tokens[$i])) {
$test['part'] = strtolower(substr($tokens[$i], 1)); $test['part'] = strtolower(substr($tokens[$i], 1));

@ -122,6 +122,7 @@ $labels['filtercreate'] = 'Create filter';
$labels['usedata'] = 'Use following data in the filter:'; $labels['usedata'] = 'Use following data in the filter:';
$labels['nextstep'] = 'Next Step'; $labels['nextstep'] = 'Next Step';
$labels['...'] = '...'; $labels['...'] = '...';
$labels['string'] = 'String';
$labels['currdate'] = 'Current date'; $labels['currdate'] = 'Current date';
$labels['datetest'] = 'Date'; $labels['datetest'] = 'Date';
$labels['dateheader'] = 'header:'; $labels['dateheader'] = 'header:';

@ -122,6 +122,7 @@ $labels['filtercreate'] = 'Create filter';
$labels['usedata'] = 'Use following data in the filter:'; $labels['usedata'] = 'Use following data in the filter:';
$labels['nextstep'] = 'Next Step'; $labels['nextstep'] = 'Next Step';
$labels['...'] = '...'; $labels['...'] = '...';
$labels['string'] = 'String';
$labels['currdate'] = 'Current date'; $labels['currdate'] = 'Current date';
$labels['datetest'] = 'Date'; $labels['datetest'] = 'Date';
$labels['dateheader'] = 'header:'; $labels['dateheader'] = 'header:';

@ -126,6 +126,7 @@ $labels['filtercreate'] = 'Create filter';
$labels['usedata'] = 'Use following data in the filter:'; $labels['usedata'] = 'Use following data in the filter:';
$labels['nextstep'] = 'Next Step'; $labels['nextstep'] = 'Next Step';
$labels['...'] = '...'; $labels['...'] = '...';
$labels['string'] = 'String';
$labels['currdate'] = 'Current date'; $labels['currdate'] = 'Current date';
$labels['datetest'] = 'Date'; $labels['datetest'] = 'Date';
$labels['dateheader'] = 'header:'; $labels['dateheader'] = 'header:';

@ -124,6 +124,7 @@ $labels['filtercreate'] = 'Créer un filtre';
$labels['usedata'] = 'Utiliser les données suivantes dans le filtre :'; $labels['usedata'] = 'Utiliser les données suivantes dans le filtre :';
$labels['nextstep'] = 'Étape suivante'; $labels['nextstep'] = 'Étape suivante';
$labels['...'] = '...'; $labels['...'] = '...';
$labels['string'] = 'Chaîne';
$labels['currdate'] = 'Date actuelle'; $labels['currdate'] = 'Date actuelle';
$labels['datetest'] = 'Date'; $labels['datetest'] = 'Date';
$labels['dateheader'] = 'en-tête :'; $labels['dateheader'] = 'en-tête :';

@ -602,6 +602,7 @@ function rule_header_select(id)
msg = document.getElementById('rule_message' + id), msg = document.getElementById('rule_message' + id),
op = document.getElementById('rule_op' + id), op = document.getElementById('rule_op' + id),
header = document.getElementById('custom_header' + id + '_list'), header = document.getElementById('custom_header' + id + '_list'),
custstr = document.getElementById('custom_var' + id + '_list'),
mod = document.getElementById('rule_mod' + id), mod = document.getElementById('rule_mod' + id),
trans = document.getElementById('rule_trans' + id), trans = document.getElementById('rule_trans' + id),
comp = document.getElementById('rule_comp' + id), comp = document.getElementById('rule_comp' + id),
@ -611,18 +612,19 @@ function rule_header_select(id)
if (h == 'size') { if (h == 'size') {
size.style.display = 'inline'; size.style.display = 'inline';
$.each([op, header, mod, trans, comp, msg], function() { this.style.display = 'none'; }); $.each([op, header, custstr, mod, trans, comp, msg], function() { this.style.display = 'none'; });
} }
else if (h == 'message') { else if (h == 'message') {
msg.style.display = 'inline'; msg.style.display = 'inline';
$.each([op, header, mod, trans, comp, size], function() { this.style.display = 'none'; }); $.each([op, header, custstr, mod, trans, comp, size], function() { this.style.display = 'none'; });
} }
else { else {
header.style.display = h != '...' ? 'none' : 'inline-block'; header.style.display = h != '...' ? 'none' : 'inline-block';
custstr.style.display = h != 'string' ? 'none' : 'inline-block';
size.style.display = 'none'; size.style.display = 'none';
op.style.display = 'inline'; op.style.display = 'inline';
comp.style.display = ''; comp.style.display = '';
mod.style.display = h == 'body' || h == 'currentdate' || h == 'date' ? 'none' : 'block'; mod.style.display = h == 'body' || h == 'currentdate' || h == 'date' || h == 'string' ? 'none' : 'block';
trans.style.display = h == 'body' ? 'block' : 'none'; trans.style.display = h == 'body' ? 'block' : 'none';
msg.style.display = h == 'message' ? 'block' : 'none'; msg.style.display = h == 'message' ? 'block' : 'none';
} }
@ -634,7 +636,9 @@ function rule_header_select(id)
rule_op_select(op, id, h); rule_op_select(op, id, h);
rule_mod_select(id, h); rule_mod_select(id, h);
obj.style.width = h == '...' ? '40px' : '';
if (h == '...') obj.style.width = '40px';
else if (h == 'string') obj.style.width = '90px';
}; };
function rule_op_select(obj, id, header) function rule_op_select(obj, id, header)
@ -668,7 +672,7 @@ function rule_mod_select(id, header)
target.style.display = obj.value != 'address' && obj.value != 'envelope' ? 'none' : 'inline'; target.style.display = obj.value != 'address' && obj.value != 'envelope' ? 'none' : 'inline';
if (index) if (index)
index.style.display = !header.match(/^(body|currentdate|size|message)$/) && obj.value != 'envelope' ? '' : 'none'; index.style.display = !header.match(/^(body|currentdate|size|message|string)$/) && obj.value != 'envelope' ? '' : 'none';
if (duplicate) if (duplicate)
duplicate.style.display = header == 'message' ? '' : 'none'; duplicate.style.display = header == 'message' ? '' : 'none';
@ -903,6 +907,7 @@ function sieve_form_init()
// small resize for header element // small resize for header element
$('select[name="_header[]"]', rcmail.gui_objects.sieveform).each(function() { $('select[name="_header[]"]', rcmail.gui_objects.sieveform).each(function() {
if (this.value == '...') this.style.width = '40px'; if (this.value == '...') this.style.width = '40px';
if (this.value == 'string') this.style.width = '90px';
}); });
// resize dialog window // resize dialog window

Loading…
Cancel
Save