summaryrefslogtreecommitdiff
path: root/plugins/managesieve/lib
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/managesieve/lib
parent7f1b565046f3d1c2272a3dc571ce6d8322b8b2ec (diff)
- managesieve: import/export
git-svn-id: https://svn.roundcube.net/trunk@3460 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins/managesieve/lib')
-rw-r--r--plugins/managesieve/lib/rcube_sieve.php60
1 files changed, 49 insertions, 11 deletions
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;