Support 'mime' extension tests - RFC5703 (#5832)

pull/6068/head
Aleksander Machniak 7 years ago
parent 7c6bbd81b0
commit 550e2fc6aa

@ -11,6 +11,7 @@ CHANGELOG Roundcube Webmail
- Managesieve: Add ability to disable filter sets and other actions (#5496, #5898)
- Managesieve: Add option managesieve_forward to enable settings dialog for simple forwarding (#6021)
- Managesieve: Support filter action with custom IMAP flags (#6011)
- Managesieve: Support 'mime' extension tests - RFC5703 (#5832)
- Changed defaults for smtp_user (%u), smtp_pass (%p) and smtp_port (587)
- Composer: Fix certificate validation errors by using packagist only (#5148)
- Enigma: Add button to send mail unencrypted if no key was found (#5913)

@ -1,6 +1,7 @@
- Added option managesieve_default_headers
- Added option managesieve_forward to enable settings dialog for simple forwarding (#6021)
- Support filter action with custom IMAP flags (#6011)
- Support 'mime' extension tests - RFC5703 (#5832)
* version 9.0 [2017-10-02]
-----------------------------------------------------------

@ -660,6 +660,9 @@ class rcube_sieve_engine
$lastindexes = rcube_utils::get_input_value('_rule_index_last', rcube_utils::INPUT_POST);
$dateheaders = rcube_utils::get_input_value('_rule_date_header', rcube_utils::INPUT_POST);
$dateparts = rcube_utils::get_input_value('_rule_date_part', rcube_utils::INPUT_POST);
$mime_parts = rcube_utils::get_input_value('_rule_mime_part', rcube_utils::INPUT_POST);
$mime_types = rcube_utils::get_input_value('_rule_mime_type', rcube_utils::INPUT_POST);
$mime_params = rcube_utils::get_input_value('_rule_mime_param', rcube_utils::INPUT_POST, true);
$message = rcube_utils::get_input_value('_rule_message', rcube_utils::INPUT_POST);
$dup_handles = rcube_utils::get_input_value('_rule_duplicate_handle', rcube_utils::INPUT_POST, true);
$dup_headers = rcube_utils::get_input_value('_rule_duplicate_header', rcube_utils::INPUT_POST, true);
@ -789,8 +792,10 @@ class rcube_sieve_engine
$index = $this->strip_value($indexes[$idx]);
$indexlast = $this->strip_value($lastindexes[$idx]);
if (preg_match('/^not/', $operator))
if (preg_match('/^not/', $operator)) {
$this->form['tests'][$i]['not'] = true;
}
$type = preg_replace('/^not/', '', $operator);
if ($type == 'exists') {
@ -909,6 +914,9 @@ class rcube_sieve_engine
$mod_type = $this->strip_value($mod_types[$idx]);
$index = $this->strip_value($indexes[$idx]);
$indexlast = $this->strip_value($lastindexes[$idx]);
$mime_param = $this->strip_value($mime_params[$idx]);
$mime_type = $mime_types[$idx];
$mime_part = $mime_parts[$idx];
if ($header == 'string') {
$cust_var = $headers = $this->strip_value(array_shift($cust_vars));
@ -988,6 +996,23 @@ class rcube_sieve_engine
$this->form['tests'][$i]['part'] = $mod_type;
}
}
if ($test == 'header') {
if (in_array($mime_type, array('type', 'subtype', 'contenttype', 'param'))) {
$this->form['tests'][$i]['mime-' . $mime_type] = true;
if ($mime_type == 'param') {
if (empty($mime_param)) {
$this->errors['tests'][$i]['mime-param'] = $this->plugin->gettext('cannotbeempty');
}
$this->form['tests'][$i]['mime-param'] = $mime_param;
}
}
if ($mime_part == 'anychild') {
$this->form['tests'][$i]['mime-anychild'] = true;
}
}
}
if ($header != 'size' && $comparator) {
@ -1819,6 +1844,53 @@ class rcube_sieve_engine
$mout .= $select_type->show($rule['part']);
$mout .= '</div>';
// Advanced modifiers (comparators)
$select_comp = new html_select(array('name' => "_rule_comp[]", 'id' => 'rule_comp_op'.$id));
$select_comp->add(rcube::Q($this->plugin->gettext('default')), '');
$select_comp->add(rcube::Q($this->plugin->gettext('octet')), 'i;octet');
$select_comp->add(rcube::Q($this->plugin->gettext('asciicasemap')), 'i;ascii-casemap');
if (in_array('comparator-i;ascii-numeric', $this->exts)) {
$select_comp->add(rcube::Q($this->plugin->gettext('asciinumeric')), 'i;ascii-numeric');
}
$need_comp = $rule['test'] != 'size' && $rule['test'] != 'duplicate';
$mout .= '<div id="rule_comp' .$id. '" class="adv input-group"' . (!$need_comp ? ' style="display:none"' : '') . '>';
$mout .= '<span class="label input-group-addon">' . rcube::Q($this->plugin->gettext('comparator')) . '</span>';
$mout .= $select_comp->show($rule['comparator']);
$mout .= '</div>';
// Advanced modifiers (mime)
if (in_array('mime', $this->exts)) {
$need_mime = !$rule || in_array($rule['test'], array('header', 'address', 'exists'));
$mime_type = '';
$select_mime = new html_select(array('name' => '_rule_mime_type[]', 'id' => 'rule_mime_type' . $id,
'style' => 'min-width:8em', 'onchange' => 'rule_mime_select(' . $id . ')'));
$select_mime->add('', '');
foreach (array('contenttype', 'type', 'subtype', 'param') as $val) {
if (isset($rule['mime-' . $val])) {
$mime_type = $val;
}
$select_mime->add(rcube::Q($this->plugin->gettext('mime-' . $val)), $val);
}
$select_mime_part = new html_select(array('name' => '_rule_mime_part[]', 'id' => 'rule_mime_part' . $id));
$select_mime_part->add(rcube::Q($this->plugin->gettext('mime-message')), '');
$select_mime_part->add(rcube::Q($this->plugin->gettext('mime-anychild')), 'anychild');
$mout .= '<div id="rule_mime_part' .$id. '" class="adv input-group"' . (!$need_mime ? ' style="display:none"' : '') . '>';
$mout .= ' <span class="label input-group-addon">' . rcube::Q($this->plugin->gettext('mimepart')) . ' </span>';
$mout .= $select_mime_part->show(!empty($rule['mime-anychild']) ? 'anychild' : '');
$mout .= '</div>';
$mout .= '<div id="rule_mime' .$id. '" class="adv input-group"' . (!$need_mime ? ' style="display:none"' : '') . '>';
$mout .= ' <span class="label input-group-addon">' . rcube::Q($this->plugin->gettext('mime')) . ' </span>';
$mout .= $select_mime->show($mime_type);
$mout .= $this->list_input($id, 'rule_mime_param', $rule['mime-param'], true,
$this->error_class($id, 'test', 'mime_param', 'rule_mime_param'), 30, $mime_type != 'param');
$mout .= '</div>';
}
// Advanced modifiers (body transformations)
$select_mod = new html_select(array('name' => "_rule_trans[]", 'id' => 'rule_trans_op'.$id,
'onchange' => 'rule_trans_select(' .$id .')'));
@ -1840,22 +1912,6 @@ class rcube_sieve_engine
));
$mout .= '</div>';
// Advanced modifiers (body transformations)
$select_comp = new html_select(array('name' => "_rule_comp[]", 'id' => 'rule_comp_op'.$id));
$select_comp->add(rcube::Q($this->plugin->gettext('default')), '');
$select_comp->add(rcube::Q($this->plugin->gettext('octet')), 'i;octet');
$select_comp->add(rcube::Q($this->plugin->gettext('asciicasemap')), 'i;ascii-casemap');
if (in_array('comparator-i;ascii-numeric', $this->exts)) {
$select_comp->add(rcube::Q($this->plugin->gettext('asciinumeric')), 'i;ascii-numeric');
}
// Comparators
$need_comp = $rule['test'] != 'size' && $rule['test'] != 'duplicate';
$mout .= '<div id="rule_comp' .$id. '" class="adv input-group"' . (!$need_comp ? ' style="display:none"' : '') . '>';
$mout .= '<span class="label input-group-addon">' . rcube::Q($this->plugin->gettext('comparator')) . '</span>';
$mout .= $select_comp->show($rule['comparator']);
$mout .= '</div>';
// Date header
if (in_array('date', $this->exts)) {
$mout .= '<div id="rule_date_header_div' .$id. '" class="adv input-group"'. ($rule['test'] != 'date' ? ' style="display:none"' : '') .'>';
@ -2424,7 +2480,7 @@ class rcube_sieve_engine
$this->rc->output->add_script($script, 'foot');
}
protected function list_input($id, $name, $value, $enabled, $class, $size=null)
protected function list_input($id, $name, $value, $enabled, $class, $size = null, $hidden = false)
{
$value = (array) $value;
$value = array_map(array('rcube', 'Q'), $value);
@ -2433,6 +2489,7 @@ class rcube_sieve_engine
return html::tag('textarea', array(
'data-type' => 'list',
'data-size' => $size,
'data-hidden' => $hidden ?: null,
'name' => '_' . $name . '['. $id .']',
'id' => $name.$id,
'disabled' => !$enabled,

@ -39,7 +39,7 @@ class rcube_sieve_script
'imap4flags', // RFC5232
'include', // RFC6609
'index', // RFC5260
'mime', // RFC5703 (except: foreverypart, break, enclose, extracttext)
'mime', // RFC5703 (except: foreverypart/break, enclose, extracttext)
'notify', // RFC5435
'regex', // draft-ietf-sieve-regex-01
'reject', // RFC5429

@ -43,6 +43,14 @@ $labels['filterregex'] = 'matches regular expression';
$labels['filternotregex'] = 'not matches regular expression';
$labels['filterunder'] = 'under';
$labels['filterover'] = 'over';
$labels['mime'] = 'MIME:';
$labels['mimepart'] = 'MIME part:';
$labels['mime-message'] = 'message';
$labels['mime-anychild'] = 'any';
$labels['mime-type'] = 'type';
$labels['mime-subtype'] = 'subtype';
$labels['mime-contenttype'] = 'content-type';
$labels['mime-param'] = 'parameter';
$labels['addrule'] = 'Add rule';
$labels['delrule'] = 'Delete rule';
$labels['messagemoveto'] = 'Move message to';

@ -625,7 +625,8 @@ rcube_webmail.prototype.managesieve_vacation_addresses_update = function(id, add
function rule_header_select(id)
{
var obj = document.getElementById('header' + id),
var is_header,
obj = document.getElementById('header' + id),
size = document.getElementById('rule_size' + id),
msg = document.getElementById('rule_message' + id),
op = document.getElementById('rule_op' + id),
@ -634,11 +635,13 @@ function rule_header_select(id)
mod = document.getElementById('rule_mod' + id),
trans = document.getElementById('rule_trans' + id),
comp = document.getElementById('rule_comp' + id),
mime = document.getElementById('rule_mime' + id),
mime_part = document.getElementById('rule_mime_part' + id),
datepart = document.getElementById('rule_date_part' + id),
dateheader = document.getElementById('rule_date_header_div' + id),
rule = $('#rule_op' + id),
h = obj.value,
set = [op, header, custstr, mod, trans, comp, size];
set = [op, header, custstr, mod, trans, comp, size, mime, mime_part];
if (h == 'size') {
if (msg) set.push(msg);
@ -650,12 +653,15 @@ function rule_header_select(id)
msg.style.display = '';
}
else {
is_header = h != 'body' && h != 'currentdate' && h != 'date' && h != 'string';
header.style.display = h != '...' ? 'none' : '';
custstr.style.display = h != 'string' ? 'none' : '';
size.style.display = 'none';
op.style.display = '';
comp.style.display = '';
mod.style.display = h == 'body' || h == 'currentdate' || h == 'date' || h == 'string' ? 'none' : '';
mime.style.display = is_header ? '' : 'none';
mime_part.style.display = is_header ? '' : 'none';
mod.style.display = is_header ? '' : 'none';
trans.style.display = h == 'body' ? '' : 'none';
if (msg)
msg.style.display = h == 'message' ? '' : 'none';
@ -672,6 +678,7 @@ function rule_header_select(id)
rule_op_select(op, id, h);
rule_mod_select(id, h);
rule_mime_select(id);
obj.style.width = h == '...' ? '40px' : '';
};
@ -732,6 +739,13 @@ function rule_adv_switch(id, elem)
}
};
function rule_mime_select(id)
{
var elem = $('#rule_mime_type' + id);
elem.parent().find('.listarea')[0].style.display = elem.val() == 'param' ? '' : 'none';
};
function action_type_select(id)
{
var obj = document.getElementById('action_type' + id),
@ -811,6 +825,9 @@ function smart_field_init(field)
else
field.prop('disabled', true);
if (field.data('hidden'))
area.hide();
field.after(area);
if (field.hasClass('error')) {

Loading…
Cancel
Save