Managesieve: Various improvement to raw script editor

pull/5507/head
Aleksander Machniak 8 years ago
parent 7215013b53
commit 39cceb2f89

@ -51,6 +51,7 @@ CHANGELOG Roundcube Webmail
- Indicate that a collapsed thread has flagged children (#5013)
- Implemented message/rfc822 attachment preview
- Update to jsTimezoneDetect 1.0.6
- Managesieve: Add (optional) RAW script editor (#5414)
- Managesieve: Add option to automatically set vacation :from address (#5428)
- Managesieve: Support 'string' test from variables extension [RFC 5229] (#5248)
- Managesieve: Support 'duplicate' extension [RFC 7352]

@ -2,6 +2,7 @@
- Fix regression where js error is thrown if server does not support 'duplicate' extension
- Add option to automatically set vacation :from address (#5428)
- Support per-host managesieve_conn_options (#5136)
- Added (optional) RAW script editor (#5414)
* version 8.7 [2016-07-19]
-----------------------------------------------------------

@ -103,3 +103,6 @@ $config['managesieve_vacation_from_init'] = false;
// Supported methods of notify extension. Default: 'mailto'
$config['managesieve_notify_methods'] = array('mailto');
// Enables scripts RAW editor feature
$config['managesieve_raw_editor'] = true;

@ -146,6 +146,8 @@ class rcube_sieve_engine
$_SESSION['managesieve_current'] = $this->sieve->current;
}
$this->rc->output->set_env('raw_sieve_editor', $this->rc->config->get('managesieve_raw_editor', true));
return $error;
}
@ -488,7 +490,7 @@ class rcube_sieve_engine
);
}
}
$this->send();
}
@ -496,22 +498,22 @@ class rcube_sieve_engine
{
// Init plugin and handle managesieve connection
$error = $this->start();
$this->rc->request_security_check(rcube_utils::INPUT_POST);
$script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_POST);
$result = $this->sieve->save_script($script_name, $_POST['rawsetcontent']);
if ($result == true) {
$this->rc->output->show_message('managesieve.setupdated', 'confirmation');
$this->send();
} else {
if ($result === false) {
$this->rc->output->show_message('managesieve.filtersaveerror', 'error');
$this->send();
}
else {
$this->rc->output->show_message('managesieve.setupdated', 'confirmation');
$this->rc->output->command('parent.managesieve_updatelist', 'refresh');
}
$this->send();
}
function save()
{
// Init plugin and handle managesieve connection
@ -1142,8 +1144,9 @@ class rcube_sieve_engine
$fid = $this->sieve->script->update_rule($fid, $this->form);
}
if ($fid !== false)
if ($fid !== false) {
$save = $this->save_script();
}
if ($save && $fid !== false) {
$this->rc->output->show_message('managesieve.filtersaved', 'confirmation');
@ -1163,7 +1166,6 @@ class rcube_sieve_engine
}
else {
$this->rc->output->show_message('managesieve.filtersaveerror', 'error');
// $this->rc->output->send();
}
}
else {
@ -1223,8 +1225,9 @@ class rcube_sieve_engine
function filtersets_list($attrib, $no_env = false)
{
// add id to message list table if not specified
if (!strlen($attrib['id']))
if (!strlen($attrib['id'])) {
$attrib['id'] = 'rcmfiltersetslist';
}
$list = $this->list_scripts();
@ -1278,37 +1281,39 @@ class rcube_sieve_engine
{
return $this->rc->output->frame($attrib, true);
}
function filterset_editraw($attrib)
function filterset_editraw($attrib)
{
$scriptName = isset($_GET['_set']) ? $_GET['_set'] : $_POST['_set'];
$script = $this->sieve->get_script($scriptName);
if ($script != false) {
$out = '<form name="filtersetrawform" action="./" method="post" enctype="multipart/form-data">'."\n";
$hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $this->rc->task));
$hiddenfields->add(array('name' => '_action', 'value' => 'plugin.managesieve-saveraw'));
$hiddenfields->add(array('name' => '_set', 'value' => $scriptName));
$hiddenfields->add(array('name' => '_seteditraw', 'value' => 1));
$hiddenfields->add(array('name' => '_framed', 'value' => ($_POST['_framed'] || $_GET['_framed'] ? 1 : 0)));
$out .= $hiddenfields->show();
$txtarea = new html_textarea(array(
'id' => 'rawfiltersettxt',
'name' => 'rawsetcontent',
'rows' => '15'
));
$out .= $txtarea->show($script);
//$out .= '<textarea id="rawfiltersettxt" name="rawsetcontent" rows="15">' . $script . '</textarea>';
$this->rc->output->add_gui_object('sievesetrawform', 'filtersetrawform');
return $out;
} else {
$script_name = isset($_GET['_set']) ? $_GET['_set'] : $_POST['_set'];
$script = $this->sieve->get_script($script_name);
$script_post = $_POST['rawsetcontent'];
$out = '<form name="filtersetrawform" action="./" method="post" enctype="multipart/form-data">'."\n";
$hiddenfields = new html_hiddenfield();
$hiddenfields->add(array('name' => '_task', 'value' => $this->rc->task));
$hiddenfields->add(array('name' => '_action', 'value' => 'plugin.managesieve-saveraw'));
$hiddenfields->add(array('name' => '_set', 'value' => $script_name));
$hiddenfields->add(array('name' => '_seteditraw', 'value' => 1));
$hiddenfields->add(array('name' => '_framed', 'value' => ($_POST['_framed'] || $_GET['_framed'] ? 1 : 0)));
$out .= $hiddenfields->show();
$txtarea = new html_textarea(array(
'id' => 'rawfiltersettxt',
'name' => 'rawsetcontent',
'rows' => '15'
));
$out .= $txtarea->show($script_post !== null ? $script_post : ($script !== false ? $script : ''));
$this->rc->output->add_gui_object('sievesetrawform', 'filtersetrawform');
if ($script === false) {
$this->rc->output->show_message('managesieve.filterunknownerror', 'error');
return '';
}
return $out;
}
function filterset_form($attrib)

@ -91,9 +91,9 @@ if (window.rcmail) {
setcnt = rcmail.filtersets_list.rowcount;
rcmail.enable_command('plugin.managesieve-set', true);
rcmail.enable_command('plugin.managesieve-setact', 'plugin.managesieve-setget', setcnt);
rcmail.enable_command('plugin.managesieve-setact', 'plugin.managesieve-setget', setcnt > 0);
rcmail.enable_command('plugin.managesieve-setdel', setcnt > 1);
rcmail.enable_command('plugin.managesieve-seteditraw', true);
rcmail.enable_command('plugin.managesieve-seteditraw', setcnt > 0 && rcmail.env.raw_sieve_editor);
// Fix dragging filters over sets list
$('tr', rcmail.gui_objects.filtersetslist).each(function (i, e) { rcmail.managesieve_fixdragend(e); });
@ -111,8 +111,7 @@ if (window.rcmail) {
rcube_webmail.prototype.managesieve_add = function()
{
this.load_managesieveframe();
this.filters_list.clear_selection();
this.load_managesieveframe('', true);
};
rcube_webmail.prototype.managesieve_del = function()
@ -138,8 +137,14 @@ rcube_webmail.prototype.managesieve_act = function()
rcube_webmail.prototype.managesieve_select = function(list)
{
var id = list.get_single_selection();
if (id != null)
this.load_managesieveframe(list.rows[id].uid);
if (id != null) {
id = list.rows[id].uid;
this.load_managesieveframe('_fid=' + id);
}
var has_id = typeof(id) != 'undefined' && id != null;
this.enable_command('plugin.managesieve-act', 'plugin.managesieve-del', has_id);
};
// Set selection
@ -148,7 +153,8 @@ rcube_webmail.prototype.managesieve_setselect = function(list)
this.show_contentframe(false);
this.filters_list.clear(true);
this.enable_command('plugin.managesieve-setdel', list.rowcount > 1);
this.enable_command('plugin.managesieve-setact', 'plugin.managesieve-setget', true);
this.enable_command('plugin.managesieve-setact', 'plugin.managesieve-setget', list.rowcount > 0);
this.enable_command('plugin.managesieve-seteditraw', list.rowcount > 0 && this.env.raw_sieve_editor);
var id = list.get_single_selection();
if (id != null)
@ -219,24 +225,13 @@ rcube_webmail.prototype.managesieve_seteditraw = function()
var id = this.filtersets_list.get_single_selection(),
script = this.env.filtersets[id];
if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
var lock = this.set_busy(true, 'loading');
target = window.frames[this.env.contentframe];
target.location.href = this.env.comm_path+'&_action=plugin.managesieve-action&_framed=1&_seteditraw=1&_unlock='+lock+'&_set='+urlencode(script);
}
this.load_managesieveframe('_seteditraw=1&_set=' + urlencode(script), true);
}
// Set add request
rcube_webmail.prototype.managesieve_setadd = function()
{
this.filters_list.clear_selection();
this.enable_command('plugin.managesieve-act', 'plugin.managesieve-del', false);
if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
var lock = this.set_busy(true, 'loading');
target = window.frames[this.env.contentframe];
target.location.href = this.env.comm_path+'&_action=plugin.managesieve-action&_framed=1&_newset=1&_unlock='+lock;
}
this.load_managesieveframe('_newset=1', true);
};
rcube_webmail.prototype.managesieve_updatelist = function(action, o)
@ -249,9 +244,8 @@ rcube_webmail.prototype.managesieve_updatelist = function(action, o)
var id = o.id, list = this.filters_list;
list.remove_row(this.managesieve_rowid(o.id));
list.clear_selection();
this.show_contentframe(false);
this.enable_command('plugin.managesieve-del', 'plugin.managesieve-act', false);
this.reset_filters_list();
// filter identifiers changed, fix the list
$('tr', this.filters_list.list).each(function() {
@ -388,22 +382,42 @@ rcube_webmail.prototype.managesieve_updatelist = function(action, o)
this.managesieve_fixdragend(row);
break;
case 'refresh':
this.reset_filters_list(true);
break;
}
this.set_busy(false);
};
// Resets filters list state
rcube_webmail.prototype.reset_filters_list = function(reload)
{
this.filters_list.clear_selection();
this.enable_command('plugin.managesieve-act', 'plugin.managesieve-del', false);
if (reload) {
var id = this.filtersets_list.get_single_selection();
this.filters_list.clear(true);
this.managesieve_list(this.env.filtersets[id]);
}
};
// load filter frame
rcube_webmail.prototype.load_managesieveframe = function(id)
rcube_webmail.prototype.load_managesieveframe = function(add_url, reset)
{
var has_id = typeof(id) != 'undefined' && id != null;
this.enable_command('plugin.managesieve-act', 'plugin.managesieve-del', has_id);
if (reset)
this.reset_filters_list();
if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
var lock = this.set_busy(true, 'loading');
target = window.frames[this.env.contentframe];
var msgid = this.set_busy(true, 'loading');
target.location.href = this.env.comm_path+'&_action=plugin.managesieve-action&_framed=1'
+(has_id ? '&_fid='+id : '')+'&_unlock='+msgid;
target.location.href = this.env.comm_path
+ '&_action=plugin.managesieve-action&_framed=1&_unlock=' + lock
+ (add_url ? ('&' + add_url) : '');
}
};
@ -479,8 +493,7 @@ rcube_webmail.prototype.managesieve_save = function()
}
this.gui_objects.sieveform.submit();
}
if (this.gui_objects.sievesetrawform) {
else if (this.gui_objects.sievesetrawform) {
this.gui_objects.sievesetrawform.submit();
}
};

@ -225,19 +225,24 @@ class managesieve extends rcube_plugin
$engine = $this->get_engine();
$engine->save();
}
/**
* Raw form save action handler
*/
function managesieve_saveraw()
{
$engine = $this->get_engine();
if (!$this->rc->config->get('managesieve_raw_editor', true)) {
return;
}
// load localization
$this->add_texts('localization/', array('filters','managefilters'));
// include main js script
$this->include_script('managesieve.js');
$engine = $this->get_engine();
$engine->saveraw();
}

@ -64,8 +64,10 @@
<ul>
<li><roundcube:button command="plugin.managesieve-setact" label="managesieve.enable" classAct="active" /></li>
<li><roundcube:button command="plugin.managesieve-setdel" label="delete" classAct="active" /></li>
<li class="separator_above"><roundcube:button command="plugin.managesieve-seteditraw" label="managesieve.filterseteditraw" classAct="active" /></li>
<li class="separator_above"><roundcube:button command="plugin.managesieve-setget" label="download" classAct="active" /></li>
<roundcube:if condition="env:raw_sieve_editor != false" />
<li><roundcube:button command="plugin.managesieve-seteditraw" label="managesieve.filterseteditraw" classAct="active" /></li>
<roundcube:endif />
<roundcube:container name="filtersetoptions" id="filtersetmenu" />
</ul>
</div>

@ -52,7 +52,9 @@
<ul class="toolbarmenu" id="filtersetmenu-menu" role="menu" aria-labelledby="aria-label-setactions">
<li role="menuitem"><roundcube:button command="plugin.managesieve-setact" label="managesieve.enable" classAct="active" /></li>
<li role="menuitem"><roundcube:button command="plugin.managesieve-setdel" label="delete" classAct="active" /></li>
<roundcube:if condition="env:raw_sieve_editor != false" />
<li role="menuitem"><roundcube:button command="plugin.managesieve-seteditraw" label="managesieve.filterseteditraw" classAct="active" /></li>
<roundcube:endif />
<li role="menuitem" class="separator_above"><roundcube:button command="plugin.managesieve-setget" label="download" classAct="active" /></li>
<roundcube:container name="filtersetoptions" id="filtersetmenu" />
</ul>

@ -1,23 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<roundcube:object name="doctype" value="html5" />
<html>
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
</head>
<body class="iframe">
<body class="iframe floatingbuttons">
<div id="filtersetraw-title" class="boxtitle"><roundcube:label name="managesieve.filterseteditraw" /></div>
<div id="filter-form" class="boxcontent">
<roundcube:object name="filterseteditraw" />
<p>
<div id="footer">
<div class="footerleft formbuttons">
<roundcube:button command="plugin.managesieve-save" type="input" class="button mainaction" label="save" />
</p>
</div>
</div>
</form>
</div>
</body>
</html>

Loading…
Cancel
Save