summaryrefslogtreecommitdiff
path: root/lib/KolabAdmin/Sieve.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/KolabAdmin/Sieve.php')
-rw-r--r--lib/KolabAdmin/Sieve.php27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/KolabAdmin/Sieve.php b/lib/KolabAdmin/Sieve.php
index 3c636f0..0233da4 100644
--- a/lib/KolabAdmin/Sieve.php
+++ b/lib/KolabAdmin/Sieve.php
@@ -110,18 +110,16 @@ class KolabAdmin_Sieve
private function _splitSegments($script)
{
$segments = array();
- preg_match_all('/^### SEGMENT START [^#]*.*?### SEGMENT END [^#]*/s', $script, $matches);
- foreach ($matches as $match) {
- preg_match('/^### SEGMENT START ([^# ]*) ?(ENABLED)?/s', $match[0], $id);
+ preg_match_all('/### SEGMENT START [^#]*.*?### SEGMENT END [^#]*/s', $script, $matches);
+ foreach ($matches[0] as $match) {
+ preg_match('/### SEGMENT START ([^# ]*) ?(ENABLED)?/s', $match, $id);
if (!empty($id[1])) {
$type = strtolower($id[1]);
$class = 'KolabAdmin_Sieve_Segment_' . ucfirst($type);
- $segments[$type] = new $class($match[0]);
+ $segments[$type] = new $class($match);
if (isset($id[2]) && $id[2] == 'ENABLED') {
$segments[$type]->setActive();
}
- } else {
- throw new Exception('Unknown segment type.');
}
}
return $segments;
@@ -144,4 +142,21 @@ class KolabAdmin_Sieve
$this->_init();
return $this->_segments['vacation'];
}
+
+ public function store()
+ {
+ $result = $this->_sieve->installScript(self::SCRIPT, $this->getScript(), true);
+ if ($result instanceOf PEAR_Error) {
+ throw new Exception($result->getMessage());
+ }
+ }
+
+ public function getScript()
+ {
+ $script = 'require "fileinto";' . "\r\n" . 'require "vacation";' . "\r\n\r\n\r\n";
+ foreach ($this->_segments as $segment) {
+ $script .= $segment->generate() . "\r\n\r\n";
+ }
+ return $script;
+ }
} \ No newline at end of file