summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authoralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2010-04-01 06:59:30 +0000
committeralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2010-04-01 06:59:30 +0000
commite2b1c538293832521f70c87d8f51f81fdbb4c2c8 (patch)
tree792e4c641481f08769be54b90872cdd22dd6a664 /plugins
parent7f1b565046f3d1c2272a3dc571ce6d8322b8b2ec (diff)
- managesieve: import/export
git-svn-id: https://svn.roundcube.net/trunk@3460 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/managesieve/Changelog3
-rw-r--r--plugins/managesieve/lib/rcube_sieve.php60
-rw-r--r--plugins/managesieve/localization/en_US.inc6
-rw-r--r--plugins/managesieve/localization/pl_PL.inc8
-rw-r--r--plugins/managesieve/managesieve.js16
-rw-r--r--plugins/managesieve/managesieve.php102
-rw-r--r--plugins/managesieve/skins/default/managesieve.css20
-rw-r--r--plugins/managesieve/skins/default/managesieve_toolbar.pngbin9535 -> 12093 bytes
-rw-r--r--plugins/managesieve/skins/default/templates/managesieve.html1
9 files changed, 181 insertions, 35 deletions
diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog
index f534b13f3..3f4f154b2 100644
--- a/plugins/managesieve/Changelog
+++ b/plugins/managesieve/Changelog
@@ -1,6 +1,9 @@
+* version 2.4 [2010-04-01]
+-----------------------------------------------------------
- Fixed bug in DIGEST-MD5 authentication (http://pear.php.net/bugs/bug.php?id=17285)
- Fixed disabling rules with many tests
- Small css unification with core
+- Scripts import/export
* version 2.3 [2010-03-18]
-----------------------------------------------------------
diff --git a/plugins/managesieve/lib/rcube_sieve.php b/plugins/managesieve/lib/rcube_sieve.php
index 1ad887a97..9f07299f8 100644
--- a/plugins/managesieve/lib/rcube_sieve.php
+++ b/plugins/managesieve/lib/rcube_sieve.php
@@ -223,30 +223,69 @@ class rcube_sieve
return $this->_set_error(SIEVE_ERROR_OTHER);
// try to parse from Roundcube format
- $this->script = new rcube_sieve_script($script, $this->disabled);
+ $this->script = $this->_parse($script);
+
+ $this->current = $name;
+
+ return true;
+ }
+
+ /**
+ * Loads script from text content
+ */
+ public function load_script($script)
+ {
+ if (!$this->sieve)
+ return $this->_set_error(SIEVE_ERROR_INTERNAL);
+
+ // try to parse from Roundcube format
+ $this->script = $this->_parse($script);
+ }
+
+ /**
+ * Creates rcube_sieve_script object from text script
+ */
+ private function _parse($txt)
+ {
+ // try to parse from Roundcube format
+ $script = new rcube_sieve_script($txt, $this->disabled);
// ... else try to import from different formats
- if (empty($this->script->content)) {
- $script = $this->_import_rules($script);
- $this->script = new rcube_sieve_script($script, $this->disabled);
+ if (empty($script->content)) {
+ $script = $this->_import_rules($txt);
+ $script = new rcube_sieve_script($script, $this->disabled);
}
// replace all elsif with if+stop, we support only ifs
- foreach ($this->script->content as $idx => $rule) {
- if (!isset($this->script->content[$idx+1])
- || preg_match('/^else|elsif$/', $this->script->content[$idx+1]['type'])) {
+ foreach ($script->content as $idx => $rule) {
+ if (!isset($script->content[$idx+1])
+ || preg_match('/^else|elsif$/', $script->content[$idx+1]['type'])) {
// 'stop' not found?
if (!preg_match('/^(stop|vacation)$/', $rule['actions'][count($rule['actions'])-1]['type'])) {
- $this->script->content[$idx]['actions'][] = array(
+ $script->content[$idx]['actions'][] = array(
'type' => 'stop'
);
}
}
}
- $this->current = $name;
+ return $script;
+ }
- return true;
+ /**
+ * Gets specified script as text
+ */
+ public function get_script($name)
+ {
+ if (!$this->sieve)
+ return $this->_set_error(SIEVE_ERROR_INTERNAL);
+
+ $content = $this->sieve->getScript($name);
+
+ if (PEAR::isError($content))
+ return $this->_set_error(SIEVE_ERROR_OTHER);
+
+ return $content;
}
/**
@@ -267,7 +306,6 @@ class rcube_sieve
return $this->save_script($name, $content);
}
-
private function _import_rules($script)
{
$i = 0;
diff --git a/plugins/managesieve/localization/en_US.inc b/plugins/managesieve/localization/en_US.inc
index ac410d3db..cdd5603ea 100644
--- a/plugins/managesieve/localization/en_US.inc
+++ b/plugins/managesieve/localization/en_US.inc
@@ -40,12 +40,14 @@ $labels['filterset'] = 'Filters set';
$labels['filtersetadd'] = 'Add filters set';
$labels['filtersetdel'] = 'Delete current filters set';
$labels['filtersetact'] = 'Activate current filters set';
+$labels['filtersetget'] = 'Download filters set in text format';
$labels['filterdef'] = 'Filter definition';
$labels['filtersetname'] = 'Filters set name';
$labels['newfilterset'] = 'New filters set';
$labels['active'] = 'active';
-$labels['copyfromset'] = 'Copy filters from set';
-$labels['none'] = '- none -';
+$labels['none'] = 'none';
+$labels['fromset'] = 'from set';
+$labels['fromfile'] = 'from file';
$labels['filterdisabled'] = 'Filter disabled';
$messages = array();
diff --git a/plugins/managesieve/localization/pl_PL.inc b/plugins/managesieve/localization/pl_PL.inc
index 6d3ca3102..324e46ad9 100644
--- a/plugins/managesieve/localization/pl_PL.inc
+++ b/plugins/managesieve/localization/pl_PL.inc
@@ -41,12 +41,14 @@ $labels['filterset'] = 'Zbiór filtrów';
$labels['filtersetadd'] = 'Dodaj zbiór filtrów';
$labels['filtersetdel'] = 'Usuń bierzący zbiór filtrów';
$labels['filtersetact'] = 'Aktywuj bierzący zbiór filtrów';
+$labels['filtersetget'] = 'Pobierz bierzący zbiór filtrów w formacie tekstowym';
$labels['filterdef'] = 'Definicja filtra';
-$labels['filtersetname'] = 'Nazwa zbioru filtrów';
+$labels['filtersetname'] = 'Nazwa zbioru';
$labels['newfilterset'] = 'Nowy zbiór filtrów';
$labels['active'] = 'aktywny';
-$labels['copyfromset'] = 'Skopiuj filtry ze zbioru';
-$labels['none'] = '- brak -';
+$labels['none'] = 'brak';
+$labels['fromset'] = 'ze zbioru';
+$labels['fromfile'] = 'z pliku';
$labels['filterdisabled'] = 'Filtr wyłączony';
$messages = array();
diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js
index 08954c1c2..f93162da3 100644
--- a/plugins/managesieve/managesieve.js
+++ b/plugins/managesieve/managesieve.js
@@ -23,6 +23,7 @@ if (window.rcmail) {
rcmail.register_command('plugin.managesieve-setadd', function() { rcmail.managesieve_setadd() }, true);
rcmail.register_command('plugin.managesieve-setdel', function() { rcmail.managesieve_setdel() }, true);
rcmail.register_command('plugin.managesieve-setact', function() { rcmail.managesieve_setact() }, true);
+ rcmail.register_command('plugin.managesieve-setget', function() { rcmail.managesieve_setget() }, true);
if (rcmail.env.action == 'plugin.managesieve')
{
@@ -33,7 +34,8 @@ if (window.rcmail) {
rcmail.enable_command('plugin.managesieve-del', 'plugin.managesieve-up',
'plugin.managesieve-down', false);
rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror);
- rcmail.enable_command('plugin.managesieve-set', rcmail.gui_objects.filtersetslist != null);
+ rcmail.enable_command('plugin.managesieve-set', 'plugin.managesieve-setget',
+ rcmail.gui_objects.filtersetslist != null);
rcmail.enable_command('plugin.managesieve-setact',
(rcmail.gui_objects.filtersetslist && rcmail.gui_objects.filtersetslist.length > 1
&& rcmail.gui_objects.filtersetslist.value != rcmail.env.active_set));
@@ -410,7 +412,14 @@ if (window.rcmail) {
rcube_webmail.prototype.managesieve_set = function()
{
var script = $(this.gui_objects.filtersetslist).val();
- location.href = this.env.comm_path+'&_action=plugin.managesieve&_sid='+script;
+ location.href = this.env.comm_path+'&_action=plugin.managesieve&_set='+script;
+ };
+
+ // Script download
+ rcube_webmail.prototype.managesieve_setget = function()
+ {
+ var script = $(this.gui_objects.filtersetslist).val();
+ location.href = this.env.comm_path+'&_action=plugin.managesieve&_act=setget&_set='+script;
};
// Set activate
@@ -466,13 +475,12 @@ if (window.rcmail) {
}
};
-
rcube_webmail.prototype.managesieve_reload = function(set)
{
this.env.reload_set = set;
window.setTimeout(function() {
location.href = rcmail.env.comm_path + '&_action=plugin.managesieve'
- + (rcmail.env.reload_set ? '&_sid=' + rcmail.env.reload_set : '')
+ + (rcmail.env.reload_set ? '&_set=' + rcmail.env.reload_set : '')
}, 500);
};
diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php
index 4c50616b1..36746782e 100644
--- a/plugins/managesieve/managesieve.php
+++ b/plugins/managesieve/managesieve.php
@@ -7,7 +7,7 @@
* It's clickable interface which operates on text scripts and communicates
* with server using managesieve protocol. Adds Filters tab in Settings.
*
- * @version 2.3
+ * @version 2.4
* @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl>
*
* Configuration (see config.inc.php.dist)
@@ -79,8 +79,8 @@ class managesieve extends rcube_plugin
$active = $this->sieve->get_active();
$_SESSION['managesieve_active'] = $active;
- if (!empty($_GET['_sid'])) {
- $script_name = get_input_value('_sid', RCUBE_INPUT_GET);
+ if (!empty($_GET['_set'])) {
+ $script_name = get_input_value('_set', RCUBE_INPUT_GET);
} else if (!empty($_SESSION['managesieve_current'])) {
$script_name = $_SESSION['managesieve_current'];
} else {
@@ -224,6 +224,33 @@ class managesieve extends rcube_plugin
$this->rc->output->show_message('managesieve.setdeleteerror', 'error');
}
}
+ else if ($action=='setget')
+ {
+ $script_name = get_input_value('_set', RCUBE_INPUT_GPC);
+ $script = $this->sieve->get_script($script_name);
+
+ if (PEAR::isError($script))
+ exit;
+
+ $browser = new rcube_browser;
+
+ // send download headers
+ header("Content-Type: application/octet-stream");
+ header("Content-Length: ".strlen($script));
+
+ if ($browser->ie)
+ header("Content-Type: application/force-download");
+ if ($browser->ie && $browser->ver < 7)
+ $filename = rawurlencode(abbreviate_string($script_name, 55));
+ else if ($browser->ie)
+ $filename = rawurlencode($script_name);
+ else
+ $filename = addcslashes($script_name, '\\"');
+
+ header("Content-Disposition: attachment; filename=\"$filename.txt\"");
+ echo $script;
+ exit;
+ }
elseif ($action=='ruleadd')
{
$rid = get_input_value('_rid', RCUBE_INPUT_GPC);
@@ -255,20 +282,47 @@ class managesieve extends rcube_plugin
// filters set add action
if (!empty($_POST['_newset']))
{
- $name = get_input_value('_name', RCUBE_INPUT_GPC);
- $copy = get_input_value('_copy', RCUBE_INPUT_GPC);
+ $name = get_input_value('_name', RCUBE_INPUT_POST);
+ $copy = get_input_value('_copy', RCUBE_INPUT_POST);
+ $from = get_input_value('_from', RCUBE_INPUT_POST);
if (!$name)
$error = 'managesieve.emptyname';
else if (mb_strlen($name)>128)
$error = 'managesieve.nametoolong';
- else if (!$this->sieve->copy($name, $copy))
+ else if ($from == 'file') {
+ // from file
+ if (is_uploaded_file($_FILES['_file']['tmp_name'])) {
+ $file = file_get_contents($_FILES['_file']['tmp_name']);
+ $file = preg_replace('/\r/', '', $file);
+ // for security don't save script directly
+ // check syntax before, like this...
+ $this->sieve->load_script($file);
+ if (!$this->sieve->save($name)) {
+ $error = 'managesieve.setcreateerror';
+ }
+ }
+ else { // upload failed
+ $err = $_FILES['_file']['error'];
+ $error = true;
+ if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
+ $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' =>
+ show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
+ }
+ else {
+ $error = 'fileuploaderror';
+ }
+ }
+ }
+ else if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) {
$error = 'managesieve.setcreateerror';
-
+ }
+
if (!$error) {
$this->rc->output->show_message('managesieve.setcreated', 'confirmation');
$this->rc->output->command('parent.managesieve_reload', $name);
-// $this->rc->session->remove('managesieve_current');
+ } else if ($msg) {
+ $this->rc->output->command('display_message', $msg, 'error');
} else {
$this->rc->output->show_message($error, 'error');
}
@@ -596,7 +650,7 @@ class managesieve extends rcube_plugin
if (!$attrib['id'])
$attrib['id'] = 'rcmfiltersetform';
- $out = '<form name="filtersetform" action="./" method="post">'."\n";
+ $out = '<form name="filtersetform" 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-save'));
@@ -605,8 +659,9 @@ class managesieve extends rcube_plugin
$out .= $hiddenfields->show();
- $name = get_input_value('_name', RCUBE_INPUT_GPC);
- $copy = get_input_value('_copy', RCUBE_INPUT_GPC);
+ $name = get_input_value('_name', RCUBE_INPUT_POST);
+ $copy = get_input_value('_copy', RCUBE_INPUT_POST);
+ $selected = get_input_value('_from', RCUBE_INPUT_POST);
$table = new html_table(array('cols' => 2));
@@ -617,6 +672,11 @@ class managesieve extends rcube_plugin
$table->add('title', sprintf('<label for="%s"><b>%s:</b></label>', '_name', Q($this->gettext('filtersetname'))));
$table->add(null, $input_name->show($name));
+ $from ='<div class="itemlist">';
+ $from .= '<input type="radio" id="from_none" name="_from" value="none"'
+ .(!$selected || $selected=='none' ? ' checked="checked"' : '').'></input>';
+ $from .= sprintf('<label for="%s">%s</label> ', 'from_none', Q($this->gettext('none')));
+
// filters set list
$list = $this->sieve->get_scripts();
$active = $this->sieve->get_active();
@@ -625,12 +685,26 @@ class managesieve extends rcube_plugin
asort($list, SORT_LOCALE_STRING);
- $select->add($this->gettext('none'), '');
foreach($list as $set)
$select->add($set . ($set == $active ? ' ('.$this->gettext('active').')' : ''), $set);
- $table->add('title', '<label>'.$this->gettext('copyfromset').':</label>');
- $table->add(null, $select->show($copy));
+ $from .= '<br /><input type="radio" id="from_set" name="_from" value="set"'
+ .($selected=='set' ? ' checked="checked"' : '').'></input>';
+ $from .= sprintf('<label for="%s">%s:</label> ', 'from_set', Q($this->gettext('fromset')));
+ $from .= $select->show($copy);
+
+ // script upload box
+ $upload = new html_inputfield(array('name' => '_file', 'id' => '_file', 'size' => 30,
+ 'type' => 'file', 'class' => ($this->errors['name'] ? 'error' : '')));
+
+ $from .= '<br /><input type="radio" id="from_file" name="_from" value="file"'
+ .($selected=='file' ? ' checked="checked"' : '').'></input>';
+ $from .= sprintf('<label for="%s">%s:</label> ', 'from_file', Q($this->gettext('fromfile')));
+ $from .= $upload->show();
+ $from .= '</div>';
+
+ $table->add('title', '<label>'.$this->gettext('filters').':</label>');
+ $table->add(null, $from);
$out .= $table->show();
diff --git a/plugins/managesieve/skins/default/managesieve.css b/plugins/managesieve/skins/default/managesieve.css
index 53168c889..4349084af 100644
--- a/plugins/managesieve/skins/default/managesieve.css
+++ b/plugins/managesieve/skins/default/managesieve.css
@@ -131,10 +131,18 @@
background-position: -192px -32px;
}
+#filtersetsbuttons a.setget {
+ background-position: -224px 0px;
+}
+
+#filtersetsbuttons a.setgetsel {
+ background-position: -224px -32px;
+}
+
#filtersetselect
{
position: absolute;
- left: 360px;
+ left: 375px;
top: 90px;
}
@@ -271,3 +279,13 @@ span.label
text-align: right;
float: right;
}
+
+div .itemlist
+{
+ line-height: 25px;
+}
+
+div .itemlist input
+{
+ vertical-align: middle;
+}
diff --git a/plugins/managesieve/skins/default/managesieve_toolbar.png b/plugins/managesieve/skins/default/managesieve_toolbar.png
index 3f96a9681..473dbc8df 100644
--- a/plugins/managesieve/skins/default/managesieve_toolbar.png
+++ b/plugins/managesieve/skins/default/managesieve_toolbar.png
Binary files differ
diff --git a/plugins/managesieve/skins/default/templates/managesieve.html b/plugins/managesieve/skins/default/templates/managesieve.html
index f99466e80..a88c244a8 100644
--- a/plugins/managesieve/skins/default/templates/managesieve.html
+++ b/plugins/managesieve/skins/default/templates/managesieve.html
@@ -32,6 +32,7 @@
<roundcube:button command="plugin.managesieve-setadd" type="link" class="buttonPas setadd" classSel="button setaddsel" classAct="button setadd" title="managesieve.filtersetadd" content=" " />
<roundcube:button command="plugin.managesieve-setdel" type="link" class="buttonPas setdel" classSel="button setdelsel" classAct="button setdel" title="managesieve.filtersetdel" content=" " />
<roundcube:button command="plugin.managesieve-setact" type="link" class="buttonPas setset" classSel="button setsetsel" classAct="button setset" title="managesieve.filtersetact" content=" " />
+<roundcube:button command="plugin.managesieve-setget" type="link" class="buttonPas setget" classSel="button setgetsel" classAct="button setget" title="managesieve.filtersetget" content=" " />
</div>
<div id="filtersetselect">
<roundcube:label name="managesieve.filterset" />: